Example #1
0
        public string GetMessageText()
        {
            byte[] msgBytes = GetMessageBytes();
            if (msgBytes == null)
            {
                return(null);
            }
            string message = null;
            Udh    udh     = null;

            GetMessageText(out message, out udh);
            return(message);
        }
Example #2
0
        public virtual void GetMessageText(out string message, out Udh udh)
        {
            message = null; udh = null;
            byte[] msgBytes = GetMessageBytes();
            if (msgBytes == null)
            {
                return;
            }
            ByteBuffer buffer = new ByteBuffer(msgBytes);

            //Check if the UDH is set in the esm_class field
            if ((EsmClass & EsmClass.UdhiIndicator) == EsmClass.UdhiIndicator)
            {
                _Log.Info("200020:UDH field presense detected;");
                if (vTraceSwitch.TraceInfo)
                {
                    Trace.WriteLine("200020:UDH field presense detected;");
                }
                try { udh = Udh.Parse(buffer, vSmppEncodingService); }
                catch (Exception ex)
                {
                    _Log.ErrorFormat("20023:UDH field parsing error - {0}", ex, new ByteBuffer(msgBytes).DumpString());
                    if (vTraceSwitch.TraceError)
                    {
                        Trace.WriteLine(string.Format(
                                            "20023:UDH field parsing error - {0} {1};",
                                            new ByteBuffer(msgBytes).DumpString(), ex.Message));
                    }
                    throw;
                }
            }
            //Check if we have something remaining in the buffer
            if (buffer.Length == 0)
            {
                return;
            }
            try { message = vSmppEncodingService.GetStringFromBytes(buffer.ToBytes(), DataCoding); }
            catch (Exception ex1)
            {
                _Log.ErrorFormat("200019:SMS message decoding failure - {0}", ex1, new ByteBuffer(msgBytes).DumpString());
                if (vTraceSwitch.TraceError)
                {
                    Trace.WriteLine(string.Format(
                                        "200019:SMS message decoding failure - {0} {1};",
                                        new ByteBuffer(msgBytes).DumpString(), ex1.Message));
                }
                throw;
            }
        }
Example #3
0
        protected override IEnumerable <SendSmPDU> GetPDUs(DataCoding defaultEncoding)
        {
            SubmitSm sm = CreateSubmitSm();

            sm.SourceAddress.Address      = vSourceAddress;
            sm.DestinationAddress.Address = vDestinatinoAddress; // Urgh, typo :(
            sm.DataCoding = defaultEncoding;
            if (!string.IsNullOrEmpty(UserMessageReference))
            {
                var msgIdBytes = SMPPEncodingUtil.GetBytesFromCString(UserMessageReference);
                sm.Tlv.Add(new Lib.Protocol.Tlv.Tlv(Lib.Protocol.Tlv.Tag.user_message_reference, (ushort)msgIdBytes.Length, msgIdBytes));
            }

            if (vRegisterDeliveryNotification)
            {
                sm.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt;
            }

            vMaxMessageLength = GetMaxMessageLength(defaultEncoding, false);
            byte[] bytes = SMPPEncodingUtil.GetBytesFromString(vText, defaultEncoding);

            string uni   = Encoding.Unicode.GetString(bytes);
            string ascii = Encoding.ASCII.GetString(bytes);
            string utf8  = Encoding.UTF8.GetString(bytes);

            // Unicode encoding return 2 items for 1 char
            // We check vText Length first
            if (vText.Length > vMaxMessageLength && bytes.Length > vMaxMessageLength) // Split into multiple!
            {
                var SegID = new Random().Next(1000, 9999);                            // create random SegmentID
                vMaxMessageLength = GetMaxMessageLength(defaultEncoding, true);
                var messages      = Split(vText, vMaxMessageLength);
                var totalSegments = messages.Count;                   // get the number of (how many) parts
                var udh           = new Udh(SegID, totalSegments, 0); // ID, Total, part

                for (int i = 0; i < totalSegments; i++)
                {
                    udh.MessageSequence = i + 1;                          // seq+1 , - parts of the message
                    sm.SetMessageText(messages[i], defaultEncoding, udh); // send parts of the message + all other UDH settings
                    yield return(sm);
                }
            }
            else
            {
                sm.SetMessageBytes(bytes);
                yield return(sm);
            }
        }
