Beispiel #1
0
        public void Start(byte index)
        {
            this.sqlCon = new SqlConnection(SharedClass.GetConnectionString(Environment.PRODUCTION));
            this.sqlCmd = new SqlCommand("VC_Call_Hangup_Processor", this.sqlCon);
            this._groupCallSqlConProduction = new SqlConnection(SharedClass.GetConnectionString(Environment.PRODUCTION));
            this._groupCallSqlCmdProduction = new SqlCommand("VC_GroupCall_Hangup_Processor", this._groupCallSqlConProduction);

            if (SharedClass.PollStaging)
            {
                this.sqlConStaging = new SqlConnection(SharedClass.GetConnectionString(Environment.STAGING));
                this.sqlCmdStaging = new SqlCommand("VC_Call_Hangup_Processor", this.sqlConStaging);

                this._groupCallSqlConStaging = new SqlConnection(SharedClass.GetConnectionString(Environment.STAGING));
                this._groupCallSqlCmdStaging = new SqlCommand("VC_GroupCall_Hangup_Processor", this._groupCallSqlConStaging);
            }


            this.xmlDoc      = new XmlDocument();
            this.rootElement = this.xmlDoc.CreateElement("Call");
            this.xmlDoc.AppendChild((XmlNode)this.rootElement);
            Thread thread = !SharedClass.IsHangupProcessInMemory ? new Thread(new ThreadStart(this.StartRMQProcessing)) : new Thread(new ThreadStart(this.StartInMemoryProcessing));

            thread.Name = "HangupDataProcessor_" + index.ToString();
            thread.Start();
        }
Beispiel #2
0
 public void ReEnQueueToDataBase(bool isDeQueued = true, string reason = "")
 {
     System.Data.SqlClient.SqlConnection sqlCon = null;
     System.Data.SqlClient.SqlCommand    sqlCmd = null;
     try
     {
         if (reason.Length > 500)
         {
             reason = reason.Substring(0, 500);
         }
         sqlCon = new System.Data.SqlClient.SqlConnection(SharedClass.GetConnectionString(this._environment));
         sqlCmd = new System.Data.SqlClient.SqlCommand("Update BulkVoiceRequests with(rowlock) Set Status = @Status, Reason = @Reason Where Id = @BulkRequestId", sqlCon);
         // + ((isDeQueued == true) ? 9 : 0).ToString() + " Where Id = " + this.id.ToString(), sqlCon);
         sqlCmd.Parameters.Add("@Status", System.Data.SqlDbType.TinyInt).Value       = isDeQueued == true ? 9 : 0;
         sqlCmd.Parameters.Add("@Reason", System.Data.SqlDbType.VarChar, -1).Value   = reason;
         sqlCmd.Parameters.Add("@BulkRequestId", System.Data.SqlDbType.BigInt).Value = this._id;
         sqlCon.Open();
         sqlCmd.ExecuteNonQuery();
         sqlCon.Close();
     }
     catch (Exception e)
     {
         SharedClass.Logger.Error("Error ReEnQueuing BulkRequest : " + e.ToString());
     }
 }
Beispiel #3
0
        private void SetLastQueuedSlno()
        {
            SharedClass.Logger.Info("Getting Last Queued Slno's");
            SqlCommand    sqlCmd = (SqlCommand)null;
            SqlConnection sqlCon = (SqlConnection)null;

            try
            {
                sqlCon = new SqlConnection(SharedClass.GetConnectionString(Environment.PRODUCTION));
                sqlCmd = new SqlCommand("SELECT Id,ISNULL(HPQLastSlno,0) as HPSlno, ISNULL(MPQLastSlno,0) as MPSlno, ISNULL(LPQLastSlno,0) as LPSlno From VoiceGateways WITH(NOLOCK)", sqlCon);
                sqlCon.Open();
                SqlDataReader reader = sqlCmd.ExecuteReader();
                while (reader.Read())
                {
                    CallsQueueSlno.SetSlno(Convert.ToInt32(reader["Id"]), Environment.PRODUCTION, Priority.PriorityMode.High, Convert.ToInt64(reader["HPSlno"]));
                    CallsQueueSlno.SetSlno(Convert.ToInt32(reader["Id"]), Environment.PRODUCTION, Priority.PriorityMode.Medium, Convert.ToInt64(reader["MPSlno"]));
                    CallsQueueSlno.SetSlno(Convert.ToInt32(reader["Id"]), Environment.PRODUCTION, Priority.PriorityMode.Low, Convert.ToInt64(reader["LPSlno"]));
                }
                sqlCon.Close();
            }
            catch (Exception ex)
            {
                SharedClass.Logger.Error("Exception in Getting Last Queued Slno Reason : " + ex.ToString());
            }

            if (SharedClass.PollStaging)
            {
                try
                {
                    sqlCon = new SqlConnection(SharedClass.GetConnectionString(Environment.STAGING));
                    sqlCmd = new SqlCommand("SELECT Id,ISNULL(HPQLastSlno,0) as HPSlno, ISNULL(MPQLastSlno,0) as MPSlno, ISNULL(LPQLastSlno,0) as LPSlno From VoiceGateways WITH(NOLOCK)", sqlCon);
                    sqlCon.Open();
                    SqlDataReader reader = sqlCmd.ExecuteReader();
                    while (reader.Read())
                    {
                        CallsQueueSlno.SetSlno(Convert.ToInt32(reader["Id"]), Environment.STAGING, Priority.PriorityMode.High, Convert.ToInt64(reader["HPSlno"]));
                        CallsQueueSlno.SetSlno(Convert.ToInt32(reader["Id"]), Environment.STAGING, Priority.PriorityMode.Medium, Convert.ToInt64(reader["MPSlno"]));
                        CallsQueueSlno.SetSlno(Convert.ToInt32(reader["Id"]), Environment.STAGING, Priority.PriorityMode.Low, Convert.ToInt64(reader["LPSlno"]));
                    }
                    sqlCon.Close();
                }
                catch (Exception ex)
                {
                    SharedClass.Logger.Error("Exception in Getting Last Queued Slno Of Staging Reason : " + ex.ToString());
                }
            }
        }
