예제 #1
0
 public static IMessage CreateMessage(DecodedShortMessage msg)
 {
     SimpleMessage simpleMessage = new SimpleMessage(msg);
     if (!simpleMessage.isCSMS)
     {
         return simpleMessage;
     }
     else
     {
         MultiMessage multiMessage = new MultiMessage(new IMessage[] { simpleMessage });
         return multiMessage;
     }
 }
예제 #2
0
 /// <summary>
 /// Construct a SimpleMessage from DecodedShortMessage
 /// </summary>
 /// <param name="msg">input message</param>
 public SimpleMessage(DecodedShortMessage msg)
 {
     var originalData = msg.Data;
     if (originalData is SmsDeliverPdu)
     {
         SmsDeliverPdu newData = (SmsDeliverPdu)originalData;
         bool _isUnicode = (msg.Data.UserDataLength != msg.Data.UserDataText.Length); // check if SMS is unicode
         bool _isCSMS = msg.Data.UserDataHeaderPresent;
         string _pureMessage;
         if (!_isCSMS)
             _pureMessage = newData.UserDataText;
         else if (_isUnicode)
             _pureMessage = msg.Data.GetUserDataTextWithoutHeader();
         else
             _pureMessage = newData.UserDataText.Substring(msg.Data.GetUserDataHeader().Length + 1);
         Initialize(newData.GetTimestamp().ToDateTime(), newData.OriginatingAddress, (_isCSMS) ? msg.Data.GetUserDataHeader() : null, _isUnicode, _isCSMS, _pureMessage);
     }
 }
예제 #3
0
 private void MessageReceived(DecodedShortMessage message)
 {
     var data = message.Data as SmsDeliverPdu;
     foreach (var participantAnswer in _round.ParticipantAnswers)
     {
         if (participantAnswer.Participant.PhoneNumber == data.OriginatingAddress)
         {
             string messageText = message.Data.UserDataText;
             foreach (var answer in _round.Question.AvailableAnswers)
             {
                 if (string.Compare(answer.Letter, messageText, true) == 0)
                 {
                     participantAnswer.Answer = answer;
                     break;
                 }
             }
         }
     }
 }
예제 #4
0
        private void MessageReceived(DecodedShortMessage message)
        {
            var data = message.Data as SmsDeliverPdu;

            bool found = false;
            foreach (var participant in _quiz.Participants)
            {
                if (participant.PhoneNumber == data.OriginatingAddress)
                {
                    found = true;
                    participant.Name = Regex.Replace(data.UserDataText, "\\s+", " ");
                }
            }
            if (!found)
            {
                var participant = new Participant();
                participant.Name = Regex.Replace(data.UserDataText, "\\s+", " ");
                participant.PhoneNumber = data.OriginatingAddress;
                _quiz.Participants.Add(participant);
            }
        }
예제 #5
0
		/// <summary>
		/// Reads and decodes short messages from phone.
		/// </summary>
		/// <param name="status">The status of the messages to read.</param>
		/// <param name="storage">The storage to look in for the messages.</param>
		/// <returns>An array of decoded messages.</returns>
		/// <remarks>As the decoded version of the message is not always guaranteed to
		/// be exactly the same when encoded back, do not use this function if you want
		/// to save the message in their original form. Use <see cref="M:GsmComm.GsmCommunication.GsmCommMain.ReadRawMessages(GsmComm.GsmCommunication.PhoneMessageStatus,System.String)" /> instead
		/// for that case.
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.ReadRawMessages(GsmComm.GsmCommunication.PhoneMessageStatus,System.String)" />
		/// </remarks>
		public DecodedShortMessage[] ReadMessages(PhoneMessageStatus status, string storage)
		{
			this.LogIt(LogLevel.Info, "Reading messages...");
			ArrayList arrayLists = new ArrayList();
			this.theDevice.SelectReadStorage(storage);
			ShortMessageFromPhone[] shortMessageFromPhoneArray = this.theDevice.ListMessages(status);
			for (int i = 0; i < (int)shortMessageFromPhoneArray.Length; i++)
			{
				ShortMessageFromPhone shortMessageFromPhone = shortMessageFromPhoneArray[i];
				try
				{
					if (!Enum.IsDefined(typeof(PhoneMessageStatus), shortMessageFromPhone.Status))
					{
						int num = shortMessageFromPhone.Status;
						throw new CommException(string.Concat("Unknown message status \"", num.ToString(), "\"!"));
					}
					else
					{
						int num1 = shortMessageFromPhone.Status;
						PhoneMessageStatus phoneMessageStatu = (PhoneMessageStatus)Enum.Parse(typeof(PhoneMessageStatus), num1.ToString());
						arrayLists.Add(new DecodedShortMessage(shortMessageFromPhone.Index, this.DecodeShortMessage(shortMessageFromPhone), phoneMessageStatu, storage));
					}
				}
				catch (Exception exception1)
				{
					Exception exception = exception1;
					this.LogIt(LogLevel.Error, string.Concat("Error while decoding a message: ", exception.Message, " The message was ignored."));
				}
			}
			DecodedShortMessage[] decodedShortMessageArray = new DecodedShortMessage[arrayLists.Count];
			arrayLists.CopyTo(decodedShortMessageArray);
			return decodedShortMessageArray;
		}
예제 #6
0
		/// <summary>
		/// Reads a single short message.
		/// </summary>
		/// <param name="index">The index of the message to read.</param>
		/// <param name="storage">The storage to look in for the message.</param>
		/// <returns>A <see cref="T:GsmComm.GsmCommunication.DecodedShortMessage" /> object containing the message at the index specified.</returns>
		public DecodedShortMessage ReadMessage(int index, string storage)
		{
			this.LogIt(LogLevel.Info, "Reading message...");
			this.theDevice.SelectReadStorage(storage);
			ShortMessageFromPhone shortMessageFromPhone = this.theDevice.ReadMessage(index);
			if (!Enum.IsDefined(typeof(PhoneMessageStatus), shortMessageFromPhone.Status))
			{
				int status = shortMessageFromPhone.Status;
				throw new CommException(string.Concat("Unknown message status \"", status.ToString(), "\"!"));
			}
			else
			{
				int num = shortMessageFromPhone.Status;
				PhoneMessageStatus phoneMessageStatu = (PhoneMessageStatus)Enum.Parse(typeof(PhoneMessageStatus), num.ToString());
				DecodedShortMessage decodedShortMessage = new DecodedShortMessage(shortMessageFromPhone.Index, this.DecodeShortMessage(shortMessageFromPhone), phoneMessageStatu, storage);
				return decodedShortMessage;
			}
		}
예제 #7
0
 /// <summary>
 /// Online Convert DecodedShortMessage --> SimpleMessage
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static SimpleMessage ToSimpleMessage(DecodedShortMessage msg)
 {
     return new SimpleMessage(msg);
 }