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; } }
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 void Init() { var connectionProfiles = NetworkInformation.GetConnectionProfiles(); ConnectionProfile ethernetConnectionProfile = null; foreach (var item in NetworkInformation.GetHostNames()) { string name = item.DisplayName; string name2 = item.CanonicalName; if (connectionProfiles.Where(x => x.NetworkAdapter?.NetworkAdapterId == item.IPInformation?.NetworkAdapter?.NetworkAdapterId).FirstOrDefault() != null) { ethernetConnectionProfile = connectionProfiles.Where(x => x.NetworkAdapter?.NetworkAdapterId == item.IPInformation?.NetworkAdapter?.NetworkAdapterId).First(); } } _tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(ethernetConnectionProfile); var config = _tetheringManager.GetCurrentAccessPointConfiguration(); _setting.Name = config.Ssid; _setting.Password = config.Passphrase; }
private async Task <bool> StartNetworkOperatorTetheringManager(WlanSetting setting) { var Config = _tetheringManager.GetCurrentAccessPointConfiguration(); _setting = setting; Config.Ssid = setting.Name; Config.Passphrase = setting.Password; await _tetheringManager.ConfigureAccessPointAsync(Config); var result = await _tetheringManager.StartTetheringAsync(); if (result.Status == TetheringOperationStatus.Success) { return(true); } else { return(false); } }