Ejemplo 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
            });
        }
Ejemplo 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
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Put agent entity into the cache and assign a key.
        /// </summary>
        /// <param name="key">Key to use. Is additionally a back link to person.</param>
        /// <param name="value">Agent entity to put into the cache.</param>
        public static void PutAgent (int key, Agent value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Check whether Person cache contains Person with mentioned key. Throw an error if not.
                if (!(PersonCache.ContainsKey(key)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Agent cache.")
                    {
                        Operation = "put",
                        TableName = "Agent",
                        FieldName = "key",
                        ReadableMessage = $"Can not put new entry into Agent cache because Person with key {key} does not exist."
                    };
                }

                // Normal operation.
                AgentCache.Put (key, value);
                tx.Commit();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Put deal entity into the cache. <br/>
        /// Referential integrity is checked on: <br/>
        /// Deal.key - EstateObject.key <br/>
        /// Deal.BuyerID - Person.key <br/>
        /// Deal.SellerID - Person.key <br/>
        /// Deal.AgentID - Agent.key <br/>
        /// </summary>
        /// <param name="value">Deal to put into the cache.</param>
        public static void PutDeal (int key, Deal value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if EstateObject with mentioned key is not found.
                if (!(ObjectCache.ContainsKey(key)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Deal cache.")
                    {
                        Operation = "put",
                        TableName = "Deal",
                        FieldName = "key",
                        ReadableMessage = $"Can not put new entry into Deal cache because EstateObject with key {key} does not exist."
                    };
                }

                // Error if Person with key = value.BuyerID is not found.
                if (!(PersonCache.ContainsKey(value.BuyerID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Deal cache.")
                    {
                        Operation = "put",
                        TableName = "Deal",
                        FieldName = "BuyerID",
                        ReadableMessage = $"Can not put new entry into Deal cache because Person with key {value.BuyerID} does not exist."
                    };
                }

                // Error if Person with key = value.SellerID is not found.
                if (!(PersonCache.ContainsKey(value.SellerID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Deal cache.")
                    {
                        Operation = "put",
                        TableName = "Deal",
                        FieldName = "SellerID",
                        ReadableMessage = $"Can not put new entry into Deal cache because Person with key {value.SellerID} does not exist."
                    };
                }

                // Error if Agent with key = value.AgentID is not found.
                if (!(AgentCache.ContainsKey(value.AgentID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Deal cache.")
                    {
                        Operation = "put",
                        TableName = "Deal",
                        FieldName = "AgentID",
                        ReadableMessage = $"Can not put new entry into Deal cache because Agent with key {value.AgentID} does not exist."
                    };
                }

                // Normal operation
                DealCache.Put (key, value);
                tx.Commit();
            }
        }