private void OnCacheValueBeRemoved(string key, FailFastUserCacheValue cacheValue, RemoveReason reason)
 {
     Logger.TraceInformation(ExTraceGlobals.FailFastCacheTracer, "Remove value from the cache. Key: {0}. CacheValue: {1}. Reason: {2}", new object[]
     {
         key,
         cacheValue.ToString(),
         reason
     });
     FailFastModule.RemotePowershellPerfCounter.FailFastUserCacheSize.RawValue = (long)base.Count;
 }
        protected override void InsertValueToCache(string key, BlockedType blockedType, TimeSpan blockedTime)
        {
            if (!FailFastUserCache.FailFastEnabled)
            {
                return;
            }
            Logger.EnterFunction(ExTraceGlobals.FailFastCacheTracer, "PrimaryFailFastUserCache.InsertValueToCache");
            blockedTime = PrimaryFailFastUserCache.GetValidBlockedTime(blockedTime);
            Logger.TraceDebug(ExTraceGlobals.FailFastCacheTracer, "Try to insert value to the cache. Key: {0}. BlockedType: {1}. BlockedTime: {2}.", new object[]
            {
                key,
                blockedType,
                blockedTime
            });
            FailFastUserCacheValue failFastUserCacheValue;

            if (base.TryGetValue(key, out failFastUserCacheValue) && failFastUserCacheValue.IsValid && failFastUserCacheValue.BlockedType > blockedType)
            {
                Logger.TraceDebug(ExTraceGlobals.FailFastCacheTracer, "Adding blocked type {0} that has smaller scope than existing one {1}.", new object[]
                {
                    blockedType,
                    failFastUserCacheValue.BlockedType
                });
                return;
            }
            if (failFastUserCacheValue == null || !failFastUserCacheValue.IsValid)
            {
                failFastUserCacheValue = new FailFastUserCacheValue(blockedType, blockedTime);
            }
            else
            {
                failFastUserCacheValue.BlockedTime = blockedTime;
                failFastUserCacheValue.BlockedType = blockedType;
                failFastUserCacheValue.AddedTime   = DateTime.UtcNow;
                failFastUserCacheValue.HitCount++;
            }
            Logger.LogEvent(TaskEventLogConstants.Tuple_LogUserAddedToFailFastUserCached, "UserAddedToFailFastCache:" + key, new object[]
            {
                key,
                failFastUserCacheValue.ToString()
            });
            Logger.TraceInformation(ExTraceGlobals.FailFastCacheTracer, "Insert value to the cache. Key: {0}. CacheValue: {1}.", new object[]
            {
                key,
                failFastUserCacheValue.ToString()
            });
            base.InsertAbsolute(key, failFastUserCacheValue, blockedTime, new RemoveItemDelegate <string, FailFastUserCacheValue>(this.OnCacheValueBeRemoved));
            FailFastModule.RemotePowershellPerfCounter.FailFastUserCacheSize.RawValue = (long)base.Count;
            Logger.ExitFunction(ExTraceGlobals.FailFastCacheTracer, "PrimaryFailFastUserCache.InsertValueToCache");
        }
 // Token: 0x06000044 RID: 68 RVA: 0x0000310B File Offset: 0x0000130B
 internal override bool IsUserInCache(string userToken, string userTenant, out string cacheKey, out FailFastUserCacheValue cacheValue, out BlockedReason blockedReason)
 {
     throw new NotSupportedException("The IsUserBlocked should not be invoked from PassiveFailFastUserCache.");
 }
 internal override bool IsUserInCache(string userToken, string userTenant, out string cacheKey, out FailFastUserCacheValue cacheValue, out BlockedReason blockedReason)
 {
     cacheKey      = null;
     cacheValue    = null;
     blockedReason = BlockedReason.None;
     if (!FailFastUserCache.FailFastEnabled)
     {
         return(false);
     }
     Logger.EnterFunction(ExTraceGlobals.FailFastCacheTracer, "PrimaryFailFastUserCache.IsUserBlocked.");
     if (base.TryGetValue(userToken, out cacheValue) && cacheValue.IsValid)
     {
         blockedReason = BlockedReason.BySelf;
         cacheKey      = userToken;
         Logger.TraceDebug(ExTraceGlobals.FailFastCacheTracer, "User key {0} exist. CachedValue: {1}", new object[]
         {
             userToken,
             cacheValue.ToString()
         });
         return(true);
     }
     if (!string.IsNullOrEmpty(userTenant))
     {
         string text = "Tenant:C8E2A9F6-0E7A-4bcc-95A0-9CE1BCA7EE68:" + userTenant;
         if (base.TryGetValue(text, out cacheValue) && cacheValue.IsValid)
         {
             cacheKey      = text;
             blockedReason = BlockedReason.ByTenant;
             Logger.TraceDebug(ExTraceGlobals.FailFastCacheTracer, "Tenant Key {0} exist. CachedValue: {1}", new object[]
             {
                 text,
                 cacheValue.ToString()
             });
             return(true);
         }
     }
     if (base.TryGetValue("AllUsers:D3511BCA-379C-4a38-97E5-0FDA0C231C33", out cacheValue) && cacheValue.IsValid)
     {
         blockedReason = BlockedReason.ByServer;
         cacheKey      = "AllUsers:D3511BCA-379C-4a38-97E5-0FDA0C231C33";
         Logger.TraceDebug(ExTraceGlobals.FailFastCacheTracer, "All User Key {0} exist. CacheValue: {1}", new object[]
         {
             "AllUsers:D3511BCA-379C-4a38-97E5-0FDA0C231C33",
             cacheValue.ToString()
         });
         return(true);
     }
     Logger.ExitFunction(ExTraceGlobals.FailFastCacheTracer, "PrimaryFailFastUserCache.IsUserBlocked.");
     return(false);
 }
 // Token: 0x06000006 RID: 6 RVA: 0x000021D0 File Offset: 0x000003D0
 internal static bool ShouldFailFastUserInCache(string userToken, string cacheKey, FailFastUserCacheValue cacheValue, BlockedReason blockedReason)
 {
     Logger.EnterFunction(ExTraceGlobals.FailFastModuleTracer, "ConnectedUserManager.ShouldFailFastUserInCache");
     if (blockedReason == BlockedReason.BySelf)
     {
         if (cacheValue.HitCount >= 3)
         {
             Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "User {0} is considered fail-fast because blocked reason is Self. cacheValue: {1}", new object[]
             {
                 userToken,
                 cacheValue
             });
             return(true);
         }
         return(false);
     }
     else
     {
         bool flag;
         if (!ConnectedUserManager.connectedUserCache.TryGetValue(userToken, out flag))
         {
             Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "User {0} is considered fail-fast because he is not in connected user cache.", new object[]
             {
                 userToken
             });
             return(true);
         }
         Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "ConnectedUserManager.ShouldFailFastUserInCache");
         return(false);
     }
 }