Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves access points and interfaces from the device and updates the view.
        /// </summary>
        private async Task DownloadAccessPointsAsync()
        {
            BusyStateManager.EnterBusy();
            BusyStateManager.SetMessage(SeverityType.Info, "Retrieving access points and interfaces.");

            /* Temporary store selected interface and access point so they can be restored after download. */
            Guid?  interfaceId = SelectedInterface?.Id;
            string profileName = SelectedAccessPoint?.ProfileName;
            string ssid        = SelectedAccessPoint?.Ssid;

            /* Scan and download access points and interfaces. */
            await _mainController.ScanNetworkAsync(TimeSpan.FromSeconds(_configurationProvider.Timeout),
                                                   CancellationToken.None);

            IEnumerable <AccessPoint> accessPoints = await _mainController.GetWiFiAccessPointsAsync();

            IEnumerable <Interface> interfaces = await _mainController.GetWiFiInterfacesAsync();

            if (accessPoints == default(IEnumerable <AccessPoint>) || interfaces == default(IEnumerable <Interface>))
            {
                AccessPoints = new ObservableCollection <AccessPoint>(Enumerable.Empty <AccessPoint>());
                WiFiAccessPointViewSource.Source = AccessPoints;
                Interfaces = new ObservableCollection <Interface>(Enumerable.Empty <Interface>());
            }
            else
            {
                /* User specified threshold is used to filter access points that meet this threshold. */
                AccessPoints = new ObservableCollection <AccessPoint>(accessPoints
                                                                      .Where(x => x.LinkQuality > _configurationProvider.Threshold));
                WiFiAccessPointViewSource.Source = AccessPoints;
                Interfaces = new ObservableCollection <Interface>(interfaces);
            }

            /* Restore selected interface and access point. */
            Interface   selectedInterface   = Interfaces.Where(x => x.Id == interfaceId).FirstOrDefault();
            AccessPoint selectedAccessPoint = default(AccessPoint);

            if (!string.IsNullOrEmpty(profileName))
            {
                selectedAccessPoint = AccessPoints.Where(x => x.Id == interfaceId &&
                                                         x.ProfileName == profileName).FirstOrDefault();
            }
            else if (!string.IsNullOrEmpty(ssid))
            {
                selectedAccessPoint = AccessPoints.Where(x => x.Id == interfaceId &&
                                                         x.Ssid.Equals(ssid, StringComparison.Ordinal)).FirstOrDefault();
            }

            SelectedInterface = selectedInterface == default(Interface) ?
                                Interfaces.FirstOrDefault() : selectedInterface;

            if (selectedAccessPoint != default(AccessPoint))
            {
                SelectedAccessPoint = selectedAccessPoint;
            }

            BusyStateManager.SetMessage(SeverityType.None);
            BusyStateManager.ExitBusy();
        }
Ejemplo n.º 2
0
 public void Update()
 {
     AccessPoints = AccessPoints.Where(
         ap => (ap.LastTime != null) && ((DateTime.Now - ap.LastTime) < TimeSpan.FromSeconds(MAX_AP_INVISIBLE_TIME_SEC))).ToList();
 }