Exemplo n.º 1
0
        /// <summary>
        /// 离开聊天
        /// </summary>
        /// <returns></returns>
        public JsonResult LeftChat(string tid, string interactionID, string agentID, string queueName, int keepAlive)
        {
            string chatContent = string.Empty;

            if (!string.IsNullOrEmpty(interactionID))
            {
                try
                {
                    AgentChatContext context         = new AgentChatContext(tid, interactionID, agentID);
                    bool             isKeepRoomAlive = (keepAlive == 1);
                    context.LeftChat(isKeepRoomAlive);
                    try
                    {
                        System.Threading.Thread.Sleep(100);
                        chatContent = JsonConvert.SerializeObject(context.Room.Messages);
                    }
                    catch (Exception ex)
                    {
                        ChatLog.GetInstance().FormatMessage("异常信息:序列化聊天消息时异常。{0}", ex.Message);
                    }
                    chatContent = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(chatContent));

                    if (!isKeepRoomAlive)
                    {
                        // 移除缓存项
                        AgentCache.GetInstance().RemoveAgent(tid, agentID, interactionID);

                        // Room从缓存移除
                        if (context.Room != null)
                        {
                            ChatRoomCache.GetInstance().RemoveItem(context.Room);
                            ChatLog.GetInstance().FormatMessage("Room移除缓存。TicketID:{0},SessionID:{1},AgentID:{2}", tid, interactionID, agentID);
                        }
                    }
                    // 记录日志
                    if (!string.IsNullOrEmpty(queueName))
                    {
                        ChatLog.GetInstance().LogEvent(ChatEvent.TransferQueue, queueName);
                    }
                    else if (isKeepRoomAlive)
                    {
                        ChatLog.GetInstance().LogEvent(ChatEvent.TransferPerson, agentID);
                    }
                }
                catch (Exception ex)
                {
                    ChatLog.GetInstance().LogException(ex);
                }
            }
            return(new JsonpResult()
            {
                Data = chatContent, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetInfo(string agentID)
        {
            AgentIndexMessage indexData = new AgentIndexMessage();

            if (!string.IsNullOrEmpty(agentID))
            {
                try
                {
                    List <LenovoAgent> agents = AgentCache.GetInstance().GetAgents(agentID);
                    indexData.Init(agents);
                }
                catch (Exception ex)
                {
                    ChatLog.GetInstance().LogException(ex);
                }
            }
            return(new JsonpResult()
            {
                Data = indexData, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }