mCore™ .NET SMS Library 1.2

mCore.SMS.QueueSmartMessageSent Event

Description:

If Queue.Enabled property is set as True, the QueueSmartMessageSent Event is raised at the end of sending each unsent Smart SMS that was added to the message queue previously using mCore.SMS.SendSmartMessageToQueue method.

The QueueSmartMessageSent event is raised on a secondary thread.

Namespace: mCore
Assembly: mCoreLib (in mCoreLib.dll)

Remarks:

Exceptions:

mCore.GeneralException

Usage Example:

Visual Basic
Public Class MyClass
   Public WithEvents objSMS As New mCore.SMS
   Public Sub SendQueue()
      Dim strResult As String = ""
      Dim strMsg As String = "This is a test message"
      Dim strKey as String
      Try
         SetCommParameters()
         objSMS.DeliveryReport = True
 

         'Send Smart SMS to phone application port 1500
         strKey = objSMS.SendSmartMessageToQueue("+919873094767", strMsg, _
                                                 1500, mCore.QueuePriority.High)
         MsgBox("Smart SMS added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

         objSMS.DeliveryReport = False
         'No delivery report for the following Smart SMS
         strKey = objSMS.SendSmartMessageToQueue("+919810098765", strMsg, 1500)
         MsgBox("Smart SMS added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

         objSMS.DeliveryReport = True
         strKey = objSMS.SendSmartMessageToQueue("+919811045678", strMsg, _
                                                 1500, mCore.QueuePriority.Low)
         MsgBox("Smart SMS added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

         'Message queue is enabled
         objSMS.Queue.Enabled = True

         'Smart SMS can be added to the queue even
         'when the Message queue is enabled

         strKey = objSMS.SendSmartMessageToQueue("+919873012345", strMsg, _
                                                1500, mCore.QueuePriority.High)
         MsgBox("Smart SMS added to queue." & vbCrLf & _
                  "[Queue Key: " & strKey & "]")

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message, MsgBoxStyle.Critical, "mCore Demo")
      Catch ex As Exception
      End Try
   End Sub

   'Event at the start of sending a queued Smart SMS
   Private Sub objSMS_QueueSmartMessageSending(ByVal sender As Object, _
                     ByVal e As mCore.QueueSmartMessageSendingEventArgs) _
                     Handles objSMS.QueueSmartMessageSending
      MsgBox("Sending Smart SMS to: " & e.DestinationNumber & vbCrLf & _
                     "[Queue Key: " & e.QueueMessageKey & _
                     "]", MsgBoxStyle.Information, "SENDING SMART SMS")
   End Sub

   'Event at the end of sending a queued Smart SMS

   Private Sub objSMS_QueueSmartMessageSent(ByVal sender As Object, _
                       ByVal e As mCore.QueueSmartMessageSentEventArgs) _
                       Handles objSMS.QueueSmartMessageSent
      If e.ErrorCode > 0 Then
         MsgBox("Smart SMS sending FAILED to: " & e.DestinationNumber & _
               vbCrLf & "[ERROR: " & e.ErrorDescription & _
               "]" & vbCrLf & "[Queue Key: " & e.QueueMessageKey & _
               "]", MsgBoxStyle.Critical, "SMART SMS FAILED")
      Else
         MsgBox("Smart SMS SENT to: " & e.DestinationNumber & vbCrLf & _
               "[Queue Key: " & e.QueueMessageKey & _
               "]", MsgBoxStyle.Information, "SMART SMS SENT")
      End If
   End Sub

   'Delivery Report Event Handling
   'A message box will pop-up whenever
   'a delivery report is received

   Private Sub objSMS_NewDeliveryReport(ByVal sender As Object, _
               ByVal e As mCore.NewDeliveryReportEventArgs) _
               Handles objSMS.NewDeliveryReport
      If e.Status Then
         MsgBox("MESSAGE DELIVERED" & vbCrLf & vbCrLf & "TO: " & _
               e.Phone & vbCrLf & vbCrLf & "DELIVERY DATE/TIME: " _
               & e.DeliveryTimeStamp.ToString & vbCrLf & vbCrLf & _
               "[Message Ref.: " & e.MessageReference.ToString & _
               "]", MsgBoxStyle.Information, "DELIVERY REPORT")
      Else
         MsgBox("MESSAGE DELIVERY FAILED" & vbCrLf & vbCrLf & _
               "TO: " & e.Phone & vbCrLf & vbCrLf & _
               "REPORT DATE/TIME: " & e.DeliveryTimeStamp & _
               vbCrLf & vbCrLf & "[Message Ref.: " & _
               e.MessageReference.ToString & "]", _
               MsgBoxStyle.Critical, "DELIVERY REPORT")
      End If
   End Sub

   Public Sub SetCommParameters()
      Try
         objSMS.Port = "COM1"
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200
         objSMS.DataBits = mCore.DataBits.Eight
         objSMS.StopBits = mCore.StopBits.One
         objSMS.Parity = mCore.Parity.None
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message)
      Catch ex As Exception
      End Try
   End Function
End Class

 
C#

class MyClass
{
   public mCore.SMS objSMS = new mCore.SMS();

   public MyClass()

   {
      objSMS.NewDeliveryReport +=
         new mCore.SMS.NewDeliveryReportEventHandler(objSMS_NewDeliveryReport);

      objSMS.QueueSMSSending +=
         new mCore.SMS.QueueSmartMessageSendingEventHandler(objSMS_QueueSMSSending);

      objSMS.QueueSMSSent +=
         new mCore.SMS.QueueSmartMessageSentEventHandler(objSMS_QueueSMSSent);
   }

   public static void SendQueue()
   {
      string strResult = "";
      string strMsg = "This is a test message";
      string strKey = "";
      try
      {

         SetCommParameters();
         objSMS.DeliveryReport = true;
 

         //Send Smart SMS to phone application port 1500
         strKey = objSMS.SendSmartMessageToQueue
                        ("+919873094767", strMsg, 1500, mCore.QueuePriority.High);
         MessageBox.Show("Smart SMS added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");

         objSMS.DeliveryReport = false;
         //No delivery report for the following Smart SMS
         strKey = objSMS.SendSmartMessageToQueue
                        ("+919810098765", strMsg, 1500, mCore.QueuePriority.Low);
         MessageBox.Show("Smart SMS added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");

         objSMS.DeliveryReport = true;
         strKey = objSMS.SendSmartMessageToQueue
                        ("+919811045678", strMsg, 1500, mCore.QueuePriority.High);
         MessageBox.Show("Smart SMS added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");

         //Message queue is enabled
         objSMS.Queue.Enabled = true;

         //Smart SMS can be added to the queue even
         //when the Message queue is enabled

         strKey = objSMS.SendSmartMessageToQueue
                        ("+919873012345", strMsg, 1500, mCore.QueuePriority.High);
         MessageBox.Show("Smart SMS added to queue.\r\n" +
                  "[Queue Key: " + strKey + "]");
      }

      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }
      catch (Exception e)
      {
      }
   }

   //Event at the start of sending a queued Smart SMS
   private void objSMS_QueueSmartMessageSending
      (object sender, mCore.QueueSmartMessageSendingEventArgs e)
   {
      MessageBox.Show("Sending message to: " + e.DestinationNumber + "/r/n" +
            "[Queue Key: " + e.QueueMessageKey + "]");
   }

   //Event at the end of sending a queued Smart SMS
   private void objSMS_QueueSmartMessageSent
      (object sender, mCore.QueueSmartMessageSentEventArgs e)
   {
      if (e.ErrorCode > 0)
      {
         MessageBox.Show("Smart SMS sending FAILED to: " + e.DestinationNumber +
               "/r/n" + "[ERROR: " + e.ErrorDescription + _
               "]/r/n[Queue Key: " & e.QueueMessageKey + "]");
      }
      else
      {
         MessageBox.Show("Smart SMS SENT to: " + e.DestinationNumber +
               "/r/n" + "[ERROR: " + e.ErrorDescription + _
               "]/r/n[Queue Key: " & e.QueueMessageKey + "]");
      }
   }

   //Delivery Report Event Handling
   //A message box will pop-up whenever
   //a delivery report is received

   private void objSMS_NewDeliveryReport
      (object sender, mCore.NewDeliveryReportEventArgs e)
   {
      if (e.Status)
      {
         MessageBox.Show("MESSAGE DELIVERED" + "/r/n/r/n" +
            "TO: " + e.Phone + "/r/n/r/n" +
            "DELIVERY DATE/TIME: " + e.DeliveryTimeStamp.ToString() +
            "/r/n/r/n" + "[Message Ref.: " +
            e.MessageReference.ToString() + "]");
      }
      else
      {
         MessageBox.Show("MESSAGE DELIVERY FAILED" + "/r/n/r/n" +
            "TO: " + e.Phone + "/r/n/r/n" +
            "REPORT DATE/TIME: " + e.DeliveryTimeStamp.ToString() +
            "/r/n/r/n" + "[Message Ref.: " +
            e.MessageReference.ToString() + "]");
      }
   }

   public static void SetCommParameters()
   {
      try
      {
         objSMS.Port = "COM1";
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200;
         objSMS.DataBits = mCore.DataBits.Eight;
         objSMS.StopBits = mCore.StopBits.One;
         objSMS.Parity = mCore.Parity.None;
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS;
      }

      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }
      catch (Exception e)
      {
      }
   }
}

See Also:

mCore.QueueSmartMessageSentEventArgs Class
mCore.SMS.QueueSmartMessageSentEventHandler Delegate
Queue.Enabled Property
mCore.SMS.QueueSmartMessageSending Event
 

Copyright © IG Logix Softech Pvt Ltd, All Rights Reserved