Exemplo n.º 1
0
        /// <summary>
        /// Enumerates wireless profile information in preference order.
        /// </summary>
        /// <returns>Wireless profile information</returns>
        public static IEnumerable <ProfilePack> EnumerateProfiles()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => ConvertToInterfaceInfo(x)))
                {
                    var interfaceIsConnected = (interfaceInfo.State == InterfaceState.Connected);

                    var availableNetworkList = Base.GetAvailableNetworkList(client.Handle, interfaceInfo.Id)
                                               .Where(x => !string.IsNullOrWhiteSpace(x.strProfileName))
                                               .ToArray();

                    var connection = Base.GetConnectionAttributes(client.Handle, interfaceInfo.Id);

                    var profileInfoList = Base.GetProfileInfoList(client.Handle, interfaceInfo.Id);

                    int position = 0;

                    foreach (var profileInfo in profileInfoList)
                    {
                        var availableNetwork = availableNetworkList.FirstOrDefault(x => x.strProfileName.Equals(profileInfo.strProfileName, StringComparison.Ordinal));
                        var signalQuality    = (int)availableNetwork.wlanSignalQuality;

                        var profileIsConnected = interfaceIsConnected && profileInfo.strProfileName.Equals(connection.strProfileName, StringComparison.Ordinal);

                        //Debug.WriteLine("Interface: {0}, Profile: {1}, Signal {2}, Position: {3}, Connected {4}",
                        //	interfaceInfo.Description,
                        //	profileInfo.strProfileName,
                        //	signalQuality,
                        //	position,
                        //	profileIsConnected);

                        var profile = GetProfile(
                            client.Handle,
                            interfaceInfo,
                            profileInfo.strProfileName,
                            signalQuality,
                            position++,
                            profileIsConnected);

                        if (profile != null)
                        {
                            yield return(profile);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enumerates wireless profile names in preference order.
        /// </summary>
        /// <returns>Wireless profile names</returns>
        public static IEnumerable <string> EnumerateProfileNames()
        {
            using (var client = new Base.WlanClient())
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var profileInfoList = Base.GetProfileInfoList(client.Handle, interfaceInfo.InterfaceGuid);

                    foreach (var profileInfo in profileInfoList)
                    {
                        //Debug.WriteLine("Interface: {0}, Profile: {1}",
                        //	interfaceInfo.strInterfaceDescription,
                        //	profileInfo.strProfileName);

                        yield return(profileInfo.strProfileName);
                    }
                }
            }
        }