Exemplo n.º 1
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            try
            {
                try
                {
                    openPort();
                }
                catch (Exception ex)
                {
                    //not handling
                }

                do
                {
                    foreach (var smsQueue in m_SmsNos)
                    {
                        try
                        {
                            Thread.Sleep(500);

                            if (sendMsg(smsQueue, worker, e))
                            {
                                //MessageBox.Show("Message has sent successfully", "Successfully Sent", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                            else
                            {
                                //MessageBox.Show("Failed to send message", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    m_SmsNos = miscDAL.GetSMSQueue();
                    Thread.Sleep(1000);
                }while (true);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                throw ex;
            }
            finally
            {
                closePort();
            }
        }
Exemplo n.º 2
0
        public SMSEngine(string conString)
        {
            ConnectionString.con_string = conString;
            miscDAL = new DAL.MiscDAL();

            try
            {
                m_SmsNos = miscDAL.GetSMSQueue();
                StartSMSEngine();
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                throw ex;
            }
        }
Exemplo n.º 3
0
        public SMSEngine()
        {
            miscDAL             = new DAL.MiscDAL();
            Modems              = new List <Modem>();
            ApplicationLogsList = new ObservableCollection <ApplicationLog>();
            //Enable the cross acces to this collection elsewhere
            BindingOperations.EnableCollectionSynchronization(ApplicationLogsList, _syncLock);

            message = "Starting SMS Engine";
            AddLog(EventLevel.Information.ToString(), DateTime.Now, EventSource.Initilization.ToString(), message);

            try
            {
                ConLocal     = miscDAL.OpenLocalDatabaseConnection();
                ConLocalSync = miscDAL.OpenLocalDatabaseConnection();
                m_SmsNos     = miscDAL.GetSMSQueue(ConLocal);
                StartDataTimer();
                StartSMSEngine();
                try
                {
                    OpenOnlineConnectionAsync();
                    //ConOnline = miscDAL.OpenOnlineDatabaseConnection();
                    //m_IsOnlineConnectionOpen = true;
                }
                catch (Exception ex)
                {
                    m_IsOnlineConnectionOpen = false;
                    message = "Online Server Exception: " + ex.Message;
                    AddLog(EventLevel.Information.ToString(), DateTime.Now, EventSource.Initilization.ToString(), message);
                    //MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                message = "Exception: " + ex.Message;
                AddLog(EventLevel.Information.ToString(), DateTime.Now, EventSource.Initilization.ToString(), message);
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                try
                {
                    AddNewModems();
                }
                catch (Exception ex)
                {
                    message = "Background worker started, ADD Modems Count= " + Modems.Count + " Exception: " + ex.Message;
                    AddLog(EventLevel.Error.ToString(), DateTime.Now, EventSource.bw_DoWork.ToString(), message);
                }
                m_TryCount = 0;
                BackgroundWorker worker = sender as BackgroundWorker;
                do
                {
                    Modem SelectedComm;
                    if (Modems.Count > 0)
                    {
                        m_TryCount = 0;
                        message    = "Background worker started, Modems Count= " + Modems.Count;
                        AddLog(EventLevel.Information.ToString(), DateTime.Now, EventSource.bw_DoWork.ToString(), message);

                        //deep copy for selected Comm
                        SelectedComm = new Modem()
                        {
                            GsmCommMain  = Modems[0].GsmCommMain,
                            IsFree       = Modems[0].IsFree,
                            StartTime    = Modems[0].StartTime,
                            TotalSmsSent = Modems[0].TotalSmsSent,
                        };

                        AddLog(EventLevel.Information.ToString(), DateTime.Now, EventSource.bw_DoWork.ToString(), "Selected Modem:" + SelectedComm.GsmCommMain.PortName);
                        try
                        {
                            do
                            {
                                foreach (var smsQueue in m_SmsNos)
                                {
                                    Thread.Sleep(500);
                                    if (SelectedComm != null && Modems.Count > 0)
                                    {
                                        SendMessage(smsQueue, SelectedComm, worker, e);
                                    }
                                    Thread.Sleep(500);
                                    //deep copy for selected item
                                    try
                                    {
                                        Modem _selectedModem = SelectModem(SelectedComm).Result;
                                        if (_selectedModem != null)
                                        {
                                            SelectedComm = new Modem()
                                            {
                                                GsmCommMain  = _selectedModem.GsmCommMain,
                                                IsFree       = _selectedModem.IsFree,
                                                StartTime    = _selectedModem.StartTime,
                                                TotalSmsSent = _selectedModem.TotalSmsSent,
                                            };
                                        }
                                        m_SmsNos = miscDAL.GetSMSQueue(ConLocal);
                                    }
                                    catch (Exception ex)
                                    {
                                        SelectedComm = null;
                                        message      = "Selected Modem = Null ";
                                        AddLog(EventLevel.Information.ToString(), DateTime.Now, EventSource.bw_DoWork.ToString(), message);
                                    }
                                }
                                m_SmsNos = miscDAL.GetSMSQueue(ConLocal);
                                message  = "Queue Count=" + m_SmsNos.Count;
                                AddLog(EventLevel.Information.ToString(), DateTime.Now, EventSource.bw_DoWork.ToString(), message);
                                Thread.Sleep(1000);
                            }while (true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        finally
                        {
                            //StopSMSEnging();
                        }
                    }
                    else
                    {
                        m_TryCount++;
                        AddNewModems();
                        message = " Modems Count= " + Modems.Count;
                        AddLog(EventLevel.Warning.ToString(), DateTime.Now, EventSource.bw_DoWork.ToString(), message);
                        Thread.Sleep(2000);
                        if (m_TryCount > 10)
                        {
                            CloseWindow();
                        }
                    }
                }while (Modems.Count == 0);
            }
            catch (Exception ex)
            {
                message = "Backgound Worker Exception: " + ex.Message;
                AddLog(EventLevel.Error.ToString(), DateTime.Now, EventSource.bw_DoWork.ToString(), message);
            }
        }