/// <summary> /// Check for existing wifi profile in the cache. If a WiFi profile exits, automatically connects /// to that WiFi AP. /// </summary> private async Task CheckWifiSetting() { try { var vault = new Windows.Security.Credentials.PasswordVault(); var credentialList = vault.RetrieveAll(); if (credentialList?.Count > 0) { Log("Connecting to stored Wifi Profile..."); var credential = credentialList[0]; await m_wiFiManager.Initialize(); credential.RetrievePassword(); WiFiConnectionStatus status = await m_wiFiManager.Connect(credential.UserName, credential.Password); if (status == WiFiConnectionStatus.Success) { Log("Connected to AP " + credential.UserName + "."); return; } Log("Failed to connected to AP " + credential.UserName + "."); } m_chatServer.StartListening(); m_bluetoothManager.StartWatcher(); } catch (Exception e) { Log("CheckWifiSetting::[ERROR]" + e.Message); } return; }
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); }
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); } var item = SwitchToItemState(network, WifiConnectedState, true); if (item != null) { item.IsSelected = true; } }); NetworkConnected?.Invoke(this, new EventArgs()); } else { var resourceLoader = ResourceLoader.GetForCurrentView(); network.Message = resourceLoader.GetString(status.ToString() + "Text"); network.IsMessageVisible = true; SwitchToItemState(network, WifiConnectState, true); } }
private async void OnChatServerMessageReceived(object sender, RFCommServer.MessageReceivedEventArgs e) { string[] parsedMsg = e.Message.Split(separator, StringSplitOptions.RemoveEmptyEntries); if ("CONNECT" == parsedMsg[0]) { string key = (parsedMsg.Length > 2) ? parsedMsg[2] : String.Empty; WiFiConnectionStatus status = await m_wiFiManager.Connect(parsedMsg[1], key); switch (status) { case (WiFiConnectionStatus.Success): m_chatServer.SendMessage("Successfully connected to " + parsedMsg[1] + "."); m_chatServer.SendMessage("Disconnecting the RFComm Session"); SetWifiProfile(parsedMsg[1], key); OnChatServerWiFiConnected(); break; case (WiFiConnectionStatus.InvalidCredential): m_chatServer.SendMessage(string.Format("Failed to connected to {0}: Invalid Credential", parsedMsg[1])); break; case (WiFiConnectionStatus.Timeout): m_chatServer.SendMessage(string.Format("Failed to connected to {0}: Timeout", parsedMsg[1])); break; case (WiFiConnectionStatus.NetworkNotAvailable): m_chatServer.SendMessage(string.Format("Failed to connected to {0}: Network Not Available", parsedMsg[1])); SendNetworkList(); break; case (WiFiConnectionStatus.AccessRevoked): m_chatServer.SendMessage(string.Format("Failed to connected to {0}: Access Revoked", parsedMsg[1])); break; case (WiFiConnectionStatus.UnsupportedAuthenticationProtocol): m_chatServer.SendMessage(string.Format("Failed to connected to {0}: Unsupported Authentication Protocol", parsedMsg[1])); break; default: m_chatServer.SendMessage(string.Format("Failed to connected to {0}: Unspecified Failure", parsedMsg[1])); break; } } else if ("REFRESH" == parsedMsg[0]) { SendNetworkList(); } }
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 static WifiErrorCode Convert(this WiFiConnectionStatus connectionStatus) { switch (connectionStatus) { case WiFiConnectionStatus.UnspecifiedFailure: return(WifiErrorCode.Unknown); case WiFiConnectionStatus.Success: return(WifiErrorCode.Success); case WiFiConnectionStatus.AccessRevoked: return(WifiErrorCode.AccessRevoked); case WiFiConnectionStatus.InvalidCredential: return(WifiErrorCode.InvalidCredentials); case WiFiConnectionStatus.NetworkNotAvailable: return(WifiErrorCode.NetworkNotAvailable); case WiFiConnectionStatus.Timeout: return(WifiErrorCode.Timeout); case WiFiConnectionStatus.UnsupportedAuthenticationProtocol: return(WifiErrorCode.UnsupportedAuthenticationProtocol); default: return(WifiErrorCode.Unknown); } }
internal WiFiConnectionResult(WiFiConnectionStatus ConnectionStatus) { _ConnectionStatus = ConnectionStatus; }