Beispiel #1
0
        /// <summary>
        /// Compose a SMS using the required encoding, Supports 16 and 7 bit encoding
        /// 7-bit encoding implemented by [www.codeproblem.com]
        /// </summary>
        /// <param name="messageEncoding">SMS encoding type</param>
        /// <returns>string of packed SMS</returns>
        public virtual string Compose(SMSEncoding messageEncoding)
        {
            if (messageEncoding == SMSEncoding.UCS2)
            {
                if (_message.Length > 70)
                {
                    throw new ArgumentOutOfRangeException("Message.Length", _message.Length, "Message length can not be greater that 70 chars for unicode messages.");
                }
            }
            if (messageEncoding == SMSEncoding._7bit)
            {
                if (_message.Length > 160)
                {
                    throw new ArgumentOutOfRangeException("Message.Length", _message.Length, "Message length can not be greater that 160 chars for 7-bit messages.");
                }
            }
            ComposePDUType();

            string encodedData = "00";                                     //Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used. Note: This octet is optional. On some phones this octet should be omitted! (Using the SMSC stored in phone is thus implicit)

            encodedData += Convert.ToString(_pduType, 16).PadLeft(2, '0'); //PDU type (forst octet)
            encodedData += Convert.ToString(MessageReference, 16).PadLeft(2, '0');
            encodedData += EncodePhoneNumber(PhoneNumber);
            encodedData += "00";                                                       //Protocol identifier (Short Message Type 0)
            encodedData += Convert.ToString((int)messageEncoding, 16).PadLeft(2, '0'); //Data coding scheme
            //encodedData += "10"; //Data coding scheme

            if (_validityPeriodFormat != ValidityPeriodFormat.FieldNotPresent)
            {
                encodedData += Convert.ToString(_validityPeriod, 16).PadLeft(2, '0');                 //Validity Period
            }
            byte[] messageBytes = null;

            switch (messageEncoding)
            {
            case SMSEncoding.UCS2:
                messageBytes = EncodeUCS2(_message);
                encodedData += Convert.ToString(messageBytes.Length, 16).PadLeft(2, '0');     //Length of message
                break;

            case SMSEncoding._7bit:
                messageBytes = Encode7bit(_message);
                encodedData += Convert.ToString(_message.Length, 16).PadLeft(2, '0');     //Length of message
                break;

            default:
                messageBytes = new byte[0];
                break;
            }


            foreach (byte b in messageBytes)
            {
                encodedData += Convert.ToString(b, 16).PadLeft(2, '0');
            }

            return(encodedData.ToUpper());
        }
Beispiel #2
0
        /// <summary>
        /// Compose a Multipart SMS and returns the string array of PDU for each SMS part,
        /// Support only 7-bit encoding
        /// [www.codeproblem.com]
        /// </summary>
        /// <param name="messageEncoding">Message Encoding used</param>
        /// <returns>string[] of SMS PDUs</returns>
        public string[] ComposeLongSMS(SMSEncoding messageEncoding)
        {
            //setting the in parts properties
            InParts = true;

            //Generate a random Message ID
            InPartsID = RandomNumber(1, 254);

            //Setting total parts field
            int parts = (int)(Math.Ceiling(((double)(_message.Length) / 153)));

            TotalParts = parts;

            if (!InParts)
            {
                throw new InvalidOperationException("Set the InParts property before calling ComposeLongSMS");
            }
            if (_userDataHeader.Length != 5)
            {
                throw new InvalidOperationException("UserDataHeader field must contain valid values for long SMS");
            }

            //storing the origional message for backup
            string origionalMessage = _message;

            //Final SMS strings
            string[] strSMSArray = new string[parts];

            //now break the long SMS in parts
            for (int i = 1; i <= parts; i++)
            {
                Part = i;

                //First get 7-bit ASCII for the UDH
                byte[] _udh = new byte[6];
                _udh[0] = 5; //length of header
                Array.Copy(_userDataHeader, 0, _udh, 1, _userDataHeader.Length);

                //Now Encode the header
                string header = EncodeMultiPartHeader(_udh);

                int lengthToCut = ((((i - 1) * 153) + 153) > origionalMessage.Length) ? origionalMessage.Length - ((i - 1) * 153) : 153;
                _message = origionalMessage.Substring((i - 1) * 153, lengthToCut);

                //adding user data header to message
                _message = header + _message;

                //Compose this single sms
                string finalmessage = Compose(messageEncoding);

                //Storing in array
                strSMSArray[i - 1] = finalmessage;
            }

            //returning the array
            return(strSMSArray);
        }
Beispiel #3
0
        public virtual string Compose(SMSEncoding messageEncoding)
        {
            ComposePDUType();

            string encodedData = "00";                                     //Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used. Note: This octet is optional. On some phones this octet should be omitted! (Using the SMSC stored in phone is thus implicit)

            encodedData += Convert.ToString(_pduType, 16).PadLeft(2, '0'); //PDU type (forst octet)
            encodedData += Convert.ToString(MessageReference, 16).PadLeft(2, '0');
            encodedData += EncodePhoneNumber(PhoneNumber);
            encodedData += "00";                                                       //Protocol identifier (Short Message Type 0)
            encodedData += Convert.ToString((int)messageEncoding, 16).PadLeft(2, '0'); //Data coding scheme

            if (_validityPeriodFormat != ValidityPeriodFormat.FieldNotPresent)
            {
                encodedData += Convert.ToString(_validityPeriod, 16).PadLeft(2, '0'); //Validity Period
            }
            byte[] messageBytes = null;

            switch (messageEncoding)
            {
            case SMSEncoding.UCS2:
                messageBytes = EncodeUCS2(_message);
                break;

            default:
                messageBytes = new byte[0];
                break;
            }

            encodedData += Convert.ToString(messageBytes.Length, 16).PadLeft(2, '0'); //Length of message

            foreach (byte b in messageBytes)
            {
                encodedData += Convert.ToString(b, 16).PadLeft(2, '0');
            }

            return(encodedData.ToUpper());
        }
 public SMS(string number, string subject, SMSEncoding encoding = SMSEncoding.SMS)
 {
     this.number   = number;
     this.subject  = subject;
     this.encoding = encoding;
 }
 public SMS(string number, SMSEncoding encoding = SMSEncoding.SMS)
 {
     this.number   = number;
     this.subject  = string.Empty;
     this.encoding = encoding;
 }
Beispiel #6
0
        public virtual string Compose(SMSEncoding messageEncoding)
        {
            ComposePDUType();

            string encodedData = "00"; //Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used. Note: This octet is optional. On some phones this octet should be omitted! (Using the SMSC stored in phone is thus implicit)

            encodedData += Convert.ToString(_pduType, 16).PadLeft(2, '0'); //PDU type (forst octet)
            encodedData += Convert.ToString(MessageReference, 16).PadLeft(2, '0');
            encodedData += EncodePhoneNumber(PhoneNumber);
            encodedData += "00"; //Protocol identifier (Short Message Type 0)
            encodedData += Convert.ToString((int) messageEncoding, 16).PadLeft(2, '0'); //Data coding scheme

            if (_validityPeriodFormat != ValidityPeriodFormat.FieldNotPresent)
                encodedData += Convert.ToString(_validityPeriod, 16).PadLeft(2, '0'); //Validity Period

            byte[] messageBytes = null;

            switch (messageEncoding) {
                case SMSEncoding.UCS2:
                    messageBytes = EncodeUCS2(_message);
                    break;
                default:
                    messageBytes = new byte[0];
                    break;
            }

            encodedData += Convert.ToString(messageBytes.Length, 16).PadLeft(2, '0'); //Length of message

            foreach (byte b in messageBytes)
                encodedData += Convert.ToString(b, 16).PadLeft(2, '0');

            return encodedData.ToUpper();
        }
Beispiel #7
0
 public SMS(string number, string subject, SMSEncoding encoding = SMSEncoding.SMS)
 {
     this.number = number;
     this.subject = subject;
     this.encoding = encoding;
 }
Beispiel #8
0
 public SMS(string number, SMSEncoding encoding = SMSEncoding.SMS)
 {
     this.number = number;
     this.subject = string.Empty;
     this.encoding = encoding;
 }
