コード例 #1
0
        private void CacheInsert <TResult>(TResult instance, Func <TResult, List <Tuple <string, KeyType> > > getAdditionalKeys = null, IEnumerable <PropertyDefinition> objectProperties = null) where TResult : IConfigurable, new()
        {
            ArgumentValidator.ThrowIfNull("query", instance);
            Stopwatch stopwatch = Stopwatch.StartNew();

            CachePerformanceTracker.StartLogging();
            bool   isNewProxyObject = false;
            int    retryCount       = 0;
            Guid   activityId       = Guid.Empty;
            string callerInfo       = null;
            string error            = null;

            try
            {
                List <Tuple <string, KeyType> > keys = null;
                TSession session = this.GetSession();
                if (session.ActivityScope != null)
                {
                    TSession session2 = this.GetSession();
                    if (session2.ActivityScope.Status == ActivityContextStatus.ActivityStarted)
                    {
                        TSession session3 = this.GetSession();
                        activityId = session3.ActivityScope.ActivityId;
                    }
                }
                TSession session4 = this.GetSession();
                callerInfo = session4.CallerInfo;
                if (getAdditionalKeys != null)
                {
                    keys = getAdditionalKeys(instance);
                }
                ICacheDirectorySession cacheDirectorySession = this.GetCacheSession() as ICacheDirectorySession;
                bool flag = false;
                if (((IDirectorySession)this).SessionSettings.TenantConsistencyMode == TenantConsistencyMode.IgnoreRetiredTenants && (TenantRelocationStateCache.IsTenantRetired((ADObjectId)instance.Identity) || TenantRelocationStateCache.IsTenantArriving((ADObjectId)instance.Identity)))
                {
                    ExTraceGlobals.SessionTracer.TraceWarning <ObjectId>((long)this.GetHashCode(), "CacheInsert. DN {0}. Tenant Is Retired or Arriving, skipping.", instance.Identity);
                }
                else
                {
                    if (!instance.GetType().Equals(CompositeDirectorySession <TSession> .ExchangeConfigUnitCUType) && (TenantRelocationStateCache.IsTenantLockedDown((ADObjectId)instance.Identity) || TenantRelocationStateCache.IsTenantRetired((ADObjectId)instance.Identity)))
                    {
                        flag = true;
                    }
                    int num = flag ? 30 : Configuration.GetCacheExpirationForObject(instance as ADRawEntry);
                    CacheItemPriority cacheItemPriority = flag ? CacheItemPriority.Default : Configuration.GetCachePriorityForObject(instance as ADRawEntry);
                    if (cacheDirectorySession != null)
                    {
                        cacheDirectorySession.Insert(instance, objectProperties, keys, num, cacheItemPriority);
                    }
                    else
                    {
                        TSession tsession = this.GetCacheSession();
                        tsession.Save(instance);
                    }
                    CacheDirectorySession cacheDirectorySession2 = this.GetCacheSession() as CacheDirectorySession;
                    if (cacheDirectorySession2 != null)
                    {
                        isNewProxyObject = cacheDirectorySession2.IsNewProxyObject;
                        retryCount       = cacheDirectorySession2.RetryCount;
                    }
                    ExTraceGlobals.SessionTracer.TraceDebug((long)this.GetHashCode(), "CacheInsert. DN={0}, IsTenantLockedDownOrRetired={1}, CacheExpiration={2}, Priority={3}", new object[]
                    {
                        instance.Identity,
                        flag,
                        num,
                        cacheItemPriority
                    });
                }
            }
            catch (TransientException ex)
            {
                ExTraceGlobals.SessionTracer.TraceError <ObjectId, TransientException>((long)this.GetHashCode(), "CacheInsert. DN {0}. Exception {1}", instance.Identity, ex);
                error = ex.ToString();
            }
            catch (Exception ex2)
            {
                error = ex2.ToString();
                throw;
            }
            finally
            {
                stopwatch.Stop();
                string     cachePerformanceTracker = CachePerformanceTracker.StopLogging();
                ADRawEntry adrawEntry = instance as ADRawEntry;
                CacheProtocolLog.BeginAppend("Save", (adrawEntry != null) ? adrawEntry.GetDistinguishedNameOrName() : "<NULL>", DateTime.MinValue, stopwatch.ElapsedMilliseconds, -1L, -1L, stopwatch.ElapsedMilliseconds, -1L, isNewProxyObject, retryCount, instance.GetType().Name, cachePerformanceTracker, activityId, callerInfo, error);
            }
        }