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
- RewritingPass.cs
- CodeTypeOfExpression.cs
- OleDbSchemaGuid.cs
- CallId.cs
- MethodImplAttribute.cs
- BufferedGraphics.cs
- ExtensionDataObject.cs
- CodeMemberProperty.cs
- ReadOnlyCollectionBase.cs
- InstanceOwnerQueryResult.cs
- MachineKeyConverter.cs
- StrokeCollection.cs
- GridViewSortEventArgs.cs
- EventArgs.cs
- StyleSheetComponentEditor.cs
- ElementUtil.cs
- DbException.cs
- InputScopeNameConverter.cs
- Membership.cs
- ClickablePoint.cs
- InputScopeNameConverter.cs
- CodeIndexerExpression.cs
- IISUnsafeMethods.cs
- CodeExpressionCollection.cs
- SqlCacheDependencySection.cs
- ToolZone.cs
- x509store.cs
- ConfigsHelper.cs
- PhysicalFontFamily.cs
- SystemIPAddressInformation.cs
- ThreadAttributes.cs
- TypePresenter.xaml.cs
- ValidationPropertyAttribute.cs
- HttpProfileGroupBase.cs
- DefaultCommandConverter.cs
- MatrixAnimationUsingKeyFrames.cs
- WebPartExportVerb.cs
- Helper.cs
- Line.cs
- DataGridViewCellStyle.cs
- RelationalExpressions.cs
- RenderDataDrawingContext.cs
- ToolBar.cs
- GroupDescription.cs
- HostAdapter.cs
- HashCodeCombiner.cs
- XmlReader.cs
- CanonicalFontFamilyReference.cs
- Point4DConverter.cs
- UriScheme.cs
- ReadOnlyCollection.cs
- SectionXmlInfo.cs
- DataSetUtil.cs
- ReadWriteObjectLock.cs
- Drawing.cs
- CodeConstructor.cs
- InstanceDescriptor.cs
- ListViewUpdatedEventArgs.cs
- XmlSubtreeReader.cs
- StaticDataManager.cs
- GlobalItem.cs
- XomlCompilerHelpers.cs
- SelectionRange.cs
- RedistVersionInfo.cs
- ParserExtension.cs
- AssemblyBuilder.cs
- ReadWriteControlDesigner.cs
- SizeChangedInfo.cs
- DataRowComparer.cs
- Mapping.cs
- SoapSchemaMember.cs
- FlagPanel.cs
- ValidationError.cs
- EntityStoreSchemaFilterEntry.cs
- AutomationInteropProvider.cs
- MetadataArtifactLoaderResource.cs
- PropertyGridCommands.cs
- NumberAction.cs
- OpCellTreeNode.cs
- ZipIOCentralDirectoryFileHeader.cs
- ServiceAuthorizationBehavior.cs
- NativeCompoundFileAPIs.cs
- HierarchicalDataSourceControl.cs
- DoubleAnimationClockResource.cs
- Int16AnimationUsingKeyFrames.cs
- FormsAuthenticationEventArgs.cs
- ToolboxDataAttribute.cs
- SByteConverter.cs
- OleDbError.cs
- FontFamily.cs
- DataObjectAttribute.cs
- CodeAttributeDeclaration.cs
- CapabilitiesRule.cs
- TextSpanModifier.cs
- SecurityContextTokenValidationException.cs
- SspiHelper.cs
- AbsoluteQuery.cs
- ContextMenuStrip.cs
- HttpHandlerAction.cs
- DoubleLinkList.cs