private async void TgSwitch_Toggled(object sender, RoutedEventArgs e) { tgSwitch.IsEnabled = false; if (tgSwitch.IsOn && (tetheringManager.TetheringOperationalState == TetheringOperationalState.Off)) { bool fNewConfig = false; ConfGui_Enable(false); NetworkOperatorTetheringAccessPointConfiguration apConfig = tetheringManager.GetCurrentAccessPointConfiguration(); if (txtSSID.Text != apConfig.Ssid) { apConfig.Ssid = txtSSID.Text; fNewConfig = true; } if (txtPass.Password != apConfig.Passphrase) { apConfig.Passphrase = txtPass.Password; fNewConfig = true; } if (fNewConfig) { await tetheringManager.ConfigureAccessPointAsync(apConfig); } var result = await tetheringManager.StartTetheringAsync(); if (result.Status != TetheringOperationStatus.Success) { // txtStatus.Text = "Can't start!"; } } else if (!tgSwitch.IsOn && (tetheringManager.TetheringOperationalState == TetheringOperationalState.On)) { var result = await tetheringManager.StopTetheringAsync(); if (result.Status == TetheringOperationStatus.Success) { SetupTethering(); } else { // txtStatus.Text = "Can't stop!"; } } }
/// <summary> /// update UI using latest tethering state /// </summary> private void UpdateUIWithTetheringState() { if (tetheringManager == null) { StartTetheringButton.IsEnabled = false; StopTetheringButton.IsEnabled = false; Apply.IsEnabled = false; } else { var newState = tetheringManager.TetheringOperationalState; Apply.IsEnabled = true; switch (newState) { case TetheringOperationalState.Unknown: StartTetheringButton.IsEnabled = false; StopTetheringButton.IsEnabled = false; break; case TetheringOperationalState.On: StartTetheringButton.IsEnabled = false; StopTetheringButton.IsEnabled = true; break; case TetheringOperationalState.Off: StartTetheringButton.IsEnabled = true; StopTetheringButton.IsEnabled = false; break; case TetheringOperationalState.InTransition: StartTetheringButton.IsEnabled = false; StopTetheringButton.IsEnabled = false; break; } if (newState == TetheringOperationalState.On) { // query the current number of clients var connectedClients = tetheringManager.ClientCount; rootPage.NotifyUser(connectedClients.ToString() + " of " + tetheringManager.MaxClientCount.ToString() + " are connected to your tethering network", NotifyType.StatusMessage); } NetworkOperatorTetheringAccessPointConfiguration current = tetheringManager.GetCurrentAccessPointConfiguration(); NetworkName.Text = current.Ssid; Password.Text = current.Passphrase; } }
/// <summary> /// Creates a new HotspotManager with the default connection profile. /// Returns null if no profile exists. /// </summary> public static async Task <HotspotManager> CreateAsync(string ssid, string passphrase) { var profile = await SelectBestProfile(); if (profile != null) { var config = new NetworkOperatorTetheringAccessPointConfiguration { Ssid = ssid, Passphrase = passphrase }; return(await CreateAsync(profile, config)); } return(null); }
/// <remarks> /// The required device capability has not been declared in the manifest. /// </remarks> private async void Connect_Click(object sender, RoutedEventArgs e) { var tetheringManager = GetCurrentTetheringManage(); string apSsid = txtSSID.Text; string apPass = txtPASS.Text; var accessPointConfig = new NetworkOperatorTetheringAccessPointConfiguration() { Ssid = apSsid, Passphrase = apPass }; await tetheringManager.ConfigureAccessPointAsync(accessPointConfig); await tetheringManager.StartTetheringAsync(); UpdateTetheringStatus(); }
private async void Apply_Click(object sender, RoutedEventArgs e) { try { // read the new configuration from the UI NetworkOperatorTetheringAccessPointConfiguration newConfiguration = new NetworkOperatorTetheringAccessPointConfiguration(); newConfiguration.Ssid = NetworkName.Text; newConfiguration.Passphrase = Password.Text; await tetheringManager.ConfigureAccessPointAsync(newConfiguration); rootPage.NotifyUser("Operation completed.", NotifyType.StatusMessage); } catch (Exception ex) { rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage); return; } }
private bool SetupTethering() { conProfile = NetworkInformation.GetInternetConnectionProfile(); if (conProfile.ProfileName == "WFD_GROUP_OWNER_PROFILE") { txtWAN.Text = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView().GetString("Default"); } else { txtWAN.Text = conProfile.ProfileName; } tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(conProfile); NetworkOperatorTetheringAccessPointConfiguration apConfig = tetheringManager.GetCurrentAccessPointConfiguration(); txtSSID.Text = apConfig.Ssid; txtPass.Password = apConfig.Passphrase; return(true); }
private MeasureBackgroundTask() { logModel.AppendLog(Log.CreateLog("Measure Service starting...", Log.LogType.System)); userSettings = new UserSettings(); var taskUser = Task.Run(async() => { userSettings = await userSettingsModel.GetUserSettingsAsync(); }); taskUser.Wait(); logModel.AppendLog(Log.CreateLog("UserSettings retreived", Log.LogType.System)); //Disable Diagnostic Mode on restart if (userSettings.isDiagnosticModeEnable) { userSettings.isDiagnosticModeEnable = false; var taskUserSync = Task.Run(async() => { await userSettingsModel.SyncUserSettings(userSettings); }); taskUserSync.Wait(); } var taskTethering = Task.Run(async() => { try { var connectedProfile = NetworkInformation.GetInternetConnectionProfile(); if (connectedProfile != null) { logModel.AppendLog(Log.CreateLog(String.Format("Connected Profile found - {0}", connectedProfile.ProfileName), Log.LogType.System)); } bool isWLANConnection = (connectedProfile == null) ? false : connectedProfile.IsWlanConnectionProfile; if (isWLANConnection == false) { logModel.AppendLog(Log.CreateLog("Device offline", Log.LogType.System)); ConnectionProfileFilter filter = new ConnectionProfileFilter(); filter.IsWlanConnectionProfile = true; var profile = await NetworkInformation.FindConnectionProfilesAsync(filter); var defaultProfile = profile.FirstOrDefault(); if (defaultProfile != null) { logModel.AppendLog(Log.CreateLog(String.Format("Default Profile found - {0}", defaultProfile.ProfileName), Log.LogType.System)); var networkOperatorTetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(defaultProfile); if (networkOperatorTetheringManager.TetheringOperationalState != TetheringOperationalState.On) { var config = new NetworkOperatorTetheringAccessPointConfiguration(); config.Ssid = userSettings.SSID; config.Passphrase = userSettings.ACCESS_POINT_PWD; logModel.AppendLog(Log.CreateLog("Access Point creation init...", Log.LogType.System)); await networkOperatorTetheringManager.ConfigureAccessPointAsync(config); var rslt = await networkOperatorTetheringManager.StartTetheringAsync(); await Task.Delay(5000); logModel.AppendLog(Log.CreateLog("Access Point creation ending...", Log.LogType.System)); if (rslt.Status == TetheringOperationStatus.Success) { logModel.AppendLog(Log.CreateLog("Access Point created", Log.LogType.System)); } else { logModel.AppendLog(Log.CreateLog(String.Format("Access Point creation failed - {0}", rslt.AdditionalErrorMessage), Log.LogType.Warning)); } } else { logModel.AppendLog(Log.CreateLog(String.Format("Access Point already on - {0}", networkOperatorTetheringManager.TetheringOperationalState.ToString()), Log.LogType.System)); } } else { logModel.AppendLog(Log.CreateLog("No default profile found", Log.LogType.System)); } } else { logModel.AppendLog(Log.CreateLog("No connection profile found", Log.LogType.System)); } } catch (Exception ex) { logModel.AppendLog(Log.CreateErrorLog("Error on Access Point init", ex)); } }); taskTethering.Wait(); bw.WorkerSupportsCancellation = true; bw.WorkerReportsProgress = true; bw.DoWork += Bw_DoWork; bw.RunWorkerCompleted += Bw_RunWorkerCompleted; bw.ProgressChanged += Bw_ProgressChanged; }
/// <summary> /// Creates a new HotspotManager with the given connection profile and configuration. /// </summary> public static async Task <HotspotManager> CreateAsync(ConnectionProfile profile, NetworkOperatorTetheringAccessPointConfiguration configuration) { var hotspot = new HotspotManager { tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(profile) }; await hotspot.tetheringManager.ConfigureAccessPointAsync(configuration); return(hotspot); }
private async void Apply_Click(object sender, RoutedEventArgs e) { try { // read the new configuration from the UI NetworkOperatorTetheringAccessPointConfiguration newConfiguration = new NetworkOperatorTetheringAccessPointConfiguration(); newConfiguration.Ssid = NetworkName.Text; newConfiguration.Passphrase = Password.Text; await tetheringManager.ConfigureAccessPointAsync(newConfiguration); rootPage.NotifyUser("Operation completed.", NotifyType.StatusMessage); } catch (Exception ex) { rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage); return; } }