private async Task ConnectToWiFiAsync(WiFiListViewItemPresenter network, PasswordCredential credential, CoreDispatcher dispatcher) { await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SwitchToItemState(network, WiFiConnectingState, false); }); Task <WiFiConnectionStatus> didConnect = null; if (network.IsEapAvailable) { didConnect = (credential == null) ? ConnectToNetwork(network, _automatic) : ConnectToNetworkWithPassword(network, _automatic, credential); } else { didConnect = (credential == null) ? ConnectToNetwork(network, network.ConnectAutomatically) : ConnectToNetworkWithPassword(network, network.ConnectAutomatically, credential); } WiFiConnectionStatus status = await didConnect; await OnConnected(network, status, dispatcher); }
public async Task <WiFiConnectionStatus> ConnectToNetwork(WiFiListViewItemPresenter network, bool autoConnect) { await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _availableNetworksLock.WaitAsync(); }); if (network == null) { return(WiFiConnectionStatus.UnspecifiedFailure); } try { var result = await network.Adapter.ConnectAsync(network.AvailableNetwork, autoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual); // Call redirect only for Open WiFi if (NetworkPresenter.IsNetworkOpen(network)) { // Navigate to http://www.msftconnecttest.com/redirect await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await DoRedirectDialogAsync(); }); } App.LogService.Write($"LEAVE {result.ConnectionStatus}"); return(result.ConnectionStatus); } catch (Exception) { return(WiFiConnectionStatus.UnspecifiedFailure); } }
private async Task OnConnected(WiFiListViewItemPresenter network, WiFiConnectionStatus status, CoreDispatcher dispatcher) { if (status == WiFiConnectionStatus.Success) { await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var itemLocation = WiFiListViewItems.IndexOf(network); // Don't move if index is -1 or 0 if (itemLocation > 0) { // Make sure first network doesn't also show connected SwitchToItemState(WiFiListViewItems[0], WiFiInitialState, true); // Show current connected network at top of list in connected state WiFiListViewItems.Move(itemLocation, 0); } network.Message = string.Empty; network.IsMessageVisible = false; var item = SwitchToItemState(network, WiFiConnectedState, true); if (item != null) { item.IsSelected = true; } }); if (!NetworkPresenter.IsNetworkOpen(network)) { NetworkConnected?.Invoke(this, new EventArgs()); } } else { // Entering the wrong password may cause connection attempts to timeout // Disconnecting the adapter will return it to a non-busy state if (status == WiFiConnectionStatus.Timeout) { network.Adapter.Disconnect(); } var resourceLoader = ResourceLoader.GetForCurrentView(); network.Message = Common.GetLocalizedText(status.ToString() + "Text"); network.IsMessageVisible = true; SwitchToItemState(network, WiFiConnectState, true); } }
public async Task <WiFiConnectionStatus> ConnectToNetworkWithPassword(WiFiListViewItemPresenter network, bool autoConnect, PasswordCredential password) { try { var result = await network.Adapter.ConnectAsync( network.AvailableNetwork, autoConnect?WiFiReconnectionKind.Automatic : WiFiReconnectionKind.Manual, password); App.LogService.Write($"LEAVE {result.ConnectionStatus}"); return(result.ConnectionStatus); } catch (Exception) { return(WiFiConnectionStatus.UnspecifiedFailure); } }