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
- PointConverter.cs
- BrushConverter.cs
- TypeUsage.cs
- FixedTextView.cs
- MediaPlayerState.cs
- NativeMethods.cs
- HwndKeyboardInputProvider.cs
- AuthenticationServiceManager.cs
- DataListItem.cs
- HwndMouseInputProvider.cs
- TextAnchor.cs
- MarshalDirectiveException.cs
- dataobject.cs
- BindingWorker.cs
- UIAgentAsyncParams.cs
- Dynamic.cs
- RijndaelManagedTransform.cs
- ArgumentOutOfRangeException.cs
- OSFeature.cs
- DelegatingTypeDescriptionProvider.cs
- ClientSponsor.cs
- SessionSwitchEventArgs.cs
- WebServiceData.cs
- TrustSection.cs
- KeyFrames.cs
- PublisherIdentityPermission.cs
- CompilerHelpers.cs
- CorrelationKey.cs
- BooleanStorage.cs
- StackSpiller.Generated.cs
- ConstraintConverter.cs
- PreservationFileReader.cs
- GroupBox.cs
- ComponentCollection.cs
- PrinterResolution.cs
- WizardPanelChangingEventArgs.cs
- CodePrimitiveExpression.cs
- SoapEnumAttribute.cs
- FieldNameLookup.cs
- DBConnectionString.cs
- CommandField.cs
- Focus.cs
- LifetimeManager.cs
- PnrpPeerResolverBindingElement.cs
- NetCodeGroup.cs
- FactoryMaker.cs
- sqlmetadatafactory.cs
- SmtpNetworkElement.cs
- ModelUIElement3D.cs
- ValueUnavailableException.cs
- AnnotationResourceChangedEventArgs.cs
- DataControlFieldCollection.cs
- MaskedTextBoxTextEditorDropDown.cs
- EventProxy.cs
- PasswordDeriveBytes.cs
- CreatingCookieEventArgs.cs
- XmlBoundElement.cs
- InterleavedZipPartStream.cs
- Utils.cs
- ResourceSet.cs
- ViewValidator.cs
- SafeLibraryHandle.cs
- MemberInfoSerializationHolder.cs
- ConfigurationProperty.cs
- BufferedGraphics.cs
- Parameter.cs
- ParseHttpDate.cs
- SystemEvents.cs
- DataGridViewDataConnection.cs
- DistributedTransactionPermission.cs
- BigInt.cs
- MailSettingsSection.cs
- DiffuseMaterial.cs
- PopupRootAutomationPeer.cs
- cryptoapiTransform.cs
- DataControlFieldHeaderCell.cs
- ConsoleKeyInfo.cs
- NavigationExpr.cs
- DataGridViewCellStyleEditor.cs
- VersionPair.cs
- _Events.cs
- Int32RectValueSerializer.cs
- ObjectIDGenerator.cs
- SqlProviderServices.cs
- ZipIOBlockManager.cs
- Model3D.cs
- VirtualizedCellInfoCollection.cs
- SelectedCellsCollection.cs
- FillErrorEventArgs.cs
- PrintDocument.cs
- FactoryMaker.cs
- ConditionalAttribute.cs
- WebPartHelpVerb.cs
- FileAuthorizationModule.cs
- Int32Converter.cs
- CodeDOMProvider.cs
- RegistryKey.cs
- DiscardableAttribute.cs
- Image.cs
- ColorConverter.cs