Ejemplo n.º 1
0
        private string StatusToString(PhoneMessageStatus status)
        {
            // Map a message status to a string
            string ret;

            switch (status)
            {
            case PhoneMessageStatus.All:
                ret = "All";
                break;

            case PhoneMessageStatus.ReceivedRead:
                ret = "Read";
                break;

            case PhoneMessageStatus.ReceivedUnread:
                ret = "Unread";
                break;

            case PhoneMessageStatus.StoredSent:
                ret = "Sent";
                break;

            case PhoneMessageStatus.StoredUnsent:
                ret = "Unsent";
                break;

            default:
                ret = "Unknown (" + status.ToString() + ")";
                break;
            }
            return(ret);
        }
 /// <summary>
 ///
 /// </summary>
 public PhoneMessageOperation(int pkid, Account assessor, PhoneMessageStatus status, string answer)
 {
     _PKID     = pkid;
     _Assessor = assessor;
     _Answer   = answer;
     _Status   = status;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:GsmComm.GsmCommunication.ShortMessageFromPhone" />class.
 /// </summary>
 /// <param name="index">The index where the message is saved in the device in the <see cref="F:GsmComm.GsmCommunication.DecodedShortMessage.storage" />.</param>
 /// <param name="data">The decoded message.</param>
 /// <param name="status">The parsed message status.</param>
 /// <param name="storage">The phone storage the message was read from.</param>
 public DecodedShortMessage(int index, SmsPdu data, PhoneMessageStatus status, string storage)
 {
     this.index   = index;
     this.data    = data;
     this.status  = status;
     this.storage = storage;
 }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <PhoneMessage> GetPhoneMessageByCondition(int assessorID, PhoneMessageStatus status)
        {
            List <PhoneMessage> phoneMessageList = new List <PhoneMessage>();
            SqlCommand          cmd = new SqlCommand();

            cmd.Parameters.Add(_AssessorID, SqlDbType.Int).Value = assessorID;
            cmd.Parameters.Add(_Status, SqlDbType.Int).Value     = status;
            using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetPhoneMessageByCondition", cmd))
            {
                while (sdr.Read())
                {
                    PhoneMessage phoneMessage = new PhoneMessage();
                    phoneMessage.Message          = sdr[_DBMessage].ToString();
                    phoneMessage.PhoneMessageType = new PhoneMessageType((PhoneMessageEnumType)sdr[_DBType], Convert.ToInt32(sdr[_DBTypeID]));
                    phoneMessage.PKID             = Convert.ToInt32(sdr[_DBPKID]);
                    phoneMessage.Requester        = new Account(Convert.ToInt32(sdr[_DBRequesterID]), "", "");
                    phoneMessage.Assessor         = new Account(Convert.ToInt32(sdr[_DBAssessorID]), "", "");
                    phoneMessage.Answer           = sdr[_DBAnswer].ToString();
                    phoneMessage.Status           = (PhoneMessageStatus)sdr[_DBStatus];
                    phoneMessage.SendTime         = sdr[_DBSendTime] == DBNull.Value ? Convert.ToDateTime("2008-11-1") : Convert.ToDateTime(sdr[_DBSendTime]);
                    phoneMessageList.Add(phoneMessage);
                }
            }
            return(phoneMessageList);
        }
Ejemplo n.º 5
0
        public List <SystemError> GetPhoneMessageByCondition(string name, PhoneMessageStatus status, Account loginUser)
        {
            GetPhoneMessageError getphonemessageerror = new GetPhoneMessageError(name, status, loginUser);

            getphonemessageerror.Excute();
            return(getphonemessageerror.SystemErrorList);
        }
        public async Task <List <MessageViewModel> > GetMessagesAsync(PhoneMessageStatus status, string storage)
        {
            var tcs = new TaskCompletionSource <DecodedShortMessage[]>();

            await Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        var messages = Model.ReadMessages(status, storage);
                        tcs.SetResult(messages);
                        break;
                    }
                    catch (CommException)
                    {
                        Task.Delay(1000);
                    }
                    catch (Exception)
                    {
                        break;
                    }
                }
            });

            return(tcs.Task.Result.Select(c =>
                                          new MessageViewModel(c, Model.PortName, storage,
                                                               PhoneMessageStatus.ReceivedRead)).ToList());
        }
Ejemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="status"></param>
 public GetPhoneMessageError(string name, PhoneMessageStatus status, Account loginuser)
 {
     _Name            = name;
     _Status          = status;
     _LoginUser       = loginuser;
     _SystemErrorList = new List <SystemError>();
 }
Ejemplo n.º 8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="T:GsmComm.GsmCommunication.ShortMessageFromPhone" />class.
		/// </summary>
		/// <param name="index">The index where the message is saved in the device in the <see cref="F:GsmComm.GsmCommunication.DecodedShortMessage.storage" />.</param>
		/// <param name="data">The decoded message.</param>
		/// <param name="status">The parsed message status.</param>
		/// <param name="storage">The phone storage the message was read from.</param>
		public DecodedShortMessage(int index, SmsPdu data, PhoneMessageStatus status, string storage)
		{
			this.index = index;
			this.data = data;
			this.status = status;
			this.storage = storage;
		}
 public MessageViewModel(DecodedShortMessage model, string port, string location, PhoneMessageStatus status)
     : base(model)
 {
     MessageData = (SmsDeliverPdu)Model.Data;
     Status      = status;
     Port        = port;
     PhoneNumber = MessageData.OriginatingAddress;
     Location    = location == "SM" ? "SIM" : "MEMORY";
 }
Ejemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 public PhoneMessage(int pkid, Account requester, Account assessor, PhoneMessageStatus status, string answer, string message)
 {
     _PKID      = pkid;
     _Requester = requester;
     _Message   = message;
     _Assessor  = assessor;
     _Answer    = answer;
     _Status    = status;
 }
Ejemplo n.º 11
0
        public static List <PhoneMessageSystemError> Turn(List <SystemError> types, PhoneMessageStatus status)
        {
            List <PhoneMessageSystemError> list = new List <PhoneMessageSystemError>();

            foreach (SystemError t in types)
            {
                list.Add(new PhoneMessageSystemError(t, status));
            }
            return(list);
        }
Ejemplo n.º 12
0
 private string StatusToString(PhoneMessageStatus status)
 {
     // Map a message status to a string
     string ret;
     switch(status)
     {
         case PhoneMessageStatus.All:
             ret = "All";
             break;
         case PhoneMessageStatus.ReceivedRead:
             ret = "Read";
             break;
         case PhoneMessageStatus.ReceivedUnread:
             ret = "Unread";
             break;
         case PhoneMessageStatus.StoredSent:
             ret = "Sent";
             break;
         case PhoneMessageStatus.StoredUnsent:
             ret = "Unsent";
             break;
         default:
             ret = "Unknown (" + status.ToString() + ")";
             break;
     }
     return ret;
 }
