private static TopologyProvider InitializeInstance()
        {
            ExTraceGlobals.TopologyProviderTracer.TraceDebug(0L, "Starting InitializeInstance and waiting for the lock");
            TopologyProvider result;

            lock (TopologyProvider.instanceLockRoot)
            {
                int adamPort;
                switch (TopologyProvider.SelectTopologyMode(out adamPort))
                {
                case TopologyMode.ADTopologyService:
                {
                    ServiceTopologyProvider serviceTopologyProvider = new ServiceTopologyProvider();
                    serviceTopologyProvider.SuppressDisposeTracker();
                    TopologyProvider.staticInstance = serviceTopologyProvider;
                    break;
                }

                case TopologyMode.Adam:
                    TopologyProvider.staticInstance = new AdamTopologyProvider(adamPort);
                    break;

                case TopologyMode.Ldap:
                    TopologyProvider.staticInstance = new LdapTopologyProvider();
                    break;
                }
                ExTraceGlobals.TopologyProviderTracer.TraceDebug <int>(0L, "TopologyProvider::InitializeInstance created {0}", (int)TopologyProvider.CurrentTopologyMode);
                result = TopologyProvider.staticInstance;
            }
            return(result);
        }
        protected void PopulateDomainNamingContexts(string partitionFqdn)
        {
            TopologyProvider.EnforceNonEmptyPartition(partitionFqdn);
            ADServerInfo defaultServerInfo = this.GetDefaultServerInfo(partitionFqdn);

            if (string.IsNullOrEmpty(defaultServerInfo.WritableNC) || string.IsNullOrEmpty(defaultServerInfo.RootDomainNC))
            {
                PooledLdapConnection pooledLdapConnection = LdapConnectionPool.CreateOneTimeConnection(null, defaultServerInfo, LocatorFlags.None);
                try
                {
                    if (string.IsNullOrEmpty(pooledLdapConnection.ADServerInfo.WritableNC) && !TopologyProvider.IsAdamTopology())
                    {
                        this.LogRootDSEReadFailureAndThrow("domainNamingContext", defaultServerInfo.FqdnPlusPort);
                    }
                    this.domainNCs[partitionFqdn] = ADObjectId.ParseExtendedDN(pooledLdapConnection.ADServerInfo.WritableNC);
                    if (string.IsNullOrEmpty(pooledLdapConnection.ADServerInfo.RootDomainNC) && !TopologyProvider.IsAdamTopology())
                    {
                        this.LogRootDSEReadFailureAndThrow("rootDomainNamingContext", defaultServerInfo.FqdnPlusPort);
                    }
                    this.rootDomainNCs[partitionFqdn] = ADObjectId.ParseExtendedDN(pooledLdapConnection.ADServerInfo.RootDomainNC);
                    return;
                }
                finally
                {
                    pooledLdapConnection.ReturnToPool();
                }
            }
            this.domainNCs[partitionFqdn]     = ADObjectId.ParseExtendedDN(defaultServerInfo.WritableNC);
            this.rootDomainNCs[partitionFqdn] = ADObjectId.ParseExtendedDN(defaultServerInfo.RootDomainNC);
        }
        protected void PopulateConfigNamingContexts(string partitionFqdn)
        {
            TopologyProvider.EnforceNonEmptyPartition(partitionFqdn);
            ADServerInfo configDCInfo = this.GetConfigDCInfo(partitionFqdn, true);

            if (string.IsNullOrEmpty(configDCInfo.ConfigNC) || string.IsNullOrEmpty(configDCInfo.SchemaNC))
            {
                PooledLdapConnection pooledLdapConnection = LdapConnectionPool.CreateOneTimeConnection(null, configDCInfo, LocatorFlags.None);
                try
                {
                    if (string.IsNullOrEmpty(pooledLdapConnection.ADServerInfo.ConfigNC))
                    {
                        this.LogRootDSEReadFailureAndThrow("configurationNamingContext", configDCInfo.FqdnPlusPort);
                    }
                    this.configNCs[partitionFqdn] = ADObjectId.ParseExtendedDN(pooledLdapConnection.ADServerInfo.ConfigNC);
                    if (string.IsNullOrEmpty(pooledLdapConnection.ADServerInfo.SchemaNC))
                    {
                        this.LogRootDSEReadFailureAndThrow("schemaNamingContext", configDCInfo.FqdnPlusPort);
                    }
                    this.schemaNCs[partitionFqdn] = ADObjectId.ParseExtendedDN(pooledLdapConnection.ADServerInfo.SchemaNC);
                    return;
                }
                finally
                {
                    pooledLdapConnection.ReturnToPool();
                }
            }
            this.configNCs[partitionFqdn] = ADObjectId.ParseExtendedDN(configDCInfo.ConfigNC);
            this.schemaNCs[partitionFqdn] = ADObjectId.ParseExtendedDN(configDCInfo.SchemaNC);
        }
 public override IList <TopologyVersion> GetTopologyVersions(IList <string> partitionFqdns)
 {
     if (partitionFqdns == null)
     {
         throw new ArgumentNullException("partitionFqdns");
     }
     ExTraceGlobals.TopologyProviderTracer.Information <int>((long)this.GetHashCode(), "GetTopologyVersions. Partitions {0}", partitionFqdns.Count);
     TopologyVersion[] array = new TopologyVersion[partitionFqdns.Count];
     LdapTopologyProvider.MiniTopology miniTopology = null;
     for (int i = 0; i < partitionFqdns.Count; i++)
     {
         TopologyProvider.EnforceNonEmptyPartition(partitionFqdns[i]);
         int version = 1;
         if (this.topologies.TryGetValue(partitionFqdns[i], out miniTopology))
         {
             version = miniTopology.Version;
         }
         array[i] = new TopologyVersion(partitionFqdns[i], version);
     }
     if (ExTraceGlobals.TopologyProviderTracer.IsTraceEnabled(TraceType.InfoTrace))
     {
         ExTraceGlobals.TopologyProviderTracer.Information <string>((long)this.GetHashCode(), "GetTopologyVersions. Partitions {0}", string.Join(",", (object[])array));
     }
     return(array);
 }
        internal override ADSessionSettings FromAllTenantsOrRootOrgAutoDetect(ADObjectId id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.DomainId == null)
            {
                ExTraceGlobals.GetConnectionTracer.TraceDebug <string>(0L, "FromAllTenantsOrRootOrgAutoDetect(): Value '{0}' passed to id parameter doesn't have DomainId initialized, falling back to RootOrg scope set", id.ToString());
                return(ADSessionSettings.FromRootOrgScopeSet());
            }
            PartitionId partitionId = id.GetPartitionId();

            if (!ADAccountPartitionLocator.IsKnownPartition(partitionId))
            {
                ExTraceGlobals.GetConnectionTracer.TraceDebug <string>(0L, "FromAllTenantsOrRootOrgAutoDetect(): Value '{0}' passed to id parameter doesn't match any known partition, falling back to RootOrg scope set", id.ToString());
                return(ADSessionSettings.FromRootOrgScopeSet());
            }
            ExTraceGlobals.GetConnectionTracer.TraceDebug <string, string>(0L, "FromAllTenantsOrRootOrgAutoDetect(): Value '{0}' passed to id parameter matches partition {1}, returning settings bound to that partition", id.ToString(), partitionId.ToString());
            if (ADSession.IsTenantIdentity(id, partitionId.ForestFQDN))
            {
                return(ADSessionSettings.FromAllTenantsObjectId(id));
            }
            if (!TopologyProvider.IsAdamTopology())
            {
                return(ADSessionSettings.FromAccountPartitionRootOrgScopeSet(id.GetPartitionId()));
            }
            return(ADSessionSettings.FromRootOrgScopeSet());
        }
        internal static void SetProcessTopologyMode(TopologyMode mode)
        {
            if (TopologyMode.Adam == mode)
            {
                throw new ArgumentException("mode. Adam topology mode can't be specified");
            }
            if (TopologyMode.Ldap == mode && TopologyProvider.IsTopologyServiceProcess())
            {
                TopologyProvider.isRunningOnTopologyService = true;
            }
            ExTraceGlobals.TopologyProviderTracer.TraceDebug <TopologyMode, TopologyMode>(0L, "User set topology mode from {0} to {1}", (TopologyProvider.userSetTopologyMode != null) ? TopologyProvider.userSetTopologyMode.Value : TopologyProvider.CurrentTopologyMode, mode);
            TopologyProvider.userSetTopologyMode = new TopologyMode?(mode);
            int          num;
            TopologyMode topologyMode = TopologyProvider.SelectTopologyMode(out num);

            if (TopologyProvider.staticInstance != null && (TopologyProvider.userSetTopologyMode.Value != TopologyProvider.staticInstance.TopologyMode || TopologyProvider.userSetTopologyMode.Value != topologyMode))
            {
                IDisposable      disposable       = TopologyProvider.staticInstance as IDisposable;
                TopologyProvider topologyProvider = TopologyProvider.InitializeInstance();
                topologyProvider.PopulateConfigNamingContextsForLocalForest();
                topologyProvider.PopulateDomainNamingContextsForLocalForest();
                ConnectionPoolManager.Reset();
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Exemple #7
0
        // Token: 0x0600050A RID: 1290 RVA: 0x0001C860 File Offset: 0x0001AA60
        private PartitionBasedADRunspaceServerSettingsProvider GetProviderForPartition(string partitionFqdn)
        {
            ArgumentValidator.ThrowIfNullOrEmpty("partitionFqdn", partitionFqdn);
            TopologyProvider instance = TopologyProvider.GetInstance();
            SyncWrapper <PartitionBasedADRunspaceServerSettingsProvider> orAdd = this.internalProviders.GetOrAdd(partitionFqdn, (string key) => new SyncWrapper <PartitionBasedADRunspaceServerSettingsProvider>());
            PartitionBasedADRunspaceServerSettingsProvider value = orAdd.Value;

            if (value != null && Globals.GetTickDifference(value.LastTopoRecheck, Environment.TickCount) < (ulong)((long)instance.TopoRecheckIntervalMsec))
            {
                ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <string>((long)this.GetHashCode(), "ADRunspaceServerSettingsProvider {0} ignoring topology version recheck for partition.", partitionFqdn);
                return(value);
            }
            lock (orAdd)
            {
                value = orAdd.Value;
                if (value == null || Globals.GetTickDifference(value.LastTopoRecheck, Environment.TickCount) > (ulong)((long)TopologyProvider.GetInstance().TopoRecheckIntervalMsec))
                {
                    int topologyVersion = instance.GetTopologyVersion(partitionFqdn);
                    if (value == null || value.TopologyVersion != topologyVersion)
                    {
                        ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <string, int>((long)this.GetHashCode(), "ADRunspaceServerSettingsProvider {0}. Creating new provider version {1}", partitionFqdn, topologyVersion);
                        PartitionBasedADRunspaceServerSettingsProvider value2;
                        if (PartitionBasedADRunspaceServerSettingsProvider.TryCreateNew(partitionFqdn, instance, value, out value2))
                        {
                            orAdd.Value = value2;
                            orAdd.Value.TopologyVersion = topologyVersion;
                            orAdd.Value.LastTopoRecheck = Environment.TickCount;
                        }
                    }
                }
            }
            return(orAdd.Value);
        }
 protected override IList <ADServerInfo> InternalGetServersForRole(string partitionFqdn, IList <string> currentlyUsedServers, ADServerRole role, int serversRequested, bool forestWideAffinityRequested = false)
 {
     TopologyProvider.EnforceLocalForestPartition(partitionFqdn);
     return(new List <ADServerInfo>
     {
         this.GetDefaultServerInfo(partitionFqdn)
     });
 }
        protected void ClearDomainNamingContexts(string partitionFqdn)
        {
            TopologyProvider.EnforceNonEmptyPartition(partitionFqdn);
            ADObjectId adobjectId;

            this.domainNCs.TryRemove(partitionFqdn, out adobjectId);
            this.rootDomainNCs.TryRemove(partitionFqdn, out adobjectId);
        }
        protected void ClearConfigNamingContexts(string partitionFqdn)
        {
            TopologyProvider.EnforceNonEmptyPartition(partitionFqdn);
            ADObjectId adobjectId;

            this.configNCs.TryRemove(partitionFqdn, out adobjectId);
            this.schemaNCs.TryRemove(partitionFqdn, out adobjectId);
        }
Exemple #11
0
 internal static ADObjectId GetRootDomainNamingContext(string partitionFqdn)
 {
     if (!Globals.IsDatacenter)
     {
         ExTraceGlobals.ADTopologyTracer.TraceDebug <string, string>(0L, "ADSession::GetRootDomainNamingContext '{0}' will use local forest '{1}'", partitionFqdn, TopologyProvider.LocalForestFqdn);
         partitionFqdn = TopologyProvider.LocalForestFqdn;
     }
     return(TopologyProvider.GetInstance().GetRootDomainNamingContext(partitionFqdn));
 }
        internal static TopologyProvider GetInstance()
        {
            TopologyProvider topologyProvider = TopologyProvider.staticInstance;

            if (topologyProvider == null)
            {
                topologyProvider = TopologyProvider.InitializeInstance();
            }
            return(topologyProvider);
        }
        internal static void SetProcessTopologyMode(bool isAdminMode, bool publicMethodCheck)
        {
            ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, bool>(0L, "{0} method sets admin mode to {1}", publicMethodCheck ? "Public" : "Internal", isAdminMode);
            int num = 0;

            if (!publicMethodCheck || (TopologyProvider.staticInstance != null && TopologyProvider.CurrentTopologyMode == TopologyMode.Ldap && AdamTopologyProvider.CheckIfAdamConfigured(out num)) || TopologyProvider.staticInstance == null)
            {
                TopologyProvider.SetProcessTopologyMode(isAdminMode ? TopologyMode.Ldap : TopologyMode.ADTopologyService);
            }
        }
 public override IList <TopologyVersion> GetTopologyVersions(IList <string> partitionFqdns)
 {
     if (partitionFqdns == null)
     {
         throw new ArgumentException("partitionFqdns");
     }
     TopologyProvider.EnforceLocalForestPartition(partitionFqdns[0]);
     return(new List <TopologyVersion>
     {
         new TopologyVersion(partitionFqdns[0], this.topologyVersion)
     });
 }
        internal ADObjectId GetRootDomainNamingContext(string partitionFqdn)
        {
            TopologyProvider.EnforceNonEmptyPartition(partitionFqdn);
            ADObjectId result;

            if (!this.rootDomainNCs.TryGetValue(partitionFqdn, out result))
            {
                this.PopulateDomainNamingContexts(partitionFqdn);
                this.rootDomainNCs.TryGetValue(partitionFqdn, out result);
            }
            return(result);
        }
 // Token: 0x06000316 RID: 790 RVA: 0x00010B78 File Offset: 0x0000ED78
 public static bool IsKnownPartition(PartitionId partitionId)
 {
     if (TopologyProvider.IsAdamTopology())
     {
         return(true);
     }
     if (!Globals.IsMicrosoftHostedOnly && partitionId.PartitionObjectId == null)
     {
         return(false);
     }
     ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
     return(partitionId.IsLocalForestPartition() || ADAccountPartitionLocator.partitionsFQDNToGuid.ContainsKey(partitionId.ForestFQDN));
 }
Exemple #17
0
 public static void SetAdminTopologyMode()
 {
     if (!ADSession.isAdminModeEnabled)
     {
         ExTraceGlobals.ADTopologyTracer.TraceDebug(0L, "A process tried to set the Topology Mode to Admin, but this mode has been disabled");
         return;
     }
     TopologyProvider.SetProcessTopologyMode(true, true);
     if (ADSession.IsBoundToAdam)
     {
         ADSessionSettings.ClearProcessADContext();
         ConnectionPoolManager.ForceRebuild();
     }
 }
        public int GetTopologyVersion(string partitionFqdn)
        {
            TopologyProvider.EnforceNonEmptyPartition(partitionFqdn);
            IList <TopologyVersion> topologyVersions = this.GetTopologyVersions(new List <string>
            {
                partitionFqdn
            });

            if (topologyVersions.Count > 0)
            {
                return(topologyVersions[0].Version);
            }
            return(-1);
        }
Exemple #19
0
        public static void SetCurrentConfigDC(string serverName, string partitionFqdn)
        {
            if (string.IsNullOrEmpty(serverName))
            {
                throw new ArgumentNullException("serverName");
            }
            if (string.IsNullOrEmpty(partitionFqdn))
            {
                throw new ArgumentNullException("partitionFqdn");
            }
            TopologyProvider instance = TopologyProvider.GetInstance();

            instance.SetConfigDC(partitionFqdn, serverName, instance.DefaultDCPort);
        }
Exemple #20
0
        public static string GetCurrentConfigDC(string partitionFqdn)
        {
            ADSessionSettings adsessionSettings;

            if (PartitionId.IsLocalForestPartition(partitionFqdn))
            {
                adsessionSettings = ADSessionSettings.FromRootOrgScopeSet();
            }
            else
            {
                adsessionSettings = ADSessionSettings.FromAccountPartitionRootOrgScopeSet(new PartitionId(partitionFqdn));
            }
            Fqdn fqdn = adsessionSettings.ServerSettings.ConfigurationDomainController(partitionFqdn);

            if (fqdn != null)
            {
                return(fqdn.ToString());
            }
            return(TopologyProvider.GetInstance().GetConfigDC(partitionFqdn));
        }
        // Token: 0x060000AA RID: 170 RVA: 0x0000450C File Offset: 0x0000270C
        private bool NeedFullReload(ITopologyConfigurationSession session, bool forceFullReload, out string reason)
        {
            if (forceFullReload)
            {
                reason = "Full reload forced";
                return(true);
            }
            if (string.IsNullOrEmpty(this.domainController))
            {
                reason = "First read";
                return(true);
            }
            string configDCForLocalForest = TopologyProvider.GetInstance().GetConfigDCForLocalForest();

            if (!this.domainController.Equals(configDCForLocalForest, StringComparison.OrdinalIgnoreCase))
            {
                reason = string.Format("Config DC changed from {0} to {1}", this.domainController, configDCForLocalForest);
                return(true);
            }
            ExTraceGlobals.ADConfigLoaderTracer.TraceDebug((long)this.GetHashCode(), "Skipping full reload");
            reason = null;
            return(false);
        }
Exemple #22
0
 internal virtual ADSessionSettings FromRootOrgBootStrapSession(ADObjectId configNC)
 {
     if (configNC == null)
     {
         throw new ArgumentNullException("configNC");
     }
     return(ADSessionSettings.SessionSettingsFactory.CreateADSessionSettings(ADSessionSettings.SessionSettingsFactory.GlobalScopeSet, configNC, OrganizationId.ForestWideOrgId, null, ConfigScopes.RootOrg, TopologyProvider.IsAdamTopology() ? PartitionId.LocalForest : configNC.GetPartitionId()));
 }
Exemple #23
0
        protected SearchResultEntryCollection GetNextResultCollection(Type controlType, out DirectoryControl responseControl)
        {
            SearchRequest searchRequest = new SearchRequest(null, this.ldapFilter, (SearchScope)this.scope, this.ldapAttributes);

            searchRequest.Controls.AddRange(this.directoryControls);
            searchRequest.SizeLimit = this.SizeLimit;
            if (this.session.ServerTimeout != null)
            {
                searchRequest.TimeLimit = this.session.ServerTimeout.Value;
            }
            SearchResponse searchResponse = null;

            responseControl = null;
            RetryManager retryManager = new RetryManager();
            ADObjectId   adobjectId   = this.rootId;
            bool         flag         = !this.session.SessionSettings.IncludeSoftDeletedObjects && !this.session.SessionSettings.IncludeInactiveMailbox && this.session.EnforceContainerizedScoping;

            for (;;)
            {
                PooledLdapConnection readConnection = this.session.GetReadConnection(this.preferredServerName, null, ref adobjectId, this.ScopeDeterminingObject);
                Guid serviceProviderRequestId       = Guid.Empty;
                try
                {
                    try
                    {
                        if (this.useNullRoot)
                        {
                            searchRequest.DistinguishedName = null;
                        }
                        else
                        {
                            searchRequest.DistinguishedName = adobjectId.ToDNString();
                            if (flag && searchRequest.Scope == SearchScope.Subtree)
                            {
                                ADObjectId domainId = adobjectId.DomainId;
                                if (domainId != null)
                                {
                                    ADObjectId childId = domainId.GetChildId("OU", "Microsoft Exchange Hosted Organizations");
                                    ADObjectId parent  = adobjectId.Parent;
                                    if (childId != null && parent != null && ADObjectId.Equals(childId, parent))
                                    {
                                        searchRequest.Scope = SearchScope.OneLevel;
                                    }
                                }
                            }
                        }
                        if (TopologyProvider.IsAdamTopology() && string.IsNullOrEmpty(searchRequest.DistinguishedName))
                        {
                            searchRequest.Controls.Add(new SearchOptionsControl(SearchOption.PhantomRoot));
                        }
                        ExTraceGlobals.ADFindTracer.TraceDebug((long)this.GetHashCode(), "ADGenericReader::GetNextResultCollection({0}) using {1} - LDAP search from {2}, scope {3}, filter {4}", new object[]
                        {
                            controlType.Name,
                            readConnection.ADServerInfo.FqdnPlusPort,
                            searchRequest.DistinguishedName,
                            (int)searchRequest.Scope,
                            searchRequest.Filter
                        });
                        serviceProviderRequestId = Trace.TraceCasStart(CasTraceEventType.ActiveDirectory);
                        searchResponse           = (SearchResponse)readConnection.SendRequest(searchRequest, LdapOperation.Search, null, this.session.ActivityScope, this.session.CallerInfo);
                        this.preferredServerName = readConnection.ServerName;
                        this.session.UpdateServerSettings(readConnection);
                        break;
                    }
                    catch (DirectoryException de)
                    {
                        if (this.customExceptionHandler != null)
                        {
                            this.customExceptionHandler(de);
                        }
                        if (readConnection.IsResultCode(de, ResultCode.NoSuchObject))
                        {
                            ExTraceGlobals.ADFindTracer.TraceWarning <string, object>((long)this.GetHashCode(), "NoSuchObject caught when searching from {0} with filter {1}", searchRequest.DistinguishedName, searchRequest.Filter);
                            return(null);
                        }
                        if (readConnection.IsResultCode(de, ResultCode.VirtualListViewError) && this.lcid != LcidMapper.DefaultLcid)
                        {
                            ExTraceGlobals.ADFindTracer.TraceWarning <int, int>((long)this.GetHashCode(), "VirtualListView error caught when performing a VLV lookup using LCID 0x{0:X}. Falling back to US English 0x{1:X}", this.lcid, LcidMapper.DefaultLcid);
                            this.RefreshSortControlWithDefaultLCID(searchRequest);
                        }
                        else
                        {
                            retryManager.Tried(readConnection.ServerName);
                            this.session.AnalyzeDirectoryError(readConnection, searchRequest, de, retryManager.TotalRetries, retryManager[readConnection.ServerName]);
                        }
                    }
                    continue;
                }
                finally
                {
                    bool isSnapshotInProgress = PerformanceContext.Current.IsSnapshotInProgress;
                    bool flag2 = ETWTrace.ShouldTraceCasStop(serviceProviderRequestId);
                    if (isSnapshotInProgress || flag2)
                    {
                        string text = string.Format(CultureInfo.InvariantCulture, "scope: {0}, filter: {1}", new object[]
                        {
                            searchRequest.Scope,
                            searchRequest.Filter
                        });
                        if (isSnapshotInProgress)
                        {
                            PerformanceContext.Current.AppendToOperations(text);
                        }
                        if (flag2)
                        {
                            Trace.TraceCasStop(CasTraceEventType.ActiveDirectory, serviceProviderRequestId, 0, 0, readConnection.ADServerInfo.FqdnPlusPort, searchRequest.DistinguishedName, "ADGenericReader::GetNextResultCollection", text, string.Empty);
                        }
                    }
                    readConnection.ReturnToPool();
                }
                break;
            }
            responseControl = this.FindControlInCollection(searchResponse.Controls, controlType);
            return(searchResponse.Entries);
        }
Exemple #24
0
        // Token: 0x0600051F RID: 1311 RVA: 0x0001CD7C File Offset: 0x0001AF7C
        internal static bool TryCreateNew(string partitionFqdn, TopologyProvider topologyProvider, PartitionBasedADRunspaceServerSettingsProvider previousInstance, out PartitionBasedADRunspaceServerSettingsProvider newInstance)
        {
            ArgumentValidator.ThrowIfNullOrEmpty("partitionFqdn", partitionFqdn);
            ArgumentValidator.ThrowIfNull("topologyProvider", topologyProvider);
            newInstance = null;
            Dictionary <string, ADRunspaceServerSettingsProvider.ADServerInfoState> dictionary  = new Dictionary <string, ADRunspaceServerSettingsProvider.ADServerInfoState>(StringComparer.OrdinalIgnoreCase);
            Dictionary <string, ADRunspaceServerSettingsProvider.ADServerInfoState> dictionary2 = new Dictionary <string, ADRunspaceServerSettingsProvider.ADServerInfoState>(StringComparer.OrdinalIgnoreCase);
            Dictionary <string, ADRunspaceServerSettingsProvider.ADServerInfoState> dictionary3 = new Dictionary <string, ADRunspaceServerSettingsProvider.ADServerInfoState>(StringComparer.OrdinalIgnoreCase);
            HashSet <string> hashSet;

            if (previousInstance != null)
            {
                hashSet = new HashSet <string>(previousInstance.GetAllGCs(), StringComparer.OrdinalIgnoreCase);
            }
            else
            {
                hashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            }
            if (previousInstance != null && ExTraceGlobals.ServerSettingsProviderTracer.IsTraceEnabled(TraceType.DebugTrace))
            {
                string arg = string.Join(",", previousInstance.inSiteGCs.Keys);
                ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <string, int>((long)partitionFqdn.GetHashCode(), "Previous in site servers {0} (from instance {1})", arg, previousInstance.GetHashCode());
                string arg2 = string.Join(",", previousInstance.outOfSiteGCs.Keys);
                ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <string, int>((long)partitionFqdn.GetHashCode(), "Previous out of site servers {0} (from instance {1})", arg2, previousInstance.GetHashCode());
            }
            List <string>        currentlyUsedServers = (previousInstance != null) ? previousInstance.GetAllGCs().ToList <string>() : new List <string>();
            IList <ADServerInfo> serversForRole       = topologyProvider.GetServersForRole(partitionFqdn, currentlyUsedServers, ADServerRole.GlobalCatalog, 25, false);

            ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <int, string>((long)partitionFqdn.GetHashCode(), "GetServersForRole returned a list of length: {0} for forest ={1}", serversForRole.Count, partitionFqdn);
            List <string> list  = new List <string>();
            List <string> list2 = new List <string>();
            List <string> list3 = new List <string>();

            for (int i = 0; i < serversForRole.Count; i++)
            {
                ADRunspaceServerSettingsProvider.ADServerInfoState adserverInfoState = new ADRunspaceServerSettingsProvider.ADServerInfoState(serversForRole[i])
                {
                    IsDown = false
                };
                bool flag  = adserverInfoState.IsInLocalSite && previousInstance != null && !previousInstance.inSiteGCs.ContainsKey(adserverInfoState.ServerInfo.Fqdn);
                bool flag2 = !adserverInfoState.IsInLocalSite && previousInstance != null && !previousInstance.outOfSiteGCs.ContainsKey(adserverInfoState.ServerInfo.Fqdn);
                bool flag3 = flag || flag2;
                if (!hashSet.Contains(adserverInfoState.ServerInfo.Fqdn))
                {
                    if (adserverInfoState.IsInLocalSite)
                    {
                        list.Add(adserverInfoState.ServerInfo.Fqdn);
                    }
                    else
                    {
                        list2.Add(adserverInfoState.ServerInfo.Fqdn);
                    }
                }
                ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug((long)partitionFqdn.GetHashCode(), "Forest = {0}. {1} server: {2}, {3} site.", new object[]
                {
                    partitionFqdn,
                    flag3 ? "Adding a new" : "Keeping",
                    adserverInfoState.ServerInfo.Fqdn,
                    adserverInfoState.IsInLocalSite ? "in the local" : "out of"
                });
                if (adserverInfoState.IsInLocalSite)
                {
                    dictionary[adserverInfoState.ServerInfo.Fqdn] = adserverInfoState;
                }
                else
                {
                    dictionary2[adserverInfoState.ServerInfo.Fqdn] = adserverInfoState;
                }
            }
            list.Sort();
            list2.Sort();
            if (previousInstance != null)
            {
                list.InsertRange(0, previousInstance.allInSiteGCs);
                list2.InsertRange(0, previousInstance.allOutOfSiteGCs);
            }
            List <string> list4 = new List <string>(1);

            if (previousInstance != null && previousInstance.ConfigDC != null)
            {
                list4.Add(previousInstance.ConfigDC.Fqdn);
            }
            serversForRole = topologyProvider.GetServersForRole(partitionFqdn, list4, ADServerRole.ConfigurationDomainController, 1, false);
            ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <int, string>((long)partitionFqdn.GetHashCode(), "GetServersForRole returned a list of length: {0} for forest={1}", serversForRole.Count, partitionFqdn);
            ADServerInfo adserverInfo = null;

            if (serversForRole.Count > 0)
            {
                adserverInfo = serversForRole[0];
                ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <string, string, string>((long)partitionFqdn.GetHashCode(), "Forest = {0}. {1} Config DC {2}", partitionFqdn, (previousInstance != null && previousInstance.configDC != null && string.Equals(serversForRole[0].Fqdn, previousInstance.configDC.Fqdn, StringComparison.OrdinalIgnoreCase)) ? "New" : "Same", adserverInfo.Fqdn);
            }
            else if (previousInstance != null && previousInstance.configDC != null)
            {
                adserverInfo = previousInstance.ConfigDC;
            }
            if (previousInstance != null && ExTraceGlobals.ServerSettingsProviderTracer.IsTraceEnabled(TraceType.DebugTrace))
            {
                string arg3 = string.Join(",", previousInstance.inForestGCs.Keys);
                ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <string, int>((long)partitionFqdn.GetHashCode(), "Previous in forest servers {0} (from instance {1})", arg3, previousInstance.GetHashCode());
            }
            serversForRole = topologyProvider.GetServersForRole(partitionFqdn, currentlyUsedServers, ADServerRole.GlobalCatalog, 25, true);
            ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug <int, string, string>((long)partitionFqdn.GetHashCode(), "GetServersForRole returned a list of length: {0} for forest = {1}. The list is: {2}.", serversForRole.Count, partitionFqdn, string.Join <ADServerInfo>(",", serversForRole));
            for (int j = 0; j < serversForRole.Count; j++)
            {
                ADRunspaceServerSettingsProvider.ADServerInfoState adserverInfoState2 = new ADRunspaceServerSettingsProvider.ADServerInfoState(serversForRole[j], true);
                list3.Add(adserverInfoState2.ServerInfo.Fqdn);
                if (adserverInfoState2.ServerInfo.IsServerSuitable)
                {
                    adserverInfoState2.IsDown = false;
                    dictionary3[adserverInfoState2.ServerInfo.Fqdn] = adserverInfoState2;
                }
                else
                {
                    adserverInfoState2.IsDown = true;
                }
            }
            if (adserverInfo != null && (dictionary.Count > 0 || dictionary2.Count > 0))
            {
                newInstance = new PartitionBasedADRunspaceServerSettingsProvider(partitionFqdn, dictionary, dictionary2, dictionary3, adserverInfo, list, list2, list3);
                return(true);
            }
            ExTraceGlobals.ServerSettingsProviderTracer.TraceDebug((long)partitionFqdn.GetHashCode(), "{0} unable to create a new PartitionBasedADRunspaceServerSettingsProvider. CDC {1} InSiteGCs {2} OutOfSiteGCs {3}", new object[]
            {
                partitionFqdn,
                (adserverInfo != null) ? adserverInfo.FqdnPlusPort : "<NULL>",
                dictionary.Count,
                dictionary2.Count
            });
            return(false);
        }
        // Token: 0x06000595 RID: 1429 RVA: 0x0001EE98 File Offset: 0x0001D098
        internal static ADServerInfo GetServerInfoFromFqdn(string fqdn, ConnectionType connectionType)
        {
            PooledLdapConnection pooledLdapConnection = null;
            string       empty = string.Empty;
            ADServerInfo adserverInfo;

            try
            {
                string partitionFqdn = Globals.IsMicrosoftHostedOnly ? ADServerSettings.GetPartitionFqdnFromADServerFqdn(fqdn) : TopologyProvider.LocalForestFqdn;
                pooledLdapConnection = ConnectionPoolManager.GetConnection(connectionType, partitionFqdn, null, fqdn, (connectionType == ConnectionType.GlobalCatalog) ? TopologyProvider.GetInstance().DefaultGCPort : TopologyProvider.GetInstance().DefaultDCPort);
                string writableNC = pooledLdapConnection.ADServerInfo.WritableNC;
                if (!pooledLdapConnection.SessionOptions.HostName.Equals(fqdn, StringComparison.OrdinalIgnoreCase))
                {
                    throw new ADOperationException(DirectoryStrings.ErrorInvalidServerFqdn(fqdn, pooledLdapConnection.SessionOptions.HostName));
                }
                adserverInfo = pooledLdapConnection.ADServerInfo;
            }
            finally
            {
                if (pooledLdapConnection != null)
                {
                    pooledLdapConnection.ReturnToPool();
                }
            }
            return(adserverInfo);
        }
 public string GetConfigDC(string partitionFqdn)
 {
     TopologyProvider.EnforceNonEmptyPartition(partitionFqdn);
     return(this.GetConfigDC(partitionFqdn, true));
 }