/// <summary> /// 用户现在 /// </summary> /// <param name="userInfo">用户</param> /// <param name="onLineState">用户在线状态</param> public void OnLine(BaseUserInfo userInfo, int onLineState = 1) { // 写入调试信息 #if (DEBUG) // int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogOnService_OnLine, MethodBase.GetCurrentMethod()); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); userManager.OnLine(userInfo.Id, onLineState); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) // BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart, ConsoleColor.Green); #endif }
/// <summary> /// 获取在线用户列表 /// </summary> /// <param name="userInfo">用户</param> /// <returns>数据表</returns> public DataTable GetOnLineState(BaseUserInfo userInfo) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 是否需要获取用户状态 bool getOnLine = false; // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif lock (locker) { using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); // 设置为在线状态 userManager.OnLine(userInfo.Id); if (MessageService.LaseOnLineStateCheck == DateTime.MinValue) { getOnLine = true; } else { // 2008.01.23 JiRiGaLa 修正错误 TimeSpan timeSpan = DateTime.Now - MessageService.LaseOnLineStateCheck; if ((timeSpan.Minutes * 60 + timeSpan.Seconds) >= BaseSystemInfo.OnLineCheck) { getOnLine = true; } } if (OnLineStateDT == null || getOnLine) { // 检查用户在线状态(服务器专用) userManager.CheckOnLine(); // 获取在线状态列表 OnLineStateDT = userManager.GetOnLineStateDT(); OnLineStateDT.TableName = BaseUserEntity.TableName; MessageService.LaseOnLineStateCheck = DateTime.Now; } // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } } // 写入调试信息 #if (DEBUG) if (getOnLine) { BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); } #endif return OnLineStateDT; }
/// <summary> /// 获取消息状态 /// </summary> /// <param name="userInfo">用户</param> /// <param name="onLineState">用户在线状态</param> /// <param name="lastChekDate">最后检查日期</param> /// <returns>消息状态数组</returns> public string[] MessageChek(BaseUserInfo userInfo, int onLineState, string lastChekDate) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string[] returnValue = null; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); // 设置为在线状态 BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); userManager.OnLine(userInfo.Id, onLineState); // 读取信息状态 BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); returnValue = messageManager.MessageChek(); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_MessageChek, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 检查在线状态 /// </summary> /// <param name="userInfo">用户</param> /// <param name="onLineState">用户在线状态</param> /// <returns>离线人数</returns> public int CheckOnLine(BaseUserInfo userInfo, int onLineState) { // 写入调试信息 #if (DEBUG) // int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper); // 设置为在线状态 userManager.OnLine(userInfo.Id, onLineState); returnValue = userManager.CheckOnLine(); } catch (Exception ex) { LogUtil.WriteException(ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) // BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }