/// <summary> /// 创建新的用户Session /// </summary> /// <param name="userID"></param> /// <param name="ip"></param> /// <param name="mac"></param> /// <param name="stateEvent"></param> /// <param name="sessionEvent">触发创建的事件类型</param> /// <returns></returns> public UserSession CreateSession(string userID, string ip, string mac, LoginTypeEnum authType, UserSessionEventEnum sessionEvent) { UserSession session = new UserSession(userID); session.LogonInfo.IP = ip; session.LogonInfo.MAC = mac; session.LogonInfo.AuthType = authType; session.SessionEvent = sessionEvent; try { lock (_sessions) { _sessions.Add(session.SessionID, session); } } catch (Exception) { } /*--写事件日志开始--*/ SysEvent evt = new SysEvent(); evt.UserID = session.User.UserID; evt.LoginName = session.User.LoginName; evt.IP = session.LogonInfo.IP; evt.Record = String.Format("CreateSession({0}, {1}, {2}, {3})", userID, ip, authType.ToString(), sessionEvent.ToString()); evt.DoCreate(); /*--写事件日志结束--*/ return(session); }
/// <summary> /// 写日志 /// </summary> /// <param name="msg"></param> /// <param name="logType"></param> public static void Log(string msg, string logType) { SysEvent evt = new SysEvent(); if (PortalService.CurrentUserInfo != null) { evt.UserID = PortalService.CurrentUserInfo.UserID; evt.LoginName = PortalService.CurrentUserInfo.LoginName; } evt.IP = HttpContext.Current.Request.UserHostAddress; evt.Type = logType; evt.Record = msg; evt.DoCreate(); }
/// <summary> /// 创建新的用户Session /// </summary> /// <param name="userID"></param> /// <param name="ip"></param> /// <param name="mac"></param> /// <param name="stateEvent"></param> /// <returns></returns> public UserSession CreateSession(string userID, string ip, string mac, LoginTypeEnum authType) { UserSession[] orgSession = _sessions.Values.Where(s => s.User.UserID == userID).ToArray(); UserSession session; if (orgSession.Count() <= 0) { session = new UserSession(userID); session.LogonInfo.IP = ip; session.LogonInfo.MAC = mac; session.LogonInfo.AuthType = authType; if (authType == LoginTypeEnum.PCIE || authType == LoginTypeEnum.PCClient) { session.SessionEvent = UserSessionEventEnum.Login; } try { lock (_sessions) { _sessions.Add(session.SessionID, session); } } catch (Exception) { } } else { session = orgSession[0]; session.RefreshState(); } /*--写事件日志开始--*/ SysEvent evt = new SysEvent(); evt.UserID = session.User.UserID; evt.LoginName = session.User.LoginName; evt.IP = session.LogonInfo.IP; evt.Record = String.Format("CreateSession({0}, {1}, {2}, {3})", userID, ip, mac, authType.ToString()); evt.DoCreate(); /*--写事件日志结束--*/ return(session); }
/// <summary> /// 用户注销或者页面超时时释放用户状态对象 /// </summary> /// <param name="passCode"></param> /// <param name="sessionEvent">触发事件方式</param> /// <returns></returns> public bool ReleaseSession(string sessionID, UserSessionEventEnum sessionEvent) { UserSession userSession = (UserSession)_sessions[sessionID]; userSession.SessionEvent = sessionEvent; // 若触发事件为logout(主动登出), 则若登入方式为未知的话,则放弃登出 if (sessionEvent == UserSessionEventEnum.Logout && userSession.SessionEvent != UserSessionEventEnum.Login) { // return false; } if (userSession != null) { /*--写事件日志开始--*/ SysEvent evt = new SysEvent(); evt.UserID = userSession.User.UserID; evt.LoginName = userSession.User.LoginName; evt.IP = userSession.LogonInfo.IP; evt.Record = String.Format("ReleaseSession({0}, {1})", sessionID, sessionEvent.ToString()); evt.DoCreate(); /*--写事件日志结束--*/ lock (_sessions) { _sessions.Remove(sessionID); } return(true); } else { return(false); } }