Пример #1
0
        private void UpdateSMSStatus()
        {
            SharedClass.Logger.Info("Started");
            SqlConnection sqlConnection = new SqlConnection(SharedClass.ConnectionString);
            SqlCommand    sqlCommand    = new SqlCommand("UpdateSMSStatus", sqlConnection);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            while (!SharedClass.HasStopSignal)
            {
                try
                {
                    if (this.SMSStatusQueueCount() > 0)
                    {
                        SMSResult smsResult = this.DeQueueSMSStatus();
                        if (smsResult != null)
                        {
                            SharedClass.Logger.Info(string.Format("Updating Status. SMS: {0}, IsSuccessfullySent: {1}", smsResult.sms.Id, smsResult.IsSuccess));
                            sqlCommand.Parameters.Clear();
                            sqlCommand.Parameters.Add(Label.ProcedureParameters.SMS_ID, SqlDbType.BigInt).Value = smsResult.sms.Id;
                            sqlCommand.Parameters.Add(Label.ProcedureParameters.STATUS_ID, SqlDbType.Int).Value = smsResult.StatusId;
                            sqlCommand.Parameters.Add(Label.ProcedureParameters.SMS_JOB_NUMBER, SqlDbType.VarChar, 50).Value = smsResult.JobNumber;
                            sqlCommand.Parameters.Add(Label.ProcedureParameters.SUCCESS, SqlDbType.Bit).Direction            = ParameterDirection.Output;
                            sqlCommand.Parameters.Add(Label.ProcedureParameters.MESSAGE, SqlDbType.VarChar, 1000).Direction  = ParameterDirection.Output;
                            if (sqlConnection.State != ConnectionState.Open)
                            {
                                sqlConnection.Open();
                            }
                            sqlCommand.ExecuteNonQuery();
                            if (!sqlCommand.IsSuccess())
                            {
                                SharedClass.Logger.Error("Error Returned From Stored Procedure. Message: " +
                                                         (sqlCommand.Parameters[Label.ProcedureParameters.MESSAGE].Value.IsDbNull() ? "NULL" : sqlCommand.Parameters[Label.ProcedureParameters.MESSAGE].Value.ToString()));
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            Thread.Sleep(2000);
                        }
                        catch (ThreadInterruptedException e)
                        { }
                        catch (ThreadAbortException e)
                        { }
                    }
                }
                catch (Exception e)
                {
                    SharedClass.Logger.Error(e.ToString());
                }
            }
            SharedClass.Logger.Info("Exit");
        }
Пример #2
0
 private bool EnQueueSMSStatus(SMSResult smsResult)
 {
     try
     {
         while (!this._smsQueueMutex.WaitOne())
         {
             Thread.Sleep(20);
         }
         this._smsStatusQueue.Enqueue(smsResult);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
     finally
     {
         this._smsQueueMutex.ReleaseMutex();
     }
 }
Пример #3
0
        private SMSResult DeQueueSMSStatus()
        {
            SMSResult smsResult = null;

            try
            {
                while (!this._smsQueueMutex.WaitOne())
                {
                    Thread.Sleep(20);
                }
                if (this._smsStatusQueue.Count > 0)
                {
                    smsResult = this._smsStatusQueue.Dequeue();
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                this._smsQueueMutex.ReleaseMutex();
            }
            return(smsResult);
        }
Пример #4
0
        private void Push()
        {
            SharedClass.Logger.Info("Started");
            string smsResponse = string.Empty;

            while (!SharedClass.HasStopSignal)
            {
                SMSResult smsResult = null;
                smsResult = new SMSResult();

                try
                {
                    if (this.SMSQueueCount() > 0)
                    {
                        SMS sms = this.DeQueueSMS();
                        smsResult.sms = sms;
                        JObject Jobj = new JObject();
                        if (sms != null)
                        {
                            JObject smsPostdata;
                            sms.MobileNumber = sms.MobileNumber.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("+", "");
                            HttpWebRequest  webRequestObj   = null;
                            HttpWebResponse webResponseObj  = null;
                            StreamWriter    streamWriterObj = null;
                            StreamReader    streamReaderObj = null;
                            CredentialCache credentials     = new CredentialCache();

                            //if ((IsUnicode(sms.Message) == true)) {
                            //    sms.MessageType = "OL";
                            //}
                            //else {
                            //    sms.MessageType = "N";
                            //}

                            //if ((sms.MessageType == "OL")) {
                            //    sms.Message = convertHexa(sms.Message);
                            //}

                            smsPostdata = new JObject(
                                new JProperty("Text", sms.Message),
                                new JProperty("Number", sms.MobileNumber),
                                new JProperty("DRNotifyUrl", ""),
                                new JProperty("DRNotifyHttpMethod", "POST"),
                                new JProperty("Tool", "API"),
                                new JProperty("SenderId", sms.SenderId));
                            SharedClass.Logger.Info("PostData" + smsPostdata.ToString());
                            credentials.Add(new Uri(SharedClass.SMSProvider),
                                            "Basic", new NetworkCredential(SharedClass.SMSProviderAuthkey, SharedClass.SMSProviderSecretKey));
                            webRequestObj             = (HttpWebRequest)WebRequest.Create(SharedClass.SMSProvider);
                            webRequestObj.Method      = "Post";
                            webRequestObj.Credentials = credentials;
                            webRequestObj.ContentType = "application/json";
                            streamWriterObj           = new StreamWriter(webRequestObj.GetRequestStream());
                            streamWriterObj.Write(smsPostdata);
                            streamWriterObj.Flush();
                            streamWriterObj.Close();
                            webResponseObj  = (HttpWebResponse)webRequestObj.GetResponse();
                            streamReaderObj = new StreamReader(webResponseObj.GetResponseStream());
                            smsResponse     = streamReaderObj.ReadToEnd();
                            streamReaderObj.Close();

                            Jobj = JObject.Parse(smsResponse);

                            sms.JobNumber = Jobj.SelectToken("ApiId").ToString();
                            if (Convert.ToBoolean(Jobj.SelectToken("Success").ToString()))
                            {
                                smsResult.IsSuccess = true;
                                smsResult.StatusId  = 3;
                                smsResult.JobNumber = sms.JobNumber;
                            }
                            else
                            {
                                smsResult.IsSuccess = false;
                                smsResult.StatusId  = 5;
                                smsResult.JobNumber = sms.JobNumber;
                            }
                            this.EnQueueSMSStatus(smsResult);
                        }
                    }
                    else
                    {
                        try
                        {
                            Thread.Sleep(2000);
                        }
                        catch (ThreadInterruptedException e)
                        { }
                        catch (ThreadAbortException e)
                        { }
                    }
                }
                catch (Exception e)
                {
                    smsResult.StatusId  = 5;
                    smsResult.JobNumber = "";
                    this.EnQueueSMSStatus(smsResult);
                    SharedClass.Logger.Error(e.ToString());
                }
            }
            SharedClass.Logger.Info("Exit");
        }