Beispiel #1
0
        public string Monitor()
        {
            string hash = Request["Hash"];
            //更新客服在线缓存列表
            OnlineKFModel onlineKFModel = MessageManager.Instance.GetOnlineKFInfo(KfNumberId);

            if (onlineKFModel == null)
            {
                //更新客服在线缓存列表
                onlineKFModel                = new OnlineKFModel();
                onlineKFModel.Hash           = hash;
                onlineKFModel.KfNumberId     = KfNumberId;
                onlineKFModel.LastActiveDate = DateTime.Now;
                MessageManager.Instance.CacheLocalKF(onlineKFModel);
            }
            else
            {
                //判断hash
                if (!string.Equals(hash, onlineKFModel.Hash, StringComparison.OrdinalIgnoreCase))
                {
                    return("0");
                }
                onlineKFModel.LastActiveDate = DateTime.Now;
                MessageManager.Instance.CacheLocalKF(onlineKFModel);
            }

            return("1");
        }
Beispiel #2
0
        public ActionResult Chat()
        {
            if (base.LoginAdmin.KfNumbers.Count == 0)
            {
                return(Content("请选分配工号给当前管理员,方可进入客服服务界面"));
            }

            KfNumber kfNumber = (KfNumber)base.LoginAdmin.KfNumbers.ToList()[0];

            //设置客服为上线状态
            kfNumber.IsOnline = true;
            _kfNumberService.Update(kfNumber);
            //填充页面信息
            ViewBag.Department   = base.LoginAdmin.PermissionOrganization.Name;
            ViewBag.KfNumber     = kfNumber.Number + "[" + kfNumber.NickName + "]";
            ViewBag.RoleName     = base.LoginAdmin.PermissionRole.Name;
            ViewBag.OnlineStatus = kfNumber.OnlineStatus;
            string hash = Guid.NewGuid().ToString();

            ViewBag.Hash = hash;
            //获取与当前客服还未结束的会话
            IList <KfMeeting> listKfMeeting = _kfMeetingService.Table.Where(k => k.KfNumberId == kfNumber.Id && !k.IsEnd).ToList();

            ViewBag.ListKfMeeting = listKfMeeting;
            //更新在线客服缓存
            OnlineKFModel onlineKFModel = new OnlineKFModel();

            onlineKFModel.Hash           = hash;
            onlineKFModel.KfNumberId     = kfNumber.Id;
            onlineKFModel.LastActiveDate = DateTime.Now;
            MessageManager.Instance.CacheLocalKF(onlineKFModel);
            return(View());
        }
Beispiel #3
0
        /// <summary>
        /// 定时器事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // 清除不在线客服
            lock (objLock)
            {
                try
                {
                    timer.Enabled = false;
                    // 离线客服
                    List <OnlineKFModel> listOffline = new List <OnlineKFModel>();

                    Dictionary <Guid, OnlineKFModel> kfItems = _cacheManager.Get <Dictionary <Guid, OnlineKFModel> >("OnlineKFItems");

                    if (kfItems == null)
                    {
                        return;
                    }

                    // 检测在线队列,150秒无活动,设为离线
                    foreach (KeyValuePair <Guid, OnlineKFModel> kf in kfItems)
                    {
                        OnlineKFModel modelOnlineKF = kf.Value;
                        TimeSpan      ts            = DateTime.Now - modelOnlineKF.LastActiveDate;

                        if (ts.TotalSeconds >= 150)
                        {
                            listOffline.Add(modelOnlineKF);
                        }
                    }

                    // 清理离线客服
                    string errorMsg = string.Empty;

                    foreach (OnlineKFModel model in listOffline)
                    {
                        //移除缓存中的客服
                        RemoveCacheKF(model.KfNumberId);
                        //发送客服离线通知
                        new CommandManager(null).TryHandleCommand(
                            "OffLine", new string[] { model.KfNumberId.ToString(), "1" }, ref errorMsg);
                    }
                }
                catch (Exception exception)
                {
                    log.Warn("清理离线客服出现异常:" + exception.Message);
                }
                finally
                {
                    timer.Enabled = true;
                }
            }
        }
Beispiel #4
0
        //缓存相关操作

        #region [更新客服在本地队列的缓存] public void CacheLocalKF(OnlineKFModel onlineKFModel)
        /// <summary>
        /// 更新客服在本地队列的缓存
        /// </summary>
        /// <param name="onlineKFModel"></param>
        public void CacheLocalKF(OnlineKFModel onlineKFModel)
        {
            ///保存一份登录到本服务器的在线用户队列
            if (_cacheManager.Get <Dictionary <Guid, OnlineKFModel> >("OnlineKFItems") == null) //检测缓存是否存在,新增缓存并增加用户信息
            {
                Dictionary <Guid, OnlineKFModel> dictionaryKF = new Dictionary <Guid, OnlineKFModel>();
                dictionaryKF.Add(onlineKFModel.KfNumberId, onlineKFModel);
                _cacheManager.Set("OnlineKFItems", dictionaryKF, 10080);  //10080=1周
            }
            else if (CheckOnlineKFCacheIsEmpty(onlineKFModel.KfNumberId)) //检测缓存中是否存在当前用户的数据,更新用户信息
            {
                _cacheManager.Get <Dictionary <Guid, OnlineKFModel> >("OnlineKFItems")[onlineKFModel.KfNumberId] = onlineKFModel;
            }
            else //向缓存中新增用户信息
            {
                _cacheManager.Get <Dictionary <Guid, OnlineKFModel> >("OnlineKFItems").Add(onlineKFModel.KfNumberId, onlineKFModel);
            }
        }