Esempio n. 1
0
        private CustomerData DeQueue()
        {
            CustomerData Chat = null;

            try
            {
                while (!this._queueMutex.WaitOne())
                {
                    Thread.Sleep(20);
                }
                if (SharedClass.Customerqueue.Count > 0)
                {
                    Chat = SharedClass.Customerqueue.Dequeue();
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("Exception DeQueing Message. {0}", e.ToString()), LogTarget.PUBLISHER);
            }
            finally
            {
                this._queueMutex.ReleaseMutex();
            }
            return(Chat);
        }
Esempio n. 2
0
        private void HandleUIAction(JObject requestPayload)
        {
            string Action = string.Empty;
            int    AccountId = 0, WidgetId = 0, ConversationId = 0;
            string WidgetUUID, Channel;

            try
            {
                if (requestPayload.SelectToken("Action") == null || requestPayload.SelectToken("Channel") == null || requestPayload.SelectToken("ConversationId") == null || requestPayload.SelectToken("AccountId") == null || requestPayload.SelectToken("WidgetId") == null)
                {
                    responseJSonObject = new JObject(new JProperty("Success", false),
                                                     new JProperty("Message", "Insufficient request payload"));
                    return;
                }
                Action         = requestPayload.SelectToken("Action").ToString();
                AccountId      = Convert.ToInt32(requestPayload.SelectToken("AccountId").ToString());
                Channel        = requestPayload.SelectToken("Channel").ToString();
                WidgetId       = Convert.ToInt32(requestPayload.SelectToken("WidgetId").ToString());
                ConversationId = Convert.ToInt32(requestPayload.SelectToken("ConversationId").ToString());
                switch (Action)
                {
                case "NEWCHAT":
                    CustomerData chat = new CustomerData();
                    chat.AccountId      = AccountId;
                    chat.Channel        = Channel;
                    chat.WidgetId       = WidgetId;
                    chat.ConversationId = ConversationId;
                    SharedClass.Customerqueue.Enqueue(chat);

                    break;

                case "INPROGRESS":
                    //if (SharedClass.IsCampaignInstanceActive(campaignInstanceId))
                    //{
                    //    responseJSonObject = new JObject(new JProperty("Success", false),
                    //        new JProperty("Campaign already active"));
                    //}
                    //else
                    //{
                    //    Logger.Info(string.Format("Campaign InstanceId : {0} And Status : {1}", campaignInstanceId, campaignStatus));
                    //    if (!SharedClass.IsCampaignInstanceActive(campaignInstanceId) && "INPROGRESS,RESUME".Split(new char[] { ',' }).Contains(campaignStatus))
                    //    {
                    //        responseJSonObject = ResumeCampaign(campaignInstanceId);
                    //    }
                    //}
                    break;

                default:
                    responseJSonObject = new JObject(new JProperty("Success", false),
                                                     new JProperty("Message", "Invalid Campaign Status"));
                    break;
                }
            }
            catch (Exception e)
            {
                responseJSonObject = new JObject(new JProperty("Success", false),
                                                 new JProperty("Message", "Unable to perform action."));
            }
        }
