Esempio n. 1
0
        public static void LogResponse(GlsLoggerContext context, GLSLogger.StatusCode statusCode, ResponseBase response, GlsRawResponse rawResponse)
        {
            int    num = Environment.TickCount - context.TickStart;
            string resultCode;

            switch (statusCode)
            {
            case GLSLogger.StatusCode.Found:
                resultCode = "Found";
                break;

            case GLSLogger.StatusCode.NotFound:
                resultCode = "NotFound";
                break;

            case GLSLogger.StatusCode.WriteSuccess:
                resultCode = "Success";
                break;

            default:
                throw new ArgumentException("statusCode");
            }
            GLSLogger.BeginAppend(context.MethodName, context.ParameterValue, context.ResolveEndpointToIpAddress(false), resultCode, rawResponse, (long)num, string.Empty, response.TransactionID, context.ConnectionId, response.Diagnostics);
            ADProviderPerf.UpdateGlsCallLatency(context.MethodName, context.IsRead, num, true);
        }
Esempio n. 2
0
        public static T LoggingWrapper <T>(LocatorServiceClientAdapter glsClientAdapter, string parameter, string connectionId, Func <T> method) where T : ResponseBase
        {
            string ipAddress     = glsClientAdapter.ResolveEndpointToIpAddress(false);
            string diagnostics   = string.Empty;
            string transactionId = string.Empty;
            string text          = string.Empty;
            int    tickCount     = Environment.TickCount;
            T      result;

            try
            {
                GLSLogger.FaultInjectionTrace();
                result        = method();
                diagnostics   = result.Diagnostics;
                transactionId = result.TransactionID;
            }
            catch (Exception ex)
            {
                text      = ex.Message;
                ipAddress = glsClientAdapter.ResolveEndpointToIpAddress(true);
                throw;
            }
            finally
            {
                int    num        = Environment.TickCount - tickCount;
                string resultCode = string.IsNullOrEmpty(text) ? "Success" : "Exception";
                GLSLogger.BeginAppend(method.Method.Name, parameter, ipAddress, resultCode, null, (long)num, text, transactionId, connectionId, diagnostics);
                bool   isRead;
                string apiName = GLSLogger.ApiNameFromReturnType <T>(out isRead);
                ADProviderPerf.UpdateGlsCallLatency(apiName, isRead, num, string.IsNullOrEmpty(text));
            }
            return(result);
        }
 internal AdamTopologyProvider(int adamPort)
 {
     ExTraceGlobals.TopologyProviderTracer.TraceDebug <int, int>((long)this.GetHashCode(), "Creating new ADAM topo provider instance {0}, port {1}", this.GetHashCode(), adamPort);
     this.adamPort        = adamPort;
     this.topologyVersion = 1;
     ADProviderPerf.AddDCInstance(Environment.MachineName);
 }
Esempio n. 4
0
        public static void LogException(GlsLoggerContext context, Exception ex)
        {
            int        num        = Environment.TickCount - context.TickStart;
            StackTrace stackTrace = new StackTrace(false);

            GLSLogger.BeginAppend(context.MethodName, context.ParameterValue, context.ResolveEndpointToIpAddress(true), "Exception", null, (long)num, ex.Message + stackTrace.ToString(), context.RequestTrackingGuid.ToString(), context.ConnectionId, string.Empty);
            ADProviderPerf.UpdateGlsCallLatency(context.MethodName, context.IsRead, num, false);
        }
