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);
        }
 // Token: 0x06000DC5 RID: 3525 RVA: 0x0003F1E4 File Offset: 0x0003D3E4
 private void DisconnectSourceAfterConnectionMove(ConnectionInfo sourceInfo, LdapConnectionPool sourcePool, List <PooledLdapConnection> connectionsToRelease)
 {
     ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Added connection to {0} to a list of connection to release.", sourceInfo.ADServerInfo.FqdnPlusPort);
     connectionsToRelease.Add(sourceInfo.PooledLdapConnection.BorrowFromPool());
     sourceInfo.MakeDisconnected();
     Interlocked.Decrement(ref sourcePool.connectedCount);
 }
        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);
        }
 // Token: 0x06000DC3 RID: 3523 RVA: 0x0003F004 File Offset: 0x0003D204
 internal void MoveConnectionAcrossPool(LdapConnectionPool sourcePool, List <PooledLdapConnection> connectionsToRelease)
 {
     try
     {
         sourcePool.poolLock.AcquireWriterLock(-1);
         this.poolLock.AcquireReaderLock(-1);
         if (!sourcePool.isActive)
         {
             ExTraceGlobals.GetConnectionTracer.TraceWarning((long)sourcePool.GetHashCode(), "Source Pool is not active, skipping MoveConnectionAcrossPool");
         }
         else if (this.connectionInfos == null || this.connectionInfos.Length <= 0)
         {
             ExTraceGlobals.GetConnectionTracer.TraceWarning((long)this.GetHashCode(), "Target Pool does not have active connections, skipping MoveConnectionAcrossPool");
         }
         else
         {
             for (int i = 0; i < sourcePool.connectionInfos.Length; i++)
             {
                 ConnectionInfo connectionInfo = sourcePool.connectionInfos[i];
                 if (connectionInfo.ConnectionState == ConnectionState.Connected && connectionInfo.PooledLdapConnection != null && connectionInfo.PooledLdapConnection.IsUp)
                 {
                     for (int j = 0; j < this.connectionInfos.Length; j++)
                     {
                         ConnectionInfo connectionInfo2 = this.connectionInfos[j];
                         if (connectionInfo2.ConnectionState == ConnectionState.Empty && connectionInfo.ADServerInfo.Equals(connectionInfo2.ADServerInfo))
                         {
                             this.ExecuteConnectionMove(connectionInfo2, connectionInfo, sourcePool);
                             this.DisconnectSourceAfterConnectionMove(connectionInfo, sourcePool, connectionsToRelease);
                             break;
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         try
         {
             this.poolLock.ReleaseReaderLock();
         }
         catch (ApplicationException)
         {
         }
         try
         {
             sourcePool.poolLock.ReleaseWriterLock();
         }
         catch (ApplicationException)
         {
         }
     }
 }
 // Token: 0x06000DC8 RID: 3528 RVA: 0x0003F4A4 File Offset: 0x0003D6A4
 internal void MergePool(LdapConnectionPool sourcePool, List <PooledLdapConnection> connectionsToRelease)
 {
     if (!this.isActive || !sourcePool.isActive)
     {
         ExTraceGlobals.GetConnectionTracer.TraceWarning <bool, bool>((long)this.GetHashCode(), "MergePool - Pool not active. sourcePool = {0}, targetPool = {1}. skipping", sourcePool.isActive, this.isActive);
         return;
     }
     foreach (ConnectionInfo connectionInfo in sourcePool.connectionInfos)
     {
         ADServerInfo serverInfo = new ADServerInfo(connectionInfo.ADServerInfo.Fqdn, connectionInfo.ADServerInfo.PartitionFqdn, connectionInfo.ADServerInfo.Port, connectionInfo.ADServerInfo.WritableNC, connectionInfo.ADServerInfo.DnsWeight, connectionInfo.ADServerInfo.AuthType, true);
         bool         flag       = false;
         this.AppendCustomServer(serverInfo, ref flag);
     }
     this.MoveConnectionAcrossPool(sourcePool, connectionsToRelease);
 }
        private ADServerInfo GetDirectoryServer(string partitionFqdn, ADRole role)
        {
            ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, ADRole>((long)this.GetHashCode(), "GetDirectoryServer PartitionFqdn {0}. Role {1}", partitionFqdn, role);
            LocatorFlags locatorFlags = LocatorFlags.ForceRediscovery | LocatorFlags.DirectoryServicesRequired | LocatorFlags.ReturnDnsName;
            string       text         = partitionFqdn;

            if (ADRole.GlobalCatalog == role)
            {
                ADObjectId rootDomainNamingContext = base.GetRootDomainNamingContext(partitionFqdn);
                ADObjectId domainNamingContext     = base.GetDomainNamingContext(partitionFqdn);
                if (!rootDomainNamingContext.DistinguishedName.Equals(domainNamingContext.DistinguishedName, StringComparison.OrdinalIgnoreCase))
                {
                    text = NativeHelpers.CanonicalNameFromDistinguishedName(rootDomainNamingContext.DistinguishedName);
                }
                locatorFlags |= LocatorFlags.GCRequired;
            }
            ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, string, LocatorFlags>((long)this.GetHashCode(), "GetDirectoryServer. Partition Fqdn {0} Parent Domain {1}. Flags {2}", partitionFqdn, text, locatorFlags);
            ADServerInfo         serverInfo           = new ADServerInfo(null, text, (ADRole.GlobalCatalog == role) ? 3268 : 389, null, 100, AuthType.Kerberos, true);
            PooledLdapConnection pooledLdapConnection = null;
            ADServerInfo         adserverInfo         = null;

            try
            {
                pooledLdapConnection = LdapConnectionPool.CreateOneTimeConnection(null, serverInfo, locatorFlags);
                if (!string.IsNullOrEmpty(pooledLdapConnection.SessionOptions.HostName))
                {
                    adserverInfo = pooledLdapConnection.ADServerInfo.CloneWithServerNameResolved(pooledLdapConnection.SessionOptions.HostName);
                }
                ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, string>((long)this.GetHashCode(), "GetDirectoryServer. Partition Fqdn {0}. Server {1}", partitionFqdn, pooledLdapConnection.SessionOptions.HostName ?? string.Empty);
            }
            finally
            {
                if (pooledLdapConnection != null)
                {
                    pooledLdapConnection.ReturnToPool();
                }
            }
            string          text2;
            LocalizedString localizedString;

            if (adserverInfo != null && SuitabilityVerifier.IsServerSuitableIgnoreExceptions(adserverInfo.Fqdn, ADRole.GlobalCatalog == role, null, out text2, out localizedString))
            {
                return(adserverInfo);
            }
            return(LdapTopologyProvider.FindDirectoryServerForForestOrDomain(text, null, ADRole.GlobalCatalog == role));
        }
        // Token: 0x06000DBB RID: 3515 RVA: 0x0003EA50 File Offset: 0x0003CC50
        private bool OpenNewConnection(ConnectionInfo info)
        {
            ArgumentValidator.ThrowIfNull("info", info);
            if (info.ConnectionState != ConnectionState.Empty)
            {
                return(false);
            }
            if (!info.TryMakeConnecting())
            {
                return(false);
            }
            bool result = false;

            try
            {
                ExTraceGlobals.ConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "LdapConnectionPool::OpenNewConnection - opening new PooledLdapConnection to {0}", info.ADServerInfo.FqdnPlusPort);
                if (info.TryCreatePooledLdapConnection(LdapConnectionPool.RoleFromConnectionPoolType(this.type), this.type == ConnectionPoolType.ConfigDCNotifyPool, this.credential))
                {
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_NEW_CONNECTION, null, new object[]
                    {
                        info.ADServerInfo.Fqdn,
                        info.ADServerInfo.Port,
                        this.type
                    });
                    if (info.TryBindWithRetry(3) && info.TrySetNamingContexts())
                    {
                        info.MakeConnected();
                        result = true;
                        Interlocked.Increment(ref this.connectedCount);
                    }
                }
            }
            finally
            {
                if (info.ConnectionState == ConnectionState.Connecting)
                {
                    info.MakeDisconnected();
                }
            }
            return(result);
        }
 // Token: 0x06000DC4 RID: 3524 RVA: 0x0003F150 File Offset: 0x0003D350
 private void ExecuteConnectionMove(ConnectionInfo targetInfo, ConnectionInfo sourceInfo, LdapConnectionPool sourcePool)
 {
     ExTraceGlobals.GetConnectionTracer.TraceDebug <string, string, int>((long)this.GetHashCode(), "Moving connection to {0}={1} from pool {2}", sourceInfo.ADServerInfo.FqdnPlusPort, targetInfo.ADServerInfo.FqdnPlusPort, sourcePool.GetHashCode());
     targetInfo.TryMakeConnecting();
     targetInfo.PooledLdapConnection = sourceInfo.PooledLdapConnection;
     targetInfo.PooledLdapConnection.BorrowFromPool();
     targetInfo.MakeConnected();
     Interlocked.Increment(ref this.connectedCount);
     ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Moved connection to {0} to the new pool", sourceInfo.ADServerInfo.FqdnPlusPort);
 }
        // Token: 0x06000DC2 RID: 3522 RVA: 0x0003EE0C File Offset: 0x0003D00C
        private void MoveOrDisconnect(int[] serverMapping, LdapConnectionPool sourcePool, List <PooledLdapConnection> connectionsToRelease)
        {
            bool flag = sourcePool == this;

            try
            {
                sourcePool.poolLock.AcquireWriterLock(-1);
                this.poolLock.AcquireReaderLock(-1);
                if (!sourcePool.isActive)
                {
                    ExTraceGlobals.GetConnectionTracer.TraceWarning((long)sourcePool.GetHashCode(), "Source Pool is not active, skipping MoveConnectionsAndDisconnect");
                }
                else
                {
                    for (int i = 0; i < sourcePool.connectionInfos.Length; i++)
                    {
                        ConnectionInfo connectionInfo = sourcePool.connectionInfos[i];
                        if (!flag)
                        {
                            int num = -1;
                            for (int j = 0; j < serverMapping.Length; j++)
                            {
                                if (serverMapping[j] == i)
                                {
                                    num = j;
                                    break;
                                }
                            }
                            if (num != -1 && this.connectionInfos != null && this.connectionInfos.Length > 0)
                            {
                                ConnectionInfo connectionInfo2 = this.connectionInfos[num];
                                if (connectionInfo.ConnectionState == ConnectionState.Connected && connectionInfo.PooledLdapConnection.IsUp && connectionInfo2.ConnectionState == ConnectionState.Empty)
                                {
                                    this.ExecuteConnectionMove(connectionInfo2, connectionInfo, sourcePool);
                                }
                                else
                                {
                                    ExTraceGlobals.GetConnectionTracer.TraceWarning <string, int, string>((long)this.GetHashCode(), "Not moving connection to {0} because its state is {1} and IsUp={2}", connectionInfo.ADServerInfo.FqdnPlusPort, (int)connectionInfo.ConnectionState, (connectionInfo.PooledLdapConnection == null) ? "<n/a>" : connectionInfo.PooledLdapConnection.IsUp.ToString());
                                }
                            }
                        }
                        if (connectionInfo.ConnectionState == ConnectionState.Connected)
                        {
                            this.DisconnectSourceAfterConnectionMove(connectionInfo, sourcePool, connectionsToRelease);
                        }
                        else
                        {
                            ExTraceGlobals.GetConnectionTracer.TraceWarning <string, int>((long)this.GetHashCode(), "Not Disconnecting connection to {0} because its state is {1}", connectionInfo.ADServerInfo.FqdnPlusPort, (int)connectionInfo.ConnectionState);
                        }
                    }
                    ExTraceGlobals.GetConnectionTracer.TraceDebug((long)sourcePool.GetHashCode(), "Deactivating Source Pool");
                    sourcePool.isActive = false;
                }
            }
            finally
            {
                try
                {
                    this.poolLock.ReleaseReaderLock();
                }
                catch (ApplicationException)
                {
                }
                try
                {
                    sourcePool.poolLock.ReleaseWriterLock();
                }
                catch (ApplicationException)
                {
                }
            }
        }
 // Token: 0x06000DC0 RID: 3520 RVA: 0x0003ED6B File Offset: 0x0003CF6B
 internal void MoveConnectionsAndDisconnect(int[] serverMapping, LdapConnectionPool sourcePool, List <PooledLdapConnection> connectionsToRelease)
 {
     this.MoveOrDisconnect(serverMapping, sourcePool, connectionsToRelease);
 }