Esempio n. 3
0
        private (int, bool) GetAvailableAgent(CustomerData chat)
        {
            int           agentId = 0;
            bool          IsPing  = false;
            SqlConnection sqlCon  = new SqlConnection(SharedClass.ConnectionString);

            try
            {
                SqlCommand sqlCommand = new SqlCommand(StoredProcedure.GET_AVAILABLE_AGENT, sqlCon);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Clear();
                sqlCommand.Parameters.Add(ProcedureParameter.ACCOUNT_ID, SqlDbType.Int).Value            = chat.AccountId;
                sqlCommand.Parameters.Add(ProcedureParameter.WIDGET_ID, SqlDbType.BigInt).Value          = chat.WidgetId;
                sqlCommand.Parameters.Add(ProcedureParameter.CONVERSATION_ID, SqlDbType.BigInt).Value    = chat.ConversationId;
                sqlCommand.Parameters.Add(ProcedureParameter.AGENT_ID, SqlDbType.Int).Direction          = ParameterDirection.Output;
                sqlCommand.Parameters.Add(ProcedureParameter.IS_PING, SqlDbType.Bit).Direction           = ParameterDirection.Output;
                sqlCommand.Parameters.Add(ProcedureParameter.SUCCESS, SqlDbType.Bit).Direction           = ParameterDirection.Output;
                sqlCommand.Parameters.Add(ProcedureParameter.MESSAGE, SqlDbType.VarChar, 1000).Direction = ParameterDirection.Output;
                sqlCon.Open();
                sqlCommand.ExecuteNonQuery();
                sqlCon.Close();

                if (Convert.ToBoolean(sqlCommand.Parameters[ProcedureParameter.SUCCESS].Value) == true)
                {
                    if (!Convert.IsDBNull(sqlCommand.Parameters[ProcedureParameter.AGENT_ID].Value) && Convert.ToInt32(sqlCommand.Parameters[ProcedureParameter.AGENT_ID].Value) > 0)
                    {
                        agentId = Convert.ToInt32(sqlCommand.Parameters[ProcedureParameter.AGENT_ID].Value);
                        IsPing  = Convert.ToBoolean(sqlCommand.Parameters[ProcedureParameter.IS_PING].Value);
                    }
                }
                else
                {
                    Logger.Error(string.Format("No Data returned from database for Proc {0} , AccountId : {1} AND Message From DB : {2}", StoredProcedure.GET_AVAILABLE_AGENT, chat.AccountId, sqlCommand.Parameters[ProcedureParameter.MESSAGE].Value));
                    SharedClass.ThreadSleep(1000);
                }
                //Logger.Info(string.Format("Agentid : {0}", agentId));
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error at GetAvailableAgent Error : {0}", ex.ToString()));
                SharedClass.ThreadSleep(1000);
            }
            finally
            {
                if (sqlCon.State == ConnectionState.Open)
                {
                    sqlCon.Close();
                }
            }
            return(agentId, IsPing);
        }
Esempio n. 4
0
        internal bool EnQueue(CustomerData Chat)
        {
            bool enQueued = false;

            try
            {
                while (!this._queueMutex.WaitOne())
                {
                    Thread.Sleep(20);
                }
                SharedClass.Customerqueue.Enqueue(Chat);
            }
            catch (Exception e)
            {
                Logger.Error(string.Format("Exception while EnQueuing Message. {0}", e.ToString()), LogTarget.PUBLISHER);
                enQueued = false;
            }
            finally
            {
                this._queueMutex.ReleaseMutex();
            }
            return(enQueued);
        }
Esempio n. 5
0
        public void AgentCustomerMapper()
        {
            try
            {
                //int agentId = 0;
                CustomerData CusObj = null;
                Logger.Info("Agent Customer Mapper Started ");

                while (!SharedClass.HasStopSignal && this._shouldIPoll)
                {
                    try
                    {
                        if (this.QueueCount() > 0)
                        {
                            Logger.Info("Processing customer chats,Queue count : " + this.QueueCount().ToString());
                            CusObj = new CustomerData();
                            CusObj = this.DeQueue();
                            Logger.Info("Processing customer chats :" + CusObj.Channel);

                            (int agentId, bool IsPingAgent) = this.GetAvailableAgent(CusObj);
                            if (agentId > 0)
                            {
                                JObject wsMessageObj = new JObject();
                                JObject dataObj      = new JObject();

                                dataObj = new JObject(new JProperty("AccountId", CusObj.AccountId),
                                                      new JProperty("WidgetId", CusObj.WidgetId),
                                                      new JProperty("WidgetUUID", CusObj.WidgetUUID),
                                                      new JProperty("CustomerChannel", CusObj.Channel),
                                                      new JProperty("ConversationId", CusObj.ConversationId),
                                                      new JProperty("MaxAttempts", CusObj.WidgetId));

                                wsMessageObj = new JObject(new JProperty("Module", "Chat"),
                                                           new JProperty("Event", "NewChat"),
                                                           new JProperty("Channel_Name", "Agent_" + agentId.ToString()),
                                                           new JProperty("Data", dataObj));

                                this._publisher.EnQueue(wsMessageObj);
                                Logger.Info(string.Format("Enqueued the websocket Message : {0}", wsMessageObj));
                            }
                            else
                            {
                                this.EnQueue(CusObj);
                                SharedClass.ThreadSleep(1000);
                            }
                        }
                        else
                        {
                            SharedClass.ThreadSleep(1000);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(string.Format("Error at AgentCustomerMapper , Error : {0}", ex.ToString()));
                    }
                    finally
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error at AgentCustomerMapper , Error : {0}", ex.ToString()));
            }
        }