Ejemplo n.º 1
0
 /// <summary>
 /// Creates a concatenated text message.
 /// </summary>
 /// <param name="userDataText">The message text.</param>
 /// <param name="unicode">Specifies if the userDataText is to be encoded as Unicode. If not, the GSM 7-bit default alphabet is used.</param>
 /// <param name="destinationAddress">The message's destination address.</param>
 /// <returns>A set of <see cref="T:GSMCommunication.PDUDecoder.SmsSubmitPdu" /> objects that represent the message.</returns>
 /// <remarks>
 /// <para>A concatenated message makes it possible to exceed the maximum length of a normal message,
 /// created by splitting the message data into multiple parts.</para>
 /// <para>Concatenated messages are also known as long or multi-part messages.</para>
 /// <para>If no concatenation is necessary, a single, non-concatenated <see cref="T:GSMCommunication.PDUDecoder.SmsSubmitPdu" /> object is created.</para>
 /// </remarks>
 /// <exception cref="T:System.ArgumentException"><para>userDataText is so long that it would create more than 255 message parts.</para></exception>
 public static SmsSubmitPdu[] CreateConcatTextMessage(string userDataText, bool unicode, string destinationAddress)
 {
     string str;
     int length = 0;
     int num;
     byte[] bytes;
     SmsSubmitPdu smsSubmitPdu;
     int num1;
     byte num2;
     if (unicode)
     {
         num1 = 70;
     }
     else
     {
         num1 = 160;
     }
     int num3 = num1;
     if (unicode)
     {
         str = userDataText;
     }
     else
     {
         str = TextDataConverter.StringTo7Bit(userDataText);
     }
     if (str.Length <= num3)
     {
         if (unicode)
         {
             smsSubmitPdu = new SmsSubmitPdu(userDataText, destinationAddress, 8);
         }
         else
         {
             smsSubmitPdu = new SmsSubmitPdu(userDataText, destinationAddress);
         }
         SmsSubmitPdu[] smsSubmitPduArray = new SmsSubmitPdu[1];
         smsSubmitPduArray[0] = smsSubmitPdu;
         return smsSubmitPduArray;
     }
     else
     {
         ConcatMessageElement16 concatMessageElement16 = new ConcatMessageElement16(0, 0, 0);
         byte length1 = (byte)((int)SmartMessageFactory.CreateUserDataHeader(concatMessageElement16).Length);
         byte num4 = (byte)((double)length1 / 7 * 8);
         if (unicode)
         {
             num2 = length1;
         }
         else
         {
             num2 = num4;
         }
         byte num5 = num2;
         StringCollection stringCollections = new StringCollection();
         for (int i = 0; i < str.Length; i = i + length)
         {
             if (!unicode)
             {
                 if (str.Length - i < num3 - num5)
                 {
                     length = str.Length - i;
                 }
                 else
                 {
                     length = num3 - num5;
                 }
             }
             else
             {
                 if (str.Length - i < (num3 * 2 - num5) / 2)
                 {
                     length = str.Length - i;
                 }
                 else
                 {
                     length = (num3 * 2 - num5) / 2;
                 }
             }
             string str1 = str.Substring(i, length);
             stringCollections.Add(str1);
         }
         if (stringCollections.Count <= 255)
         {
             SmsSubmitPdu[] smsSubmitPduArray1 = new SmsSubmitPdu[stringCollections.Count];
             ushort num6 = SmartMessageFactory.CalcNextRefNumber();
             byte num7 = 0;
             for (int j = 0; j < stringCollections.Count; j++)
             {
                 num7 = (byte)(num7 + 1);
                 ConcatMessageElement16 concatMessageElement161 = new ConcatMessageElement16(num6, (byte)stringCollections.Count, num7);
                 byte[] numArray = SmartMessageFactory.CreateUserDataHeader(concatMessageElement161);
                 if (unicode)
                 {
                     Encoding bigEndianUnicode = Encoding.BigEndianUnicode;
                     bytes = bigEndianUnicode.GetBytes(stringCollections[j]);
                     num = (int)bytes.Length;
                 }
                 else
                 {
                     bytes = TextDataConverter.SeptetsToOctetsInt(stringCollections[j]);
                     num = stringCollections[j].Length;
                 }
                 SmsSubmitPdu smsSubmitPdu1 = new SmsSubmitPdu();
                 smsSubmitPdu1.DestinationAddress = destinationAddress;
                 if (unicode)
                 {
                     smsSubmitPdu1.DataCodingScheme = 8;
                 }
                 smsSubmitPdu1.SetUserData(bytes, (byte)num);
                 smsSubmitPdu1.AddUserDataHeader(numArray);
                 smsSubmitPduArray1[j] = smsSubmitPdu1;
             }
             return smsSubmitPduArray1;
         }
         else
         {
             throw new ArgumentException("A concatenated message must not have more than 255 parts.", "userDataText");
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates an operator logo message.
 /// </summary>
 /// <param name="operatorLogo">The operator logo. Use <see cref="M:GSMCommunication.PDUDecoder.SmartMessaging.SmartMessageFactory.CreateOperatorLogo(GSMCommunication.PDUDecoder.SmartMessaging.OtaBitmap,System.String,System.String)" /> to create one.</param>
 /// <param name="destinationAddress">The message's destination address.</param>
 /// <returns>A set of <see cref="T:GSMCommunication.PDUDecoder.SmsSubmitPdu" /> objects that represent the message.</returns>
 /// <exception cref="T:System.ArgumentNullException">operatorLogo is null.</exception>
 /// <exception cref="T:System.ArgumentException"><para>operatorLogo is an empty array.</para>
 /// <para> -or- </para><para>destinationAddress is an empty string.</para>
 /// <para> -or- </para><para>operatorLogo is so big that it would create more than 255 message parts.</para></exception>
 public static SmsSubmitPdu[] CreateOperatorLogoMessage(byte[] operatorLogo, string destinationAddress)
 {
     int length;
     if (operatorLogo != null)
     {
         if ((int)operatorLogo.Length != 0)
         {
             PortAddressElement16 portAddressElement16 = new PortAddressElement16(5506, 0);
             byte num = (byte)((int)portAddressElement16.ToByteArray().Length);
             int num1 = num + 1;
             bool flag = (int)operatorLogo.Length > 140 - num1;
             if (flag)
             {
                 ConcatMessageElement8 concatMessageElement8 = new ConcatMessageElement8(0, 0, 0);
                 num = (byte)((int)portAddressElement16.ToByteArray().Length + (int)concatMessageElement8.ToByteArray().Length);
                 num1 = num + 1;
             }
             ArrayList arrayLists = new ArrayList();
             int num2 = 0;
             byte num3 = (byte)Math.Ceiling((double)((int)operatorLogo.Length) / (double)(140 - num1));
             if (arrayLists.Count <= 255)
             {
                 ushort num4 = 1;
                 if (flag)
                 {
                     num4 = SmartMessageFactory.CalcNextRefNumber();
                 }
                 for (byte i = 1; i <= num3; i = (byte)(i + 1))
                 {
                     if ((int)operatorLogo.Length - num2 < 140 - num1)
                     {
                         length = (int)operatorLogo.Length - num2;
                     }
                     else
                     {
                         length = 140 - num1;
                     }
                     byte[] numArray = new byte[num1];
                     int length1 = 0;
                     int num5 = length1;
                     length1 = num5 + 1;
                     numArray[num5] = num;
                     portAddressElement16.ToByteArray().CopyTo(numArray, length1);
                     length1 = length1 + (int)portAddressElement16.ToByteArray().Length;
                     if (flag)
                     {
                         ConcatMessageElement8 concatMessageElement81 = new ConcatMessageElement8((byte)(num4 % 256), num3, i);
                         concatMessageElement81.ToByteArray().CopyTo(numArray, length1);
                         length1 = length1 + (int)concatMessageElement81.ToByteArray().Length;
                     }
                     byte[] numArray1 = new byte[(int)numArray.Length + length];
                     numArray.CopyTo(numArray1, 0);
                     Array.Copy(operatorLogo, num2, numArray1, length1, length);
                     SmsSubmitPdu smsSubmitPdu = new SmsSubmitPdu();
                     smsSubmitPdu.MessageFlags.UserDataHeaderPresent = true;
                     smsSubmitPdu.DataCodingScheme = 21;
                     smsSubmitPdu.DestinationAddress = destinationAddress;
                     smsSubmitPdu.SetUserData(numArray1, (byte)((int)numArray1.Length));
                     arrayLists.Add(smsSubmitPdu);
                     num2 = num2 + length;
                 }
                 SmsSubmitPdu[] smsSubmitPduArray = new SmsSubmitPdu[arrayLists.Count];
                 arrayLists.CopyTo(smsSubmitPduArray, 0);
                 return smsSubmitPduArray;
             }
             else
             {
                 throw new ArgumentException("A concatenated message must not have more than 255 parts.", "operatorLogo");
             }
         }
         else
         {
             throw new ArgumentException("operatorLogo must not be an empty array.", "operatorLogo");
         }
     }
     else
     {
         throw new ArgumentNullException("operatorLogo");
     }
 }