Exemplo n.º 1
0
        /// <summary>
        /// Click handler for the getWifiInfo button.
        /// </summary>
        /// <param name="sender">The caller of this method.</param>
        /// <param name="e">The arguments associated with this event.</param>
        private void GetWifiInfo_Click(object sender, RoutedEventArgs e)
        {
            this.ClearOutput();
            this.EnableConnectionControls(false);
            this.EnableDeviceControls(false);

            StringBuilder sb      = new StringBuilder();
            Task          getTask = new Task(
                async() =>
            {
                sb.Append(this.MarshalGetCommandOutput());
                sb.AppendLine("Getting WiFi interfaces and networks...");
                this.MarshalUpdateCommandOutput(sb.ToString());

                try
                {
                    WifiInterfaces wifiInterfaces = await portal.GetWifiInterfaces();
                    sb.AppendLine("WiFi Interfaces:");
                    foreach (WifiInterface wifiInterface in wifiInterfaces.Interfaces)
                    {
                        sb.Append(" ");
                        sb.AppendLine(wifiInterface.Description);
                        sb.Append("  GUID: ");
                        sb.AppendLine(wifiInterface.Guid.ToString());

                        WifiNetworks wifiNetworks = await portal.GetWifiNetworks(wifiInterface.Guid);
                        sb.AppendLine("  Networks:");
                        foreach (WifiNetworkInfo network in wifiNetworks.AvailableNetworks)
                        {
                            sb.Append("   SSID: ");
                            sb.AppendLine(network.Ssid);
                            sb.Append("   Profile name: ");
                            sb.AppendLine(network.ProfileName);
                            sb.Append("   is connected: ");
                            sb.AppendLine(network.IsConnected.ToString());
                            sb.Append("   Channel: ");
                            sb.AppendLine(network.Channel.ToString());
                            sb.Append("   Authentication algorithm: ");
                            sb.AppendLine(network.AuthenticationAlgorithm);
                            sb.Append("   Signal quality: ");
                            sb.AppendLine(network.SignalQuality.ToString());
                        }
                    }
                    ;
                }
                catch (Exception ex)
                {
                    sb.AppendLine("Failed to get WiFi info.");
                    sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
                }
            });

            Task continuationTask = getTask.ContinueWith(
                (t) =>
            {
                this.MarshalUpdateCommandOutput(sb.ToString());
                this.MarshalEnableDeviceControls(true);
                this.MarshalEnableConnectionControls(true);
            });

            getTask.Start();
        }