Exemple #1
0
        private static void RemoveExpiredSession()
        {
            DateTime      ep       = DateTime.Now.AddMonths(-3); //把3个月前的session 全部干掉。
            List <string> toremove = new List <string>();

            foreach (var key in _SessionPools)
            {
                if (key.Value.CreatedTime <= ep)
                {
                    toremove.Add(key.Key);
                }
            }
            SessionIdentity si = new SessionIdentity();

            foreach (string k in toremove)
            {
                //log
                if (_SessionPools[k] == null)
                {
                    marsLog.InfoFormat(string.Format("缓存中不存在此用户信息:SessionId:{0}", k));
                }
                else
                {
                    _SessionPools.TryRemove(k, out si);
                    marsLog.InfoFormat(string.Format("用户移除统计:SessionId:{0}  UserId:{1}  CreatedTime:{2}", si.SessionID, si.UserID, si.CreatedTime.ToString()));
                }
            }
        }
Exemple #2
0
        public static bool RefreshSessionIdentity(string sessionid)
        {
            SessionIdentity si = new SessionIdentity();

            if (_SessionPools.TryGetValue(sessionid, out si))
            {
                si.CreatedTime = DateTime.Now;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        public static string AddSessionIdentity(UserSessionEntity user)
        {
            SessionIdentity si = new SessionIdentity();

            si.CreatedTime = DateTime.Now;
            si.SessionID   = Guid.NewGuid().ToString("N");
            si.UserID      = user.UserID;
            si.ZoneID      = user.ZoneID;
            if (_SessionPools.TryAdd(si.SessionID, si))
            {
                return(si.SessionID);
            }
            else
            {
                return(string.Empty);
            }
        }
Exemple #4
0
        public static SessionIdentity GetIdentity(string sessionid)
        {
            if (sessionid.ToLower() == CommonSessionID)
            {
                return(new SessionIdentity()
                {
                    SessionID = CommonSessionID, UserID = 0
                });
            }
            SessionIdentity si = new SessionIdentity();

            if (_SessionPools.TryGetValue(sessionid, out si))
            {
                return(si);
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        public static bool RemoveSessionIdentity(string sessionid)
        {
            SessionIdentity si = new SessionIdentity();

            return(_SessionPools.TryRemove(sessionid, out si));
        }