Esempio n. 1
0
        private void PduReceivedEventHander(object sender, PduReceivedEventArgs e)
        {
            //This handler is interested in SingleDestinationPDU only
            SingleDestinationPdu pdu = e.Request as SingleDestinationPdu;

            if (pdu == null)
            {
                return;
            }

            //If we have just a normal message
            if (((byte)pdu.EsmClass | 0xc3) == 0xc3)
            {
                ShortMessage message;
                try { message = MessageFactory.CreateMessage(pdu); }
                catch (SmppException smppEx)
                {
                    if (VTraceSwitch.TraceError)
                    {
                        Trace.WriteLine(string.Format(
                                            "200019:SMPP message decoding failure - {0} - {1} {2};",
                                            smppEx.ErrorCode, new ByteBuffer(pdu.GetBytes()).DumpString(), smppEx.Message));
                    }
                    //Notify the SMSC that we encountered an error while processing the message
                    e.Response = pdu.CreateDefaultResponce();
                    e.Response.Header.ErrorCode = smppEx.ErrorCode;
                    return;
                }
                catch (Exception ex)
                {
                    if (VTraceSwitch.TraceError)
                    {
                        Trace.WriteLine(string.Format(
                                            "200019:SMPP message decoding failure - {0} {1};",
                                            new ByteBuffer(pdu.GetBytes()).DumpString(), ex.Message));
                    }
                    //Let the receiver know that this message was rejected
                    e.Response = pdu.CreateDefaultResponce();
                    e.Response.Header.ErrorCode = SmppErrorCode.EsmeRxPAppn; //ESME Receiver Reject Message
                    return;
                }
                RaiseMessageReceivedEvent(message);
            }
            //Or if we have received a delivery receipt
            else if ((pdu.EsmClass & EsmClass.DeliveryReceipt) == EsmClass.DeliveryReceipt)
            {
                // Extract receipted message id
                var    receiptedMessageIdTlv = pdu.Tlv.GetTlvByTag(Tag.ReceiptedMessageId);
                string receiptedMessageId    = null;
                if (receiptedMessageIdTlv != null)
                {
                    receiptedMessageId = SmppEncodingUtil.GetCStringFromBytes(receiptedMessageIdTlv.RawValue);
                }
                RaiseMessageDeliveredEvent(receiptedMessageId);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a <see cref="TextMessage"/> from a received <see cref="SingleDestinationPdu"/>
        /// </summary>
        /// <param name="pdu">The PDU from which a <see cref="TextMessage"/> is constructed</param>
        /// <returns>A <see cref="TextMessage"/> represening a text message extracted from the received PDU</returns>
        public static TextMessage CreateMessage(SingleDestinationPdu pdu)
        {
            //This version supports only text messages
            Udh    udh     = null;
            string message = null;

            pdu.GetMessageText(out message, out udh);
            TextMessage sms = null;

            //Check if the udh field is present
            if (udh != null)
            {
                sms = new TextMessage(udh.SegmentId, udh.MessageCount, udh.MessageSequence);
            }
            else
            {
                sms = new TextMessage();
            }
            sms.Text               = message == null ? "" : message;
            sms.SourceAddress      = pdu.SourceAddress.Address;
            sms.DestinationAddress = pdu.DestinationAddress.Address;
            return(sms);
        }