Beispiel #4
0
 public void UpdateProcessedCount()
 {
     System.Data.SqlClient.SqlConnection sqlCon = null;
     System.Data.SqlClient.SqlCommand    sqlCmd = null;
     try
     {
         //SharedClass.Logger.Info("BulkRequestId : " + this.id.ToString() + ", Processed : " + this.processedCount.ToString() + ", Remaining : " + (this.))
         sqlCon = new System.Data.SqlClient.SqlConnection(SharedClass.GetConnectionString(this._environment));
         sqlCmd = new System.Data.SqlClient.SqlCommand("Update BulkVoiceRequests with(rowlock) Set ProcessedCount = " + this._processedCount.ToString() + " Where Id = " + this._id.ToString(), sqlCon);
         sqlCon.Open();
         sqlCmd.ExecuteNonQuery();
         sqlCon.Close();
     }
     catch (Exception e) {
         SharedClass.Logger.Error("Error Updating BulkRequest : " + e.ToString());
     }
 }
Beispiel #5
0
        //private void UpdateLastSlno(Priority.PriorityMode mode, long slno)
        //{
        //    switch (mode)
        //    {
        //        case Priority.PriorityMode.Urgent:
        //            this._urgentPriorityQueueLastSlno = slno;
        //            break;
        //        case Priority.PriorityMode.High:
        //            this.HighPriorityQueueLastSlno = slno;
        //            break;
        //        case Priority.PriorityMode.Medium:
        //            this.MediumPriorityQueueLastSlno = slno;
        //            break;
        //        default:
        //            this.LowPriorityQueueLastSlno = slno;
        //            break;
        //    }
        //}
        //private long GetLastSlno(Priority.PriorityMode mode)
        //{
        //    long num;
        //    switch (mode)
        //    {
        //        case Priority.PriorityMode.Urgent:
        //            num = this._urgentPriorityQueueLastSlno;
        //            break;
        //        case Priority.PriorityMode.High:
        //            num = this._highPriorityQueueLastSlno;
        //            break;
        //        case Priority.PriorityMode.Medium:
        //            num = this._mediumPriorityQueueLastSlno;
        //            break;
        //        default:
        //            num = this._lowPriorityQueueLastSlno;
        //            break;
        //    }
        //    return num;
        //}

        private void UpdateLastProcessedSlno()
        {
            SharedClass.Logger.Info("Updating Last Slnos");
            SqlConnection sqlCon = (SqlConnection)null;
            SqlCommand    sqlCmd = (SqlCommand)null;

            try
            {
                sqlCon = new SqlConnection(SharedClass.GetConnectionString(Environment.PRODUCTION));
                sqlCmd = new SqlCommand("Update VoiceGateways With(Rowlock) Set UPQLastSlno = @UPQLastSlno, HPQLastSlno = @HPQLastSlno, MPQLastSlno = @MPQLastSlno , LPQLastSlno = @LPQLastSlno Where ID = @GatewayId", sqlCon);
                sqlCmd.Parameters.Add("@UPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.PRODUCTION, Priority.PriorityMode.Urgent);
                sqlCmd.Parameters.Add("@HPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.PRODUCTION, Priority.PriorityMode.High);
                sqlCmd.Parameters.Add("@MPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.PRODUCTION, Priority.PriorityMode.Medium);
                sqlCmd.Parameters.Add("@LPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.PRODUCTION, Priority.PriorityMode.Low);
                sqlCmd.Parameters.Add("@GatewayId", SqlDbType.Int).Value      = this.Id;
                sqlCon.Open();
                sqlCmd.ExecuteNonQuery();
                sqlCon.Close();
                SharedClass.Logger.Info("Updating Last Slnos Done");
            }
            catch (Exception ex)
            {
                SharedClass.Logger.Error("Exception in Updating Last Processed Slno's Reason : " + ex.ToString());
            }

            if (SharedClass.PollStaging)
            {
                try
                {
                    sqlCon = new SqlConnection(SharedClass.GetConnectionString(Environment.STAGING));
                    sqlCmd = new SqlCommand("Update VoiceGateways With(Rowlock) Set UPQLastSlno = @UPQLastSlno, HPQLastSlno = @HPQLastSlno, MPQLastSlno = @MPQLastSlno , LPQLastSlno = @LPQLastSlno Where ID = @GatewayId", sqlCon);
                    sqlCmd.Parameters.Add("@HPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.STAGING, Priority.PriorityMode.High);
                    sqlCmd.Parameters.Add("@MPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.STAGING, Priority.PriorityMode.Medium);
                    sqlCmd.Parameters.Add("@LPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.STAGING, Priority.PriorityMode.Low);
                    sqlCmd.Parameters.Add("@UPQLastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this.Id, Environment.STAGING, Priority.PriorityMode.Urgent);
                    sqlCmd.Parameters.Add("@GatewayId", SqlDbType.Int).Value      = this.Id;
                    sqlCon.Open();
                    sqlCmd.ExecuteNonQuery();
                    sqlCon.Close();
                }
                catch (Exception ex)
                {
                    SharedClass.Logger.Error("Exception in Updating Last Processed Staging Slno's  Reason : " + ex.ToString());
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main()
 {
     SharedClass.InitiaLizeLogger();
     ServiceBase[] ServicesToRun;
     ServicesToRun = new ServiceBase[]
     {
         new VoiceService()
     };
     if (System.Environment.UserInteractive)
     {
         RunInteractiveServices(ServicesToRun);
     }
     else
     {
         ServiceBase.Run(ServicesToRun);
     }
 }
Beispiel #7
0
 public void Start()
 {
     SharedClass.IsServiceCleaned = false;
     this.LoadGateways();
     if (SharedClass.RabbitMQClient != null)
     {
         SharedClass.Logger.Info("Starting RabbitMQ Client");
         SharedClass.RabbitMQClient.Start();
         for (byte iterator = 1; iterator <= SharedClass.HangupProcessorsCount; iterator++)
         {
             HangupProcessor p = new HangupProcessor();
             this._hangupProcessors.Add(p);
             p.Start(iterator);
         }
     }
     //if (SharedClass.HangupProcessor != null)
     //{
     //    SharedClass.Logger.Info("Starting Hangup Processor");
     //    SharedClass.HangupProcessor.Start();
     //}
     if (SharedClass.Listener.Ip.Length > 7 && SharedClass.Listener.Port > 0)
     {
         SharedClass.Logger.Info("Starting Listener");
         SharedClass.Listener.Initialize();
     }
     this._pollThread      = new Thread(new ParameterizedThreadStart(this.StartDbPoll));
     this._pollThread.Name = "BulkPoller";
     SharedClass.Logger.Info("Starting BulkPoller");
     this._pollThread.Start(Environment.PRODUCTION);
     if (SharedClass.PollStaging)
     {
         this._pollThreadStaging      = new Thread(new ParameterizedThreadStart(this.StartDbPoll));
         this._pollThreadStaging.Name = "BulkPollerStaging";
         this._pollThreadStaging.Start(Environment.STAGING);
     }
     this.heartBeatClient = new Client(Convert.ToString(SharedClass.GetConnectionString(Environment.PRODUCTION)), 6);
     this.heartBeatClient.Initialize();
     this._slnosLogTrhead      = new Thread(new ThreadStart(this.LogLastSlnos));
     this._slnosLogTrhead.Name = "SlnoLogger";
     this._slnosLogTrhead.Start();
 }
Beispiel #8
0
        public void Stop()
        {
            SharedClass.Logger.Info("Stopping AccountId : " + this.AccountId.ToString() + " Processor");
            BulkRequest bulkRequest = null;

            this._shouldIProcess = false;
            while (this.QueueCount() > 0)
            {
                bulkRequest = this.DeQueue();
                if (bulkRequest != null)
                {
                    bulkRequest.ReEnQueueToDataBase(isDeQueued: false, reason: "");
                }
            }
            while ((int)this._activeThreads > 0)
            {
                SharedClass.Logger.Info("AccountId " + this.AccountId.ToString() + " has still " + this.ActiveThreads.ToString() + " active process threads running");
                Thread.Sleep(1000);
            }
            SharedClass.ReleaseAccountProcessor(this.AccountId);
        }
Beispiel #9
0
        private void StartPushing()
        {
            int  loopCount = 0;
            long startTime = 0;
            long timeTaken = 0;

            while (!this._pushThreadMutex.WaitOne())
            {
                Thread.Sleep(10);
            }
            ++this._pushThreadsRunning;
            this._pushThreadMutex.ReleaseMutex();
            SharedClass.Logger.Info("Started");
            Call call = null;

            while (this._shouldIProcess && !SharedClass.HasStopSignal)
            {
                try
                {
                    if ((call = this._callsQueue.DeQueue()) == null)
                    {
                        try
                        {
                            Thread.Sleep(2000);
                        }
                        catch (ThreadInterruptedException e) { }
                    }
                    else
                    {
                        SharedClass.Logger.Info("Dequeued Call of CallId : " + call.QueueTableSlno.ToString() + " Source: " + call.Environment.ToString());
                        this.WaitForLines();

                        if (!this.ShouldIPushCall())
                        {
                            this._callsQueue.EnQueue(call, Priority.GetPriority(call.PriorityValue));
                            call = null;
                            continue;
                        }

                        startTime = SharedClass.CurrentTimeStamp();
                        this.ProcessCall(call);
                        timeTaken = SharedClass.CurrentTimeStamp() - startTime;
                        call      = null;
                        if (timeTaken < this._minTimeTaken)
                        {
                            this._minTimeTaken = timeTaken;
                        }
                        if (timeTaken > this._maxTimeTaken)
                        {
                            this._maxTimeTaken = timeTaken;
                        }
                        ++loopCount;
                        if (loopCount == 50)
                        {
                            SharedClass.Logger.Info("Processed " + loopCount + " Calls : minTime => " + _minTimeTaken + ", maxTime => " + _maxTimeTaken);
                            loopCount = 0;
                        }
                    }
                }
                catch (Exception ex)
                {
                    SharedClass.Logger.Error("Error In While Loop, " + ex.ToString());
                }
                finally {
                    if (call != null)
                    {
                        this._callsQueue.EnQueue(call, Priority.GetPriority(call.PriorityValue));
                    }
                }
            }
            SharedClass.Logger.Info("Exited From While Loop and is about to die");
            while (!this._pushThreadMutex.WaitOne())
            {
                Thread.Sleep(10);
            }
            --this._pushThreadsRunning;
            this._pushThreadMutex.ReleaseMutex();
        }
Beispiel #10
0
        private void GetPendingGroupCallsFromDataBase(object input)
        {
            PollingInput  pollingInput = (PollingInput)input;
            SqlConnection connection   = new SqlConnection(SharedClass.GetConnectionString(pollingInput.Environment));
            SqlCommand    sqlCommand   = new SqlCommand("VC_Get_PendingGroupCalls", connection);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da   = null;
            DataSet        ds   = null;
            Call           call = null;

            while (!this._pushThreadMutex.WaitOne())
            {
                Thread.Sleep(100);
            }
            ++this._pollThreadsRunning;
            this._pushThreadMutex.ReleaseMutex();
            SharedClass.Logger.Info("Started");

            while (this._shouldIPoll && !SharedClass.HasStopSignal)
            {
                try
                {
                    sqlCommand.Parameters.Clear();
                    sqlCommand.Parameters.Add("@GatewayId", SqlDbType.Int).Value   = this._id;
                    sqlCommand.Parameters.Add("@LastSlno", SqlDbType.BigInt).Value = CallsQueueSlno.GetSlno(this._id, pollingInput.Environment, pollingInput.PriorityMode);
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    da = new SqlDataAdapter();
                    da.SelectCommand = sqlCommand;
                    ds = new DataSet();
                    da.Fill(ds);
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dataRow in ds.Tables[0].Rows)
                        {
                            try
                            {
                                call                = new Call();
                                call.Environment    = pollingInput.Environment;
                                call.QueueTableSlno = Convert.ToInt64(dataRow["Id"]);
                                CallsQueueSlno.SetSlno(this.Id, pollingInput.Environment, pollingInput.PriorityMode, Convert.ToInt64(dataRow["Id"]));
                                call.CallId        = Convert.ToInt64(dataRow["CallId"]);
                                call.AccountId     = Convert.ToInt64(dataRow["AccountId"]);
                                call.UUID          = dataRow["UUID"].ToString();
                                call.CallerId      = dataRow["CallerId"].ToString();
                                call.Destination   = dataRow["Destination"].ToString();
                                call.Xml           = dataRow["Xml"].ToString();
                                call.RingUrl       = dataRow["RingUrl"].ToString();
                                call.AnswerUrl     = dataRow["AnswerUrl"].ToString();
                                call.HangupUrl     = dataRow["HangupUrl"].ToString();
                                call.Pulse         = Convert.ToByte(dataRow["Pulse"]);
                                call.PricePerPulse = float.Parse(dataRow["PricePerPulse"].ToString());
                                call.PriorityValue = Convert.ToByte(dataRow["Priority"]);
                                call.IsGroupCall   = true;
                                call.IsSipUser     = Convert.ToBoolean(dataRow["IsSipUser"].ToString());
                                this._callsQueue.EnQueue(call, pollingInput.PriorityMode);
                            }
                            catch (Exception e)
                            {
                                SharedClass.Logger.Error("Error In Constructing Call Object : " + e.ToString());
                                try
                                {
                                    PropertyInfo[] properties = call.GetType().GetProperties();
                                    foreach (PropertyInfo propertyInfo in properties)
                                    {
                                        if (propertyInfo.CanRead)
                                        {
                                            if (propertyInfo.GetValue(call) == DBNull.Value)
                                            {
                                                SharedClass.DumpLogger.Error(propertyInfo.Name + " : NULL");
                                            }
                                            else
                                            {
                                                SharedClass.DumpLogger.Error(propertyInfo.Name + " : " + propertyInfo.GetValue(call).ToString());
                                            }
                                        }
                                    }
                                }
                                catch (Exception e1)
                                { }
                                finally
                                {
                                }
                            }
                        }
                        //this.UpdateLastSlno(priorityMode, call.QueueTableSlno);
                        CallsQueueSlno.SetSlno(this._id, pollingInput.Environment, pollingInput.PriorityMode, call.QueueTableSlno);
                    }
                    else
                    {
                        try
                        {
                            Thread.Sleep(2000);
                        }
                        catch (ThreadAbortException)
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                    SharedClass.Logger.Error(("Error In Polling, " + ex.ToString()));
                }
                finally
                {
                    da = null;
                    ds = null;
                }
            }

            SharedClass.Logger.Info("Stopped Polling, ShouldIPoll : " + this._shouldIPoll + ", Has Stop Signal : " + SharedClass.HasStopSignal);
            while (!this._pushThreadMutex.WaitOne())
            {
                Thread.Sleep(100);
                SharedClass.Logger.Info("Waiting for pushThreadMutex to decrease pollThreadsRunning count");
            }
            --this._pollThreadsRunning;
            this._pushThreadMutex.ReleaseMutex();
            if (SharedClass.HasStopSignal)
            {
                return;
            }
            string str = this.GetDisplayString() + " ";
            string text;

            text = str + "UP Poller Stopped";


            lock (SharedClass.Notifier)
            {
                SharedClass.Notifier.SendSms(text);
            }
        }
Beispiel #11
0
        private JObject ProcessChunk(BulkRequest bulkRequest, System.Data.DataTable mobileUUIDsTable)
        {
            SqlConnection sqlCon               = new SqlConnection(SharedClass.GetConnectionString(bulkRequest.Environment));
            SqlCommand    sqlCmd               = new SqlCommand("Create_Call", sqlCon);
            byte          retryAttempt         = 0;
            SqlParameter  mobileUUIDParameter  = null;
            SqlParameter  xmlTagNamesParameter = null;
            XmlDocument   xmlDoc               = new XmlDocument();

            xmlDoc.LoadXml(bulkRequest.Xml);
            DataTable xmlTagNamesTable = GetXmlTagNames(xmlDoc);

retryLabel:
            try
            {
                sqlCmd.Parameters.Add("@AccountId", SqlDbType.BigInt).Value    = this._accountId;
                sqlCmd.Parameters.Add("@AccountType", SqlDbType.TinyInt).Value = this._accountType;
                sqlCmd.Parameters.Add("@ToolId", SqlDbType.TinyInt).Value      = bulkRequest.ToolId;
                sqlCmd.Parameters.Add("@Xml", SqlDbType.VarChar, bulkRequest.Xml.Length).Value = bulkRequest.Xml;
                mobileUUIDParameter           = sqlCmd.Parameters.Add("@MobileNumbersAndUUIDs", SqlDbType.Structured);
                mobileUUIDParameter.TypeName  = "dbo.MobileNumberUUIDType";
                mobileUUIDParameter.Value     = mobileUUIDsTable;
                xmlTagNamesParameter          = sqlCmd.Parameters.Add("@XmlTagNames", SqlDbType.Structured);
                xmlTagNamesParameter.TypeName = "dbo.XmlTagNames";
                xmlTagNamesParameter.Value    = xmlTagNamesTable;
                sqlCmd.CommandType            = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@IpAddress", SqlDbType.VarChar, bulkRequest.Ip.Length).Value        = bulkRequest.Ip;
                sqlCmd.Parameters.Add("@AnswerUrl", SqlDbType.VarChar, bulkRequest.AnswerUrl.Length).Value = bulkRequest.AnswerUrl;
                sqlCmd.Parameters.Add("@RingUrl", SqlDbType.VarChar, bulkRequest.RingUrl.Length).Value     = bulkRequest.RingUrl;
                sqlCmd.Parameters.Add("@HangupUrl", SqlDbType.VarChar, bulkRequest.HangupUrl.Length).Value = bulkRequest.HangupUrl;
                sqlCmd.Parameters.Add("@CallerId", SqlDbType.VarChar, bulkRequest.CallerId.Length).Value   = bulkRequest.CallerId;
                sqlCmd.Parameters.Add("@Retries", SqlDbType.TinyInt).Value           = bulkRequest.Retries;
                sqlCmd.Parameters.Add("@BulkRequestId", SqlDbType.BigInt).Value      = bulkRequest.Id;
                sqlCmd.Parameters.Add("@CampaignScheduleId", SqlDbType.BigInt).Value = bulkRequest.CampaignScheduleId;
                sqlCmd.Parameters.Add("@StatusCode", SqlDbType.Int).Direction        = System.Data.ParameterDirection.Output;
                sqlCmd.Parameters.Add("@Success", SqlDbType.Bit).Direction           = System.Data.ParameterDirection.Output;
                sqlCmd.Parameters.Add("@Message", SqlDbType.VarChar, 1000).Direction = System.Data.ParameterDirection.Output;
                sqlCon.Open();
                sqlCmd.ExecuteNonQuery();
                return(GetOutputParametersAsJSon(sqlCmd.Parameters));
            }
            catch (Exception e)
            {
                SharedClass.Logger.Error("Error Processing BulkRequest (retryAttempt : " + retryAttempt + ") : " + e.ToString());
                ++retryAttempt;
                if (retryAttempt <= 3)
                {
                    goto retryLabel;
                }
                else
                {
                    SharedClass.Logger.Error("Max Retry Attempts Reached with error : " + e.ToString());
                    return(new JObject(new JProperty("Success", false), new JProperty("Message", e.ToString())));
                }
            }
            finally {
                if (sqlCon.State == System.Data.ConnectionState.Open)
                {
                    sqlCon.Close();
                }
                sqlCon.Dispose();
                sqlCmd.Dispose();
            }
        }
Beispiel #12
0
        private void LoadConfig()
        {
            try
            {
                SharedClass.Logger.Info("Loading Configuration Variables into Application Memory");
                int  tempInt     = 0;
                byte tempByte    = 0;
                bool tempBoolean = false;
                SharedClass.SetConnectionString(ConfigurationManager.ConnectionStrings["DbConnectionString"].ConnectionString, Environment.PRODUCTION);
                if (ConfigurationManager.ConnectionStrings["DbConnectionStringStaging"] != null)
                {
                    SharedClass.Logger.Info(string.Format("Setting DbConnectionStringStaging To {0}", ConfigurationManager.ConnectionStrings["DbConnectionStringStaging"].ConnectionString));
                    SharedClass.SetConnectionString(ConfigurationManager.ConnectionStrings["DbConnectionStringStaging"].ConnectionString, Environment.STAGING);
                    SharedClass.PollStaging = true;
                }
                tempByte = SharedClass.GatewayHeartBeatSpan;
                if (ConfigurationManager.AppSettings["GatewayHeartBeatSpan"] != null)
                {
                    if (byte.TryParse(ConfigurationManager.AppSettings["GatewayHeartBeatSpan"].Trim(), out tempByte))
                    {
                        SharedClass.Logger.Info(string.Format("Setting GatewayHeartBeatSpan To {0}", ConfigurationManager.AppSettings["GatewayHeartBeatSpan"]));
                        SharedClass.GatewayHeartBeatSpan = tempByte;
                    }
                }

                if (ConfigurationManager.AppSettings["HP"] != null)
                {
                    tempByte = Priority.HpFloor;
                    if (byte.TryParse(ConfigurationManager.AppSettings["HP"].Split('-')[0].Trim(), out tempByte))
                    {
                        SharedClass.Logger.Info(string.Format("Setting HpFloor To {0}", tempByte));
                        Priority.HpFloor = tempByte;
                    }
                    tempByte = Priority.HpCeil;
                    if (byte.TryParse(ConfigurationManager.AppSettings["HP"].Split('-')[1].Trim(), out tempByte))
                    {
                        SharedClass.Logger.Info(string.Format("Setting HpCeil To {0}", tempByte));
                        Priority.HpCeil = tempByte;
                    }
                }
                if (ConfigurationManager.AppSettings["MP"] != null)
                {
                    tempByte = Priority.MpFloor;
                    if (byte.TryParse(ConfigurationManager.AppSettings["MP"].Split('-')[0].Trim(), out tempByte))
                    {
                        SharedClass.Logger.Info(string.Format("Setting MpFloor To {0}", tempByte));
                        Priority.MpFloor = tempByte;
                    }
                    tempByte = Priority.MpCeil;
                    if (byte.TryParse(ConfigurationManager.AppSettings["MP"].Split('-')[1].Trim(), out tempByte))
                    {
                        SharedClass.Logger.Info(string.Format("Setting MpCeil To {0}", tempByte));
                        Priority.MpCeil = tempByte;
                    }
                }
                if (ConfigurationManager.AppSettings["LP"] != null)
                {
                    tempByte = Priority.HpFloor;
                    if (byte.TryParse(ConfigurationManager.AppSettings["LP"].Split('-')[0].Trim(), out tempByte))
                    {
                        SharedClass.Logger.Info(string.Format("Setting LpFloor To {0}", tempByte));
                        Priority.LpFloor = tempByte;
                    }
                    tempByte = Priority.LpCeil;
                    if (byte.TryParse(ConfigurationManager.AppSettings["LP"].Split('-')[1].Trim(), out tempByte))
                    {
                        SharedClass.Logger.Info(string.Format("Setting LpCeil To {0}", tempByte));
                        Priority.LpCeil = tempByte;
                    }
                }
                if (ConfigurationManager.AppSettings["RabbitMQHost"] != null)
                {
                    SharedClass.RabbitMQClient = new RabbitMQClient();
                    //SharedClass.HangupProcessor = new HangupProcessor();
                    SharedClass.RabbitMQClient.Host = ConfigurationManager.AppSettings["RabbitMQHost"].Trim();
                    SharedClass.Logger.Info(string.Format("Setting RabbitMQHost To {0}", SharedClass.RabbitMQClient.Host));
                    if (ConfigurationManager.AppSettings["RabbitMQPort"] != null)
                    {
                        tempInt = SharedClass.RabbitMQClient.Port;
                        if (int.TryParse(ConfigurationManager.AppSettings["RabbitMQPort"].Trim(), out tempInt))
                        {
                            SharedClass.Logger.Info(string.Format("Setting RabbitMQPort To {0}", tempInt));
                            SharedClass.RabbitMQClient.Port = tempInt;
                        }
                    }
                    if (ConfigurationManager.AppSettings["RabbitMQUser"].Trim().Length > 0)
                    {
                        SharedClass.Logger.Info(string.Format("Setting RabbitMQUser To {0}", ConfigurationManager.AppSettings["RabbitMQUser"]));
                        SharedClass.RabbitMQClient.User = ConfigurationManager.AppSettings["RabbitMQUser"];
                    }
                    if (ConfigurationManager.AppSettings["RabbitMQPassword"].Trim().Length > 0)
                    {
                        SharedClass.Logger.Info(string.Format("Setting RabbitMQPassword To {0}", ConfigurationManager.AppSettings["RabbitMQPasasword"]));
                        SharedClass.RabbitMQClient.Password = ConfigurationManager.AppSettings["RabbitMQPassword"];
                    }
                }
                if (ConfigurationManager.AppSettings["AuthKey"] != null)
                {
                    SharedClass.Notifier.AuthKey = ConfigurationManager.AppSettings["AuthKey"];
                    if (ConfigurationManager.AppSettings["AuthToken"] != null)
                    {
                        SharedClass.Notifier.AuthToken = ConfigurationManager.AppSettings["AuthToken"];
                    }
                }
                if (ConfigurationManager.AppSettings["SendAlertsTo"] != null)
                {
                    SharedClass.Notifier.SendAlertsTo = ConfigurationManager.AppSettings["SendAlertsTo"];
                }
                if (ConfigurationManager.AppSettings["SenderId"] != null)
                {
                    SharedClass.Notifier.SenderId = ConfigurationManager.AppSettings["SenderId"];
                }

                SharedClass.Notifier.ApiUrl = ConfigurationManager.AppSettings["ApiUrl"] == null ? "" : ConfigurationManager.AppSettings["ApiUrl"].ToString();
                if (ConfigurationManager.AppSettings["IsHangupProcessInMemory"] != null)
                {
                    tempBoolean = false;
                    if (bool.TryParse(ConfigurationManager.AppSettings["IsHangupProcessInMemory"].Trim(), out tempBoolean))
                    {
                        SharedClass.IsHangupProcessInMemory = tempBoolean;
                    }
                }

                SharedClass.Listener.Ip   = ConfigurationManager.AppSettings["ListenerIp"] == null ? "" : ConfigurationManager.AppSettings["ListenerIp"].ToString();
                SharedClass.Listener.Port = ConfigurationManager.AppSettings["ListenerPort"] == null ? 0 : Convert.ToInt16(ConfigurationManager.AppSettings["ListenerPort"]);
                if (ConfigurationManager.AppSettings["BulkRequestBatchCount"] != null)
                {
                    tempInt = SharedClass.BulkRequestBatchCount;
                    if (int.TryParse(ConfigurationManager.AppSettings["BulkRequestBatchCount"].Trim(), out tempInt))
                    {
                        SharedClass.BulkRequestBatchCount = tempInt;
                    }
                }
            }
            catch (Exception e)
            {
                SharedClass.Logger.Info(e.ToString());
                throw new ConfigurationException("Unable to load configuration from file. Please checck application log file for exception details");
            }
        }
Beispiel #13
0
        public void LoadGateways()
        {
            SharedClass.Logger.Info("Fetching Gateways List From Database");
            SqlCommand sqlCommand = null;

            try
            {
                sqlCommand             = new SqlCommand("Get_VoiceGateways", new SqlConnection(SharedClass.GetConnectionString(Environment.PRODUCTION)));
                sqlCommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
                DataSet        dataSet        = new DataSet();
                sqlDataAdapter.SelectCommand = sqlCommand;
                sqlDataAdapter.Fill(dataSet);
                if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                    {
                        Gateway gateway       = new Gateway();
                        Thread  gatewayThread = null;
                        try
                        {
                            gateway.Id                  = Convert.ToInt16(dataRow["Id"]);
                            gateway.Name                = dataRow["Code"].ToString().Replace(" ", "");
                            gateway.ConnectUrl          = dataRow["ConnectUrl"].ToString();
                            gateway.Ip                  = dataRow["Ip"].ToString();
                            gateway.Port                = Convert.ToInt32(dataRow["Port"]);
                            gateway.MaximumConcurrency  = Convert.ToInt32(dataRow["MaximumConcurrency"]);
                            gateway.CurrenctConcurrency = Convert.ToInt32(dataRow["CurrenctConcurrency"]);
                            gateway.OriginationUrl      = dataRow["OriginationUrl"].ToString();
                            if (!gateway.OriginationUrl.EndsWith("/"))
                            {
                                gateway.OriginationUrl += "/";
                            }
                            if (dataRow["ExtraDialString"] != DBNull.Value)
                            {
                                gateway.ExtraDialString = dataRow["ExtraDialString"].ToString();
                            }
                            gateway.CountryPrefix          = dataRow["CountryPrefix"].ToString();
                            gateway.IsCountryPrefixAllowed = Convert.ToBoolean(dataRow["IsCountryPrefixAllowed"].ToString());
                            gateway.DialPrefix             = dataRow["DialPrefix"].ToString();
                            if (dataRow.Table.Columns.Contains("StartingHour") && !dataRow["StartingHour"].IsDBNull())
                            {
                                byte tempByte = 0;
                                if (byte.TryParse(dataRow["StartingHour"].ToString(), out tempByte))
                                {
                                    gateway.StartingHour = tempByte;
                                }
                            }
                            if (dataRow.Table.Columns.Contains("StoppingHour") && !dataRow["StoppingHour"].IsDBNull())
                            {
                                byte tempByte = 23;
                                if (byte.TryParse(dataRow["StoppingHour"].ToString(), out tempByte))
                                {
                                    gateway.StoppingHour = tempByte;
                                }
                            }
                            if (dataRow.Table.Columns.Contains("UrgentPriorityQueueLastSlno") && !dataRow["UrgentPriorityQueueLastSlno"].IsDBNull())
                            {
                                long tempLong = 0;
                                if (long.TryParse(dataRow["UrgentPriorityQueueLastSlno"].ToString(), out tempLong))
                                {
                                    //gateway.UrgentPriorityQueueLastSlno = tempLong;
                                    CallsQueueSlno.SetSlno(gateway.Id, Environment.PRODUCTION, Priority.PriorityMode.Urgent, tempLong);
                                }
                            }
                            //gateway.HighPriorityQueueLastSlno = Convert.ToInt64(dataRow["HighPriorityQueueLastSlno"]);
                            CallsQueueSlno.SetSlno(gateway.Id, Environment.PRODUCTION, Priority.PriorityMode.High, Convert.ToInt64(dataRow["HighPriorityQueueLastSlno"]));
                            //gateway.MediumPriorityQueueLastSlno = Convert.ToInt64(dataRow["MediumPriorityQueueLastSlno"]);
                            CallsQueueSlno.SetSlno(gateway.Id, Environment.PRODUCTION, Priority.PriorityMode.Medium, Convert.ToInt64(dataRow["MediumPriorityQueueLastSlno"]));
                            //gateway.LowPriorityQueueLastSlno = Convert.ToInt64(dataRow["LowPriorityQueueLastSlno"]);
                            CallsQueueSlno.SetSlno(gateway.Id, Environment.PRODUCTION, Priority.PriorityMode.Low, Convert.ToInt64(dataRow["LowPriorityQueueLastSlno"]));
                            gateway.NumberOfPushThreads = Convert.ToByte(dataRow["PushThreadsTotal"]);
                            gatewayThread      = new Thread(new ThreadStart(gateway.Start));
                            gatewayThread.Name = gateway.Name.Replace(" ", "");
                            SharedClass.Logger.Info("Starting Gateway " + gateway.Name);
                            gatewayThread.Start();
                        }
                        catch (Exception ex)
                        {
                            SharedClass.Logger.Error("Error Starting Gateway, " + ex.ToString());
                            SharedClass.DumpLogger.Error(dataRow.ToString());
                        }
                    }
                }
                else
                {
                    SharedClass.Logger.Error("No Gateways Returned From DataBase");
                }
            }
            catch (Exception ex)
            {
                SharedClass.Logger.Error("Error Getting Gateways List, Reason : " + ex.ToString());
            }
        }
Beispiel #14
0
        public void StartDbPoll(object input)
        {
            Environment environment = (Environment)input;

            SharedClass.Logger.Info("Started");
            SqlCommand sqlCommand = new SqlCommand("VC_Get_PendingBulkVoiceRequests", new SqlConnection(SharedClass.GetConnectionString(environment)));

            sqlCommand.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sqlDataAdapter = null;
            DataSet        dataSet        = null;

            while (!SharedClass.HasStopSignal)
            {
                try
                {
                    //if (environment == Environment.STAGING)
                    ////_isIamPollingS = true;
                    //{
                    //    while (this._pollThreadStaging.ThreadState != ThreadState.Stopped)
                    //    {
                    //        SharedClass.Logger.Info(string.Format("Staging Poll Thread Not Yet Stopped. ThreadState:{0}", this._pollThreadStaging.ThreadState));
                    //        Thread.Sleep(2000);
                    //        if (this._pollThreadStaging.ThreadState == ThreadState.WaitSleepJoin)
                    //            this._pollThreadStaging.Interrupt();
                    //    }
                    //}
                    //else
                    //{
                    //    while (this._pollThread.ThreadState != ThreadState.Stopped)
                    //    {
                    //        SharedClass.Logger.Info(string.Format("Staging Poll Thread Not Yet Stopped. ThreadState:{0}", this._pollThread.ThreadState));
                    //        Thread.Sleep(2000);
                    //        if (this._pollThread.ThreadState == ThreadState.WaitSleepJoin)
                    //            this._pollThread.Interrupt();
                    //    }
                    //}
                    sqlCommand.Parameters.Clear();
                    sqlCommand.Parameters.Add("@LastRequestId", SqlDbType.BigInt).Value = BulkRequestId.GetLastId(environment);
                    sqlDataAdapter = new SqlDataAdapter();
                    sqlDataAdapter.SelectCommand = sqlCommand;
                    dataSet = new DataSet();
                    sqlDataAdapter.Fill(dataSet);
                    if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)

                    {
                        BulkRequest bulkRequest = null;
                        foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                        {
                            try
                            {
                                bulkRequest              = new BulkRequest();
                                bulkRequest.Environment  = environment;
                                bulkRequest.Id           = Convert.ToInt64(dataRow["Id"].ToString());
                                bulkRequest.Xml          = dataRow["Xml"].ToString();
                                bulkRequest.Ip           = dataRow["Ip"].ToString();
                                bulkRequest.ToolId       = Convert.ToByte(dataRow["ToolId"]);
                                bulkRequest.Destinations = new StringBuilder(dataRow["MobileNumbersList"].ToString());
                                bulkRequest.UUIDs        = new StringBuilder(dataRow["UUIDsList"].ToString());
                                if (!dataRow["RingUrl"].IsDBNull())
                                {
                                    bulkRequest.RingUrl = dataRow["RingUrl"].ToString();
                                }
                                else
                                {
                                    bulkRequest.RingUrl = "";
                                }
                                if (!dataRow["AnswerUrl"].IsDBNull())
                                {
                                    bulkRequest.AnswerUrl = dataRow["AnswerUrl"].ToString();
                                }
                                else
                                {
                                    bulkRequest.AnswerUrl = "";
                                }
                                if (!dataRow["HangupUrl"].IsDBNull())
                                {
                                    bulkRequest.HangupUrl = dataRow["HangupUrl"].ToString();
                                }
                                else
                                {
                                    bulkRequest.HangupUrl = "";
                                }
                                if (!dataRow["Retries"].IsDBNull())
                                {
                                    bulkRequest.Retries = Convert.ToByte(dataRow["Retries"].ToString());
                                }
                                else
                                {
                                    bulkRequest.Retries = 0;
                                }
                                if (!dataRow["CallerId"].IsDBNull())
                                {
                                    bulkRequest.CallerId = dataRow["CallerId"].ToString();
                                }
                                else
                                {
                                    bulkRequest.CallerId = "";
                                }

                                if (!dataRow["Status"].IsDBNull())
                                {
                                    bulkRequest.Status = Convert.ToByte(dataRow["Status"].ToString());
                                }
                                else
                                {
                                    bulkRequest.Status = 0;
                                }
                                if (dataRow["ProcessedCount"] != DBNull.Value)
                                {
                                    bulkRequest.ProcessedCount = Convert.ToInt32(dataRow["ProcessedCount"].ToString());
                                }
                                if (!dataRow["TotalCount"].IsDBNull())
                                {
                                    bulkRequest.TotalCount = Convert.ToInt32(dataRow["TotalCount"].ToString());
                                }
                                if (dataRow["RequestId"] != DBNull.Value)
                                {
                                    bulkRequest.VoiceRequestId = Convert.ToInt64(dataRow["RequestId"].ToString());
                                }
                                bulkRequest.CampaignScheduleId = Convert.ToInt64(dataRow["CampaignScheduleId"]);
                                AccountProcessor accountProcessor = null;
                                lock (SharedClass.ActiveAccountProcessors)
                                {
                                    SharedClass.ActiveAccountProcessors.TryGetValue(Convert.ToInt32(dataRow["AccountId"].ToString()), out accountProcessor);
                                    if (accountProcessor == null)
                                    {
                                        accountProcessor           = new AccountProcessor();
                                        accountProcessor.AccountId = Convert.ToInt32(dataRow["AccountId"].ToString());
                                        Thread accountProcessorThread = new Thread(new ThreadStart(accountProcessor.Start));
                                        accountProcessorThread.Name = "Account_" + dataRow["AccountId"];
                                        accountProcessorThread.Start();
                                    }
                                    accountProcessor.EnQueue(bulkRequest);
                                }
                                BulkRequestId.SetLastId(bulkRequest.Id, environment);
                            }
                            catch (Exception ex1)
                            {
                                SharedClass.Logger.Error("Error In BulkPoll For Loop : " + ex1.ToString());
                                try
                                {
                                    PropertyInfo[] properties = bulkRequest.GetType().GetProperties();
                                    foreach (PropertyInfo propertyInfo in properties)
                                    {
                                        if (propertyInfo.CanRead)
                                        {
                                            if (propertyInfo.GetValue(bulkRequest) == DBNull.Value)
                                            {
                                                SharedClass.DumpLogger.Error(propertyInfo.Name + " : NULL");
                                            }
                                            else
                                            {
                                                SharedClass.DumpLogger.Error(propertyInfo.Name + " : " + propertyInfo.GetValue(bulkRequest).ToString());
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex2)
                                {
                                    SharedClass.Logger.Error("Error Dumping Info : " + ex2.ToString());
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SharedClass.Logger.Error("Error In BulkPoller, " + ex.ToString());
                }
                finally
                {
                    NullReferenceException referenceException;
                    try
                    {
                        sqlDataAdapter.Dispose();
                    }
                    catch (NullReferenceException ex)
                    {
                        referenceException = ex;
                    }
                    try
                    {
                        dataSet.Dispose();
                    }
                    catch (NullReferenceException ex)
                    {
                        referenceException = ex;
                    }
                    sqlDataAdapter = null;
                    dataSet        = null;
                }
                try
                {
                    Thread.Sleep(5000);
                }
                catch (ThreadAbortException ex)
                {
                    SharedClass.Logger.Error(ex);
                }
                catch (ThreadInterruptedException ex)
                {
                    SharedClass.Logger.Error(ex);
                }
            }
        }