Пример #1
0
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            lock (_commPortLock)
            {
                var communications = new GsmCommMain(_communicationsPort, _baudRate, _timeout);
                communications.Open();
                communications.DeleteMessages(DeleteScope.All, _storage);
                communications.Close();
            }

            while (!_backgroundWorker.CancellationPending)
            {
                DecodedShortMessage[] messages = null;
                lock (_commPortLock)
                {
                    var communications = new GsmCommMain(_communicationsPort, _baudRate, _timeout);
                    communications.Open();
                    messages = communications.ReadMessages(PhoneMessageStatus.ReceivedUnread, _storage);
                    communications.Close();
                }
                foreach (var message in messages)
                {
                    _backgroundWorker.ReportProgress(0, message);
                }
                Thread.Sleep(1000);
            }
        }
Пример #2
0
        private void DeleteAllMessages()
        {
            string storage = GetMessageStorage();

            try
            {
                // Delete all messages from phone memory
                comm.DeleteMessages(DeleteScope.All, "SM");
                comm.DeleteMessages(DeleteScope.All, "ME");
                //MessageBox.Show("All Messages Deleted from SIM");
            }
            catch (Exception ex)
            {
                ex.ToString();
                ReceiveUpdatesError();
            }
        }
Пример #3
0
        //
        // Summary:
        //     Delete message directly from connected modem
        //
        // Parameters:
        //   scope:
        //     Scope Delete (all/by index)
        //
        //   storage:
        //     Message storage (SIM / Phone).
        public Boolean DeleteSMS(DeleteScope scope, string storage)
        {
            bool result = false;

            try
            {
                comm.DeleteMessages(scope, storage);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(result);
        }
Пример #4
0
        private void GetAllMessagesFromAllStorage()
        {
            try
            {
                if (Gsm.IsConnected() && Gsm.IsOpen())
                {
                    DecodedShortMessage[] SimMessages = Gsm.ReadMessages(PhoneMessageStatus.All, GetMessageStorage(MessageLocation.Sim));
                    Gsm.DeleteMessages(DeleteScope.All, GetMessageStorage(MessageLocation.Sim));

                    foreach (DecodedShortMessage message in SimMessages)
                    {
                        SmsPdu pdu = (SmsPdu)message.Data;

                        if (pdu is SmsDeliverPdu)
                        {
                            // Received message
                            SmsDeliverPdu data = (SmsDeliverPdu)pdu;

                            string   sim_msg          = data.UserDataText;
                            DateTime sim_receive_date = data.SCTimestamp.ToDateTime();
                            string   sim_num          = data.OriginatingAddress;

                            //BSOB.SMS sms = new BSOB.SMS();
                            //sms.MESSAGE = sim_msg;
                            //sms.PHONENO = sim_num;
                            //sms.RECEIVEDDATE = sim_receive_date;
                            //Order(sms);

                            bsob.SMSQueuing(sim_msg, sim_num, sim_receive_date);
                            //insert statement here
                        }
                    }

                    DecodedShortMessage[] PhoneMessages = Gsm.ReadMessages(PhoneMessageStatus.All, GetMessageStorage(MessageLocation.Phone));
                    Gsm.DeleteMessages(DeleteScope.All, GetMessageStorage(MessageLocation.Phone));


                    foreach (DecodedShortMessage message in PhoneMessages)
                    {
                        SmsPdu pdu = (SmsPdu)message.Data;

                        if (pdu is SmsDeliverPdu)
                        {
                            // Received message
                            SmsDeliverPdu data = (SmsDeliverPdu)pdu;

                            string   phone_msg           = data.UserDataText;
                            DateTime phone_received_date = data.SCTimestamp.ToDateTime();
                            string   phone_num           = data.OriginatingAddress;

                            //BSOB.SMS sms = new BSOB.SMS();
                            //sms.MESSAGE = phone_msg;
                            //sms.PHONENO = phone_num;
                            //sms.RECEIVEDDATE = phone_received_date;
                            //Order(sms);

                            bsob.SMSQueuing(phone_msg, phone_num, phone_received_date);
                            //insert statement here
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError("GetAllMessagesFromAllStorage " + ex.Source + " " + ex.Message);

                if (Gsm.IsConnected() && Gsm.IsOpen())
                {
                    Gsm.Close();
                }
            }
        }
 private void DeleteMessages()
 {
     commMain.DeleteMessages(DeleteScope.All, PhoneStorageType.Sim);
 }
Пример #6
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Prompt user for connection settings
            string portName = "COM12";
            int    baudRate = GsmCommMain.DefaultBaudRate;
            int    timeout  = GsmCommMain.DefaultTimeout;

            frmConnection dlg = new frmConnection();

            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.SetData(portName, baudRate, timeout);
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                dlg.GetData(out portName, out baudRate, out timeout);
            }
            else
            {
                Close();
                return;
            }

            Cursor.Current          = Cursors.WaitCursor;
            comm                    = new GsmCommMain(portName, baudRate, timeout);
            Cursor.Current          = Cursors.Default;
            comm.PhoneConnected    += new EventHandler(comm_PhoneConnected);
            comm.PhoneDisconnected += new EventHandler(comm_PhoneDisconnected);
            comm.MessageReceived   += new MessageReceivedEventHandler(comm_MessageReceived);

            bool retry;

            do
            {
                retry = false;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    comm.Open();
                    Cursor.Current = Cursors.Default;
                    Output("Соединение", portName);

                    try
                    {
                        comm.DeleteMessages(DeleteScope.All, PhoneStorageType.Sim);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(this, "Не вставлена сим-карта. Вставьте сим-карту и запустите программу снова.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Close();
                        return;
                    }
                }
                catch (Exception)
                {
                    Cursor.Current = Cursors.Default;

                    if (MessageBox.Show(this, "Не получаеться открыть порт", "Ошибка",
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
                    {
                        retry = true;
                    }
                    else
                    {
                        Close();
                        return;
                    }
                }
            }while (retry);
            comm.EnableMessageNotifications();
        }
Пример #7
0
 private void button3_Click(object sender, EventArgs e)
 {
     comm.DeleteMessages(DeleteScope.All, PhoneStorageType.Sim);
 }