internal override T GetExtendedObjectFromIdentity(T identityObj, string identityQueryPath, ICollection <string> propertiesToFetch, bool showDeleted)
        {
            ADObject aDObject  = null;
            ADObject aDObject1 = null;
            ADObject aDObject2 = null;
            T        t;
            string   nTDSSettingsDN = this.ResolveIdentityToNTDSSettingsDN(identityObj, null, false, out aDObject, out aDObject1, out aDObject2);

            if (nTDSSettingsDN != null)
            {
                using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo))
                {
                    string[] strArrays = new string[1];
                    strArrays[0] = nTDSSettingsDN;
                    ADEntity[] domainController = aDTopologyManagement.GetDomainController(strArrays);
                    if (domainController == null || (int)domainController.Length == 0)
                    {
                        DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("GetExtendedObjectFromIdentity: No objects returned from custom action", new object[0]));
                        throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0]));
                    }
                    else
                    {
                        AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(propertiesToFetch);
                        T aDSessionInfo = this.Construct(domainController[0], attributeSetRequest);
                        aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo;
                        t = aDSessionInfo;
                    }
                }
                return(t);
            }
            else
            {
                DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("GetExtendedObjectFromIdentity: Could not find the DirectoryServer's  NTDS Settings DN", new object[0]));
                object[] identity = new object[1];
                identity[0] = identityObj.Identity;
                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.DirectoryServerNotFound, identity));
            }
        }
Exemplo n.º 2
0
        internal IEnumerable <T> GetAllDomainControllers(ICollection <string> propertiesToFetch)
        {
            IEnumerable <T>  ts;
            string           defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext;
            ADSearchScope    aDSearchScope        = ADSearchScope.Subtree;
            IADOPathNode     aDOPathNode          = ADDomainControllerFactory <T> ._domainControllerComputerObjectFilter;
            ADObjectSearcher aDObjectSearcher     = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, aDSearchScope);

            using (aDObjectSearcher)
            {
                aDObjectSearcher.Filter = aDOPathNode;
                aDObjectSearcher.Properties.AddRange(ADDomainControllerFactory <T> ._domainControllerDefaultAttributes);
                List <ADObject> aDObjects = new List <ADObject>();
                foreach (ADObject aDObject in aDObjectSearcher.FindAll())
                {
                    aDObjects.Add(aDObject);
                }
                if (aDObjects.Count != 0)
                {
                    List <string> strs = new List <string>();
                    foreach (ADObject aDObject1 in aDObjects)
                    {
                        string value = aDObject1["serverReferenceBL"].Value as string;
                        if (value == null)
                        {
                            DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("Could  not find property: {0} for identity: {1}", "serverReferenceBL", aDObject1.DistinguishedName));
                        }
                        else
                        {
                            strs.Add(string.Concat("CN=NTDS Settings,", value));
                        }
                    }
                    if (strs.Count <= 0)
                    {
                        ts = null;
                    }
                    else
                    {
                        using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo))
                        {
                            ADEntity[] domainController = aDTopologyManagement.GetDomainController(strs.ToArray());
                            if (domainController == null || (int)domainController.Length == 0)
                            {
                                ts = new List <T>();
                            }
                            else
                            {
                                List <T>            ts1 = new List <T>();
                                AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(propertiesToFetch);
                                ADEntity[]          aDEntityArray       = domainController;
                                for (int i = 0; i < (int)aDEntityArray.Length; i++)
                                {
                                    ADEntity aDEntity      = aDEntityArray[i];
                                    T        aDSessionInfo = this.Construct(aDEntity, attributeSetRequest);
                                    aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo;
                                    ts1.Add(aDSessionInfo);
                                }
                                ts = ts1;
                            }
                        }
                    }
                }
                else
                {
                    ts = new List <T>();
                }
            }
            return(ts);
        }