コード例 #1
0
        public JsonResult GetNewMessages()
        {
            if (Session["Account"] == null)
            {
                return(Json("overtime", JsonRequestBehavior.AllowGet));
            }
            StringBuilder sbid   = new StringBuilder();
            StringBuilder sbname = new StringBuilder();
            List <MIS_WebIM_SenderModel> senderList = messageBLL.GetSenderByReceiver(GetUserId());

            if (senderList != null)
            {
                foreach (MIS_WebIM_SenderModel model in senderList)
                {
                    sbid.Append(model.Sender + ",");
                    sbname.Append(model.SenderTitle + ",");
                }
            }
            //获取消息总数
            int mesCount = senderList.Sum(a => a.MessageCount);

            OnlineHttpModule.ProcessRequest();
            //格式
            //在线人数
            OnlineUserRecorder recorder = HttpContext.Cache[OnlineHttpModule.g_onlineUserRecorderCacheKey] as OnlineUserRecorder;

            return(Json(JsonHandler.CreateMessage(recorder.GetUserList().Count, sbid.ToString() + "|" + sbname.ToString(), mesCount.ToString()), JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        /// <summary>
        /// 获取全部人员
        /// </summary>
        /// <param name="id"></param>
        /// <param name="text"></param>
        /// <param name="value"></param>
        /// <param name="checkState"></param>
        /// <returns></returns>
        public JsonResult GetTreeByEasyui(string id)
        {
            OnlineUserRecorder    recorder = HttpContext.Cache[OnlineHttpModule.g_onlineUserRecorderCacheKey] as OnlineUserRecorder;
            List <SysStructModel> list     = structBLL.GetList(id);
            List <SysUser>        userList = sysUserBLL.GetListByDepId(id);

            if (userList.Count > 0)
            {
                foreach (var user in userList)
                {
                    SysStructModel addUserToStruct = new SysStructModel();
                    addUserToStruct.Id   = user.Id;
                    addUserToStruct.Name = user.TrueName;
                    addUserToStruct.Type = "member";
                    list.Insert(0, addUserToStruct);//把人员加进组
                }
            }
            var json = from m in list
                       select new SysStructUserModel()
            {
                id         = m.Id,
                text       = "<input id=\"" + m.Id + "\" class=\"" + (m.Type == "group" ? "CBGroup" : "CBMember") + "\" type=\"checkbox\" ref=\"" + id + "\" value=\"" + m.Id + "\" />" + m.Name,          //text
                attributes = m.Name,
                iconCls    = m.Type == "group" ? "fa fa-users color-green" : SetOnlineIcon(m.Id, recorder),
                state      = m.Type == "group" ? "closed" : "open"
            };

            return(Json(json));
        }
コード例 #3
0
        //判断用户是否在线
        public string SetOnlineIcon(string id, OnlineUserRecorder recorder)
        {
            if (recorder == null)
            {
                return("fa fa-user color-gray");
            }
            // 绑定在线用户列表
            IList <OnlineUser> userList = recorder.GetUserList();
            bool b = false;

            foreach (var OnlineUser in userList)
            {
                if (id == OnlineUser.UserName)
                {
                    b = true;
                }
            }
            if (b)
            {
                return("fa fa-user color-green");
            }
            else
            {
                return("fa fa-user color-gray");
            }
        }
コード例 #4
0
 public ActionResult Index()
 {
     if (Session["Account"] != null)
     {
         //获取是否开启WEBIM
         ViewBag.IsEnable = siteConfig.webimstatus;
         //获取信息间隔时间
         ViewBag.NewMesTime = siteConfig.refreshnewmessage;
         //系统名称
         ViewBag.WebName = siteConfig.webname;
         //公司名称
         ViewBag.ComName = siteConfig.webcompany;
         //网站标题
         ViewBag.Title = siteConfig.webtitle;
         //版权
         ViewBag.CopyRight = siteConfig.webcopyright;
         //在线人数
         OnlineUserRecorder recorder = HttpContext.Cache[OnlineHttpModule.g_onlineUserRecorderCacheKey] as OnlineUserRecorder;
         ViewBag.OnlineCount = recorder.GetUserList().Count;
         Account account = new Account();
         account = (Account)Session["Account"];
         return(View(account));
     }
     else
     {
         return(RedirectToAction("Index", "Account"));
     }
 }
コード例 #5
0
        // 缓存键
        //public static readonly string g_onlineUserRecorderCacheKey = "__OnlineUserRecorder";

        public static void Register()
        {
            try
            {
                // 获取在线用户记录器
                OnlineUserRecorder recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;

                if (recorder == null)
                {
                    // 创建记录器工厂
                    OnlineUserRecorderFactory factory = new OnlineUserRecorderFactory();

                    // 设置用户超时时间
                    var authConfig = (AuthenticationSection)ConfigurationManager.GetSection("system.web/authentication");
                    factory.UserTimeOutMinute = (int)authConfig.Forms.Timeout.TotalMinutes;
                    // 统计时间间隔
                    factory.StatisticEventInterval = 0; // 禁止修改

                    // 创建记录器
                    recorder = factory.Create();

                    // 缓存记录器
                    HttpContext.Current.Cache.Insert(SessionConst.OnlineUserRecorderCacheKey, recorder);
                }
            }
            catch (Exception ex)
            {
                _logger.Info(ex);
            }
        }
コード例 #6
0
        public static int GetDummyUniqueID(int minId)
        {
            // 获取在线用户记录器
            OnlineUserRecorder recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;

            if (recorder == null)
            {
                Register();
                recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;
            }

            int minDummyUniqueID = minId;

            var dummyUsers = recorder.GetUserList().Where(u => u.UniqueID >= minId).OrderBy(u => u.UniqueID).ToList();

            for (var i = 0; i < dummyUsers.Count; i++)
            {
                if (i < dummyUsers.Count - 1)
                {
                    // 两个用户之间的UniqueID差 > 1
                    if (dummyUsers[i + 1].UniqueID - dummyUsers[i].UniqueID > 1)
                    {
                        minDummyUniqueID = dummyUsers[i].UniqueID;
                        break;
                    }
                }
                else
                {
                    minDummyUniqueID = dummyUsers[i].UniqueID;
                }
            }

            return(minDummyUniqueID + 1);
        }
コード例 #7
0
        public static void ProcessRequest()
        {
            try
            {
                // 获取在线用户记录器
                OnlineUserRecorder recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;

                if (recorder == null)
                {
                    Register();
                    recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;
                }

                OnlineUser onlineUser = new OnlineUser();

                //注意session的名称是和登录保存的名称一致
                Data.Entities.User user = (Data.Entities.User)HttpContext.Current.Session[SessionConst.LoginUser];

                //用于限制用户只能在一处登录
                onlineUser.AuthenticationId = AuthenticationUtil.GetLoginUserGuid();

                onlineUser.UniqueID = user.UserId;
                //父级UserName
                onlineUser.ParentUserId = user.ParentUserId;
                //祖父级UserName
                //if (user.ParentUserId.HasValue)
                //{
                //    onlineUser.GrandUserId = new UserService().GetParentUserId(user.ParentUserId.Value);
                //}

                // 用户名称
                onlineUser.UserName = user.UserName;
                // 用户头像
                onlineUser.Avatar = user.Avatar;
                // 用户角色
                //onlineUser.UserDegree = user.UserRoles.First().RoleId;
                // SessionID
                onlineUser.SessionID = HttpContext.Current.Session.SessionID;
                // IP 地址
                //onlineUser.ClientIP = IPUtil.GetHostAddress();
                // 登录时间
                if (!onlineUser.LoginTime.HasValue)
                {
                    onlineUser.LoginTime = DateTime.Now;
                }
                // 最后活动时间
                onlineUser.ActiveTime = DateTime.Now;
                // 最后请求地址
                onlineUser.RequestURL = HttpContext.Current.Request.RawUrl;

                // 保存用户信息
                recorder.Persist(onlineUser);
            }
            catch (Exception ex)
            {
                _logger.Info(ex);
            }
        }
コード例 #8
0
        // 取最小的 还未在房间中 使用的车号
        public static int GetMinMotoNum(int roomLevel, int deskNo)
        {
            var minNums = 1;

            OnlineUserRecorder recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;

            var deskUsers = recorder.GetUsers(roomLevel, deskNo);

            for (int num = 1; num <= 10; num++)
            {
                if (!deskUsers.Where(u => u.Num == num).Any())
                {
                    minNums = num;
                    break;
                }
            }

            return(minNums);
        }
コード例 #9
0
ファイル: OnlineHttpModule.cs プロジェクト: haiyoufan/Apps
        public static void ProcessRequest()
        {
            // 获取在线用户记录器
            OnlineUserRecorder recorder = HttpContext.Current.Cache[g_onlineUserRecorderCacheKey] as OnlineUserRecorder;

            if (recorder == null)
            {
                // 创建记录器工厂
                OnlineUserRecorderFactory factory = new OnlineUserRecorderFactory();

                // 设置用户超时时间
                factory.UserTimeOutMinute = 2;

                // 统计时间间隔
                factory.StatisticEventInterval = 20;

                // 创建记录器
                recorder = factory.Create();

                // 缓存记录器
                HttpContext.Current.Cache.Insert(g_onlineUserRecorderCacheKey, recorder);
            }

            OnlineUser user = new OnlineUser();


            AccountModel model = (AccountModel)HttpContext.Current.Session["Account"];//注意session的名称是和登录保存的名称一致

            // 用户名称
            user.UserName = Convert.ToString(model.Id);
            // SessionID
            user.SessionID = HttpContext.Current.Session.SessionID;
            // IP 地址
            user.ClientIP = HttpContext.Current.Request.UserHostAddress;
            // 最后活动时间
            user.ActiveTime = DateTime.Now;
            // 最后请求地址
            user.RequestURL = HttpContext.Current.Request.RawUrl;

            // 保存用户信息
            recorder.Persist(user);
        }
コード例 #10
0
        public static void AddOnlineUser(OnlineUser onlineUser)
        {
            try
            {
                // 获取在线用户记录器
                OnlineUserRecorder recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;

                if (recorder == null)
                {
                    Register();
                    recorder = HttpContext.Current.Cache[SessionConst.OnlineUserRecorderCacheKey] as OnlineUserRecorder;
                }


                //用于限制用户只能在一处登录
                onlineUser.AuthenticationId = AuthenticationUtil.GetLoginUserGuid();

                // 用户角色
                //onlineUser.UserDegree = user.UserRoles.First().RoleId;
                // SessionID
                onlineUser.SessionID = HttpContext.Current.Session != null ? HttpContext.Current.Session.SessionID : onlineUser.UserName;
                // IP 地址
                //onlineUser.ClientIP = IPUtil.GetHostAddress();
                // 登录时间
                if (!onlineUser.LoginTime.HasValue)
                {
                    onlineUser.LoginTime = DateTime.Now;
                }
                // 最后活动时间
                onlineUser.ActiveTime = DateTime.Now;
                // 最后请求地址
                onlineUser.RequestURL = HttpContext.Current.Request.RawUrl;

                // 保存用户信息
                recorder.AddUser(onlineUser);
            }
            catch (Exception ex)
            {
                _logger.Info(ex);
            }
        }
コード例 #11
0
        public JsonResult GetPartData6()
        {
            // 获取在线用户记录器
            OnlineUserRecorder recorder = HttpContext.Cache[OnlineHttpModule.g_onlineUserRecorderCacheKey] as OnlineUserRecorder;
            StringBuilder      sb       = new StringBuilder("");

            if (recorder == null)
            {
                return(Json("在线用户", JsonRequestBehavior.AllowGet));
            }

            //// 绑定在线用户列表
            IList <OnlineUser> userList = recorder.GetUserList();

            sb.AppendFormat("在线用户:<br>");
            foreach (var OnlineUser in userList)
            {
                sb.AppendFormat(OnlineUser.UserName + "<br>");
            }
            return(Json(sb.ToString(), JsonRequestBehavior.AllowGet));
        }