Exemplo n.º 1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="ipAddress">IP地址</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状消息</param>
        /// <returns>用户实体</returns>
        public BaseUserInfo UserLogOn(BaseUserInfo userInfo, string userName, string password, bool createOpenId, out string returnStatusCode, out string returnStatusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            returnStatusCode    = StatusCode.DbError.ToString();
            returnStatusMessage = string.Empty;

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            BaseSystemInfo.IsAuthorized(userInfo);
            #endif

            BaseUserInfo returnUserInfo = null;
            // statusCode = ServiceSecurityContext.Current.PrimaryIdentity.Name;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    // 先侦测是否在线
                    userManager.CheckOnLine();
                    // 再进行登录
                    returnUserInfo      = userManager.LogOn(userName, password, createOpenId);
                    returnStatusCode    = userManager.ReturnStatusCode;
                    returnStatusMessage = userManager.GetStateMessage(returnStatusCode);
                    // 登录时会自动记录进行日志记录,所以不需要进行重复日志记录
                    // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart, ConsoleColor.Red);
            #endif

            return(returnUserInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 按用户名登录
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userName">用户名</param>
        /// <param name="returnStatusCode">返回状态码</param>
        /// <param name="returnStatusMessage">返回状消息</param>
        /// <returns>用户实体</returns>
        public BaseUserInfo LogOnByUserName(BaseUserInfo userInfo, string userName, out string returnStatusCode, out string returnStatusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            BaseSystemInfo.IsAuthorized(userInfo);
            #endif

            BaseUserInfo returnUserInfo = null;
            returnStatusCode    = string.Empty;
            returnStatusMessage = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    // 先侦测是否在线
                    userManager.CheckOnLine();
                    // 再进行登录
                    returnUserInfo      = userManager.LogOnByUserName(userName, userInfo.IPAddress, userInfo.MACAddress);
                    returnStatusCode    = userManager.ReturnStatusCode;
                    returnStatusMessage = userManager.GetStateMessage();
                    // 登录时会自动记录进行日志记录,所以不需要进行重复日志记录
                    // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnUserInfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获得内部员工列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetStaffUserDT(BaseUserInfo userInfo)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            DataTable dataTable = new DataTable(BaseStaffEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    // 检查用户在线状态(服务器专用)
                    BaseUserManager userManager = new BaseUserManager(dbHelper);
                    userManager.CheckOnLine();
                    // 获取允许登录列表
                    List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldIsStaff, 1));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0));
                    dataTable           = userManager.GetDataTable(parameters, BaseStaffEntity.FieldSortCode);
                    dataTable.TableName = BaseUserEntity.TableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogOnService_GetStaffUserDT, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(dataTable);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 服务器端检查在线状态
        /// </summary>
        /// <returns>离线人数</returns>
        public int ServerCheckOnLine()
        {
            int returnValue = 0;

            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseUserManager userManager = new BaseUserManager(dbHelper);
                    returnValue = userManager.CheckOnLine();
                }
                catch (Exception ex)
                {
                    LogUtil.WriteException(ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }
            return(returnValue);
        }
Exemplo n.º 6
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);
        }