Esempio n. 1
0
        /// <summary>
        /// Modifies the message text so that it is safe to be sent via GSM 7-Bit default encoding.
        /// </summary>
        /// <param name="data">The message text.</param>
        /// <returns>The converted message text.</returns>
        /// <remarks>Replaces invalid characters in the text and truncates it to the maximum allowed length.</remarks>
        public static string GetSafeText(string data)
        {
            bool flag  = false;
            bool flag1 = false;

            return(SmsPdu.GetSafeText(data, out flag, out flag1));
        }
Esempio n. 2
0
        internal static void SaveMessage(GsmComm.PduConverter.SmsPdu smsPdu)
        {
            // Received message
            SmsDeliverPdu data = (SmsDeliverPdu)smsPdu;

            // create our NHibernate session factory
            var sessionFactory = CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // populate the database
                using (var transaction = session.BeginTransaction())
                {
                    TMsg msg = new TMsg();
                    msg.Id      = Guid.NewGuid().ToString();
                    msg.MsgDate = data.SCTimestamp.ToDateTime();
                    msg.MsgFrom = data.OriginatingAddress;
                    msg.MsgTo   = "";
                    msg.MsgText = data.UserDataText;

                    // save both stores, this saves everything else via cascading
                    session.SaveOrUpdate(msg);

                    transaction.Commit();
                }
            }
        }
Esempio 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;
		}
Esempio n. 4
0
        private void BindGrid(SmsPdu pdu)
        {
            DataRow dr=dt.NewRow();
            SmsDeliverPdu data = (SmsDeliverPdu)pdu;

            dr[0]=data.OriginatingAddress.ToString();
            dr[1]=data.SCTimestamp.ToString();
            dr[2]=data.UserDataText;
            dt.Rows.Add(dr);

            dataGrid1.DataSource=dt;
        }
Esempio n. 5
0
		/// <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:GsmComm.PduConverter.SmsSubmitPdu" /> and <see cref="T:GsmComm.PduConverter.SmsDeliverPdu" /> objects.
		/// For all other objects, this comparison always returns false.</para>
		/// <para>For <see cref="T:GsmComm.PduConverter.SmsSubmitPdu" /> objects, the <see cref="P:GsmComm.PduConverter.SmsSubmitPdu.DestinationAddress" />,
		/// <see cref="P:GsmComm.PduConverter.SmsSubmitPdu.DestinationAddressType" /> and <see cref="P:GsmComm.PduConverter.SmartMessaging.IConcatenationInfo.ReferenceNumber" /> properties are compared.</para>
		/// <para>For <see cref="T:GsmComm.PduConverter.SmsDeliverPdu" /> objects, the <see cref="P:GsmComm.PduConverter.SmsDeliverPdu.OriginatingAddress" />,
		/// <see cref="P:GsmComm.PduConverter.SmsDeliverPdu.OriginatingAddressType" /> and <see cref="P:GsmComm.PduConverter.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");
			}
		}
Esempio n. 6
0
		/// <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;
		}
Esempio n. 7
0
		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;
		}
Esempio n. 8
0
		/// <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:GsmComm.PduConverter.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");
			}
		}
Esempio n. 9
0
        private void ShowMessage(SmsPdu pdu)
        {
            if (pdu is SmsSubmitPdu)
            {
                // Stored (sent/unsent) message
                SmsSubmitPdu data = (SmsSubmitPdu)pdu;
                Output("SENT/UNSENT MESSAGE");
                Output("Recipient: " + data.DestinationAddress);
                Output("Message text: " + data.UserDataText);
                Output("-------------------------------------------------------------------");
                return;
            }
            if (pdu is SmsDeliverPdu)
            {
                // Received message
                SmsDeliverPdu data = (SmsDeliverPdu)pdu;
                Output("RECEIVED MESSAGE");
                Output("Sender: " + data.OriginatingAddress);
                Output("Sent: " + data.SCTimestamp.ToString());
                Output("Message text: " + data.UserDataText);
                Output("-------------------------------------------------------------------");

                BindGrid(pdu);

                return;
            }
            if (pdu is SmsStatusReportPdu)
            {
                // Status report
                SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
                Output("STATUS REPORT");
                Output("Recipient: " + data.RecipientAddress);
                Output("Status: " + data.Status.ToString());
                Output("Timestamp: " + data.DischargeTime.ToString());
                Output("Message ref: " + data.MessageReference.ToString());
                Output("-------------------------------------------------------------------");
                return;
            }
            Output("Unknown message type: " + pdu.GetType().ToString());
        }
