Ejemplo n.º 1
0
        private void SendSMS()
        {
            try
            {
                // Get unsent outgoing message from the database
                string query = " WHERE NVL(ATTEMPT_COUNT,0) < 3 AND SENT_STATUS = " + (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSSentStatus.Unsent + " AND MESSAGE_DIRECTION = " + (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSDirection.Outgoing;
                VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCollection unsentSMSes = VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.GetFilteredRecords(query);
                bool DataProcess = true;
                // Send message to customer
                foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE sms in unsentSMSes)
                {
                    DataProcess = true;
                    // Send message via SMS Gateway
                    // Message will be sent if not older than 2 hours. attempt count should be less thyan equal to 5

                    if ((DateTime.Now - sms.CreationDate).TotalHours <= 2)
                    {
                        if (sms.AttemptCount < 3)
                        {
                            LogMessage("SMS sending attempt count is greater than 3 so will not be sent. SMS entry id: " + sms.EntryId + " Attempt: " + sms.AttemptCount + " ResponseCode :" + sms.ResponseCode);
                            if (sms.AttemptCount > 0)
                            {
                                if (sms.OperatorResponseCode != 3701)
                                {
                                    if ((DateTime.Now - sms.MessageSendDateTime).TotalSeconds < 60)
                                    {
                                        DataProcess = false;
                                    }
                                }
                                else
                                {
                                    DataProcess = false;
                                }
                            }
                            if (DataProcess)
                            {
                                VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE smsResponse = smsGatewayController.SendSMS(sms);
                                #region Update SMS sent status in database
                                try
                                {
                                    LogMessage("Trying to update sms sent status in database.");
                                    sms.AttemptCount++;
                                    // Update status in database
                                    smsResponse.AttemptCount        = sms.AttemptCount;
                                    smsResponse.MessageSendDateTime = DateTime.Now;
                                    smsResponse.ModificationDate    = DateTime.Now;
                                    if (smsResponse.ResponseCode == 2200)
                                    {
                                        smsResponse.SentStatus = (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSSentStatus.Sent;
                                        LogMessage("2200 status received.");
                                    }

                                    VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.UpdateFirstResponse(smsResponse);
                                    LogMessage("SMS sent status updated successfully.");
                                }
                                catch (Exception ex)
                                {
                                    LogMessage("Failed tp update message sent status in database." + ex.Message);
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            LogMessage("SMS sending attempt count is greater than 5 so will not be sent. SMS entry id: " + sms.EntryId + " Attempt: " + sms.AttemptCount);
                        }
                    }
                    //else
                    //{
                    //    LogMessage("Message is 2 hours older so will not be sent. Message Entry Id:" + sms.EntryId);
                    //}
                }
            }
            catch (Exception ex)
            {
                LogMessage("Failed to send SMS." + ex.Message);
            }
            finally
            {
                Thread.Sleep(200);
            }
        }
Ejemplo n.º 2
0
 private void SendGoSMS()
 {
     try
     {
         bool DataProcess = false;
         // Get unsent outgoing message from the database
         VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCollection unsentSMSes = VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.GetAllSendSMS();
         foreach (VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE sms in unsentSMSes)
         {
             if (sms.AttemptCount == 0)
             {
                 DataProcess = true;
             }
             else
             {
                 if (sms.AttemptCount < 3)
                 {
                     if ((DateTime.Now - sms.ModificationDate).TotalSeconds > 60)
                     {
                         DataProcess = true;
                     }
                 }
             }
             if (DataProcess)
             {
                 VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE smsResponse = smsGatewayController.SendSMS(sms);
                 #region Update SMS sent status in database
                 try
                 {
                     LogMessage("Trying to update sms sent status in database.");
                     sms.AttemptCount++;
                     smsResponse.AttemptCount        = sms.AttemptCount;
                     smsResponse.MessageSendDateTime = DateTime.Now;
                     smsResponse.ModificationDate    = DateTime.Now;
                     VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.UpdateFirstResponse(smsResponse);
                     LogMessage("SMS sent status updated successfully. SMS id : " + sms.EntryId + " with status : " + smsResponse.OperatorResponseCode.ToString());
                 }
                 catch (Exception ex)
                 {
                     LogMessage("Failed tp update message sent status in database. SMS id : " + sms.EntryId + " Exception : " + ex.Message);
                 }
             }
             #endregion
         }
     }
     catch (Exception ex)
     {
         LogMessage("Failed to send SMS." + ex.Message);
     }
     finally
     {
         Thread.Sleep(200);
     }
 }
Ejemplo n.º 3
0
        void smsMessageQueue_PeekCompleted(object sender, PeekCompletedEventArgs e)
        {
            bool         receiveRecord = false;
            MessageQueue mq            = (MessageQueue)sender;

            Message m = (Message)mq.EndPeek(e.AsyncResult);

            m.Formatter = new BinaryMessageFormatter();

            try
            {
                if (m != null)
                {
                    m.Formatter = new BinaryMessageFormatter();

                    if (m.Body != null)
                    {
                        LogMessage("New SMS found in SMS Message queue.");
                        if (m.Body is VaaaN.MLFF.Libraries.CommonLibrary.Classes.SmsNotification.SMSDetail)
                        {
                            VaaaN.MLFF.Libraries.CommonLibrary.Classes.SmsNotification.SMSDetail smsDetail = (VaaaN.MLFF.Libraries.CommonLibrary.Classes.SmsNotification.SMSDetail)m.Body;

                            #region Save balance notification in database
                            try
                            {
                                VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE smsOutgoing = new VaaaN.MLFF.Libraries.CommonLibrary.CBE.SMSCommunicationHistoryCBE();
                                smsOutgoing.EntryId               = 0;
                                smsOutgoing.TmsId                 = 1;
                                smsOutgoing.CustomerAccountId     = smsDetail.AccountId;
                                smsOutgoing.CustomerName          = smsDetail.CustomerName;
                                smsOutgoing.MobileNumber          = smsDetail.SenderMobileNumber;
                                smsOutgoing.MessageDirection      = (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSDirection.Outgoing;
                                smsOutgoing.MessageBody           = smsDetail.SMSMessage;
                                smsOutgoing.SentStatus            = (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSSentStatus.Unsent;
                                smsOutgoing.ReceivedProcessStatus = (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSReceivedMessageProcessStatus.UnProcessed;
                                smsOutgoing.MessageSendDateTime   = DateTime.Now;
                                smsOutgoing.MessageReceiveTime    = DateTime.Now;
                                smsOutgoing.MessageDeliveryStatus = (int)VaaaN.MLFF.Libraries.CommonLibrary.Constants.SMSDeliveryStatus.UnDelivered; //DELIVERED=1,UNDELIVERED=2
                                smsOutgoing.AttemptCount          = 0;
                                smsOutgoing.CreationDate          = Convert.ToDateTime(DateTime.Now.ToString(VaaaN.MLFF.Libraries.CommonLibrary.Constants.dateTimeFormat24H));
                                smsOutgoing.ModificationDate      = DateTime.Now;
                                smsOutgoing.ModifiedBy            = 0;
                                smsOutgoing.AccountHistoryId      = smsDetail.AccountHistoryId;
                                LogMessage("Inserting sms communication history. Detail:" + smsOutgoing.ToString());
                                VaaaN.MLFF.Libraries.CommonLibrary.BLL.SMSCommunicationHistoryBLL.Insert(smsOutgoing);
                                LogMessage("SMS communication history updated successfully.");
                            }
                            catch (Exception ex)
                            {
                                LogMessage("Failed to insert SMS communication history." + ex.Message);
                            }
                            #endregion

                            receiveRecord = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogMessage("Error in peeking inbox queue. " + ex.ToString());
                receiveRecord = false;
            }
            finally
            {
                if (receiveRecord)
                {
                    mq.Receive();
                }

                smsMessageQueue.BeginPeek();
            }
        }
Ejemplo n.º 4
0
 public void Remove(SMSCommunicationHistoryCBE value)
 {
     List.Remove(value);
 }
Ejemplo n.º 5
0
 public void Insert(int index, SMSCommunicationHistoryCBE value)
 {
     List.Insert(index, value);
 }
Ejemplo n.º 6
0
 public int IndexOf(SMSCommunicationHistoryCBE value)
 {
     return(List.IndexOf(value));
 }
Ejemplo n.º 7
0
 public int Add(SMSCommunicationHistoryCBE value)
 {
     return(List.Add(value));
 }