Example #1
0
 public void OnDeliveryStatusNotificationReceived(DeliveryInfoNotification deliveryInfoNotification)
 {
     if (_onDeliveryStatusNotificationReceived != null)
     {
         _onDeliveryStatusNotificationReceived(deliveryInfoNotification);
     }
 }
 private void processRequestData(String json)
 {
     try
     {
         if (json.Trim().Length > 0)
         {
             if (smsMessagingImpl != null)
             {
                 if (json.Contains("deliveryInfoNotification"))
                 {
                     DeliveryInfoNotification deliveryInfoNotification = smsMessagingImpl.ConvertJsonToDeliveryInfoNotification(json);
                     if (smsMessagingImpl.DeliveryStatusPushNotificationsListeners != null)
                     {
                         for (int i = 0; i < smsMessagingImpl.DeliveryStatusPushNotificationsListeners.Count; i++)
                         {
                             smsMessagingImpl.DeliveryStatusPushNotificationsListeners[i].OnDeliveryStatusNotificationReceived(deliveryInfoNotification);
                         }
                     }
                 }
                 else if (json.Contains("inboundSMSMessage"))
                 {
                     if (smsMessagingImpl != null)
                     {
                         if (smsMessagingImpl.InboundMessagePushNotificationsListeners != null)
                         {
                             InboundSMSMessageList smsMessagesList = smsMessagingImpl.ConvertJsonToInboundSMSMessageNotification(json);
                             for (int i = 0; i < smsMessagingImpl.InboundMessagePushNotificationsListeners.Count; i++)
                             {
                                 smsMessagingImpl.InboundMessagePushNotificationsListeners[i].OnMessageReceived(smsMessagesList);
                             }
                         }
                     }
                 }
             }
             else if (hlrClientImpl != null)
             {
                 if (json.Contains("terminalRoamingStatusList"))
                 {
                     if (hlrClientImpl.HlrPushNotificationsListeners != null)
                     {
                         RoamingNotification roamingNotification = hlrClientImpl.ConvertJsonToHLRNotification(json);
                         for (int i = 0; i < hlrClientImpl.HlrPushNotificationsListeners.Count; i++)
                         {
                             hlrClientImpl.HlrPushNotificationsListeners[i].OnHLRReceived(roamingNotification);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         if (LOGGER.IsErrorEnabled)
         {
             LOGGER.Error("Error occured while trying to process pushed JSON: " + json + ". Message: " + e.Message);
         }
     }
 }
Example #3
0
    private void ListenerCallback(IAsyncResult result)
    {
        HttpListenerContext context = listener.EndGetContext(result);

        Stream stream = context.Request.InputStream;

        int read = 0;

        byte[] buffer = new byte[1024];

        read = stream.Read(buffer, 0, buffer.Length);

        string json = Encoding.ASCII.GetString(buffer, 0, read);

        if (smsMessagingImpl != null)
        {
            if (json.Contains("deliveryInfoNotification"))
            {
                DeliveryInfoNotification deliveryInfoNotification = smsMessagingImpl.ConvertJsonToDeliveryInfo(json);
                if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                {
                    for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                    {
                        smsMessagingImpl.DeliveryStatusNotificationPushListeners[i].OnDeliveryStatusNotificationReceived(deliveryInfoNotification);
                    }
                }
            }
            else if (json.Contains("inboundSMSMessage"))
            {
                if (smsMessagingImpl != null)
                {
                    if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                    {
                        InboundSMSMessageList smsMessagesList = smsMessagingImpl.ConvertJsonToInboundSMSMessageList(json);
                        for (int i = 0; i < smsMessagingImpl.InboundMessagePushListeners.Count; i++)
                        {
                            smsMessagingImpl.InboundMessagePushListeners[i].OnMessageReceived(smsMessagesList);
                        }
                    }
                }
            }
        }
        else if (hlrClientImpl != null)
        {
            if (json.Contains("terminalRoamingStatusList"))
            {
                if (hlrClientImpl.HlrPushListeners != null)
                {
                    RoamingNotification roamingNotification = hlrClientImpl.ConvertJsonToRoamingNotification(json);
                    for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                    {
                        hlrClientImpl.HlrPushListeners[i].OnHLRReceived(roamingNotification);
                    }
                }
            }
        }
    }
Example #4
0
        public static void Execute()
        {
            Configuration configuration = new Configuration();
            SMSClient     smsClient     = new SMSClient(configuration);

            // example:on-delivery-notification
            DeliveryInfoNotification deliveryInfoNotification = smsClient.SmsMessagingClient.ConvertJsonToDeliveryInfoNotification(JSON);

            // ----------------------------------------------------------------------------------------------------
            Console.WriteLine(deliveryInfoNotification);
        }
Example #5
0
        private static void StartServer()
        {
            try
            {
                IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, port);

                server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                server.Bind(ipEnd);
                server.Listen(100);

                while (running)
                {
                    Socket clientSock = server.Accept();

                    byte[] clientData       = new byte[4096];
                    int    receivedBytesLen = clientSock.Receive(clientData);

                    string   receivedData    = Encoding.ASCII.GetString(clientData, 0, receivedBytesLen);
                    string[] arrReceivedData = System.Text.RegularExpressions.Regex.Split(receivedData, "\r\n\r\n");

                    if (arrReceivedData.Length == 2)
                    {
                        string json = arrReceivedData[1];

                        if (json.Trim().Length > 0)
                        {
                            if (json.Contains("deliveryInfoNotification"))
                            {
                                if (smsMessagingImpl != null)
                                {
                                    DeliveryInfoNotification deliveryInfoNotification = smsMessagingImpl.ConvertJsonToDeliveryInfo(json);
                                    if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                                    {
                                        for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                                        {
                                            smsMessagingImpl.DeliveryStatusNotificationPushListeners[i].OnDeliveryStatusNotificationReceived(deliveryInfoNotification, null);
                                        }
                                    }
                                }
                            }
                            else if (json.Contains("inboundSMSMessage"))
                            {
                                Console.WriteLine(json);

                                if (smsMessagingImpl != null)
                                {
                                    if (smsMessagingImpl.DeliveryStatusNotificationPushListeners != null)
                                    {
                                        InboundSMSMessageList smsMessagesList = smsMessagingImpl.ConvertJsonToInboundSMSMessageList(json);
                                        for (int i = 0; i < smsMessagingImpl.InboundMessagePushListeners.Count; i++)
                                        {
                                            smsMessagingImpl.InboundMessagePushListeners[i].OnMessageReceived(smsMessagesList, null);
                                        }
                                    }
                                }
                                else if (json.Contains("terminalRoamingStatusList"))
                                {
                                    if (hlrClientImpl != null)
                                    {
                                        if (hlrClientImpl.HlrPushListeners != null)
                                        {
                                            RoamingNotification roamingNotification = hlrClientImpl.ConvertJsonToRoamingNotification(json);
                                            for (int i = 0; i < smsMessagingImpl.DeliveryStatusNotificationPushListeners.Count; i++)
                                            {
                                                hlrClientImpl.HlrPushListeners[i].OnHLRReceived(roamingNotification, null);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (LOGGER.IsErrorEnabled)
                {
                    LOGGER.Error(e.Message);
                }

                //Stop();

                Console.WriteLine(e.Message);
            }
        }
    /// <summary>
    /// This function calls receive sms api to fetch the sms's
    /// </summary>
    private void DisplayDeliveryNotificationStatus()
    {
        string receivedMessagesFile = ConfigurationManager.AppSettings["deliveryStatusFilePath"];

        if (!string.IsNullOrEmpty(receivedMessagesFile))
        {
            receivedMessagesFile = Server.MapPath(receivedMessagesFile);
        }
        else
        {
            receivedMessagesFile = Server.MapPath("DeliveryStatus.txt");
        }
        string messagesLine = String.Empty;

        List <DeliveryInfoNotification> receiveSMSDeliveryStatusResponseData = new List <DeliveryInfoNotification>();

        if (File.Exists(receivedMessagesFile))
        {
            using (StreamReader sr = new StreamReader(receivedMessagesFile))
            {
                while (sr.Peek() >= 0)
                {
                    DeliveryInfoNotification dNot = new DeliveryInfoNotification();
                    dNot.DeliveryInfo = new DeliveryInfo();
                    messagesLine      = sr.ReadLine();
                    string[] messageValues = Regex.Split(messagesLine, "_-_-");
                    dNot.DeliveryInfo.Id             = messageValues[0];
                    dNot.DeliveryInfo.Address        = messageValues[1];
                    dNot.DeliveryInfo.DeliveryStatus = messageValues[2];
                    receiveSMSDeliveryStatusResponseData.Add(dNot);
                }
                sr.Close();
                receiveSMSDeliveryStatusResponseData.Reverse();
            }
        }

        Table notificationTable = new Table();

        notificationTable.Font.Name   = "Sans-serif";
        notificationTable.Font.Size   = 9;
        notificationTable.BorderStyle = BorderStyle.Outset;
        notificationTable.Width       = Unit.Pixel(650);

        TableRow tableRow = new TableRow();

        TableCell rowOneCellOne = new TableCell();

        rowOneCellOne.Font.Bold = true;
        rowOneCellOne.Text      = "Message ID";
        tableRow.Controls.Add(rowOneCellOne);

        rowOneCellOne           = new TableCell();
        rowOneCellOne.Font.Bold = true;
        rowOneCellOne.Text      = "Address";
        tableRow.Controls.Add(rowOneCellOne);

        rowOneCellOne           = new TableCell();
        rowOneCellOne.Font.Bold = true;
        rowOneCellOne.Text      = "Delivery Status";
        tableRow.Controls.Add(rowOneCellOne);

        notificationTable.Controls.Add(tableRow);

        foreach (DeliveryInfoNotification dNot in receiveSMSDeliveryStatusResponseData)
        {
            if (null != dNot.DeliveryInfo)
            {
                tableRow = new TableRow();

                rowOneCellOne           = new TableCell();
                rowOneCellOne.Font.Bold = true;
                rowOneCellOne.Text      = dNot.DeliveryInfo.Id;
                tableRow.Controls.Add(rowOneCellOne);

                rowOneCellOne           = new TableCell();
                rowOneCellOne.Font.Bold = true;
                rowOneCellOne.Text      = dNot.DeliveryInfo.Address;
                tableRow.Controls.Add(rowOneCellOne);

                rowOneCellOne           = new TableCell();
                rowOneCellOne.Font.Bold = true;
                rowOneCellOne.Text      = dNot.DeliveryInfo.DeliveryStatus;
                tableRow.Controls.Add(rowOneCellOne);
                notificationTable.Controls.Add(tableRow);
            }
        }

        notificationTable.BorderWidth = 1;
        notificationsPanel.Controls.Add(notificationTable);
    }
    /// <summary>
    /// This function calls receive sms api to fetch the sms's
    /// </summary>
    private void DisplayDeliveryNotificationStatus()
    {
        string receivedMessagesFile = ConfigurationManager.AppSettings["deliveryStatusFilePath"];
        if (!string.IsNullOrEmpty(receivedMessagesFile))
            receivedMessagesFile = Server.MapPath(receivedMessagesFile);
        else
            receivedMessagesFile = Server.MapPath("DeliveryStatus.txt");
        string messagesLine = String.Empty;

        List<DeliveryInfoNotification> receiveSMSDeliveryStatusResponseData = new List<DeliveryInfoNotification>();

        if (File.Exists(receivedMessagesFile))
        {
            using (StreamReader sr = new StreamReader(receivedMessagesFile))
            {
                while (sr.Peek() >= 0)
                {
                    DeliveryInfoNotification dNot = new DeliveryInfoNotification();
                    dNot.DeliveryInfo = new DeliveryInfo();
                    messagesLine = sr.ReadLine();
                    string[] messageValues = Regex.Split(messagesLine, "_-_-");
                    dNot.DeliveryInfo.Id = messageValues[0];
                    dNot.DeliveryInfo.Address= messageValues[1];
                    dNot.DeliveryInfo.DeliveryStatus = messageValues[2];
                    receiveSMSDeliveryStatusResponseData.Add(dNot);
                }
                sr.Close();
                receiveSMSDeliveryStatusResponseData.Reverse();
            }
        }

        Table notificationTable = new Table();
        notificationTable.Font.Name = "Sans-serif";
        notificationTable.Font.Size = 9;
        notificationTable.BorderStyle = BorderStyle.Outset;
        notificationTable.Width = Unit.Pixel(650);

        TableRow tableRow = new TableRow();

        TableCell rowOneCellOne = new TableCell();
        rowOneCellOne.Font.Bold = true;
        rowOneCellOne.Text = "Message ID";
        tableRow.Controls.Add(rowOneCellOne);

        rowOneCellOne = new TableCell();
        rowOneCellOne.Font.Bold = true;
        rowOneCellOne.Text = "Address";
        tableRow.Controls.Add(rowOneCellOne);

        rowOneCellOne = new TableCell();
        rowOneCellOne.Font.Bold = true;
        rowOneCellOne.Text = "Delivery Status";
        tableRow.Controls.Add(rowOneCellOne);

        notificationTable.Controls.Add(tableRow);

        foreach(DeliveryInfoNotification dNot in receiveSMSDeliveryStatusResponseData)
        {
            if (null != dNot.DeliveryInfo)
            {
                tableRow = new TableRow();

                rowOneCellOne = new TableCell();
                rowOneCellOne.Font.Bold = true;
                rowOneCellOne.Text = dNot.DeliveryInfo.Id;
                tableRow.Controls.Add(rowOneCellOne);

                rowOneCellOne = new TableCell();
                rowOneCellOne.Font.Bold = true;
                rowOneCellOne.Text = dNot.DeliveryInfo.Address;
                tableRow.Controls.Add(rowOneCellOne);

                rowOneCellOne = new TableCell();
                rowOneCellOne.Font.Bold = true;
                rowOneCellOne.Text = dNot.DeliveryInfo.DeliveryStatus;
                tableRow.Controls.Add(rowOneCellOne);
                notificationTable.Controls.Add(tableRow);
            }
        }

        notificationTable.BorderWidth = 1;
        notificationsPanel.Controls.Add(notificationTable);
        
    }