예제 #1
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);
        }
        // Token: 0x06000332 RID: 818 RVA: 0x00011BF4 File Offset: 0x0000FDF4
        private static void LoadPartitionCacheIfNecessary()
        {
            if (ADAccountPartitionLocator.partitionsFQDNToGuid == null)
            {
                ADAccountPartitionLocator.RefreshAllAccountPartitions();
                Interlocked.Exchange(ref ADAccountPartitionLocator.lastRefreshTick, Environment.TickCount);
                return;
            }
            int num = ADAccountPartitionLocator.lastRefreshTick;

            if (Globals.GetTickDifference(num, Environment.TickCount) > (ulong)ADAccountPartitionLocator.PartitionCacheRefreshEveryNMilliseconds)
            {
                int num2 = Interlocked.CompareExchange(ref ADAccountPartitionLocator.lastRefreshTick, Environment.TickCount, num);
                if (num == num2)
                {
                    ADAccountPartitionLocator.RefreshAllAccountPartitions();
                }
            }
        }
        // Token: 0x06000DC9 RID: 3529 RVA: 0x0003F560 File Offset: 0x0003D760
        internal PooledLdapConnection GetConnection(ADObjectId domain, string serverName, int port, ref bool newPoolAvailable, ref bool pendingConnections, ref bool serverConnectionPresentButDownOrDisconnected, ref Exception extraDownOrDisconnectedException)
        {
            PooledLdapConnection result = null;

            newPoolAvailable   = false;
            pendingConnections = false;
            serverConnectionPresentButDownOrDisconnected = false;
            int  tickCount = Environment.TickCount;
            bool flag      = serverName != null;
            bool flag2     = domain != null;
            bool flag3     = !flag2 && !flag;

            ExTraceGlobals.GetConnectionTracer.TraceDebug <ConnectionPoolType, string, string>((long)this.GetHashCode(), "LdapConnectionPool.GetConnection of type {0} by {1} ({2})", this.type, flag ? "Server" : (flag2 ? "Domain" : "Load balancing"), flag ? serverName : (flag2 ? domain.ToDNString() : "Least loaded"));
            this.CheckBadConnections();
            try
            {
                this.poolLock.AcquireReaderLock(-1);
                if (!this.isActive)
                {
                    ExTraceGlobals.GetConnectionTracer.TraceWarning((long)this.GetHashCode(), "Pool is not active, skipping GetConnection");
                    newPoolAvailable = true;
                    return(null);
                }
                bool flag4 = false;
                int  num   = int.MinValue;
                int  num2  = -1;
                for (int i = 0; i < this.connectionInfos.Length; i++)
                {
                    ConnectionInfo connectionInfo = this.connectionInfos[i];
                    if (!flag4 && connectionInfo.ConnectionState == ConnectionState.Empty)
                    {
                        ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "GetConnection: Opening connection for {0}.", connectionInfo.ADServerInfo.FqdnPlusPort);
                        this.OpenNewConnection(connectionInfo);
                    }
                    if (connectionInfo.ConnectionState == ConnectionState.Connecting)
                    {
                        ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Connection to {0} is pending, skipping.", connectionInfo.ADServerInfo.FqdnPlusPort);
                        pendingConnections = true;
                    }
                    else if (connectionInfo.ConnectionState != ConnectionState.Connected || !connectionInfo.PooledLdapConnection.IsUp)
                    {
                        ExTraceGlobals.GetConnectionTracer.TraceDebug <string, int, string>((long)this.GetHashCode(), "Connection to {0} is {1}{2}, skipping.", connectionInfo.ADServerInfo.FqdnPlusPort, (int)connectionInfo.ConnectionState, (connectionInfo.ConnectionState == ConnectionState.Connected) ? (connectionInfo.PooledLdapConnection.IsUp ? "and UP" : "and DOWN") : string.Empty);
                        if (flag && this.IsServerMatch(i, serverName, port))
                        {
                            serverConnectionPresentButDownOrDisconnected = true;
                            extraDownOrDisconnectedException             = connectionInfo.LastLdapException;
                            ExTraceGlobals.GetConnectionTracer.TraceError <string, int>((long)this.GetHashCode(), "LdapConnectionPool.GetConnection: {0}:{1} is present but is down or disconnected", serverName, port);
                            break;
                        }
                    }
                    else
                    {
                        int num3 = int.MinValue;
                        if (flag3)
                        {
                            num3  = this.CalculateLoadBalancingQuality(i);
                            flag4 = (connectionInfo.PooledLdapConnection.OutstandingRequestCount == 0);
                        }
                        else if (flag)
                        {
                            num3  = this.CalculateQualityByServerMatch(i, serverName, port);
                            flag4 = (num3 > num);
                        }
                        else
                        {
                            if (this.IsDomainMatch(i, domain))
                            {
                                num3 = this.CalculateLoadBalancingQuality(i);
                            }
                            flag4 = (num3 > num);
                        }
                        ExTraceGlobals.GetConnectionTracer.TraceDebug((long)this.GetHashCode(), "Connection to {0}:{1} has quality {2}. suitableConnectionFound {3}", new object[]
                        {
                            connectionInfo.ADServerInfo.Fqdn,
                            connectionInfo.ADServerInfo.Port,
                            num3,
                            flag4
                        });
                        if (num3 > num)
                        {
                            num  = num3;
                            num2 = i;
                        }
                    }
                }
                if (num2 > -1)
                {
                    ConnectionInfo connectionInfo2 = this.connectionInfos[num2];
                    connectionInfo2.ADServerInfo.IncrementRequestCount();
                    Interlocked.Increment(ref this.totalRequestCount);
                    Interlocked.Exchange(ref this.lastUsedConnectionIndex, num2);
                    result = connectionInfo2.PooledLdapConnection.BorrowFromPool();
                    ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Returning connection to {0}.", connectionInfo2.ADServerInfo.FqdnPlusPort);
                }
            }
            finally
            {
                try
                {
                    this.poolLock.ReleaseReaderLock();
                    ExTraceGlobals.GetConnectionTracer.TracePerformance <ulong>((long)this.GetHashCode(), "GetConnection time spend {0} milliseconds.", Globals.GetTickDifference(tickCount, Environment.TickCount));
                }
                catch (ApplicationException)
                {
                }
            }
            return(result);
        }