public static void AddUserConn(MyConn conn) { if (conn != null) { string userId = conn.MyUserId; if (!string.IsNullOrWhiteSpace(userId)) { User user; if (!UserDic.ContainsKey(userId)) { user = new User(); user.UserId = userId; user.UserName = string.Format("user_{0}", userId); user.MyConnDic.Add(conn.MyConnId, conn); UserDic.Add(userId, user); } else { user = UserDic[userId]; if (!user.MyConnDic.ContainsKey(conn.MyConnId)) { user.MyConnDic.Add(conn.MyConnId, conn); } } } } }
public static void RemoveUserConn(MyConn conn) { if (conn != null) { string userId = conn.MyUserId; if (!string.IsNullOrWhiteSpace(userId)) { User user; if (UserDic.ContainsKey(userId)) { user = UserDic[userId]; user.MyConnDic.Remove(conn.MyConnId); } } } }