/// <summary> /// Determines whether all parts of a concatenated message are present. /// </summary> /// <param name="parts">The parts that make up the concatenated message.</param> /// <returns>true if all parts are present, false otherwise.</returns> /// <exception cref="T:System.ArgumentNullException">parts is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <para>The reference numbers differ between the message parts.</para> /// <para> -or- </para> /// <para>The number of total messages differs between the message parts.</para> /// <para> -or- </para> /// <para>A non-concatenated message part is present at an invalid position.</para> /// </exception> public static bool AreAllConcatPartsPresent(IList <SmsPdu> parts) { bool flag = false; SmartMessageDecoder.GetConcatUserData(parts, false, true, true, out flag); return(flag); }
/// <summary> /// Gets the concatenation information of a message. /// </summary> /// <param name="pdu">The message to get the information of.</param> /// <returns>An object implementing <see cref="T:GSMCommunication.PDUDecoder.SmartMessaging.IConcatenationInfo" />, if /// the message is a part of a concatenated message, null otherwise.</returns> /// <remarks> /// <para>The returned information can be used to discover the parts of a concatenated message /// or recombine the parts back into one message.</para> /// </remarks> public static IConcatenationInfo GetConcatenationInfo(SmsPdu pdu) { if (pdu != null) { IConcatenationInfo concatenationInfo = null; if (pdu.UserDataHeaderPresent) { byte[] userDataHeader = pdu.GetUserDataHeader(); InformationElement[] informationElementArray = SmartMessageDecoder.DecodeUserDataHeader(userDataHeader); InformationElement[] informationElementArray1 = informationElementArray; int num = 0; while (num < (int)informationElementArray1.Length) { InformationElement informationElement = informationElementArray1[num]; if (informationElement as IConcatenationInfo == null) { num++; } else { concatenationInfo = (IConcatenationInfo)informationElement; break; } } } return(concatenationInfo); } else { throw new ArgumentNullException("pdu"); } }
/// <summary> /// Combines the parts of a concatenated message into a single message text. /// </summary> /// <param name="parts">The parts that make up the concatenated message.</param> /// <returns>A string containing the combined message text of all parts.</returns> /// <remarks> /// <para>All parts must be available, but can be in any order.</para> /// <para>The user data is converted into text according to the data coding scheme specified in the message. /// If you want the user data to be returned in its binary format, use <see cref="M:GSMCommunication.PDUDecoder.SmartMessaging.SmartMessageDecoder.CombineConcatMessage(System.Collections.Generic.IList{GSMCommunication.PDUDecoder.SmsPdu})" /> instead.</para> /// <para>If the first part is a non-concatenated message, its user data is returned back as text, and no more parts are processed /// afterwards.</para> /// </remarks> /// <exception cref="T:System.ArgumentNullException">parts is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <para>Not all parts of the message are available.</para> /// <para> -or- </para> /// <para>The reference numbers differ between the message parts.</para> /// <para> -or- </para> /// <para>The number of total messages differs between the message parts.</para> /// <para> -or- </para> /// <para>A non-concatenated message part is present at an invalid position.</para> /// </exception> /// <seealso cref="M:GSMCommunication.PDUDecoder.SmartMessaging.SmartMessageDecoder.CombineConcatMessage(System.Collections.Generic.IList{GSMCommunication.PDUDecoder.SmsPdu})" /> public static string CombineConcatMessageText(IList <SmsPdu> parts) { bool flag = false; List <object> concatUserData = SmartMessageDecoder.GetConcatUserData(parts, true, false, false, out flag); StringBuilder stringBuilder = new StringBuilder(); foreach (string concatUserDatum in concatUserData) { stringBuilder.Append(concatUserDatum); } return(stringBuilder.ToString()); }
/// <summary> /// Combines the parts of a concatenated message into a single message. /// </summary> /// <param name="parts">The parts that make up the concatenated message.</param> /// <returns>A byte array containing the combined user data of all parts without any headers.</returns> /// <remarks> /// <para>All parts must be available, but can be in any order.</para> /// <para>The user data is returned in its binary format. If you want the user data to be /// returned as text, use <see cref="M:GSMCommunication.PDUDecoder.SmartMessaging.SmartMessageDecoder.CombineConcatMessageText(System.Collections.Generic.IList{GSMCommunication.PDUDecoder.SmsPdu})" /> instead.</para> /// <para>If the first part is a non-concatenated message, its user data is returned back, and no more parts are processed /// afterwards.</para> /// </remarks> /// <exception cref="T:System.ArgumentNullException">parts is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <para>Not all parts of the message are available.</para> /// <para> -or- </para> /// <para>The reference numbers differ between the message parts.</para> /// <para> -or- </para> /// <para>The number of total messages differs between the message parts.</para> /// <para> -or- </para> /// <para>A non-concatenated message part is present at an invalid position.</para> /// </exception> /// <seealso cref="M:GSMCommunication.PDUDecoder.SmartMessaging.SmartMessageDecoder.CombineConcatMessageText(System.Collections.Generic.IList{GSMCommunication.PDUDecoder.SmsPdu})" /> public static byte[] CombineConcatMessage(IList <SmsPdu> parts) { bool flag = false; List <object> concatUserData = SmartMessageDecoder.GetConcatUserData(parts, false, false, false, out flag); List <byte> nums = new List <byte>(); foreach (byte[] concatUserDatum in concatUserData) { nums.AddRange(concatUserDatum); } return(nums.ToArray()); }
private static bool HaveSameReferenceNumber(SmsPdu pdu1, SmsPdu pdu2) { bool flag = false; if (SmartMessageDecoder.IsPartOfConcatMessage(pdu1) && SmartMessageDecoder.IsPartOfConcatMessage(pdu2)) { IConcatenationInfo concatenationInfo = SmartMessageDecoder.GetConcatenationInfo(pdu1); IConcatenationInfo concatenationInfo1 = SmartMessageDecoder.GetConcatenationInfo(pdu2); if (concatenationInfo.ReferenceNumber == concatenationInfo1.ReferenceNumber) { flag = true; } } return(flag); }
/// <summary> /// Determines whether two messages are part of the same concatenated message. /// </summary> /// <param name="pdu1">The first message to compare.</param> /// <param name="pdu2">The second message to compare.</param> /// <returns>true if both messages appear to belong to the same concatenated message, false otherwise.</returns> /// <remarks> /// <para>This comparison is supported for <see cref="T:GSMCommunication.PDUDecoder.SmsSubmitPdu" /> and <see cref="T:GSMCommunication.PDUDecoder.SmsDeliverPdu" /> objects. /// For all other objects, this comparison always returns false.</para> /// <para>For <see cref="T:GSMCommunication.PDUDecoder.SmsSubmitPdu" /> objects, the <see cref="P:GSMCommunication.PDUDecoder.SmsSubmitPdu.DestinationAddress" />, /// <see cref="P:GSMCommunication.PDUDecoder.SmsSubmitPdu.DestinationAddressType" /> and <see cref="P:GSMCommunication.PDUDecoder.SmartMessaging.IConcatenationInfo.ReferenceNumber" /> properties are compared.</para> /// <para>For <see cref="T:GSMCommunication.PDUDecoder.SmsDeliverPdu" /> objects, the <see cref="P:GSMCommunication.PDUDecoder.SmsDeliverPdu.OriginatingAddress" />, /// <see cref="P:GSMCommunication.PDUDecoder.SmsDeliverPdu.OriginatingAddressType" /> and <see cref="P:GSMCommunication.PDUDecoder.SmartMessaging.IConcatenationInfo.ReferenceNumber" /> properties are compared.</para> /// </remarks> /// <exception cref="T:System.ArgumentNullException">pdu1 or pdu2 is null.</exception> public static bool ArePartOfSameMessage(SmsPdu pdu1, SmsPdu pdu2) { if (pdu1 != null) { if (pdu2 != null) { bool flag = false; if (pdu1 as SmsDeliverPdu == null || pdu2 as SmsDeliverPdu == null) { if (pdu1 is SmsSubmitPdu && pdu2 is SmsSubmitPdu) { SmsSubmitPdu smsSubmitPdu = (SmsSubmitPdu)pdu1; SmsSubmitPdu smsSubmitPdu1 = (SmsSubmitPdu)pdu2; if (smsSubmitPdu.DestinationAddress == smsSubmitPdu1.DestinationAddress && smsSubmitPdu.DestinationAddressType == smsSubmitPdu1.DestinationAddressType) { flag = SmartMessageDecoder.HaveSameReferenceNumber(pdu1, pdu2); } } } else { SmsDeliverPdu smsDeliverPdu = (SmsDeliverPdu)pdu1; SmsDeliverPdu smsDeliverPdu1 = (SmsDeliverPdu)pdu2; if (smsDeliverPdu.OriginatingAddress == smsDeliverPdu1.OriginatingAddress && smsDeliverPdu.OriginatingAddressType == smsDeliverPdu1.OriginatingAddressType) { flag = SmartMessageDecoder.HaveSameReferenceNumber(pdu1, pdu2); } } return(flag); } else { throw new ArgumentNullException("pdu2"); } } else { throw new ArgumentNullException("pdu1"); } }
private static SortedList <IConcatenationInfo, SmsPdu> SortConcatMessageParts(IList <SmsPdu> parts) { IConcatenationInfo concatenationInfo; IConcatenationInfo concatenationInfo1 = null; SortedList <IConcatenationInfo, SmsPdu> concatenationInfos = new SortedList <IConcatenationInfo, SmsPdu>(new ConcatInfoComparer()); foreach (SmsPdu part in parts) { if (concatenationInfo1 != null) { if (!SmartMessageDecoder.IsPartOfConcatMessage(part)) { throw new ArgumentException("A non-concatenated message part is present at an invalid position.", "parts"); } else { concatenationInfo = SmartMessageDecoder.GetConcatenationInfo(part); if (concatenationInfo1.ReferenceNumber == concatenationInfo.ReferenceNumber) { if (concatenationInfo1.TotalMessages != concatenationInfo.TotalMessages) { throw new ArgumentException("The number of total messages differs between the message parts.", "parts"); } } else { throw new ArgumentException("The reference numbers differ between the message parts.", "parts"); } } } else { concatenationInfo = SmartMessageDecoder.GetConcatenationInfo(part); } concatenationInfos.Add(concatenationInfo, part); concatenationInfo1 = concatenationInfo; } return(concatenationInfos); }
/// <summary> /// Determines whether a message is part of a concatenated message. /// </summary> /// <param name="pdu">The message.</param> /// <returns>true if the message is part of a concatenated message, false otherwise.</returns> public static bool IsPartOfConcatMessage(SmsPdu pdu) { return(SmartMessageDecoder.GetConcatenationInfo(pdu) != null); }
/// <summary> /// Retrieves the user data of all parts of a concatenated message. /// </summary> /// <param name="parts">The parts that make up the concatenated message.</param> /// <param name="outputAsText">If true, formats the returned user data as text. If false, returns the user data /// in its binary form.</param> /// <param name="allowMissingParts">Specifies whether missing parts are allowed. If true, null is returned /// in the resulting list in place of every missing part. If false, an exception is raised when a part is /// missing.</param> /// <param name="noOutput">If set to true, does not fill the returned list with data. If set to false, the data is returned /// normally. Use this in conjunction with allowMissingParts set to true to verify whether all message parts are present.</param> /// <param name="allPartsAvailable">Is set to true if all message parts are available, false otherwise. Use this in conjunction /// with allowMissingParts set to true to verify whether all message parts are present.</param> /// <returns>A list of objects containing the user data of every part without any headers. /// The outputAsText parameter determines the actual data type that is returned. If outputAsText is true, the return type is a /// list of byte arrays, if false a list of strings is returned. /// </returns> /// <remarks> /// <para>The parts can be in any order.</para> /// <para>If the first part is a non-concatenated message, its user data is returned back, and no more parts are processed /// afterwards.</para> /// </remarks> /// <exception cref="T:System.ArgumentNullException">parts is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <para>Not all parts of the message are available and allowMissingParts is false.</para> /// <para> -or- </para> /// <para>The reference numbers differ between the message parts.</para> /// <para> -or- </para> /// <para>The number of total messages differs between the message parts.</para> /// <para> -or- </para> /// <para>A non-concatenated message part is present at an invalid position.</para> /// </exception> private static List <object> GetConcatUserData(IList <SmsPdu> parts, bool outputAsText, bool allowMissingParts, bool noOutput, out bool allPartsAvailable) { if (parts != null) { allPartsAvailable = true; List <object> objs = new List <object>(); if (parts.Count > 0) { SmsPdu item = parts[0]; if (!SmartMessageDecoder.IsPartOfConcatMessage(item)) { if (!noOutput) { if (!outputAsText) { objs.Add(item.UserData); } else { objs.Add(item.UserDataText); } } } else { SortedList <IConcatenationInfo, SmsPdu> concatenationInfos = SmartMessageDecoder.SortConcatMessageParts(parts); int totalMessages = concatenationInfos.Keys[0].TotalMessages; int num = 0; for (int i = 1; i <= totalMessages; i++) { bool flag = false; if (num < concatenationInfos.Count) { IConcatenationInfo concatenationInfo = concatenationInfos.Keys[num]; SmsPdu smsPdu = concatenationInfos.Values[num]; if (i == concatenationInfo.CurrentNumber) { if (!noOutput) { if (!outputAsText) { objs.Add(smsPdu.GetUserDataWithoutHeader()); } else { objs.Add(smsPdu.GetUserDataTextWithoutHeader()); } } num++; } else { flag = true; } } else { flag = true; } if (flag) { allPartsAvailable = false; if (!allowMissingParts) { throw new ArgumentException(string.Concat("Not all parts of the message are available. Part #", i, " is missing."), "parts"); } else { if (!noOutput) { objs.Add(null); } } } } } } return(objs); } else { throw new ArgumentNullException("parts"); } }