Esempio n. 5
0
 // Token: 0x060004A8 RID: 1192 RVA: 0x0001B1D7 File Offset: 0x000193D7
 public static void UpdateDirectoryADRawCachePropertiesMismatchRate(bool mismatch)
 {
     ADProviderPerf.directoryADRawEntryPropertiesMisMatchCounter.Value.AddDenominator(1L);
     if (mismatch)
     {
         ADProviderPerf.directoryADRawEntryPropertiesMisMatchCounter.Value.AddNumerator(1L);
     }
     ADProviderPerf.InitializeTimerIfRequired();
 }
        protected override IList <ADServerInfo> InternalGetServersForRole(string partitionFqdn, IList <string> currentlyUsedServers, ADServerRole role, int serversRequested, bool forestWideAffinityRequested = false)
        {
            LdapTopologyProvider.MiniTopology miniTopology = new LdapTopologyProvider.MiniTopology(partitionFqdn);
            miniTopology = this.topologies.GetOrAdd(partitionFqdn, miniTopology);
            if (ExTraceGlobals.TopologyProviderTracer.IsTraceEnabled(TraceType.DebugTrace))
            {
                ExTraceGlobals.TopologyProviderTracer.TraceDebug((long)this.GetHashCode(), "PartitionFqdn {0}. GetServersForRole {1}, {2} current: [{3}], need {4} servers", new object[]
                {
                    partitionFqdn,
                    role,
                    currentlyUsedServers.Count,
                    string.Join(",", currentlyUsedServers ?? Enumerable.Empty <string>()),
                    serversRequested
                });
            }
            ADServerInfo adserverInfo = null;

            if (miniTopology.DCInfo == null)
            {
                adserverInfo = this.GetDirectoryServer(partitionFqdn, ADRole.DomainController);
                miniTopology.SetServerInfo(adserverInfo, ADServerRole.DomainController);
                miniTopology.IncrementTopologyVersion();
                adserverInfo = null;
            }
            switch (role)
            {
            case ADServerRole.GlobalCatalog:
                adserverInfo = miniTopology.GCInfo;
                if (adserverInfo == null)
                {
                    adserverInfo = this.GetDirectoryServer(partitionFqdn, ADRole.GlobalCatalog);
                    miniTopology.SetServerInfo(adserverInfo, role);
                    miniTopology.IncrementTopologyVersion();
                }
                break;

            case ADServerRole.DomainController:
            case ADServerRole.ConfigurationDomainController:
                adserverInfo = ((ADServerRole.DomainController == role) ? miniTopology.DCInfo : miniTopology.CDCInfo);
                if (adserverInfo == null)
                {
                    adserverInfo = this.GetDirectoryServer(partitionFqdn, ADRole.DomainController);
                    miniTopology.SetServerInfo(adserverInfo, role);
                    miniTopology.IncrementTopologyVersion();
                }
                break;
            }
            ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, string>((long)this.GetHashCode(), "PartitionFqdn {0}. GetServerForRole returning 1 server {1}", partitionFqdn, adserverInfo.FqdnPlusPort);
            ADProviderPerf.AddDCInstance(adserverInfo.Fqdn);
            ADServerInfo adserverInfo2 = (ADServerInfo)adserverInfo.Clone();

            adserverInfo2.Mapping = (adserverInfo2.Fqdn.Equals((currentlyUsedServers == null || currentlyUsedServers.Count == 0) ? string.Empty : currentlyUsedServers[0], StringComparison.OrdinalIgnoreCase) ? 0 : -1);
            return(new List <ADServerInfo>
            {
                adserverInfo2
            });
        }
        // Token: 0x06000DCB RID: 3531 RVA: 0x0003F978 File Offset: 0x0003DB78
        internal static PooledLdapConnection CreateOneTimeConnection(NetworkCredential networkCredential, ADServerInfo serverInfo, LocatorFlags connectionFlags = LocatorFlags.None)
        {
            string arg = "<null>\\<null>";

            if (networkCredential != null)
            {
                arg = networkCredential.Domain + "\\" + networkCredential.UserName;
            }
            else
            {
                using (WindowsIdentity current = WindowsIdentity.GetCurrent())
                {
                    if (current.ImpersonationLevel == TokenImpersonationLevel.Delegation || current.ImpersonationLevel == TokenImpersonationLevel.Impersonation)
                    {
                        arg = current.Name;
                    }
                }
            }
            ExTraceGlobals.ConnectionTracer.TraceDebug <string, string>(0L, "LdapConnectionPool::CreateOneTimeConnection - opening new ONE-TIME PooledLdapConnection to {0} as {1}", serverInfo.FqdnPlusPort, arg);
            ADProviderPerf.AddDCInstance(serverInfo.Fqdn);
            ADServerRole         role = (serverInfo.Port == 389) ? ADServerRole.DomainController : ADServerRole.GlobalCatalog;
            bool                 flag = false;
            PooledLdapConnection pooledLdapConnection = null;
            PooledLdapConnection result;

            try
            {
                pooledLdapConnection = new PooledLdapConnection(serverInfo, role, false, networkCredential);
                if (LocatorFlags.None != connectionFlags)
                {
                    pooledLdapConnection.SessionOptions.LocatorFlag |= connectionFlags;
                }
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_NEW_CONNECTION, null, new object[]
                {
                    serverInfo.Fqdn,
                    serverInfo.Port,
                    string.Empty
                });
                pooledLdapConnection.BindWithRetry(3);
                pooledLdapConnection.SetNamingContexts();
                flag   = true;
                result = pooledLdapConnection;
            }
            catch (LdapException ex)
            {
                throw new ADTransientException(DirectoryStrings.ExceptionCreateLdapConnection(serverInfo.FqdnPlusPort, ex.Message, (uint)ex.ErrorCode), ex);
            }
            finally
            {
                if (!flag && pooledLdapConnection != null)
                {
                    pooledLdapConnection.ReturnToPool();
                }
            }
            return(result);
        }
 public override void SetConfigDC(string partitionFqdn, string serverName, int port)
 {
     base.SetConfigDC(partitionFqdn, serverName, port);
     ExTraceGlobals.TopologyProviderTracer.TraceDebug <string, string, int>((long)this.GetHashCode(), "PartitionFqdn {0} setting Config DC to {1}:{2}", partitionFqdn, serverName, port);
     LdapTopologyProvider.MiniTopology miniTopology = new LdapTopologyProvider.MiniTopology(partitionFqdn);
     miniTopology = this.topologies.GetOrAdd(partitionFqdn, miniTopology);
     miniTopology.SetServerInfo(new ADServerInfo(serverName, partitionFqdn, port, null, 100, AuthType.Kerberos, true), ADServerRole.ConfigurationDomainController);
     miniTopology.IncrementTopologyVersion();
     ADProviderPerf.AddDCInstance(serverName);
 }
 // Token: 0x06000DC7 RID: 3527 RVA: 0x0003F2F4 File Offset: 0x0003D4F4
 internal void AppendCustomServer(ADServerInfo serverInfo, ref bool presentAndDownOrDisconnected)
 {
     presentAndDownOrDisconnected = false;
     try
     {
         this.poolLock.AcquireWriterLock(-1);
         if (!this.isActive)
         {
             ExTraceGlobals.GetConnectionTracer.TraceWarning((long)this.GetHashCode(), "Pool is not active, skipping AppendCustomServer");
         }
         else
         {
             for (int i = 0; i < this.connectionInfos.Length; i++)
             {
                 ConnectionInfo connectionInfo = this.connectionInfos[i];
                 if (connectionInfo.ADServerInfo.Equals(serverInfo))
                 {
                     ExTraceGlobals.GetConnectionTracer.TraceWarning <string>((long)this.GetHashCode(), "AppendCustomServer: {0} is already in the list", serverInfo.FqdnPlusPort);
                     if (connectionInfo.ConnectionState == ConnectionState.Disconnected || (connectionInfo.ConnectionState == ConnectionState.Connected && !connectionInfo.PooledLdapConnection.IsUp))
                     {
                         ExTraceGlobals.GetConnectionTracer.TraceWarning <string, string>((long)this.GetHashCode(), "AppendCustomServer: {0} is {1}", serverInfo.FqdnPlusPort, (connectionInfo.ConnectionState == ConnectionState.Disconnected) ? "Disconnected" : "Down");
                         presentAndDownOrDisconnected = true;
                     }
                     return;
                 }
             }
             ExTraceGlobals.GetConnectionTracer.TraceDebug <string>((long)this.GetHashCode(), "Adding custom connection to {0}", serverInfo.Fqdn);
             ADProviderPerf.AddDCInstance(serverInfo.Fqdn);
             ConnectionInfo[] array = new ConnectionInfo[this.connectionInfos.Length + 1];
             this.connectionInfos.CopyTo(array, 0);
             array[array.Length - 1] = new ConnectionInfo(serverInfo);
             this.connectionInfos    = array;
             ADServerInfo[] array2 = new ADServerInfo[this.serverInfos.Length + 1];
             this.serverInfos.CopyTo(array2, 0);
             array2[array2.Length - 1] = serverInfo;
             this.serverInfos          = array2;
         }
     }
     finally
     {
         try
         {
             this.poolLock.ReleaseWriterLock();
         }
         catch (ApplicationException)
         {
         }
     }
 }
