Пример #1
0
        private async void ConnectButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Lock down the UX
            ConnectButton.IsEnabled = false;

            ScanNetworks.IsEnabled = false;
            NetworkList.IsEnabled  = false;
            Psk.IsEnabled          = false;

            wifiConfigMessageProtocolClient.WifiAddNetworkStatusReceived += WifiConfigMessageProtocolClient_WifiAddNetworkStatusReceived;

            try
            {
                await wifiConfigMessageProtocolClient.AddWifiNetworkAsync(
                    service,
                    requestedNetwork.Ssid,
                    requestedNetwork.SecurityType,
                    requestedNetwork.SecurityType == SecurityType.WPA2?Psk.Password : null);
            }
            catch (Exception ex)
            {
                MessageDialog exceptionAlert = new MessageDialog(ex.Message, "Alert");
                exceptionAlert.Commands.Add(new UICommand("OK"));
                await exceptionAlert.ShowAsync();

                ConnectButton.IsEnabled = true;

                ScanNetworks.IsEnabled = true;
                NetworkList.IsEnabled  = true;
                Psk.IsEnabled          = true;
            }
        }
        private async void ConnectButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Lock down the UX
            ConnectButton.IsEnabled = false;

            ScanNetworks.IsEnabled = false;
            NetworkList.IsEnabled  = false;
            Psk.IsEnabled          = false;

            wifiConfigMessageProtocolClient.WifiAddNetworkStatusReceived += WifiConfigMessageProtocolClient_WifiAddNetworkStatusReceived;

            try
            {
                byte[]       ssidBytes    = System.Text.Encoding.UTF8.GetBytes(SsidTextBox.Text);
                SecurityType st           = (SecurityType)NTCombo.SelectedItem;
                string       psk          = (st == SecurityType.WPA2) ? Psk.Password : null;
                bool         targetedScan = TargetedScanToggleSwitch.IsOn;

                await wifiConfigMessageProtocolClient.AddWifiNetworkAsync(service, ssidBytes, st, psk, targetedScan);
            }
            catch (Exception ex)
            {
                MessageDialog exceptionAlert = new MessageDialog(ex.Message, "Alert");
                exceptionAlert.Commands.Add(new UICommand("OK"));
                await exceptionAlert.ShowAsync();

                ConnectButton.IsEnabled = true;

                ScanNetworks.IsEnabled = true;
                NetworkList.IsEnabled  = true;
                Psk.IsEnabled          = true;
            }
        }