Example #1
0
 public void UpdateUserInfo(string userID, SessionUser userInfo)
 {
     foreach (string key in new ArrayList(hashtable.Keys))
     {
         SessionUser entity = hashtable[key] as SessionUser;
         if (entity != null && entity.UserName.Equals(userID))
         {
             hashtable[key] = userInfo;
         }
     }
 }
Example #2
0
 internal void Refresh()
 {
     foreach (string key in new ArrayList(hashtable.Keys))
     {
         SessionUser entity = hashtable[key] as SessionUser;
         if (entity == null || (DateTime.Now - entity.LastActiveTime).TotalMinutes > timeout)
         {
             hashtable.Remove(key);
         }
     }
 }
Example #3
0
        /// <summary>
        /// 根据Session ID,获取登录信息
        /// </summary>
        /// <param name="key">Session ID</param>
        /// <returns>登录信息,如果不存在则返回NULL</returns>
        public SessionUser GetConnect(string key)
        {
            SessionUser result = null;

            if (hashtable.ContainsKey(key))
            {
                result = hashtable[key] as SessionUser;
                result.LastActiveTime = DateTime.Now;
                hashtable[key]        = result;
            }
            return(result);
        }
Example #4
0
 /// <summary>
 /// 根据用户ID设置登录状态
 /// </summary>
 /// <param name="userID">用户ID</param>
 /// <param name="State">登录状态</param>
 /// <param name="Agent">连接媒介</param>
 internal void SetStateByUserID(string userID, ConnectState State, ConnectAgent Agent)
 {
     foreach (string key in new ArrayList(hashtable.Keys))
     {
         SessionUser entity = hashtable[key] as SessionUser;
         if (entity != null && entity.UserName.Equals(userID) && entity.Agent.Equals(Agent))
         {
             entity.State   = State;
             hashtable[key] = entity;
         }
     }
 }
Example #5
0
 /// <summary>
 /// 登录信息添加到缓存
 /// </summary>
 /// <param name="key">Session ID</param>
 /// <param name="userInfo">登录信息</param>
 public void Add(string key, SessionUser userInfo)
 {
     // 挤掉先前登录的用户
     //SetStateByUserID(userInfo.UserName, ConnectStatus.AnotherConnected, userInfo.Agent);
     // 添加缓存
     if (hashtable.ContainsKey(key))
     {
         hashtable[key] = userInfo;
     }
     else
     {
         hashtable.Add(key, userInfo);
     }
 }
Example #6
0
        /// <summary>
        /// 获取在线用户
        /// </summary>
        /// <returns>登录信息列表</returns>
        public IList <SessionUser> OnlineUsers()
        {
            IList <SessionUser> result = new List <SessionUser>();

            foreach (string key in new ArrayList(hashtable.Keys))
            {
                SessionUser entity = hashtable[key] as SessionUser;
                if (entity != null && entity.State.Equals(ConnectState.Connection))
                {
                    result.Add(entity);
                }
            }
            return(result);
        }
Example #7
0
 public SessionUser GetUserByUserName(string userId)
 {
     try
     {
         foreach (string key in new ArrayList(hashtable.Keys))
         {
             SessionUser entity = hashtable[key] as SessionUser;
             if (entity != null && entity.Name == userId)
             {
                 return(entity);
             }
         }
     }
     catch (Exception)
     {
         return(null);
     }
     return(null);
 }