Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / Role / DirectoryRedirect.cs / 1305376 / DirectoryRedirect.cs
#region Using directives using System; using System.Collections.Generic; using System.Text; using System.DirectoryServices; #endregion namespace System.Workflow.Activities { [Serializable] sealed internal class DirectoryRedirect : IDirectoryOperation { private String m_getPropertyName; private String m_searchPropertyName; private bool m_recursive; public DirectoryRedirect(String getPropertyName, String searchPropertyName) : this( getPropertyName, searchPropertyName, false ) { } public DirectoryRedirect(String getPropertyName, String searchPropertyName, bool recursive) { if (getPropertyName == null) throw new ArgumentNullException("getPropertyName"); if (searchPropertyName == null) throw new ArgumentNullException("searchPropertyName"); this.m_getPropertyName = getPropertyName; this.m_searchPropertyName = searchPropertyName; this.m_recursive = recursive; } public void GetResult(DirectoryEntry rootEntry, DirectoryEntry currentEntry, Listresponse) { if (rootEntry == null) throw new ArgumentNullException("rootEntry"); if (currentEntry == null) throw new ArgumentNullException("currentEntry"); if (response == null) throw new ArgumentNullException("response"); if (!this.m_recursive) { using (DirectorySearcher searcher = CreateSearcher(rootEntry, currentEntry)) { foreach (SearchResult result in searcher.FindAll()) { response.Add(result.GetDirectoryEntry()); } } } else { Dictionary dResponse = new Dictionary (); Stack stack = new Stack (); stack.Push(currentEntry); while (stack.Count != 0) { DirectoryEntry currentTop = stack.Pop(); using (DirectorySearcher searcher = CreateSearcher(rootEntry, currentTop)) { foreach (SearchResult result in searcher.FindAll()) { DirectoryEntry newEntry = result.GetDirectoryEntry(); if (!dResponse.ContainsKey(newEntry.Guid)) dResponse.Add(newEntry.Guid, newEntry); stack.Push(newEntry); } } } response.AddRange(dResponse.Values); } } private DirectorySearcher CreateSearcher(DirectoryEntry rootEntry, DirectoryEntry currentEntry) { DirectorySearcher searcher = new DirectorySearcher(rootEntry); PropertyValueCollection values = currentEntry.Properties[this.m_getPropertyName]; System.Diagnostics.Debug.Assert(values.Count == 1); searcher.Filter = "(" + this.m_searchPropertyName + "=" + values[0] + ")"; return searcher; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. #region Using directives using System; using System.Collections.Generic; using System.Text; using System.DirectoryServices; #endregion namespace System.Workflow.Activities { [Serializable] sealed internal class DirectoryRedirect : IDirectoryOperation { private String m_getPropertyName; private String m_searchPropertyName; private bool m_recursive; public DirectoryRedirect(String getPropertyName, String searchPropertyName) : this( getPropertyName, searchPropertyName, false ) { } public DirectoryRedirect(String getPropertyName, String searchPropertyName, bool recursive) { if (getPropertyName == null) throw new ArgumentNullException("getPropertyName"); if (searchPropertyName == null) throw new ArgumentNullException("searchPropertyName"); this.m_getPropertyName = getPropertyName; this.m_searchPropertyName = searchPropertyName; this.m_recursive = recursive; } public void GetResult(DirectoryEntry rootEntry, DirectoryEntry currentEntry, List response) { if (rootEntry == null) throw new ArgumentNullException("rootEntry"); if (currentEntry == null) throw new ArgumentNullException("currentEntry"); if (response == null) throw new ArgumentNullException("response"); if (!this.m_recursive) { using (DirectorySearcher searcher = CreateSearcher(rootEntry, currentEntry)) { foreach (SearchResult result in searcher.FindAll()) { response.Add(result.GetDirectoryEntry()); } } } else { Dictionary dResponse = new Dictionary (); Stack stack = new Stack (); stack.Push(currentEntry); while (stack.Count != 0) { DirectoryEntry currentTop = stack.Pop(); using (DirectorySearcher searcher = CreateSearcher(rootEntry, currentTop)) { foreach (SearchResult result in searcher.FindAll()) { DirectoryEntry newEntry = result.GetDirectoryEntry(); if (!dResponse.ContainsKey(newEntry.Guid)) dResponse.Add(newEntry.Guid, newEntry); stack.Push(newEntry); } } } response.AddRange(dResponse.Values); } } private DirectorySearcher CreateSearcher(DirectoryEntry rootEntry, DirectoryEntry currentEntry) { DirectorySearcher searcher = new DirectorySearcher(rootEntry); PropertyValueCollection values = currentEntry.Properties[this.m_getPropertyName]; System.Diagnostics.Debug.Assert(values.Count == 1); searcher.Filter = "(" + this.m_searchPropertyName + "=" + values[0] + ")"; return searcher; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TabletCollection.cs
- DesigntimeLicenseContextSerializer.cs
- DataList.cs
- ContextProperty.cs
- ArrayTypeMismatchException.cs
- SerializerDescriptor.cs
- DynamicActionMessageFilter.cs
- MetadataAssemblyHelper.cs
- HttpResponseHeader.cs
- DragStartedEventArgs.cs
- CaseInsensitiveHashCodeProvider.cs
- _FixedSizeReader.cs
- HttpCacheParams.cs
- JsonStringDataContract.cs
- PaperSource.cs
- ImplicitInputBrush.cs
- tooltip.cs
- _ConnectOverlappedAsyncResult.cs
- FormViewPagerRow.cs
- ToolStripGrip.cs
- RawTextInputReport.cs
- XmlSchemaSimpleContentRestriction.cs
- _BaseOverlappedAsyncResult.cs
- DefaultExpression.cs
- TransformerInfoCollection.cs
- TextEditorParagraphs.cs
- SubpageParaClient.cs
- DPTypeDescriptorContext.cs
- GridViewRow.cs
- GridView.cs
- MessageEncodingBindingElementImporter.cs
- LayoutExceptionEventArgs.cs
- StartUpEventArgs.cs
- LayoutUtils.cs
- ToolboxBitmapAttribute.cs
- XmlnsCache.cs
- TransformDescriptor.cs
- LineVisual.cs
- MdImport.cs
- RIPEMD160Managed.cs
- SHA512.cs
- SqlTrackingQuery.cs
- SafeThreadHandle.cs
- RtfControlWordInfo.cs
- AnnotationResource.cs
- CustomWebEventKey.cs
- GeometryHitTestParameters.cs
- Debug.cs
- WebPartMenu.cs
- SpellCheck.cs
- _MultipleConnectAsync.cs
- DbgUtil.cs
- GeometryHitTestParameters.cs
- SHA384CryptoServiceProvider.cs
- VisualBrush.cs
- FormViewPagerRow.cs
- KeyValuePairs.cs
- ListItemCollection.cs
- InheritablePropertyChangeInfo.cs
- ValuePatternIdentifiers.cs
- Preprocessor.cs
- TextElementEditingBehaviorAttribute.cs
- RIPEMD160Managed.cs
- Int32Collection.cs
- GeneralTransformGroup.cs
- WebHttpBehavior.cs
- SecurityUniqueId.cs
- DbDataReader.cs
- WebPartManagerInternals.cs
- MarshalByRefObject.cs
- XmlCompatibilityReader.cs
- TraceLevelStore.cs
- UrlAuthorizationModule.cs
- Setter.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- PngBitmapEncoder.cs
- DataGridColumnsPage.cs
- ParserStreamGeometryContext.cs
- HttpVersion.cs
- HtmlTableCell.cs
- TextEditorCharacters.cs
- OrderedHashRepartitionStream.cs
- DashStyle.cs
- _TLSstream.cs
- HandlerFactoryCache.cs
- UriExt.cs
- QueryCacheEntry.cs
- ReadonlyMessageFilter.cs
- StringInfo.cs
- XmlDataDocument.cs
- ContextDataSourceContextData.cs
- WinEventQueueItem.cs
- ItemList.cs
- WeakReferenceKey.cs
- NativeDirectoryServicesQueryAPIs.cs
- WeakRefEnumerator.cs
- SmtpTransport.cs
- DeviceContexts.cs
- CompositeScriptReference.cs
- ParagraphVisual.cs