Beispiel #9
0
        /// <summary>
        /// Compose a Multipart SMS and returns the string array of PDU for each SMS part,
        /// Support only 7-bit encoding
        /// [www.codeproblem.com]
        /// </summary>
        /// <param name="messageEncoding">Message Encoding used</param>
        /// <returns>string[] of SMS PDUs</returns>
        public string[] ComposeLongSMS(SMSEncoding messageEncoding)
        {
            //setting the in parts properties
            InParts = true;

            //Generate a random Message ID
            InPartsID = RandomNumber(1, 254);

            //Setting total parts field
            int parts = (int)(Math.Ceiling(((double)(_message.Length) / 153)));
            TotalParts = parts;

            if (!InParts)
            {
                throw new InvalidOperationException("Set the InParts property before calling ComposeLongSMS");
            }
            if (_userDataHeader.Length != 5)
            {
                throw new InvalidOperationException("UserDataHeader field must contain valid values for long SMS");
            }

            //storing the origional message for backup
            string origionalMessage = _message;

            //Final SMS strings
            string[] strSMSArray = new string[parts];

            //now break the long SMS in parts
            for (int i = 1; i <= parts; i++)
            {
                Part = i;

                //First get 7-bit ASCII for the UDH
                byte[] _udh = new byte[6];
                _udh[0] = 5; //length of header
                Array.Copy(_userDataHeader, 0, _udh, 1, _userDataHeader.Length);

                //Now Encode the header
                string header = EncodeMultiPartHeader(_udh);

                int lengthToCut = ((((i - 1) * 153) + 153) > origionalMessage.Length) ? origionalMessage.Length - ((i - 1) * 153) : 153;
                _message = origionalMessage.Substring((i - 1) * 153, lengthToCut);

                //adding user data header to message
                _message = header + _message;

                //Compose this single sms
                string finalmessage = Compose(messageEncoding);

                //Storing in array
                strSMSArray[i - 1] = finalmessage;
            }

            //returning the array
            return strSMSArray;
        }
Beispiel #10
0
        /// <summary>
        /// Compose a SMS using the required encoding, Supports 16 and 7 bit encoding
        /// 7-bit encoding implemented by [www.codeproblem.com]
        /// </summary>
        /// <param name="messageEncoding">SMS encoding type</param>
        /// <returns>string of packed SMS</returns>
        public virtual string Compose(SMSEncoding messageEncoding)
        {
            if (messageEncoding == SMSEncoding.UCS2)
            {
                if (_message.Length > 70)
                    throw new ArgumentOutOfRangeException("Message.Length", _message.Length, "Message length can not be greater that 70 chars for unicode messages.");
            }
            if (messageEncoding == SMSEncoding._7bit)
            {
                if(_message.Length > 160)
                    throw new ArgumentOutOfRangeException("Message.Length", _message.Length, "Message length can not be greater that 160 chars for 7-bit messages.");
            }
            ComposePDUType();

            string encodedData = "00"; //Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used. Note: This octet is optional. On some phones this octet should be omitted! (Using the SMSC stored in phone is thus implicit)

            encodedData += Convert.ToString(_pduType, 16).PadLeft(2, '0'); //PDU type (forst octet)
            encodedData += Convert.ToString(MessageReference, 16).PadLeft(2, '0');
            encodedData += EncodePhoneNumber(PhoneNumber);
            encodedData += "00"; //Protocol identifier (Short Message Type 0)
            encodedData += Convert.ToString((int) messageEncoding, 16).PadLeft(2, '0'); //Data coding scheme

            if (_validityPeriodFormat != ValidityPeriodFormat.FieldNotPresent)
                encodedData += Convert.ToString(_validityPeriod, 16).PadLeft(2, '0'); //Validity Period

            byte[] messageBytes = null;

            switch (messageEncoding) {
                case SMSEncoding.UCS2:
                    messageBytes = EncodeUCS2(_message);
                    encodedData += Convert.ToString(messageBytes.Length, 16).PadLeft(2, '0'); //Length of message
                    break;
                case SMSEncoding._7bit:
                    messageBytes = Encode7bit(_message);
                    encodedData += Convert.ToString(_message.Length, 16).PadLeft(2, '0'); //Length of message
                    break;
                default:
                    messageBytes = new byte[0];
                    break;
            }

            foreach (byte b in messageBytes)
                encodedData += Convert.ToString(b, 16).PadLeft(2, '0');

            return encodedData.ToUpper();
        }