Пример #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();
        }
Пример #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());
     }
 }
Пример #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());
                }
            }
        }
Пример #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());
     }
 }
Пример #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());
                }
            }
        }
Пример #6
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();
 }
Пример #7
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);
            }
        }
Пример #8
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();
            }
        }
Пример #9
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());
            }
        }
Пример #10
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);
                }
            }
        }