Ejemplo n.º 13
0
		/// <summary>
		/// AT+CMGL. Reads SMS messages from the current read/delete storage using the PDU mode.
		/// </summary>
		/// <param name="status">The message status</param>
		/// <returns>An array of <see cref="T:GsmComm.GsmCommunication.ShortMessage" /> objects representing the messages read.</returns>
		/// <remarks>Always switches to PDU mode at the beginning.</remarks>
		public ShortMessageFromPhone[] ListMessages(PhoneMessageStatus status)
		{
			ShortMessageFromPhone[] shortMessageFromPhoneArray;
			lock (this)
			{
				this.VerifyValidConnection();
				this.ActivatePduMode();
				this.LogIt(LogLevel.Info, string.Concat("Reading messages, requesting status \"", status.ToString(), "\"..."));
				string str = string.Concat("AT+CMGL=", (int)status);
				string str1 = this.ExecAndReceiveMultiple(str);
				ArrayList arrayLists = new ArrayList();
				Regex regex = new Regex("\\+CMGL: (\\d+),(\\d+),(?:\"(\\w*)\")?,(\\d+)\\r\\n(\\w+)");
				for (Match i = regex.Match(str1); i.Success; i = i.NextMatch())
				{
					int num = int.Parse(i.Groups[1].Value);
					int num1 = int.Parse(i.Groups[2].Value);
					string value = i.Groups[3].Value;
					int num2 = int.Parse(i.Groups[4].Value);
					string value1 = i.Groups[5].Value;
					string[] strArrays = new string[8];
					strArrays[0] = "index=";
					strArrays[1] = num.ToString();
					strArrays[2] = ", stat=";
					strArrays[3] = num1.ToString();
					strArrays[4] = ", alpha=\"";
					strArrays[5] = value;
					strArrays[6] = "\", length=";
					strArrays[7] = num2.ToString();
					this.LogIt(LogLevel.Info, string.Concat(strArrays));
					ShortMessageFromPhone shortMessageFromPhone = new ShortMessageFromPhone(num, num1, value, num2, value1);
					arrayLists.Add(shortMessageFromPhone);
				}
				int count = arrayLists.Count;
				this.LogIt(LogLevel.Info, string.Concat(count.ToString(), " message(s) read."));
				ShortMessageFromPhone[] shortMessageFromPhoneArray1 = new ShortMessageFromPhone[arrayLists.Count];
				arrayLists.CopyTo(shortMessageFromPhoneArray1, 0);
				shortMessageFromPhoneArray = shortMessageFromPhoneArray1;
			}
			return shortMessageFromPhoneArray;
		}
Ejemplo n.º 14
0
		/// <summary>
		/// Reads short messages in their original form 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 undecoded short messages, as read from the phone.</returns>
		/// <remarks><para>This function is intended to download the messages exactly as they are
		/// returned from the phone, e.g. for a backup. If you want to use the messages
		/// directly, e.g. displaying them to the user without saving them, use the <see cref="M:GsmComm.GsmCommunication.GsmCommMain.ReadMessages(GsmComm.GsmCommunication.PhoneMessageStatus,System.String)" />
		/// function instead.</para>
		/// <para>If you want to decode the saved messages later, you can use the <see cref="M:GsmComm.GsmCommunication.GsmCommMain.DecodeShortMessage(GsmComm.GsmCommunication.ShortMessageFromPhone)" />
		/// function.</para>
		/// <para>You can import the saved message back to the phone using the <see cref="M:GsmComm.GsmCommunication.GsmCommMain.WriteRawMessage(GsmComm.GsmCommunication.ShortMessageFromPhone,System.String)" />
		/// function.</para>
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.ReadMessages(GsmComm.GsmCommunication.PhoneMessageStatus,System.String)" />
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.DecodeShortMessage(GsmComm.GsmCommunication.ShortMessageFromPhone)" />
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.WriteRawMessageWithoutStatus(GsmComm.GsmCommunication.ShortMessage,System.String)" />
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.WriteRawMessage(GsmComm.GsmCommunication.ShortMessageFromPhone,System.String)" />
		/// </remarks>
		public ShortMessageFromPhone[] ReadRawMessages(PhoneMessageStatus status, string storage)
		{
			this.LogIt(LogLevel.Info, "Reading messages...");
			new ArrayList();
			this.theDevice.SelectReadStorage(storage);
			return this.theDevice.ListMessages(status);
		}
Ejemplo n.º 15
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;
		}
Ejemplo n.º 16
0
 public PhoneMessageSystemError(SystemError systemerror, PhoneMessageStatus status)
 {
     _SystemError = systemerror;
     _Status      = status;
 }