public void DisconnectNetwork(WiFiListViewItemPresenter network) { network.Adapter.Disconnect(); }
public static bool IsNetworkOpen(WiFiListViewItemPresenter network) { return(network.AvailableNetwork.SecuritySettings.NetworkEncryptionType == NetworkEncryptionType.None); }
public async Task <bool> UpdateAvailableNetworksAsync(bool refreshIfNeeded) { App.LogService.Write($"refreshIfNeeded={refreshIfNeeded}"); try { await _availableNetworksLock.WaitAsync(); if ((await TestAccess()) == false) { return(false); } if (refreshIfNeeded && !IsRefreshNeeded()) { return(true); } LastRefresh = DateTime.Now; _enumAdaptersCompleted.WaitOne(); List <WiFiAdapter> WiFiAdaptersList = new List <WiFiAdapter>(_wiFiAdapters.Values); foreach (var adapter in WiFiAdaptersList) { if (adapter == null) { return(false); } try { await adapter.ScanAsync(); } catch (Exception) { // ScanAsync() can throw an exception if the scan timeouts. continue; } if (adapter.NetworkReport == null) { continue; } DateTime reportTime = DateTime.Now; foreach (var network in adapter.NetworkReport.AvailableNetworks) { if (!string.IsNullOrWhiteSpace(network.Ssid)) { if (_availableNetworks.ContainsKey(network.Ssid)) { _availableNetworks.TryRemove(network.Ssid, out WiFiListViewItemPresenter value); } var item = new WiFiListViewItemPresenter(network, adapter, reportTime); if (_availableNetworks.TryAdd(network.Ssid, item)) { await item.InitializeAsync(); App.LogService.Write($"Adding {network.Ssid}"); } } } // Remove some jitter from the list when refresh is repeatedly clicked // by remembering networks from the last 5 minutes DateTime expireTime = DateTime.Now - TimeSpan.FromMinutes(5); foreach (var key in _availableNetworks.Keys) { if (_availableNetworks[key].LastSeen < expireTime) { _availableNetworks.TryRemove(key, out WiFiListViewItemPresenter value); } } } return(true); } finally { _availableNetworksLock.Release(); } }