コード例 #1
0
        /// <summary>
        /// Provides call on the phone and return the status of call
        /// </summary>
        /// <param name="phoneItem">Mobile phone item</param>
        /// <param name="guiEvent">Event which will be passed to GUI</param>
        /// <returns>True if number is activated and notification is sent if it is enabled</returns>
        private bool ProcessCall(XmlTelephoneItem phoneItem, ReadPortEvent guiEvent)
        {
            bool retVal = false;

            guiEvent.Code = _dialUp(phoneItem.Telephone, guiEvent);

            if (DoubleCheckOnTimeout && guiEvent.Code == ResponseCode.TIMEOUT)
            {
                guiEvent.Code = _hangUp();
                if (guiEvent.Code == ResponseCode.OK)
                {
                    Thread.Sleep(WaitCall * 1000);

                    // The second attempt to find out the activation in case line of operator is not stable
                    guiEvent.Code = _dialUp(phoneItem.Telephone, guiEvent);
                }
                else if (guiEvent.Code == ResponseCode.TIMEOUT)
                {
                    // in case modem is not responding on hang up
                    return(true);
                }
            }

            if (guiEvent.Code == ResponseCode.CONNECT || guiEvent.Code == ResponseCode.RING ||
                guiEvent.Code == ResponseCode.BUSY || guiEvent.Code == ResponseCode.NO_ANSWER ||
                guiEvent.Code == ResponseCode.TIMEOUT)
            {
                if (_hangUp() == ResponseCode.OK)
                {
                    retVal = true;
                    if (SendNotification)
                    {
                        Thread.Sleep(WaitCall * 1000);

                        retVal = ProcessNotification(phoneItem.Telephone, guiEvent);
                    }
                }
                else if (guiEvent.Code == ResponseCode.TIMEOUT)
                {
                    // in case modem is not responding on hang up
                    return(false);
                }
            }
            else
            {
                // don't hang up phone on ERROR, BLACKLISTED, NO_ANSWER_MODEM, NO_ANSWER, NO_CARRIER, etc.
                return(false);
            }
            return(retVal);
        }
コード例 #2
0
        public static void AddTelephone(this ListView listView, XmlTelephoneItem item)
        {
            var aItem     = new ListViewItem(item.Telephone, item.DateActivated != String.Empty ? 0 : -1);
            var aDateItem = new ListViewItem.ListViewSubItem(aItem, item.Date);

            aItem.SubItems.Add(aDateItem);
            var aDateActivatedItem = new ListViewItem.ListViewSubItem(aItem, item.DateActivated);

            aItem.SubItems.Add(aDateActivatedItem);
            var aCommentItem = new ListViewItem.ListViewSubItem(aItem, item.Comment);

            aItem.SubItems.Add(aCommentItem);

            listView.Items.Add(aItem);
        }
コード例 #3
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;

            Thread.CurrentThread.CurrentCulture   = _culture;
            Thread.CurrentThread.CurrentUICulture = _culture;

            Initialization();

            // Call only those phone items which are in some named group from settings.
            foreach (var phoneItem in _listTelephones.Where(x => _groupSettings.Any(g => g.GroupName == x.GroupName)))
            {
                if (!worker.CancellationPending)
                {
                    ValidateIntroductoryVersion();

                    _currentPhoneItem = phoneItem;

                    var guiEvent = new ReadPortEvent {
                        Telephone = _currentPhoneItem.Telephone
                    };
                    switch (Operation)
                    {
                    case PortReaderOperation.Call:
                        if (!_currentPhoneItem.IsActivated())
                        {
                            if (ProcessCall(_currentPhoneItem, guiEvent))
                            {
                                guiEvent.Activated = true;
                                OnTelephoneReadReady(guiEvent);
                                Thread.Sleep(WaitCall * 1000);
                            }
                            else
                            {
                                OnTelephoneReadReady(guiEvent);

                                if (guiEvent.Code == ResponseCode.NO_ANSWER_MODEM || guiEvent.Code == ResponseCode.BLACKLISTED)
                                {
                                    Logger.Write(ResourceManagerProvider.GetLocalizedString("MSG_MODEM_PORT_RESET", Application.CurrentCulture));
                                    // pause in 1 minute
                                    Thread.Sleep(60000);

                                    ClosePort();
                                    OpenPort();
                                    Initialize3GModem();
                                }
                                else
                                {
                                    Thread.Sleep(WaitCall * 1000);
                                }
                            }
                        }
                        break;

                    case PortReaderOperation.Notification:
                        ProcessNotification(_currentPhoneItem.Telephone, guiEvent);
                        OnNotificationReadReady(guiEvent);
                        Thread.Sleep(WaitCall * 1000);
                        break;
                    }
                }
                else
                {
                    e.Cancel = true;
                    break;
                }
            }
        }