Beispiel #1
0
 internal static void UserContextRemovedCallback(string key, object value, CacheItemRemovedReason reason)
 {
     try
     {
     }
     finally
     {
         try
         {
             UserContextManager.UserContextCacheWrapper userContextCacheWrapper = value as UserContextManager.UserContextCacheWrapper;
             if (userContextCacheWrapper.UserContext != null)
             {
                 ExTraceGlobals.UserContextTracer.TraceDebug <string, UserContext, int>(0L, "Removing user context from cache, Key={0}, User context instance={1}, Reason={2}", key, userContextCacheWrapper.UserContext, (int)reason);
                 UserContextManager.TerminateSession(userContextCacheWrapper.UserContext, reason);
             }
         }
         catch (ThreadAbortException)
         {
         }
         catch (Exception exception)
         {
             if (Globals.SendWatsonReports)
             {
                 ExTraceGlobals.CoreTracer.TraceDebug(0L, "Sending watson report");
                 ExWatson.SendReport(exception, ReportOptions.None, null);
             }
         }
     }
 }
Beispiel #2
0
        internal static UserContext TryGetUserContextFromCache(UserContextKey userContextKey)
        {
            ExTraceGlobals.UserContextCallTracer.TraceDebug(0L, "UserContextManager.TryGetUserContextFromCache");
            UserContext userContext = null;

            try
            {
                ExTraceGlobals.UserContextTracer.TraceDebug <UserContextKey>(0L, "Attempting to fetch user context from the cache.  Key={0}", userContextKey);
                UserContextManager.UserContextCacheWrapper userContextCacheWrapper = (UserContextManager.UserContextCacheWrapper)HttpRuntime.Cache.Get(userContextKey.ToString());
                if (userContextCacheWrapper != null && userContextCacheWrapper.UserContext != null)
                {
                    userContext = userContextCacheWrapper.UserContext;
                    ExTraceGlobals.UserContextTracer.TraceDebug <UserContextKey, UserContext>(0L, "User context found in cache. Key={0}, User context instance={1}", userContextKey, userContext);
                    userContext.UpdateLastAccessedTime();
                    userContext.Lock(true);
                }
                else
                {
                    ExTraceGlobals.UserContextTracer.TraceDebug <string>(0L, "An object for this user context ID value is not present in the cache (probably was expired), so we are going to reuse the user context ID value for the new session", userContextKey.UserContextId);
                }
            }
            finally
            {
                if (userContext != null && userContext.State != UserContextState.Active && userContext.LockedByCurrentThread())
                {
                    userContext.Unlock();
                    userContext = null;
                }
            }
            return(userContext);
        }
Beispiel #3
0
 internal static void InsertIntoCache(UserContext userContext)
 {
     UserContextManager.UserContextCacheWrapper userContextCacheWrapper = (UserContextManager.UserContextCacheWrapper)HttpRuntime.Cache.Get(userContext.Key.ToString());
     if (userContextCacheWrapper == null)
     {
         userContextCacheWrapper = new UserContextManager.UserContextCacheWrapper();
     }
     userContextCacheWrapper.UserContext = userContext;
     HttpRuntime.Cache.Insert(userContext.Key.ToString(), userContextCacheWrapper, null, DateTime.MaxValue, new TimeSpan(userContext.CalculateTimeout() * 10000L), CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(UserContextManager.UserContextRemovedCallback));
 }
Beispiel #4
0
 internal static OwaRWLockWrapper GetUserContextKeyLock(string userContextKeyString)
 {
     UserContextManager.UserContextCacheWrapper userContextCacheWrapper = (UserContextManager.UserContextCacheWrapper)HttpRuntime.Cache.Get(userContextKeyString);
     if (userContextCacheWrapper == null)
     {
         lock (UserContextManager.lockObject)
         {
             userContextCacheWrapper = (UserContextManager.UserContextCacheWrapper)HttpRuntime.Cache.Get(userContextKeyString);
             if (userContextCacheWrapper == null)
             {
                 userContextCacheWrapper = new UserContextManager.UserContextCacheWrapper
                 {
                     Lock = new OwaRWLockWrapper()
                 };
                 HttpRuntime.Cache.Insert(userContextKeyString, userContextCacheWrapper, null, DateTime.MaxValue, TimeSpan.FromMinutes(2.5), CacheItemPriority.NotRemovable, null);
             }
         }
     }
     return(userContextCacheWrapper.Lock);
 }