Esempio n. 10
0
        // Token: 0x060004A9 RID: 1193 RVA: 0x0001B208 File Offset: 0x00019408
        public static void UpdateADDriverCacheHitRate(bool cacheHit)
        {
            ADProviderPerf.adDriverCacheHitCounter.Value.AddDenominator(1L);
            if (cacheHit)
            {
                ADProviderPerf.adDriverCacheHitCounter.Value.AddNumerator(1L);
            }
            MSExchangeADAccessCacheCountersInstance value = ADProviderPerf.processADDriverCacheCounters.Value;

            if (value != null)
            {
                value.NumberOfCacheRequests.Increment();
            }
            ADProviderPerf.InitializeTimerIfRequired();
        }
Esempio n. 11
0
        // Token: 0x060004A0 RID: 1184 RVA: 0x0001A93C File Offset: 0x00018B3C
        public static void UpdateProcessTimeSearchPercentileCounter(uint value)
        {
            if (Globals.InstanceType == InstanceType.NotInitialized)
            {
                Globals.InitializeUnknownPerfCounterInstance();
            }
            ADProviderPerf.perProcessPercentileADLatency.AddValue((long)((ulong)value));
            uint value2 = (uint)ADProviderPerf.perProcessPercentileADLatency.PercentileQuery(90.0);

            ADProviderPerf.UpdateProcessCounter(Counter.ProcessTimeSearchNinetiethPercentile, UpdateType.Add, value2);
            ADProviderPerf.UpdateProcessCounter(Counter.ProcessTimeSearchNinetiethPercentileBase, UpdateType.Add, 1U);
            value2 = (uint)ADProviderPerf.perProcessPercentileADLatency.PercentileQuery(95.0);
            ADProviderPerf.UpdateProcessCounter(Counter.ProcessTimeSearchNinetyFifthPercentile, UpdateType.Add, value2);
            ADProviderPerf.UpdateProcessCounter(Counter.ProcessTimeSearchNinetyFifthPercentileBase, UpdateType.Add, 1U);
            value2 = (uint)ADProviderPerf.perProcessPercentileADLatency.PercentileQuery(99.0);
            ADProviderPerf.UpdateProcessCounter(Counter.ProcessTimeSearchNinetyNinethPercentile, UpdateType.Add, value2);
            ADProviderPerf.UpdateProcessCounter(Counter.ProcessTimeSearchNinetyNinethPercentileBase, UpdateType.Add, 1U);
        }
Esempio n. 12
0
        private ADRawEntry[] GetNextResultCollection()
        {
            this.vlvRequestControl.ContextId = base.Cookie;
            DirectoryControl            directoryControl;
            SearchResultEntryCollection nextResultCollection = base.GetNextResultCollection(typeof(VlvResponseControl), out directoryControl);

            ADProviderPerf.UpdateProcessCounter(Counter.ProcessRateVlv, UpdateType.Add, 1U);
            ADProviderPerf.UpdateDCCounter(base.PreferredServerName, Counter.DCRateVlv, UpdateType.Add, 1U);
            base.Cookie = null;
            if (directoryControl != null)
            {
                VlvResponseControl vlvResponseControl = (VlvResponseControl)directoryControl;
                base.Cookie            = vlvResponseControl.ContextId;
                this.estimatedRowCount = vlvResponseControl.ContentCount;
                this.currentRow        = vlvResponseControl.TargetPosition;
            }
            if (nextResultCollection == null)
            {
                return(null);
            }
            return(base.Session.ObjectsFromEntries <ADRawEntry>(nextResultCollection, base.PreferredServerName, this.properties, ADVirtualListView.dummyADRawEntry));
        }
Esempio n. 13
0
        protected override SearchResultEntryCollection GetNextResultCollection()
        {
            this.pageResultRequestControl.Cookie   = base.Cookie;
            this.pageResultRequestControl.PageSize = base.PageSize;
            if (base.PagesReturned > 0)
            {
                ADProviderPerf.UpdateProcessCounter(Counter.ProcessRatePaged, UpdateType.Add, 1U);
                ADProviderPerf.UpdateDCCounter(base.PreferredServerName, Counter.DCRatePaged, UpdateType.Add, 1U);
            }
            DirectoryControl            directoryControl;
            SearchResultEntryCollection nextResultCollection = base.GetNextResultCollection(typeof(PageResultResponseControl), out directoryControl);

            base.Cookie = ((directoryControl == null) ? null : ((PageResultResponseControl)directoryControl).Cookie);
            if (base.Cookie == null || base.Cookie.Length == 0 || nextResultCollection == null)
            {
                base.RetrievedAllData = new bool?(true);
            }
            else
            {
                base.RetrievedAllData = new bool?(false);
            }
            return(nextResultCollection);
        }
