public TObject Get <TObject>(DirectoryCacheRequest cacheRequest) where TObject : ADRawEntry, new()
        {
            ArgumentValidator.ThrowIfNull("cacheRequest", cacheRequest);
            CacheUtils.PopulateAndCheckObjectType <TObject>(cacheRequest);
            SimpleADObject sADO       = null;
            int            retryCount = 0;
            long           apiTime    = 0L;
            Stopwatch      stopwatch  = Stopwatch.StartNew();

            ExchangeDirectoryCacheProvider.proxyPool.CallServiceWithRetry(delegate(IPooledServiceProxy <IDirectoryCacheClient> proxy)
            {
                Stopwatch stopwatch3 = Stopwatch.StartNew();
                try
                {
                    retryCount++;
                    this.IsNewProxyObject    = string.IsNullOrEmpty(proxy.Tag);
                    GetObjectContext @object = proxy.Client.GetObject(cacheRequest);
                    sADO             = @object.Object;
                    this.ResultState = @object.ResultState;
                    CachePerformanceTracker.AddPerfData(Operation.WCFBeginOperation, @object.BeginOperationLatency);
                    CachePerformanceTracker.AddPerfData(Operation.WCFEndOperation, @object.EndOperationLatency);
                    proxy.Tag = DateTime.UtcNow.ToString();
                }
                finally
                {
                    stopwatch3.Stop();
                    CachePerformanceTracker.AddPerfData(Operation.WCFGetOperation, stopwatch3.ElapsedMilliseconds);
                    apiTime = stopwatch3.ElapsedMilliseconds;
                }
            }, string.Format("Get Object {0}", typeof(TObject).FullName), 3);
            stopwatch.Stop();
            CachePerformanceTracker.AddPerfData(Operation.WCFProxyObjectCreation, stopwatch.ElapsedMilliseconds - apiTime);
            this.RetryCount = retryCount;
            TObject result = default(TObject);

            if (sADO != null)
            {
                Stopwatch stopwatch2 = Stopwatch.StartNew();
                CachePerformanceTracker.AddPerfData(Operation.DataSize, (long)sADO.Data.Length);
                sADO.Initialize(false);
                stopwatch2.Stop();
                CachePerformanceTracker.AddPerfData(Operation.ObjectInitialization, stopwatch2.ElapsedMilliseconds);
                stopwatch2.Restart();
                if (!typeof(TObject).Equals(typeof(ADRawEntry)))
                {
                    result = SimpleADObject.CreateFrom <TObject>(sADO, null, cacheRequest.ADPropertiesRequested);
                }
                else
                {
                    result = (TObject)((object)SimpleADObject.CreateFrom(sADO, cacheRequest.ADPropertiesRequested));
                }
                stopwatch2.Stop();
                CachePerformanceTracker.AddPerfData(Operation.ObjectCreation, stopwatch2.ElapsedMilliseconds);
            }
            return(result);
        }
예제 #2
0
        // Token: 0x06000926 RID: 2342 RVA: 0x00028630 File Offset: 0x00026830
        public GetObjectContext EndGetObject(IAsyncResult result)
        {
            ArgumentValidator.ThrowIfNull("result", result);
            ArgumentValidator.ThrowIfTypeInvalid <LazyAsyncResult>("result", result);
            LazyAsyncResult lazyAsyncResult = (LazyAsyncResult)result;

            if (lazyAsyncResult.EndCalled)
            {
                throw new InvalidOperationException("End was already called. Invalid Begin/End");
            }
            lazyAsyncResult.EndCalled = true;
            GetObjectContext getObjectContext = (GetObjectContext)lazyAsyncResult.AsyncObject;

            this.stopwatch.Stop();
            getObjectContext.EndOperationLatency = this.stopwatch.ElapsedMilliseconds;
            return(getObjectContext);
        }
