public async Task< WiFiProfile> getWiFiProfileAsync(String token, String identifier) { Uri baseUri = new Uri("https://vmnac-int.fon.com/onboarding/windows/result/"); String add = "?token=" + token + "&identifier=" + identifier; Uri myUri = new Uri(baseUri, add); // Create a request for the URL. WebRequest request = WebRequest.Create(myUri); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; // Get the response. WebResponse response = await request.GetResponseAsync(); // Display the status. //Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. String responseFromServer = reader.ReadToEnd(); inner = JsonConvert.DeserializeObject<WiFiProfile>(responseFromServer); // Clean up the streams and the response. // reader // response.Close(); return inner; }
protected override async void OnActivated(IActivatedEventArgs args) { Messages parameters = new Messages(); Frame rootFrame = Window.Current.Content as Frame; WiFiAdapter firstAdapter; WiFiConnectionResult result1; ObservableCollection <WiFiNetworkDisplay> ResultCollection = new ObservableCollection <WiFiNetworkDisplay>(); // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(WiFiConfigPage)); } // Ensure the current window is active Window.Current.Activate(); if (args.Kind == ActivationKind.Protocol) { ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs; // Handle URI activation // The received URI is eventArgs.Uri.AbsoluteUri Uri myUri1 = new Uri(eventArgs.Uri.AbsoluteUri); WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(myUri1.Query); String token = decoder.GetFirstValueByName("token"); String identifier = decoder.GetFirstValueByName("identifier"); String Ssid; String password; int numVal = Int32.Parse(identifier); WiFiProfile z = new WiFiProfile(); try { z = await OnboardingService.getInstance().getWiFiProfileAsync(token, identifier); } catch { parameters.Clear(); parameters.Notification = "Cannot get network profile "; parameters.Result = "Net or system error!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); return; } Ssid = z.getUser_policies().getSsid(); parameters.Notification = "Start connecting to " + z.getUser_policies().getEap_type() + " network."; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(5)); WiFiConfiguration wc = z.getWifiConfiguration(); Window.Current.Activate(); await CertificateEnrollmentManager.UserCertificateEnrollmentManager.ImportPfxDataAsync( z.getUser_policies().getPublic_ca(), "", ExportOption.NotExportable, KeyProtectionLevel.NoConsent, InstallOptions.None, "Test"); var access = await WiFiAdapter.RequestAccessAsync(); if (access != WiFiAccessStatus.Allowed) { parameters.Clear(); parameters.Notification = "No WiFi Adapter. Or access is denied!"; parameters.Result = "System error!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); return; } else { switch (numVal) { case 2: { //////////////////////////////////////////////////////////////////// //EAP-TTLS var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()); if (result.Count >= 1) { firstAdapter = await WiFiAdapter.FromIdAsync(result[0].Id); await firstAdapter.ScanAsync(); var report = firstAdapter.NetworkReport; // var message = string.Format("Network Report Timestamp: { 0}", report.Timestamp); var message = "Find "; ResultCollection.Clear(); foreach (var network in report.AvailableNetworks) { //Format the network information message += string.Format("NetworkName: {0}\n ", network.Ssid); ResultCollection.Add(new WiFiNetworkDisplay(network, firstAdapter)); } var q = ResultCollection.Where(X => X.Ssid == "ALCATEL1").FirstOrDefault(); if (q == null) { parameters.Clear(); parameters.Notification = "Cannot find network with ssid: " + Ssid; parameters.Result = "Net error!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); return; } WiFiNetworkDisplay selectedNetwork = q; WiFiConnectionResult result0; WiFiReconnectionKind reconnectionKind = WiFiReconnectionKind.Manual; if (selectedNetwork.AvailableNetwork.SecuritySettings.NetworkAuthenticationType == Windows.Networking.Connectivity.NetworkAuthenticationType.Open80211) { result0 = await firstAdapter.ConnectAsync(selectedNetwork.AvailableNetwork, reconnectionKind); } else { var credential = new PasswordCredential(); String Password = z.getUser_policies().getPassword(); String Username = z.getUser_policies().getUsername(); credential.Password = "******"; // Password; credential.UserName = Username; parameters.Clear(); parameters.Notification = message; parameters.Result = string.Format("!!Connecting to {0} ", Ssid); rootFrame.Navigate(typeof(WiFiConfigPage), parameters); System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(5)); result0 = await firstAdapter.ConnectAsync(selectedNetwork.AvailableNetwork, reconnectionKind, credential); } if (result0.ConnectionStatus == WiFiConnectionStatus.Success) { parameters.Clear(); parameters.Notification = string.Format("Successfully connected to {0}.", selectedNetwork.Ssid); parameters.Result = "Success!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); // refresh the webpage // webViewGrid.Visibility = Visibility.Visible; // toggleBrowserButton.Content = "Hide Browser Control"; // refreshBrowserButton.Visibility = Visibility.Visible; } else { parameters.Clear(); parameters.Result = "Error!"; parameters.Notification = string.Format("Could not connect to {0}. Error: {1}", selectedNetwork.Ssid, result0.ConnectionStatus); rootFrame.Navigate(typeof(WiFiConfigPage), parameters); } } else { parameters.Clear(); parameters.Notification = "No WiFi Adapter. Or access is denied!"; parameters.Result = "System error!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); return; } break; } /////////////////////////// case 1: { parameters.Clear(); parameters.Notification = "Not implemented yet"; parameters.Result = "System warning!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); break; } case 3: { parameters.Clear(); parameters.Notification = "Not implemented yet"; parameters.Result = "System waninbg!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); break; } case 4: { //////////////////////////////////////////////////////////////////// //EAP-PEAP var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()); if (result.Count >= 1) { firstAdapter = await WiFiAdapter.FromIdAsync(result[0].Id); await firstAdapter.ScanAsync(); var report = firstAdapter.NetworkReport; // var message = string.Format("Network Report Timestamp: { 0}", report.Timestamp); var message = "Find "; ResultCollection.Clear(); foreach (var network in report.AvailableNetworks) { //Format the network information message += string.Format("NetworkName: {0}\n ", network.Ssid); ResultCollection.Add(new WiFiNetworkDisplay(network, firstAdapter)); } var q = ResultCollection.Where(X => X.Ssid == Ssid).FirstOrDefault(); if (q == null) { parameters.Clear(); parameters.Notification = "Cannot find network with ssid: " + Ssid; parameters.Result = "Net error!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); return; } WiFiNetworkDisplay selectedNetwork = q; WiFiConnectionResult result0; WiFiReconnectionKind reconnectionKind = WiFiReconnectionKind.Manual; if (selectedNetwork.AvailableNetwork.SecuritySettings.NetworkAuthenticationType == Windows.Networking.Connectivity.NetworkAuthenticationType.Open80211) { result0 = await firstAdapter.ConnectAsync(selectedNetwork.AvailableNetwork, reconnectionKind); } else { var credential = new PasswordCredential(); String Password = z.getUser_policies().getPassword(); String Username = z.getUser_policies().getUsername(); credential.Password = Password; credential.UserName = Username; parameters.Clear(); parameters.Notification = message; parameters.Result = string.Format("Connecting to {0} ", Ssid); rootFrame.Navigate(typeof(WiFiConfigPage), parameters); System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(5)); result0 = await firstAdapter.ConnectAsync(selectedNetwork.AvailableNetwork, reconnectionKind, credential); } if (result0.ConnectionStatus == WiFiConnectionStatus.Success) { parameters.Clear(); parameters.Notification = string.Format("Successfully connected to {0}.", selectedNetwork.Ssid); parameters.Result = "Success!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); // refresh the webpage // webViewGrid.Visibility = Visibility.Visible; // toggleBrowserButton.Content = "Hide Browser Control"; // refreshBrowserButton.Visibility = Visibility.Visible; } else { parameters.Clear(); parameters.Result = "Error!"; parameters.Notification = string.Format("Could not connect to {0}. Error: {1}", selectedNetwork.Ssid, result0.ConnectionStatus); rootFrame.Navigate(typeof(WiFiConfigPage), parameters); } } else { parameters.Clear(); parameters.Notification = "No WiFi Adapter. Or access is denied!"; parameters.Result = "System error!"; rootFrame.Navigate(typeof(WiFiConfigPage), parameters); return; } break; } /////////////////////////// default: { break; } }//switch end } } }
private OnboardingService() { inner = new WiFiProfile(); inner.setToken("test"); }