Esempio n. 14
0
        // Token: 0x060004A7 RID: 1191 RVA: 0x0001B068 File Offset: 0x00019268
        public static void UpdateDirectoryCacheHitRatio(bool cacheHit, ObjectType objectType)
        {
            ADProviderPerf.directoryCacheHitCounter.Value.AddDenominator(1L);
            if (cacheHit)
            {
                ADProviderPerf.directoryCacheHitCounter.Value.AddNumerator(1L);
            }
            if (objectType <= ObjectType.ActiveSyncMiniRecipient)
            {
                if (objectType <= ObjectType.MiniRecipient)
                {
                    switch (objectType)
                    {
                    case ObjectType.ExchangeConfigurationUnit:
                        ADProviderPerf.directoryConfigUnitCacheHitCounter.Value.AddDenominator(1L);
                        if (cacheHit)
                        {
                            ADProviderPerf.directoryConfigUnitCacheHitCounter.Value.AddNumerator(1L);
                            goto IL_15D;
                        }
                        goto IL_15D;

                    case ObjectType.Recipient:
                        break;

                    case ObjectType.ExchangeConfigurationUnit | ObjectType.Recipient:
                        goto IL_15D;

                    case ObjectType.AcceptedDomain:
                        ADProviderPerf.directoryAcceptedDomainCacheHitCounter.Value.AddDenominator(1L);
                        if (cacheHit)
                        {
                            ADProviderPerf.directoryAcceptedDomainCacheHitCounter.Value.AddNumerator(1L);
                            goto IL_15D;
                        }
                        goto IL_15D;

                    default:
                        if (objectType != ObjectType.MiniRecipient)
                        {
                            goto IL_15D;
                        }
                        break;
                    }
                }
                else if (objectType != ObjectType.TransportMiniRecipient && objectType != ObjectType.OWAMiniRecipient && objectType != ObjectType.ActiveSyncMiniRecipient)
                {
                    goto IL_15D;
                }
            }
            else if (objectType <= ObjectType.StorageMiniRecipient)
            {
                if (objectType != ObjectType.ADRawEntry)
                {
                    if (objectType != ObjectType.StorageMiniRecipient)
                    {
                        goto IL_15D;
                    }
                }
                else
                {
                    ADProviderPerf.directoryADRawEntryCacheHitCounter.Value.AddDenominator(1L);
                    if (cacheHit)
                    {
                        ADProviderPerf.directoryADRawEntryCacheHitCounter.Value.AddNumerator(1L);
                        goto IL_15D;
                    }
                    goto IL_15D;
                }
            }
            else if (objectType != ObjectType.LoadBalancingMiniRecipient && objectType != ObjectType.MiniRecipientWithTokenGroups && objectType != ObjectType.FrontEndMiniRecipient)
            {
                goto IL_15D;
            }
            ADProviderPerf.directoryRecipientCacheHitCounter.Value.AddDenominator(1L);
            if (cacheHit)
            {
                ADProviderPerf.directoryRecipientCacheHitCounter.Value.AddNumerator(1L);
            }
IL_15D:
            ADProviderPerf.InitializeTimerIfRequired();
        }
        // Token: 0x0600032A RID: 810 RVA: 0x00011460 File Offset: 0x0000F660
        private static bool TryLookUpAccountForest(Guid externalDirectoryOrganizationId, string acceptedDomain, string msaUserNetID, out TenantPartitionCacheItem cacheItem)
        {
            cacheItem = null;
            Exception ex = null;

            if (acceptedDomain == string.Empty)
            {
                throw new ArgumentException(acceptedDomain);
            }
            if (msaUserNetID == string.Empty)
            {
                throw new ArgumentException(msaUserNetID);
            }
            try
            {
                IGlobalDirectorySession globalSession = DirectorySessionFactory.GetGlobalSession(null);
                bool   dataFromOfflineService         = false;
                string resourceForestFqdn;
                string text;
                string tenantName;
                bool   flag;
                if (acceptedDomain != null)
                {
                    if (ADAccountPartitionLocator.acceptedDomainPartitionCache.TryGetValue(acceptedDomain, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.AcceptedDomain, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.AcceptedDomain, false);
                    string text2;
                    flag = globalSession.TryGetTenantForestsByDomain(acceptedDomain, out externalDirectoryOrganizationId, out resourceForestFqdn, out text, out text2, out tenantName, out dataFromOfflineService);
                }
                else if (externalDirectoryOrganizationId != Guid.Empty)
                {
                    if (ADAccountPartitionLocator.externalOrgIdPartitionCache.TryGetValue(externalDirectoryOrganizationId, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.ExternalDirectoryObjectId, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.ExternalDirectoryObjectId, false);
                    flag = globalSession.TryGetTenantForestsByOrgGuid(externalDirectoryOrganizationId, out resourceForestFqdn, out text, out tenantName, out dataFromOfflineService);
                }
                else
                {
                    if (ADAccountPartitionLocator.msaUserNetIdPartitionCache.TryGetValue(msaUserNetID, out cacheItem))
                    {
                        ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.MSAUserNetID, true);
                        return(true);
                    }
                    ADProviderPerf.UpdateGlsCacheHitRatio(GlsLookupKey.MSAUserNetID, false);
                    flag = globalSession.TryGetTenantForestsByMSAUserNetID(msaUserNetID, out externalDirectoryOrganizationId, out resourceForestFqdn, out text, out tenantName);
                }
                if (flag)
                {
                    ADAccountPartitionLocator.LoadPartitionCacheIfNecessary();
                    Guid accountPartitionGuid;
                    ADAccountPartitionLocator.partitionsFQDNToGuid.TryGetValue(text, out accountPartitionGuid);
                    cacheItem = new TenantPartitionCacheItem(accountPartitionGuid, text, resourceForestFqdn, externalDirectoryOrganizationId, tenantName, dataFromOfflineService);
                    ADAccountPartitionLocator.InsertCacheMaps(cacheItem, acceptedDomain, msaUserNetID);
                    return(true);
                }
            }
            catch (MServTransientException ex2)
            {
                ex = ex2;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (MServPermanentException ex3)
            {
                ex = ex3;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (TransientException ex4)
            {
                ex = ex4;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (GlsPermanentException ex5)
            {
                ex = ex5;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            catch (GlsTenantNotFoundException ex6)
            {
                ex = ex6;
                if (!GlsMServDirectorySession.ShouldScanAllForests)
                {
                    throw;
                }
            }
            if (ex != null)
            {
                ExTraceGlobals.GLSTracer.TraceWarning <Exception>(0L, "Got exception while doing GLS lookup in ADAccountPartitionLocator, ignoring it until 2605034 is fixed {0}", ex);
            }
            return(false);
        }
Esempio n. 16
0
        // Token: 0x060003B5 RID: 949 RVA: 0x00015440 File Offset: 0x00013640
        internal static ADObject CreateAndInitializeRecipientObject <TRecipientObject>(ADPropertyBag propertyBag, ADRawEntry dummyObject, IRecipientSession recipientSession) where TRecipientObject : IConfigurable, new()
        {
            ArgumentValidator.ThrowIfNull("propertyBag", propertyBag);
            ArgumentValidator.ThrowIfNull("dummyObject", dummyObject);
            MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[ADObjectSchema.ObjectClass];
            ADObject adobject;

            if (dummyObject is OWAMiniRecipient)
            {
                adobject = new OWAMiniRecipient();
            }
            else if (dummyObject is ActiveSyncMiniRecipient)
            {
                adobject = new ActiveSyncMiniRecipient();
            }
            else if (dummyObject is StorageMiniRecipient)
            {
                adobject = new StorageMiniRecipient();
            }
            else if (dummyObject is TransportMiniRecipient)
            {
                adobject = new TransportMiniRecipient();
            }
            else if (dummyObject is LoadBalancingMiniRecipient)
            {
                adobject = new LoadBalancingMiniRecipient();
            }
            else if (dummyObject is MiniRecipientWithTokenGroups)
            {
                adobject = new MiniRecipientWithTokenGroups();
            }
            else if (dummyObject is FrontEndMiniRecipient)
            {
                adobject = new FrontEndMiniRecipient();
            }
            else if (dummyObject is MiniRecipient)
            {
                adobject = new MiniRecipient();
            }
            else if (dummyObject is RemovedMailbox)
            {
                adobject = new RemovedMailbox();
            }
            else if (dummyObject is DeletedRecipient)
            {
                adobject = new DeletedRecipient();
            }
            else if (multiValuedProperty.Contains(ADComputerRecipient.MostDerivedClass))
            {
                adobject = new ADComputerRecipient();
            }
            else if (multiValuedProperty.Contains(ADUser.MostDerivedClass))
            {
                adobject = new ADUser();
            }
            else if (multiValuedProperty.Contains(ADContact.MostDerivedClass))
            {
                adobject = new ADContact();
            }
            else if (multiValuedProperty.Contains(ADGroup.MostDerivedClass))
            {
                adobject = new ADGroup();
            }
            else if (multiValuedProperty.Contains(ADDynamicGroup.MostDerivedClass))
            {
                adobject = new ADDynamicGroup();
            }
            else if (multiValuedProperty.Contains(ADPublicFolder.MostDerivedClass))
            {
                adobject = new ADPublicFolder();
            }
            else if (multiValuedProperty.Contains(ADSystemAttendantMailbox.MostDerivedClass))
            {
                adobject = new ADSystemAttendantMailbox();
            }
            else if (multiValuedProperty.Contains(ADSystemMailbox.MostDerivedClass))
            {
                adobject = new ADSystemMailbox();
            }
            else if (multiValuedProperty.Contains(ADPublicDatabase.MostDerivedClass))
            {
                adobject = new ADPublicDatabase();
            }
            else
            {
                if (!multiValuedProperty.Contains(ADMicrosoftExchangeRecipient.MostDerivedClass))
                {
                    string objectClass = string.Empty;
                    foreach (string text in multiValuedProperty)
                    {
                        objectClass = text;
                    }
                    ObjectValidationError error = new ObjectValidationError(DirectoryStrings.UnsupportedObjectClass(objectClass), (ADObjectId)propertyBag[ADObjectSchema.Id], string.Empty);
                    ADProviderPerf.UpdateProcessCounter(Counter.ProcessRateCriticalValidationFailures, UpdateType.Update, 1U);
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_VALIDATION_FAILED_FCO_MODE_RECIPIENT, ((ADObjectId)propertyBag[ADObjectSchema.Id]).ToString(), new object[]
                    {
                        ((ADObjectId)propertyBag[ADObjectSchema.Id]).ToDNString()
                    });
                    throw new DataValidationException(error);
                }
                adobject = new ADMicrosoftExchangeRecipient();
            }
            adobject.m_Session   = recipientSession;
            adobject.propertyBag = propertyBag;
            adobject.Initialize();
            adobject.ResetChangeTracking(true);
            if (recipientSession != null)
            {
                adobject.SetIsReadOnly(recipientSession.ReadOnly);
            }
            ExTraceGlobals.ADReadDetailsTracer.TraceDebug <string, RecipientType>((long)((recipientSession != null) ? recipientSession.GetHashCode() : 0), "ADRecipientObjectSession::CreateObject - Got {0} as {1}", adobject.DistinguishedName, (RecipientType)adobject[ADRecipientSchema.RecipientType]);
            return(adobject);
        }
        protected TResult ExecuteSingleObjectQueryWithFallback <TResult>(Func <TSession, TResult> query, Func <TResult, List <Tuple <string, KeyType> > > getAdditionalKeys = null, IEnumerable <PropertyDefinition> properties = null) where TResult : ADRawEntry, new()
        {
            ArgumentValidator.ThrowIfNull("query", query);
            if (!Configuration.IsCacheEnabled(typeof(TResult)))
            {
                return(query(this.GetSession()));
            }
            Stopwatch stopwatch = Stopwatch.StartNew();

            CachePerformanceTracker.StartLogging();
            CompositeDirectorySession <TSession> .TraceState traceState = CompositeDirectorySession <TSession> .TraceState.None;
            CacheMode          cacheModeForCurrentProcess = Configuration.GetCacheModeForCurrentProcess();
            double             num                = -1.0;
            double             num2               = -1.0;
            double             num3               = -1.0;
            double             num4               = -1.0;
            TResult            tresult            = default(TResult);
            string             text               = string.Empty;
            Guid               guid               = Guid.Empty;
            ADCacheResultState adcacheResultState = ADCacheResultState.Succeed;
            bool               flag               = true;
            int num5 = 0;

            try
            {
                Stopwatch stopwatch2 = null;
                ADObject  adobject   = null;
                try
                {
                    TSession session = this.GetSession();
                    if (session.ActivityScope != null)
                    {
                        TSession session2 = this.GetSession();
                        if (session2.ActivityScope.Status == ActivityContextStatus.ActivityStarted)
                        {
                            TSession session3 = this.GetSession();
                            guid = session3.ActivityScope.ActivityId;
                        }
                    }
                    if (!this.CacheSessionForDeletingOnly && (CacheMode.Read & cacheModeForCurrentProcess) != CacheMode.Disabled)
                    {
                        TSession session4 = this.GetSession();
                        if (!session4.SessionSettings.IncludeSoftDeletedObjectLinks)
                        {
                            if (properties != null || !typeof(TResult).Equals(typeof(ADRawEntry)))
                            {
                                traceState |= CompositeDirectorySession <TSession> .TraceState.CacheRead;
                                stopwatch2  = Stopwatch.StartNew();
                                tresult     = query(this.GetCacheSession());
                                CacheDirectorySession cacheDirectorySession = this.GetCacheSession() as CacheDirectorySession;
                                if (cacheDirectorySession != null)
                                {
                                    adcacheResultState = cacheDirectorySession.ResultState;
                                    flag = cacheDirectorySession.IsNewProxyObject;
                                    num5 = cacheDirectorySession.RetryCount;
                                }
                                stopwatch2.Stop();
                                num = (double)stopwatch2.ElapsedMilliseconds;
                                goto IL_19A;
                            }
                            goto IL_19A;
                        }
                    }
                    if ((CacheMode.Read & cacheModeForCurrentProcess) == CacheMode.Disabled || this.CacheSessionForDeletingOnly)
                    {
                        adcacheResultState = ADCacheResultState.CacheModeIsNotRead;
                    }
                    else
                    {
                        adcacheResultState = ADCacheResultState.SoftDeletedObject;
                    }
IL_19A:
                    if (tresult != null && tresult.Id != null)
                    {
                        TSession session5 = this.GetSession();
                        if (ADSession.ShouldFilterCNFObject(session5.SessionSettings, tresult.Id))
                        {
                            tresult            = default(TResult);
                            adcacheResultState = ADCacheResultState.CNFedObject;
                        }
                        else
                        {
                            TSession session6 = this.GetSession();
                            if (ADSession.ShouldFilterSoftDeleteObject(session6.SessionSettings, tresult.Id))
                            {
                                tresult            = default(TResult);
                                adcacheResultState = ADCacheResultState.SoftDeletedObject;
                            }
                            else
                            {
                                if (tresult.Id != null && tresult.Id.DomainId != null)
                                {
                                    TSession session7 = this.GetSession();
                                    if (!session7.SessionSettings.PartitionId.Equals(tresult.Id.GetPartitionId()))
                                    {
                                        if (ExEnvironment.IsTest)
                                        {
                                            TSession session8 = this.GetSession();
                                            if (session8.SessionSettings.PartitionId.ForestFQDN.EndsWith(tresult.Id.GetPartitionId().ForestFQDN, StringComparison.OrdinalIgnoreCase))
                                            {
                                                goto IL_341;
                                            }
                                        }
                                        ExEventLog.EventTuple tuple_WrongObjectReturned = DirectoryEventLogConstants.Tuple_WrongObjectReturned;
                                        string   name     = typeof(TResult).Name;
                                        object[] array    = new object[2];
                                        object[] array2   = array;
                                        int      num6     = 0;
                                        TSession session9 = this.GetSession();
                                        array2[num6] = session9.SessionSettings.PartitionId.ForestFQDN;
                                        array[1]     = tresult.Id.GetPartitionId().ForestFQDN;
                                        Globals.LogEvent(tuple_WrongObjectReturned, name, array);
                                        tresult            = default(TResult);
                                        adcacheResultState = ADCacheResultState.WrongForest;
                                        goto IL_3E1;
                                    }
                                }
IL_341:
                                TSession session10 = this.GetSession();
                                if (session10.SessionSettings.CurrentOrganizationId != OrganizationId.ForestWideOrgId)
                                {
                                    TSession       session11             = this.GetSession();
                                    OrganizationId currentOrganizationId = session11.SessionSettings.CurrentOrganizationId;
                                    if (!tresult.Id.IsDescendantOf(currentOrganizationId.OrganizationalUnit) && !tresult.Id.IsDescendantOf(currentOrganizationId.ConfigurationUnit.Parent))
                                    {
                                        tresult            = default(TResult);
                                        adcacheResultState = ADCacheResultState.OranizationIdMismatch;
                                    }
                                }
                            }
                        }
                    }
                    else if (tresult != null)
                    {
                        tresult = default(TResult);
                    }
                    else
                    {
                        adcacheResultState = ADCacheResultState.NotFound;
                    }
IL_3E1:
                    adobject = (tresult as ADObject);
                }
                catch (Exception ex)
                {
                    tresult            = default(TResult);
                    adcacheResultState = ADCacheResultState.ExceptionHappened;
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_CallADCacheServiceFailed, typeof(TResult).Name, new object[]
                    {
                        ex.ToString()
                    });
                    text = ex.ToString();
                }
                if (tresult == null)
                {
                    traceState |= CompositeDirectorySession <TSession> .TraceState.ADRead;
                    stopwatch2  = Stopwatch.StartNew();
                    tresult     = query(this.GetSession());
                    adobject    = (tresult as ADObject);
                    stopwatch2.Stop();
                    num4 = (double)stopwatch2.ElapsedMilliseconds;
                    stopwatch2.Restart();
                    bool flag2 = true;
                    if (adobject != null)
                    {
                        TSession session12 = this.GetSession();
                        if (!session12.ReadOnly && CompositeDirectorySession <TSession> .ExchangeConfigUnitCUType.Equals(adobject.GetType()) && OrganizationId.ForestWideOrgId.Equals(adobject.OrganizationId))
                        {
                            ExTraceGlobals.SessionTracer.TraceWarning <string>((long)this.GetHashCode(), "Newly created ExchangeCU with organizationId equals to RootOrgId, ignored till is fully populated. DN {0}", tresult.GetDistinguishedNameOrName());
                            flag2 = false;
                        }
                    }
                    if (tresult != null && CacheUtils.GetObjectTypeFor(tresult.GetType(), false) == ObjectType.Unknown)
                    {
                        flag2 = false;
                    }
                    if (tresult != null && ((CacheMode.SyncWrite | CacheMode.AsyncWrite) & cacheModeForCurrentProcess) != CacheMode.Disabled && tresult.Id != null && !tresult.Id.IsDeleted && flag2)
                    {
                        traceState |= CompositeDirectorySession <TSession> .TraceState.CacheInsert;
                        if ((CacheMode.SyncWrite & cacheModeForCurrentProcess) != CacheMode.Disabled)
                        {
                            try
                            {
                                this.CacheInsert <TResult>(tresult, getAdditionalKeys, properties);
                                goto IL_5C8;
                            }
                            catch (Exception ex2)
                            {
                                Globals.LogEvent(DirectoryEventLogConstants.Tuple_CallADCacheServiceFailed, "CacheInsert", new object[]
                                {
                                    ex2.ToString()
                                });
                                text += ex2.Message;
                                goto IL_5C8;
                            }
                        }
                        TSession session13 = this.GetSession();
                        if (session13.ReadOnly)
                        {
                            this.AsyncCacheInsert <TResult>(tresult, getAdditionalKeys, properties);
                        }
                        else
                        {
                            adcacheResultState |= ADCacheResultState.WritableSession;
                        }
                    }
IL_5C8:
                    stopwatch2.Stop();
                    num3 = (double)stopwatch2.ElapsedMilliseconds;
                }
                if (adobject != null)
                {
                    adobject.m_Session = this;
                }
            }
            finally
            {
                stopwatch.Stop();
                string   text2                   = CachePerformanceTracker.StopLogging();
                string   operation               = "Read";
                string   dn                      = (tresult != null) ? tresult.GetDistinguishedNameOrName() : "<NULL>";
                DateTime whenReadUTC             = (tresult != null) ? ((tresult.WhenReadUTC != null) ? tresult.WhenReadUTC.Value : DateTime.MinValue) : DateTime.MinValue;
                long     elapsedMilliseconds     = stopwatch.ElapsedMilliseconds;
                long     wcfGetProcessingTime    = (long)num;
                long     wcfRemoveProcessingTime = (long)num2;
                long     wcfPutProcessingTime    = (long)num3;
                long     adProcessingTime        = (long)num4;
                bool     isNewProxyObject        = flag;
                int      retryCount              = num5;
                string   objectType              = (tresult != null) ? tresult.GetType().Name : typeof(TResult).Name;
                string   cachePerformanceTracker = text2;
                Guid     activityId              = guid;
                TSession session14               = this.GetSession();
                CacheProtocolLog.BeginAppend(operation, dn, whenReadUTC, elapsedMilliseconds, wcfGetProcessingTime, wcfRemoveProcessingTime, wcfPutProcessingTime, adProcessingTime, isNewProxyObject, retryCount, objectType, cachePerformanceTracker, activityId, session14.CallerInfo, string.Format("ResultState:{0};{1}", (int)adcacheResultState, text));
                ExTraceGlobals.SessionTracer.TraceDebug((long)this.GetHashCode(), "ExecuteSingleObjectQueryWithFallback. Cache Mode {0}. TraceState {1}. DN {2}. WhenRead {3}. IsCached {4}.", new object[]
                {
                    cacheModeForCurrentProcess,
                    traceState,
                    (tresult != null) ? tresult.GetDistinguishedNameOrName() : "<NULL>",
                    (tresult != null) ? ((tresult.WhenReadUTC != null) ? tresult.WhenReadUTC.Value.ToString() : "<NULL>") : "<NULL>",
                    tresult != null && tresult.IsCached
                });
                ExTraceGlobals.SessionTracer.TracePerformance((long)this.GetHashCode(), "ExecuteSingleObjectQueryWithFallback.  Cache Mode {0}. TraceState {1}. DN {2}. TotalTime {3}. GetCacheTime {4}. RemoveCacheTime {5}. PutCacheTime {6}. ADTime {7}. WCFDetails [{8}]", new object[]
                {
                    cacheModeForCurrentProcess,
                    traceState,
                    (tresult != null) ? tresult.GetDistinguishedNameOrName() : "<NULL>",
                    stopwatch.ElapsedMilliseconds,
                    num,
                    num2,
                    num3,
                    num4,
                    text2
                });
                if (tresult != null)
                {
                    ADProviderPerf.UpdateADDriverCacheHitRate(tresult.IsCached);
                }
            }
            return(tresult);
        }
Esempio n. 18
0
        // Token: 0x060006F4 RID: 1780 RVA: 0x00025650 File Offset: 0x00023850
        protected override SearchResultEntryCollection GetNextResultCollection()
        {
            if (base.Session.NetworkCredential == null)
            {
                this.vlvRequestControl.ContextId = base.Cookie;
            }
            this.vlvRequestControl.Offset = this.offSet;
            if (this.searchForward)
            {
                this.vlvRequestControl.BeforeCount = 0;
                this.vlvRequestControl.AfterCount  = (this.includeBookmarkObject ? (base.PageSize - 1) : base.PageSize);
            }
            else
            {
                this.vlvRequestControl.BeforeCount = (this.includeBookmarkObject ? (base.PageSize - 1) : base.PageSize);
                this.vlvRequestControl.AfterCount  = 0;
            }
            DirectoryControl            directoryControl            = null;
            SearchResultEntryCollection searchResultEntryCollection = null;

            try
            {
                searchResultEntryCollection = base.GetNextResultCollection(typeof(VlvResponseControl), out directoryControl);
            }
            catch (ADInvalidHandleCookieException ex)
            {
                if (this.vlvRequestControl.ContextId == null || this.vlvRequestControl.ContextId.Length == 0)
                {
                    throw;
                }
                ExTraceGlobals.ADFindTracer.TraceDebug <string>((long)this.GetHashCode(), "ADVlvPagedReader::GetNextResultCollection encounter an exception \"{0}\". Clear the cookie and try again.", ex.Message);
                this.vlvRequestControl.ContextId = null;
                searchResultEntryCollection      = base.GetNextResultCollection(typeof(VlvResponseControl), out directoryControl);
            }
            ADProviderPerf.UpdateProcessCounter(Counter.ProcessRateVlv, UpdateType.Add, 1U);
            ADProviderPerf.UpdateDCCounter(base.PreferredServerName, Counter.DCRateVlv, UpdateType.Add, 1U);
            base.Cookie = ((directoryControl == null) ? null : ((VlvResponseControl)directoryControl).ContextId);
            if (!this.searchForward)
            {
                base.RetrievedAllData = new bool?(true);
            }
            if (directoryControl == null || searchResultEntryCollection.Count == 0)
            {
                base.RetrievedAllData = new bool?(true);
            }
            else
            {
                this.totalCount = ((VlvResponseControl)directoryControl).ContentCount;
                if (this.searchForward && base.PagesReturned == 0)
                {
                    this.offSet = ((VlvResponseControl)directoryControl).TargetPosition;
                    if (!this.includeBookmarkObject)
                    {
                        this.offSet++;
                    }
                }
                if (!this.searchForward)
                {
                    this.offSet = ((VlvResponseControl)directoryControl).TargetPosition - searchResultEntryCollection.Count + 1;
                }
                this.firstEntry = (string)searchResultEntryCollection[0].Attributes[ADRecipientSchema.DisplayName.LdapDisplayName].GetValues(typeof(string))[0];
                this.lastEntry  = (string)searchResultEntryCollection[searchResultEntryCollection.Count - 1].Attributes[ADRecipientSchema.DisplayName.LdapDisplayName].GetValues(typeof(string))[0];
                if (string.Compare(this.firstEntry, this.lastEntry, new CultureInfo(base.Lcid), CompareOptions.OrdinalIgnoreCase) == 0)
                {
                    base.RetrievedAllData = new bool?(true);
                }
                if (this.searchForward)
                {
                    this.vlvRequestControl.Target = Encoding.UTF8.GetBytes(this.lastEntry);
                }
                else
                {
                    this.vlvRequestControl.Target = Encoding.UTF8.GetBytes(this.firstEntry);
                }
            }
            return(searchResultEntryCollection);
        }
Esempio n. 19
0
        // Token: 0x060004A3 RID: 1187 RVA: 0x0001AA18 File Offset: 0x00018C18
        public static void UpdateGlsCallLatency(string apiName, bool isRead, int latencyMsec, bool success)
        {
            GlsProcessPerformanceCountersInstance value = ADProviderPerf.processGlsCounters.Value;

            GlsPerformanceCounters.AverageOverallLatency.IncrementBy((long)latencyMsec);
            GlsPerformanceCounters.AverageOverallLatencyBase.Increment();
            if (isRead)
            {
                GlsPerformanceCounters.AverageReadLatency.IncrementBy((long)latencyMsec);
                GlsPerformanceCounters.AverageReadLatencyBase.Increment();
                if (value != null)
                {
                    value.AverageReadLatency.IncrementBy((long)latencyMsec);
                    value.AverageReadLatencyBase.Increment();
                }
            }
            else
            {
                GlsPerformanceCounters.AverageWriteLatency.IncrementBy((long)latencyMsec);
                GlsPerformanceCounters.AverageWriteLatencyBase.Increment();
                if (value != null)
                {
                    value.AverageWriteLatency.IncrementBy((long)latencyMsec);
                    value.AverageWriteLatencyBase.Increment();
                }
            }
            if (value != null)
            {
                value.AverageOverallLatency.IncrementBy((long)latencyMsec);
                value.AverageOverallLatencyBase.Increment();
                ADProviderPerf.perProcessPercentileGlsLatency.AddValue((long)latencyMsec);
                uint num = (uint)ADProviderPerf.perProcessPercentileGlsLatency.PercentileQuery(95.0);
                value.NinetyFifthPercentileLatency.IncrementBy((long)((ulong)num));
                value.NinetyFifthPercentileLatencyBase.Increment();
                num = (uint)ADProviderPerf.perProcessPercentileGlsLatency.PercentileQuery(99.0);
                value.NinetyNinthPercentileLatency.IncrementBy((long)((ulong)num));
                value.NinetyNinthPercentileLatencyBase.Increment();
                lock (ADProviderPerf.slidingTotalLockRoot)
                {
                    if (success)
                    {
                        ADProviderPerf.successesPerMinute.AddValue(1L);
                    }
                    else
                    {
                        ADProviderPerf.failuresPerMinute.AddValue(1L);
                    }
                }
                ADProviderPerf.InitializeTimerIfRequired();
            }
            switch (apiName)
            {
            case "FindTenant":
                GlsApiPerformanceCounters.FindTenantAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.FindTenantAverageOverallLatencyBase.Increment();
                return;

            case "FindDomain":
            case "FindDomains":
                GlsApiPerformanceCounters.FindDomainAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.FindDomainAverageOverallLatencyBase.Increment();
                return;

            case "FindUser":
                GlsApiPerformanceCounters.FindUserAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.FindUserAverageOverallLatencyBase.Increment();
                return;

            case "SaveTenant":
                GlsApiPerformanceCounters.SaveTenantAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.SaveTenantAverageOverallLatencyBase.Increment();
                return;

            case "SaveDomain":
                GlsApiPerformanceCounters.SaveDomainAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.SaveDomainAverageOverallLatencyBase.Increment();
                return;

            case "SaveUser":
                GlsApiPerformanceCounters.SaveUserAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.SaveUserAverageOverallLatencyBase.Increment();
                return;

            case "DeleteTenant":
                GlsApiPerformanceCounters.DeleteTenantAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.DeleteTenantAverageOverallLatencyBase.Increment();
                return;

            case "DeleteDomain":
                GlsApiPerformanceCounters.DeleteDomainAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.DeleteDomainAverageOverallLatencyBase.Increment();
                return;

            case "DeleteUser":
                GlsApiPerformanceCounters.DeleteUserAverageOverallLatency.IncrementBy((long)latencyMsec);
                GlsApiPerformanceCounters.DeleteUserAverageOverallLatencyBase.Increment();
                return;
            }
            throw new ArgumentException("Unknown API " + apiName);
        }