Ejemplo n.º 1
0
        void server_evClientSubmitMulti(object sender, SmppServerClient client, SubmitMulti data)
        {
            _log.Info("Client {0} sends message From:{1} to multiple destinations:{2}, Text: {3}",
                      client.RemoteEndPoint, data.SourceAddress, data.DestinationAddresses.Count,
                      data.GetMessageText(client.EncodingMapper));

            _messageComposer.AddMessage(data);

            if (data.RegisteredDelivery == 1)
            {
                SmeAddress destinationAddress = data.DestinationAddresses[0] as SmeAddress;

                string messageText = data.GetMessageText(client.EncodingMapper);

                //Send Delivery Receipt when required
                Task.Run(() => client.Deliver(
                             SMS.ForDeliver()
                             .From(data.SourceAddress)
                             .To(destinationAddress)
                             .Coding(data.DataCoding)
                             .Receipt(new Receipt
                {
                    DoneDate   = DateTime.Now,
                    State      = MessageState.Delivered,
                    MessageId  = data.Response.MessageId,
                    ErrorCode  = "0",
                    SubmitDate = DateTime.Now,
                    Text       = messageText.Substring(0, Math.Max(20, messageText.Length))
                }
                                      )
                             ));
            }
        }
        //</DeliverMessagesOnBind>

        //How to send message to connected client
        //
        //<DeliverToClient>
        public async Task DeliverToClient(SmppServerSample.TextMessage message)
        {
            string systemId = GetSystemIdByServiceAddress(message.ServiceAddress);

            SmppServerClient client = FindClient(systemId);

            await client.Deliver(SMS.ForDeliver()
                                 .From(message.PhoneNumber)
                                 .To(message.ServiceAddress)
                                 .Text(message.Text)
                                 );
        }
Ejemplo n.º 3
0
        private void server_evClientSubmitSm(object sender, SmppServerClient client, SubmitSm data)
        {
            long messageId = Interlocked.Increment(ref messageIdCounter);

            // You can set your own MessageId
            data.Response.MessageId = messageId.ToString();

            _log.Info("Client {0} sends message From:{1}, To:{2}, Text: {3}",
                      client.RemoteEndPoint, data.SourceAddress, data.DestinationAddress,
                      data.GetMessageText(client.EncodingMapper));


            _messageComposer.AddMessage(data);



            // Set unsuccess response status
            //data.Response.Status = CommandStatus.ESME_RSUBMITFAIL;


            if (data.SMSCReceipt != SMSCDeliveryReceipt.NotRequested)
            {
                //Send Delivery Receipt when required

                string messageText = data.GetMessageText(client.EncodingMapper);

                var dlrBuilder = SMS.ForDeliver()
                                 .From(data.DestinationAddress)
                                 .To(data.SourceAddress)
                                 .Receipt(new Receipt
                {
                    DoneDate   = DateTime.Now,
                    State      = MessageState.Delivered,
                    MessageId  = data.Response.MessageId,
                    ErrorCode  = "0",
                    SubmitDate = DateTime.Now,
                    Text       = messageText.Substring(0, Math.Min(20, messageText.Length))
                });

                if (data.DataCoding == DataCodings.UCS2)
                {
                    //short_message field cannot contain user data longer than 255 octets,
                    //therefore for UCS2 encoding we are sending DLR in message_payload parameter
                    dlrBuilder.MessageInPayload();
                }

                client.Deliver(dlrBuilder).ConfigureAwait(false);
            }
        }
        private async Task DeliverMessagesAsync(SmppServerClient client, Bind pdu)
        {
            var messages = _messageStore.GetMessagesForClient(pdu.SystemId, pdu.SystemType);

            foreach (TextMessage message in messages)
            {
                var pduBuilder = SMS.ForDeliver()
                                 .From(message.PhoneNumber)
                                 .To(message.ServiceAddress)
                                 .Text(message.Text);

                var responses = await client.Deliver(pduBuilder);

                _messageStore.UpdateMessageState(message.Id, responses);
            }
        }
Ejemplo n.º 5
0
        private async void bSubmit_Click(object sender, EventArgs e)
        {
            if (_client != null)
            {
                SmeAddress source      = new SmeAddress(tbSrcAdr.Text, (AddressTON)byte.Parse(tbSrcAdrTON.Text), (AddressNPI)byte.Parse(tbSrcAdrNPI.Text));
                SmeAddress destination = new SmeAddress(tbDestAdr.Text, (AddressTON)byte.Parse(tbDestAdrTON.Text), (AddressNPI)byte.Parse(tbDestAdrNPI.Text));

                await _client.Deliver(SMS.ForDeliver()
                                      .From(source)
                                      .To(destination)
                                      .Coding(GetDataCoding())
                                      .Text(tbSend.Text)
                                      );

                DialogResult = DialogResult.OK;
            }
        }
Ejemplo n.º 6
0
        private async Task DeliverMessagesAsync(SmppServerClient client, Bind pdu)
        {
            var messages = _messageStore.GetMessagesForClient(pdu.SystemId, pdu.SystemType);

            foreach (TextMessage message in messages)
            {
                var pduBuilder = SMS.ForDeliver()
                                 .From(message.PhoneNumber)
                                 .To(message.ServiceAddress)
                                 .Text(message.Text);

                var responses = await client.Deliver(pduBuilder);

                if (responses.All(x => x.Header.Status == CommandStatus.ESME_ROK))
                {
                    _messageStore.MessageWasDelivered(message.Id);
                }
            }

            Console.WriteLine($"Dummy messages have been sent to the client with systemId {pdu.SystemId}.");
        }
Ejemplo n.º 7
0
 private async void WhenServerReceivesPDU(object sender, SmppServerClient serverClient, SubmitSm data)
 {
     if (data.RegisteredDelivery == 1)
     {
         //Send Delivery Receipt when required
         await serverClient.Deliver(
             SMS.ForDeliver()
             .From(data.SourceAddress)
             .To(data.DestinationAddress)
             .Coding(data.DataCoding)
             .Receipt(new Receipt
         {
             DoneDate   = DateTime.Now,
             State      = MessageState.Delivered,
             MessageId  = data.Response.MessageId,
             ErrorCode  = "0",
             SubmitDate = DateTime.Now
         }
                      )
             )
         .ConfigureAwait(false);
     }
 }