示例#1
0
        /// <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);
        }