Пример #1
0
        // PRIVATE STATIC
        // The idea is that the thread will sleep based on the shortest timespan for the session in place
        private static void ExpireIdleSessions()
        {
            TimeSpan timeout = SessionManager.sessionMaxIdleTime;

            while (sessionThreadFlag)
            {
                foreach (string key in SessionManager.sessionsBag.Keys)
                {
                    SessionContainer sessionContainer = (SessionContainer)SessionManager.sessionsBag[key];

                    if (sessionContainer.NeedExpireSession(SessionManager.sessionMaxIdleTime))
                    {
                        if (!SessionManager.sessionsBag.TryRemove(key, out SessionContainer container))
                        {
                            Console.WriteLine("On ExpireIdleSessions - Could not remove SessionContainer from sessions bag - sessionId=[" + key + "]");
                        }

                        if (SessionManager.sessionsBag.Count == 0)
                        {
                            SessionManager.sessionThreadFlag = false;
                        }
                    }
                    else
                    {
                        TimeSpan expirationTime = sessionContainer.GetExpirationDurationInMinutes(SessionManager.sessionMaxIdleTime);

                        if (expirationTime.CompareTo(timeout) < 0)
                        {
                            timeout = expirationTime;
                        }
                    }
                }
                Thread.Sleep(timeout);
            }
        }
Пример #2
0
        public static bool SetValue(string sessionId, string key, object value)
        {
            bool bRet = false;

            if (SessionManager.sessionsBag.ContainsKey(sessionId))
            {
                SessionContainer sessionContainer = (SessionContainer)SessionManager.sessionsBag[sessionId];

                if (!sessionContainer.NeedExpireSession(SessionManager.sessionMaxIdleTime))
                {
                    sessionContainer.SetValue(key, value);
                    bRet = true;
                }
            }

            return(bRet);
        }
Пример #3
0
        public static object GetValue(string sessionId, string key)
        {
            object objRet = null;

            if (SessionManager.sessionsBag.ContainsKey(sessionId))
            {
                SessionContainer sessionContainer = (SessionContainer)SessionManager.sessionsBag[sessionId];

                if (sessionContainer.NeedExpireSession(SessionManager.sessionMaxIdleTime))
                {
                    if (!SessionManager.sessionsBag.TryRemove(sessionId, out SessionContainer container))
                    {
                        Console.WriteLine("On GetValue - Could not remove SessionContainer from sessions bag - sessionId=[" + sessionId + "]");
                    }
                }
                else
                {
                    objRet = sessionContainer.GetValue(key);
                }
            }
            return(objRet);
        }
Пример #4
0
        public static bool IsSessionExpired(string sessionId)
        {
            bool bRet = false;

            if (SessionManager.sessionsBag.ContainsKey(sessionId))
            {
                SessionContainer sessionContainer = (SessionContainer)SessionManager.sessionsBag[sessionId];

                if (sessionContainer.NeedExpireSession(SessionManager.sessionMaxIdleTime))
                {
                    bRet = true;
                    if (!SessionManager.sessionsBag.TryRemove(sessionId, out SessionContainer container))
                    {
                        Console.WriteLine("On IsSessionExpired - Could not remove SessionContainer from sessions bag - sessionId=[" + sessionId + "]");
                    }
                }
            }
            else
            {
                bRet = true;
            }

            return(bRet);
        }