Example #1
0
 private void FireMessageRetrieved(InboundSMSMessageList smsMessageList, RequestException e)
 {
     for (int i = 0; i < smsMessagingImpl.InboundMessagePullListeners.Count; i++)
     {
         smsMessagingImpl.InboundMessagePullListeners[i].OnMessageReceived(smsMessageList, e);
     }
 }
 public void OnMessageReceived(InboundSMSMessageList smsMessageList)
 {
     if (_onMessageReceived != null)
     {
         _onMessageReceived(smsMessageList);
     }
 }
Example #3
0
 public void OnMessageReceived(InboundSMSMessageList smsMessageList, RequestException e)
 {
     if (_onMessageReceived != null)
     {
         _onMessageReceived(smsMessageList, e);
     }
 }
 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 #5
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);
                    }
                }
            }
        }
    }
        public static void Execute()
        {
            Configuration configuration = new Configuration();
            SMSClient     smsClient     = new SMSClient(configuration);

            // example:on-mo
            InboundSMSMessageList inboundSMSMessageList = smsClient.SmsMessagingClient.ConvertJsonToInboundSMSMessageNotification(JSON);

            // ----------------------------------------------------------------------------------------------------
            Console.WriteLine(inboundSMSMessageList);
        }
        public static void Execute()
        {
            // Configure in the 'app.config' which Logger levels are enabled(all levels are enabled in the example)
            // Check http://logging.apache.org/log4net/release/manual/configuration.html for more informations about the log4net configuration
            XmlConfigurator.Configure(new FileInfo("OneApiExamples.exe.config"));


            // Initialize Configuration object 
            Configuration configuration = new Configuration(System.Configuration.ConfigurationManager.AppSettings.Get("Username"),
                                                            System.Configuration.ConfigurationManager.AppSettings.Get("Password"));

            // Initialize SMSClient using the Configuration object
            SMSClient smsClient = new SMSClient(configuration);

            // example:retrieve-inbound-messages
            InboundSMSMessageList inboundSMSMessageList = smsClient.SmsMessagingClient.GetInboundMessages();
            // ---------------------------------------------------------------------------------------------------- 
            Console.WriteLine(inboundSMSMessageList);

        }
Example #8
0
 public void Run(Object stateInfo)
 {
     if ((smsMessagingImpl.InboundMessagePullListeners != null) &&
         (smsMessagingImpl.InboundMessagePullListeners.Count > 0))
     {
         try
         {
             InboundSMSMessageList smsMessageList = smsMessagingImpl.GetInboundMessages();
             if ((smsMessageList != null) &&
                 (smsMessageList.InboundSMSMessage != null) &&
                 (smsMessageList.InboundSMSMessage.Length > 0))
             {
                 FireMessageRetrieved(smsMessageList, null);
             }
         }
         catch (RequestException e)
         {
             FireMessageRetrieved(null, e);
         }
     }
 }
Example #9
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);
            }
        }