Beispiel #1
0
 internal static byte[] EncodeString(string str, SmppEncodingService smppEncodingService)
 {
     if (str == null)
     {
         str = "";
     }
     return(smppEncodingService.GetBytesFromString(str));
 }
Beispiel #2
0
        protected override IEnumerable <SendSmPDU> GetPDUs(DataCoding defaultEncoding, SmppEncodingService smppEncodingService)
        {
            SubmitSm sm = CreateSubmitSm(smppEncodingService);

            sm.SourceAddress.Address      = vSourceAddress;
            sm.DestinationAddress.Address = vDestinatinoAddress; // Urgh, typo :(
            sm.DataCoding = defaultEncoding;
            if (SubmitUserMessageReference)
            {
                sm.SetOptionalParamString(Lib.Protocol.Tlv.Tag.user_message_reference, UserMessageReference);
            }

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

            vMaxMessageLength = GetMaxMessageLength(defaultEncoding, false);
            byte[] bytes = smppEncodingService.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);
            }
        }