Esempio n. 10
0
		private void ShowMessage(SmsPdu pdu)
		{
			if (pdu is SmsSubmitPdu)
			{
				// Stored (sent/unsent) message
				SmsSubmitPdu data = (SmsSubmitPdu)pdu;
				Output("SENT/UNSENT MESSAGE");
				Output("Recipient: " + data.DestinationAddress);
				Output("Message text: " + data.UserDataText);
				Output("-------------------------------------------------------------------");
				return;
			}
			if (pdu is SmsDeliverPdu)
			{
				// Received message
				SmsDeliverPdu data = (SmsDeliverPdu)pdu;
				Output("Mensaje Recibido");
				Output("Emisor: " + data.OriginatingAddress);
				Output("Hora de envio: " + data.SCTimestamp.ToString());
				Output("Texto del mensaje: " + data.UserDataText);
				Output("-------------------------------------------------------------------");
                try
                {
                    var request = (HttpWebRequest)WebRequest.Create(Constants.getServer() + "/api/v1/sms/create");
                    var postData = MessageToJson(data.SCTimestamp.ToString(),data.OriginatingAddress, data.UserDataText,DateTime.Now.Ticks.ToString());
                    var data2 = Encoding.UTF8.GetBytes(postData);
                    request.Method = "POST";
                    request.ContentType = "application/json";
                    request.ContentLength = data2.Length;
                    using (var stream = request.GetRequestStream())
                    {
                        stream.Write(data2, 0, data2.Length);
                    }
                    var response = (HttpWebResponse)request.GetResponse();
                    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                    response.Close();
                }
                catch (System.Net.WebException wx)
                {
                    MessageBox.Show(wx.Message);
                }
                CommSetting.comm.DeleteMessages(DeleteScope.All, PhoneStorageType.Sim);
				return;
			}
			if (pdu is SmsStatusReportPdu)
			{
				// Status report
				SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
				Output("STATUS REPORT");
				Output("Recipient: " + data.RecipientAddress);
				Output("Status: " + data.Status.ToString());
				Output("Timestamp: " + data.DischargeTime.ToString());
				Output("Message ref: " + data.MessageReference.ToString());
				Output("-------------------------------------------------------------------");
				return;
			}
			Output("Unknown message type: " + pdu.GetType().ToString());
		}
Esempio n. 11
0
		private void ShowMessage(SmsPdu pdu,int index)
		{
			if (pdu is SmsSubmitPdu)
			{
				// Stored (sent/unsent) message
				SmsSubmitPdu data = (SmsSubmitPdu)pdu;
				return;
			}
			if (pdu is SmsDeliverPdu)
			{
				// Received message
				SmsDeliverPdu data = (SmsDeliverPdu)pdu;
				
				BindGrid(pdu,index);

				return;
			}
			if (pdu is SmsStatusReportPdu)
			{
				// Status report
				SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
				return;
			}
			
		}
Esempio n. 12
0
        private void ShowMessage(SmsPdu pdu)
        {
            if (pdu is SmsDeliverPdu)
            {
                setFullBar(false);
                // Received message
                SmsDeliverPdu data = (SmsDeliverPdu)pdu;
                string toWrite="";
                toWrite = data.UserDataText;
                string dt = data.SCTimestamp.Day + "/" + data.SCTimestamp.Month + "/" + data.SCTimestamp.Year + " " + data.SCTimestamp.Hour + ":" + data.SCTimestamp.Minute + ":" + data.SCTimestamp.Second;
                if (data.UserDataText.IndexOf("$GPRMC") > -1)
                {
                    validGPS(data.UserDataText, data.OriginatingAddress,dt,true);
                    Output(dt+" Ricevuto posizione del terminale: " + data.OriginatingAddress);
                    makeLog(data.OriginatingAddress, "Ricevuto posizione del terminale: " + data.OriginatingAddress);
                    saveNewPosition(data.OriginatingAddress, data.UserDataText);
                }
                if (data.UserDataText.IndexOf("KTA") > -1)
                {
                    parseKFTString(data.UserDataText, data.OriginatingAddress, dt,true);
                    Output(dt + " Ricevuto posizione del terminale: " + data.OriginatingAddress);
                    makeLog(data.OriginatingAddress, "Ricevuto posizione del terminale: " + data.OriginatingAddress);
                    saveNewPosition(data.OriginatingAddress, data.UserDataText);
                    frmAllarm.addNewAllarm(dt, data.OriginatingAddress, "Ricevuto posizione del terminale: " + data.OriginatingAddress);
                }
                if(data.UserDataText.IndexOf("\nHP=")>-1)
                {
                    parseCP100string(data.UserDataText,data.OriginatingAddress,dt,true);
                    makeLog(data.OriginatingAddress, "Ricevuto posizione del terminale: " + data.OriginatingAddress);
                    saveNewPosition(data.OriginatingAddress, data.UserDataText);
                }
                if (data.UserDataText.IndexOf("VKT%") > -1)
                {
                    string TipoMessaggio = data.UserDataText.Substring(data.UserDataText.LastIndexOf("VKT%")+4, 4);
                    string[] Mess = data.UserDataText.Split(':');
                    string Messaggio = Mess[Mess.Length-1];
                    string m = "";
                    m = getMessage(Messaggio);
                    if (m != "")
                    {
                        frmAllarm.addNewAllarm(dt, data.OriginatingAddress, m);
                    }
                }

                makeLog(data.OriginatingAddress, toWrite);
                return;
            }
        }