Example #4
0
        private void PduReceivedEventHander(object sender, PduReceivedEventArgs e)
        {
            MessageBox.Show("Сработало событие received");
            SingleDestinationPDU pdu = e.Request as SingleDestinationPDU;

            if (pdu == null)
            {
                return;
            }

            Udh    udh     = null;                    //We need to test if the UDH field is present
            string message = null;                    //This will hold the message text

            pdu.GetMessageText(out message, out udh); //Get message text and UDH from the PDU
            MessageBox.Show("Пришедшее на номер: " + message + " , " + pdu.Header.ErrorCode.ToString());
        }
Example #5
0
        public virtual void SetMessageText(string message, DataCoding dataCoding, Udh udh)
        {
            ByteBuffer buffer = new ByteBuffer(160);

            if (udh != null)
            {
                buffer.Append(udh.GetBytes());
            }
            buffer.Append(SMPPEncodingUtil.GetBytesFromString(message, dataCoding));
            SetMessageBytes(buffer.ToBytes());
            if (udh != null)
            {
                EsmClass = EsmClass | EsmClass.UdhiIndicator;
            }
            DataCoding = dataCoding;
        }
Example #6
0
        protected override IEnumerable <SendSmPdu> GetPdUs(DataCoding defaultEncoding)
        {
            SubmitSm sm = new SubmitSm();

            sm.SourceAddress.Address      = VSourceAddress;
            sm.DestinationAddress.Address = VDestinatinoAddress; // Urgh, typo :(
            sm.DataCoding = defaultEncoding;
            if (VRegisterDeliveryNotification)
            {
                sm.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt;
            }

            _vMaxMessageLength = GetMaxMessageLength(defaultEncoding, false);
            byte[] bytes = SmppEncodingUtil.GetBytesFromString(_vText, defaultEncoding);

            // Unicode encoding return 2 items for 1 char
            // We check vText Length first
            if (_vText.Length > _vMaxMessageLength && bytes.Length > _vMaxMessageLength) // Split into multiple!
            {
                var segId = new Random().Next(1000, 9999);                               // create random SegmentID
                _vMaxMessageLength = GetMaxMessageLength(defaultEncoding, true);
                var messages      = Split(_vText, _vMaxMessageLength);
                var totalSegments = messages.Count;                   // get the number of (how many) parts
                var udh           = new Udh(segId, totalSegments, 0); // ID, Total, part

                for (int i = 0; i < totalSegments; i++)
                {
                    udh.MessageSequence = i + 1;                          // seq+1 , - parts of the message
                    sm.SetMessageText(messages[i], defaultEncoding, udh); // send parts of the message + all other UDH settings
                    yield return(sm);
                }
            }
            else
            {
                sm.SetMessageBytes(bytes);
                yield return(sm);
            }
        }
        /// <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);
        }
Example #8
0
 public virtual void GetMessageText(out string message, out Udh udh)
 {
     message = null; udh = null;
     byte[] msgBytes = GetMessageBytes();
     if (msgBytes == null) { return; }
     ByteBuffer buffer = new ByteBuffer(msgBytes);
     //Check if the UDH is set in the esm_class field
     if ((EsmClass & EsmClass.UdhiIndicator) == EsmClass.UdhiIndicator)
     {
         if (vTraceSwitch.TraceInfo) { Trace.WriteLine("200020:UDH field presense detected;"); }
         try { udh = Udh.Parse(buffer); }
         catch (Exception ex)
         {
             if (vTraceSwitch.TraceError)
             {
                 Trace.WriteLine(string.Format(
                     "20023:UDH field parsing error - {0} {1};",
                     new ByteBuffer(msgBytes).DumpString(), ex.Message));
             }
             throw;
         }
     }
     //Check if we have something remaining in the buffer
     if (buffer.Length == 0) { return; }
     DataCoding = DataCoding.ASCII;
     try { message = SMPPEncodingUtil.GetStringFromBytes(buffer.ToBytes(), DataCoding); }
     catch (Exception ex1)
     {
         if (vTraceSwitch.TraceError)
         {
             Trace.WriteLine(string.Format(
                 "200019:SMS message decoding failure - {0} {1};",
                 new ByteBuffer(msgBytes).DumpString(), ex1.Message));
         }
         throw;
     }
 }
Example #9
0
 public virtual void SetMessageText(string message, DataCoding dataCoding, Udh udh)
 {
     ByteBuffer buffer = new ByteBuffer(160);
     if (udh != null) { buffer.Append(udh.GetBytes()); }
     buffer.Append(SMPPEncodingUtil.GetBytesFromString(message, dataCoding));
     SetMessageBytes(buffer.ToBytes());
     if (udh != null) { EsmClass = EsmClass | EsmClass.UdhiIndicator; }
     DataCoding = dataCoding;
 }