Example #1
0
        /// <summary>
        /// Process recived messages
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public List <SplitMessage> ReadResponseMessages(string data)
        {
            List <SplitMessage> listMessages = new List <SplitMessage>();

            try
            {
                // \d+ is used for decimal value
                // .* is used for any character
                //Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.*)");
                Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""(.*)");
                Match m = r.Match(data);

                if (!m.Success)
                {
                    m = r.Match(data);
                }
                while (m.Success)
                {
                    SplitMessage msg = new SplitMessage();
                    msg.Index    = m.Groups[1].Value;
                    msg.Status   = m.Groups[2].Value;
                    msg.Sender   = m.Groups[3].Value;
                    msg.Alphabet = m.Groups[4].Value;
                    msg.Sent     = m.Groups[5].Value;
                    msg.Message  = m.Groups[6].Value.Replace('\r', ' ');
                    if (msg.Message.EndsWith("OK"))
                    {
                        msg.Message = msg.Message.Remove(msg.Message.Length - 2, 2);
                    }
                    listMessages.Add(msg);

                    m = m.NextMatch();

                    Constants.ReadMsgsIndex.Enqueue(msg.Index);
                }
            }
            catch (Exception ex)
            {
                Logger.Logger.WriteLog(ex);
            }
            return(listMessages);
        }
Example #2
0
        private string SendSMS(string phoneno, string message)
        {
            string statusmsg = string.Empty;

            try
            {
                // phoneno = "8885212132";
                //  message = "select 17985";
                SplitMessage outmsg = new SplitMessage();


                if (BaseClass.SRPortComm.SendMessage(phoneno, message))
                {
                    statusmsg = "Completed";

                    int result = BaseClass._BAL.SaveSMSDetails((int)BaseClass.CRUDOperations.Insert, 0, BaseClass.MessageType.Request.ToString(),
                                                               BaseClass.SMSType.Related.ToString(), DateTime.Now.Date.ToString("dd/MM/yyyy"), DateTime.Now.ToString("HH:mm:ss"),
                                                               phoneno, message, statusmsg);

                    if (!string.IsNullOrEmpty(outmsg.Message))
                    {
                        BaseClass._BAL.SaveSMSDetails((int)BaseClass.CRUDOperations.Insert, 0, BaseClass.MessageType.Response.ToString(),
                                                      BaseClass.SMSType.Related.ToString(), DateTime.Now.Date.ToString("dd/MM/yyyy"), DateTime.Now.ToString("HH:mm:ss"),
                                                      phoneno, message, statusmsg);
                    }

                    // MessageBox.Show("Message has sent successfully");
                }
                else
                {
                    statusmsg = "Fail";
                    MessageBox.Show("Failed to send message");
                }
            }
            catch (Exception ex)
            {
                Logger.Logger.WriteLog(ex);
            }
            return(statusmsg);
        }