예제 #3
0
 // Token: 0x06000925 RID: 2341 RVA: 0x000285E4 File Offset: 0x000267E4
 public IAsyncResult BeginGetObject(DirectoryCacheRequest cacheRequest, AsyncCallback callback, object asyncState)
 {
     this.stopwatch = Stopwatch.StartNew();
     return(this.Invoke(delegate
     {
         ArgumentValidator.ThrowIfNull("cacheRequest", cacheRequest);
         if (cacheRequest.ObjectType == ObjectType.ADRawEntry && cacheRequest.Properties == null)
         {
             throw new ArgumentException("properties cannot be null when request object type is ADRawEntry");
         }
         MSExchangeDirectoryCacheServiceCounters.NumberOfCacheReadRequests.Increment();
         GetObjectContext getObjectContext = new GetObjectContext();
         getObjectContext.ResultState = ADCacheResultState.NotFound;
         LazyAsyncResult lazyAsyncResult = new LazyAsyncResult(getObjectContext, asyncState, callback);
         ExTraceGlobals.WCFServiceEndpointTracer.TraceDebug <DirectoryCacheRequest>((long)this.GetHashCode(), "Begin GetObject. Request {0}", cacheRequest);
         MSExchangeDirectoryCacheServiceCounters.CacheHitRatioBase.Increment();
         ObjectTuple objectTuple = null;
         foreach (Tuple <string, KeyType> tuple in cacheRequest.Keys)
         {
             CacheEntry cacheEntry = null;
             foreach (KeyType keyType in DirectoryCacheService.AllSupportedKeyTypes)
             {
                 if ((keyType & tuple.Item2) != KeyType.None)
                 {
                     string composedKey = this.GetComposedKey(cacheRequest.ForestOrPartitionFqdn, tuple.Item1, keyType);
                     string text = (string)CacheManager.Instance.KeyTable.Get(composedKey, null);
                     if (text != null)
                     {
                         cacheEntry = (CacheEntry)CacheManager.Instance.ADObjectCache.Get(text, null);
                         if (cacheEntry != null && cacheEntry[keyType].Contains(composedKey.ToLower()))
                         {
                             break;
                         }
                         if (cacheEntry != null)
                         {
                             if (ExTraceGlobals.WCFServiceEndpointTracer.IsTraceEnabled(TraceType.DebugTrace))
                             {
                                 string keyValues = string.Empty;
                                 cacheEntry[keyType].ForEach(delegate(string keyVal)
                                 {
                                     keyValues += keyVal;
                                     keyValues += ",";
                                 });
                                 ExTraceGlobals.WCFServiceEndpointTracer.TraceDebug <string, string>((long)this.GetHashCode(), "the key {0} does not match the cacheEntry's one {1}", composedKey, keyValues);
                             }
                             cacheEntry = null;
                         }
                     }
                 }
             }
             if (cacheEntry != null)
             {
                 if (cacheEntry.Invalid)
                 {
                     break;
                 }
                 foreach (ObjectTuple objectTuple2 in cacheEntry.SimpleADObjectList)
                 {
                     if (objectTuple2.ObjType == cacheRequest.ObjectType)
                     {
                         objectTuple = objectTuple2;
                         break;
                     }
                 }
                 if (objectTuple == null)
                 {
                     break;
                 }
                 if (cacheRequest.Properties != null)
                 {
                     foreach (string key in cacheRequest.Properties)
                     {
                         if (!objectTuple.ADObject.Properties.ContainsKey(key))
                         {
                             objectTuple = null;
                             getObjectContext.ResultState = ADCacheResultState.PropertiesMissing;
                             ADProviderPerf.UpdateDirectoryADRawCachePropertiesMismatchRate(true);
                             break;
                         }
                     }
                 }
                 if (objectTuple == null)
                 {
                     break;
                 }
                 getObjectContext.Object = objectTuple.ADObject;
                 getObjectContext.ResultState = ADCacheResultState.Succeed;
                 if (cacheRequest.Properties != null)
                 {
                     ADProviderPerf.UpdateDirectoryADRawCachePropertiesMismatchRate(false);
                     break;
                 }
                 break;
             }
         }
         ExTraceGlobals.WCFServiceEndpointTracer.TraceDebug <string, string>((long)this.GetHashCode(), "Begin GetObject. Request {0}. Was Cache {1}", cacheRequest.RequestId, (getObjectContext.Object != null) ? "HIT" : "MISS");
         ADProviderPerf.UpdateDirectoryCacheHitRatio(null != getObjectContext.Object, cacheRequest.ObjectType);
         this.stopwatch.Stop();
         getObjectContext.BeginOperationLatency = this.stopwatch.ElapsedMilliseconds;
         this.stopwatch.Restart();
         callback(lazyAsyncResult);
         return lazyAsyncResult;
     }));
 }