예제 #1
0
        public static ADServer PickGlobalCatalog(string configDCName)
        {
            ADServer adserver = DirectoryUtilities.DomainControllerFromName(configDCName);

            if (adserver != null && DirectoryUtilities.IsGlobalCatalog(adserver) && adserver.IsAvailable())
            {
                return(adserver);
            }
            ADForest localForest = ADForest.GetLocalForest();
            ADSite   localSite   = DirectoryUtilities.ConfigurationSession.GetLocalSite();

            if (localSite == null)
            {
                throw new ADInitializationException(Strings.LocalSiteNotFound);
            }
            ReadOnlyCollection <ADServer> readOnlyCollection = localForest.FindAllGlobalCatalogs();

            foreach (ADServer adserver2 in readOnlyCollection)
            {
                if (adserver2.ValidateRead().Length == 0 && adserver2.Site.Equals(localSite.Id) && adserver2.IsAvailable())
                {
                    return(adserver2);
                }
            }
            foreach (ADServer adserver3 in readOnlyCollection)
            {
                if (adserver3.ValidateRead().Length == 0 && adserver3.IsAvailable())
                {
                    return(adserver3);
                }
            }
            throw new ADInitializationException(Strings.NoGCsAvailableException(localForest.Fqdn));
        }
예제 #2
0
        private ADServer ValidateDC(string fqdn)
        {
            ADServer adserver = base.GlobalConfigSession.FindDCByFqdn(fqdn);

            if (adserver == null)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorDCNotFound(fqdn)), ErrorCategory.InvalidOperation, this.Identity);
            }
            if (!adserver.IsAvailable())
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorDCNotAvailable(fqdn)), ErrorCategory.InvalidOperation, this.Identity);
            }
            return(adserver);
        }
예제 #3
0
        public static ADServer PickLocalDomainController()
        {
            ADServer adserver = DirectoryUtilities.DomainControllerFromName("localhost");

            if (adserver != null && DirectoryUtilities.IsGlobalCatalog(adserver) && adserver.IsAvailable())
            {
                return(adserver);
            }
            ADSite localSite = DirectoryUtilities.ConfigurationSession.GetLocalSite();

            if (localSite == null)
            {
                throw new ADInitializationException(Strings.LocalSiteNotFound);
            }
            ADDomain addomain = ADForest.GetLocalForest().FindLocalDomain();

            if (addomain == null)
            {
                throw new ADInitializationException(Strings.LocalDomainNotFoundException);
            }
            ReadOnlyCollection <ADServer> readOnlyCollection = addomain.FindAllDomainControllers();

            foreach (ADServer adserver2 in readOnlyCollection)
            {
                if (adserver2.ValidateRead().Length == 0 && adserver2.Site.Equals(localSite.Id) && adserver2.IsAvailable() && DirectoryUtilities.IsGlobalCatalog(adserver2))
                {
                    return(adserver2);
                }
            }
            if (adserver != null)
            {
                return(adserver);
            }
            foreach (ADServer adserver3 in readOnlyCollection)
            {
                if (adserver3.ValidateRead().Length == 0 && adserver3.Site.Equals(localSite.Id) && adserver3.IsAvailable())
                {
                    return(adserver3);
                }
            }
            throw new ADInitializationException(Strings.NoDCsAvailableException(addomain.Name, localSite.Name));
        }