Exemple #1
0
        /// <summary>
        /// Search for plugged-in USB modems.
        /// </summary>
        private void LookForDevices()
        {
            Task.Run(() =>
            {
                // If the app is connected to a modem, close the connetion
                // before refreshing the list.
                if (_modem.IsOpen)
                {
                    DisconnectRasConn();
                    CloseShop();
                }

                // Update status
                _view.UpdateToolStripStatus("Finding devices...");

                // Get connected and <available> modems.
                _modemList = Modem.GetModems();

                _view.ClearDeviceList();
                _view.AddDevicesToList(_modemList);

                // Select the modem that was used most recently
                var lastUsedModem = Settings.Default.LastUsedModem;

                if (_modemList.Count == 0)
                {
                    _view.UpdateToolStripStatus("Devices not found");
                    return;
                }

                // Update status
                _view.UpdateToolStripStatus($"{_view.NumberFoundDevices} devices found.");

                // Select the first modem in the list if none has been used previously.
                if (lastUsedModem.Equals(string.Empty))
                {
                    _view.SelectedModem = _modemList.First().Model;
                }
                else
                {
                    // Check if lastUsedModem is connected, if it is, use that
                    // if not, use the first one found on the list.
                    if (_modemList.Find(device => device.Model.Equals(lastUsedModem)) != null)
                    {
                        _view.SelectedModem = _modemList
                                              .FirstOrDefault(device => device.Model == lastUsedModem)
                                              ?.Model;
                    }
                    else
                    {
                        _view.SelectedModem = _modemList.First().Model;
                    }
                }

                // Connect to modem
                OpenShop();
            });
        }