浏览代码

添加managedwifi代码,可连接到指定wifi,可判断是否已连接wifi

yuzhengyang 6 年之前
父节点
当前提交
84a852f106

+ 4 - 0
Azylee.Utils/Azylee.Core/Azylee.Core.csproj

@@ -116,6 +116,7 @@
     <Compile Include="LogUtils\SimpleLogUtils\LogType.cs" />
     <Compile Include="LogUtils\StatusLogUtils\StatusLogModel.cs" />
     <Compile Include="LogUtils\StatusLogUtils\StatusLog.cs" />
+    <Compile Include="ModelUtils\ResultModels\ResultData.cs" />
     <Compile Include="NetUtils\IPFormatter.cs" />
     <Compile Include="NetUtils\MacFormatter.cs" />
     <Compile Include="NetUtils\NetConnectionInfo.cs" />
@@ -126,6 +127,9 @@
     <Compile Include="NetUtils\NetProcessTool.cs" />
     <Compile Include="NetUtils\NetworkAdapterTool.cs" />
     <Compile Include="NetUtils\PingTool.cs" />
+    <Compile Include="NetUtils\WifiManUtils\Wlan.cs" />
+    <Compile Include="NetUtils\WifiManUtils\WlanClient.cs" />
+    <Compile Include="NetUtils\WifiManUtils\WlanTool.cs" />
     <Compile Include="ProcessUtils\ProcessInfoTool.cs" />
     <Compile Include="ProcessUtils\ProcessStarter.cs" />
     <Compile Include="ProcessUtils\ProcessTool.cs" />

+ 57 - 0
Azylee.Utils/Azylee.Core/ModelUtils/ResultModels/ResultData.cs

@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.Core.ModelUtils.ResultModels
+{
+    /// <summary>
+    /// 用于方法执行返回结果
+    /// </summary>
+    public class ResultData
+    {
+        /// <summary>
+        /// 状态
+        /// </summary>
+        public int Status { get; set; }
+        /// <summary>
+        /// 成功与否
+        /// </summary>
+        public bool IsSuccess { get; set; }
+        /// <summary>
+        /// 描述
+        /// </summary>
+        public string Description { get; set; }
+
+        /// <summary>
+        /// 默认构造函数
+        /// </summary>
+        public ResultData()
+        {
+
+        }
+        /// <summary>
+        /// 自定义构造函数
+        /// </summary>
+        /// <param name="isSucc"></param>
+        /// <param name="desc"></param>
+        public ResultData(bool isSucc, string desc)
+        {
+            IsSuccess = isSucc;
+            Description = desc;
+        }
+        /// <summary>
+        /// 初始化(默认为异常结果)
+        /// </summary>
+        /// <returns></returns>
+        public static ResultData InitForError()
+        {
+            return new ResultData()
+            {
+                IsSuccess = false,
+                Status = -1,
+                Description = "未知异常"
+            };
+        }
+    }
+}

文件差异内容过多而无法显示
+ 1670 - 0
Azylee.Utils/Azylee.Core/NetUtils/WifiManUtils/Wlan.cs


+ 847 - 0
Azylee.Utils/Azylee.Core/NetUtils/WifiManUtils/WlanClient.cs

@@ -0,0 +1,847 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Net.NetworkInformation;
+using System.Threading;
+using System.Text;
+
+namespace Azylee.Core.NetUtils.WifiManUtils
+{
+    /// <summary>
+    /// Represents a client to the Zeroconf (Native Wifi) service.
+    /// </summary>
+    /// <remarks>
+    /// This class is the entrypoint to Native Wifi management. To manage WiFi settings, create an instance
+    /// of this class.
+    /// </remarks>
+    public class WlanClient : IDisposable
+    {
+        /// <summary>
+        /// Represents a Wifi network interface.
+        /// </summary>
+        public class WlanInterface
+        {
+            private readonly WlanClient client;
+            private Wlan.WlanInterfaceInfo info;
+
+            #region Events
+            /// <summary>
+            /// Represents a method that will handle <see cref="WlanNotification"/> events.
+            /// </summary>
+            /// <param name="notifyData">The notification data.</param>
+            public delegate void WlanNotificationEventHandler(Wlan.WlanNotificationData notifyData);
+
+            /// <summary>
+            /// Represents a method that will handle <see cref="WlanConnectionNotification"/> events.
+            /// </summary>
+            /// <param name="notifyData">The notification data.</param>
+            /// <param name="connNotifyData">The notification data.</param>
+            public delegate void WlanConnectionNotificationEventHandler(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData);
+
+            /// <summary>
+            /// Represents a method that will handle <see cref="WlanReasonNotification"/> events.
+            /// </summary>
+            /// <param name="notifyData">The notification data.</param>
+            /// <param name="reasonCode">The reason code.</param>
+            public delegate void WlanReasonNotificationEventHandler(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode);
+
+            /// <summary>
+            /// Occurs when an event of any kind occurs on a WLAN interface.
+            /// </summary>
+            public event WlanNotificationEventHandler WlanNotification;
+
+            /// <summary>
+            /// Occurs when a WLAN interface changes connection state.
+            /// </summary>
+            public event WlanConnectionNotificationEventHandler WlanConnectionNotification;
+
+            /// <summary>
+            /// Occurs when a WLAN operation fails due to some reason.
+            /// </summary>
+            public event WlanReasonNotificationEventHandler WlanReasonNotification;
+
+            #endregion
+
+            #region Event queue
+            private bool queueEvents;
+            private readonly AutoResetEvent eventQueueFilled = new AutoResetEvent(false);
+            private readonly Queue<object> eventQueue = new Queue<object>();
+
+            private struct WlanConnectionNotificationEventData
+            {
+                public Wlan.WlanNotificationData notifyData;
+                public Wlan.WlanConnectionNotificationData connNotifyData;
+            }
+            private struct WlanReasonNotificationData
+            {
+                public Wlan.WlanNotificationData notifyData;
+                public Wlan.WlanReasonCode reasonCode;
+            }
+            #endregion
+
+            internal WlanInterface(WlanClient client, Wlan.WlanInterfaceInfo info)
+            {
+                this.client = client;
+                this.info = info;
+            }
+
+            /// <summary>
+            /// Sets a parameter of the interface whose data type is <see cref="int"/>.
+            /// </summary>
+            /// <param name="opCode">The opcode of the parameter.</param>
+            /// <param name="value">The value to set.</param>
+            private void SetInterfaceInt(Wlan.WlanIntfOpcode opCode, int value)
+            {
+                IntPtr valuePtr = Marshal.AllocHGlobal(sizeof(int));
+                Marshal.WriteInt32(valuePtr, value);
+                try
+                {
+                    Wlan.ThrowIfError(
+                        Wlan.WlanSetInterface(client.clientHandle, info.interfaceGuid, opCode, sizeof(int), valuePtr, IntPtr.Zero));
+                }
+                finally
+                {
+                    Marshal.FreeHGlobal(valuePtr);
+                }
+            }
+
+            /// <summary>
+            /// Gets a parameter of the interface whose data type is <see cref="int"/>.
+            /// </summary>
+            /// <param name="opCode">The opcode of the parameter.</param>
+            /// <returns>The integer value.</returns>
+            private int GetInterfaceInt(Wlan.WlanIntfOpcode opCode)
+            {
+                IntPtr valuePtr;
+                int valueSize;
+                Wlan.WlanOpcodeValueType opcodeValueType;
+                Wlan.ThrowIfError(
+                    Wlan.WlanQueryInterface(client.clientHandle, info.interfaceGuid, opCode, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType));
+                try
+                {
+                    return Marshal.ReadInt32(valuePtr);
+                }
+                finally
+                {
+                    Wlan.WlanFreeMemory(valuePtr);
+                }
+            }
+
+            /// <summary>
+            /// Gets or sets a value indicating whether this <see cref="WlanInterface"/> is automatically configured.
+            /// </summary>
+            /// <value><c>true</c> if "autoconf" is enabled; otherwise, <c>false</c>.</value>
+            public bool Autoconf
+            {
+                get
+                {
+                    return GetInterfaceInt(Wlan.WlanIntfOpcode.AutoconfEnabled) != 0;
+                }
+                set
+                {
+                    SetInterfaceInt(Wlan.WlanIntfOpcode.AutoconfEnabled, value ? 1 : 0);
+                }
+            }
+
+            /// <summary>
+            /// Gets or sets the BSS type for the indicated interface.
+            /// </summary>
+            /// <value>The type of the BSS.</value>
+            public Wlan.Dot11BssType BssType
+            {
+                get
+                {
+                    return (Wlan.Dot11BssType)GetInterfaceInt(Wlan.WlanIntfOpcode.BssType);
+                }
+                set
+                {
+                    SetInterfaceInt(Wlan.WlanIntfOpcode.BssType, (int)value);
+                }
+            }
+
+            /// <summary>
+            /// Gets the state of the interface.
+            /// </summary>
+            /// <value>The state of the interface.</value>
+            public Wlan.WlanInterfaceState InterfaceState
+            {
+                get
+                {
+                    return (Wlan.WlanInterfaceState)GetInterfaceInt(Wlan.WlanIntfOpcode.InterfaceState);
+                }
+            }
+
+            /// <summary>
+            /// Gets the channel.
+            /// </summary>
+            /// <value>The channel.</value>
+            /// <remarks>Not supported on Windows XP SP2.</remarks>
+            public int Channel
+            {
+                get
+                {
+                    return GetInterfaceInt(Wlan.WlanIntfOpcode.ChannelNumber);
+                }
+            }
+
+            /// <summary>
+            /// Gets the RSSI.
+            /// </summary>
+            /// <value>The RSSI.</value>
+            /// <remarks>Not supported on Windows XP SP2.</remarks>
+            public int RSSI
+            {
+                get
+                {
+                    return GetInterfaceInt(Wlan.WlanIntfOpcode.RSSI);
+                }
+            }
+
+            /// <summary>
+            /// Gets the radio state.
+            /// </summary>
+            /// <value>The radio state.</value>
+            /// <remarks>Not supported on Windows XP.</remarks>
+            public Wlan.WlanRadioState RadioState
+            {
+                get
+                {
+                    int valueSize;
+                    IntPtr valuePtr;
+                    Wlan.WlanOpcodeValueType opcodeValueType;
+                    Wlan.ThrowIfError(
+                        Wlan.WlanQueryInterface(client.clientHandle, info.interfaceGuid, Wlan.WlanIntfOpcode.RadioState, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType));
+                    try
+                    {
+                        return (Wlan.WlanRadioState)Marshal.PtrToStructure(valuePtr, typeof(Wlan.WlanRadioState));
+                    }
+                    finally
+                    {
+                        Wlan.WlanFreeMemory(valuePtr);
+                    }
+                }
+            }
+
+            /// <summary>
+            /// Gets the current operation mode.
+            /// </summary>
+            /// <value>The current operation mode.</value>
+            /// <remarks>Not supported on Windows XP SP2.</remarks>
+            public Wlan.Dot11OperationMode CurrentOperationMode
+            {
+                get
+                {
+                    return (Wlan.Dot11OperationMode)GetInterfaceInt(Wlan.WlanIntfOpcode.CurrentOperationMode);
+                }
+            }
+
+            /// <summary>
+            /// Gets the attributes of the current connection.
+            /// </summary>
+            /// <value>The current connection attributes.</value>
+            /// <exception cref="Win32Exception">An exception with code 0x0000139F (The group or resource is not in the correct state to perform the requested operation.) will be thrown if the interface is not connected to a network.</exception>
+            public Wlan.WlanConnectionAttributes CurrentConnection
+            {
+                get
+                {
+                    int valueSize;
+                    IntPtr valuePtr;
+                    Wlan.WlanOpcodeValueType opcodeValueType;
+                    Wlan.ThrowIfError(
+                        Wlan.WlanQueryInterface(client.clientHandle, info.interfaceGuid, Wlan.WlanIntfOpcode.CurrentConnection, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType));
+                    try
+                    {
+                        return (Wlan.WlanConnectionAttributes)Marshal.PtrToStructure(valuePtr, typeof(Wlan.WlanConnectionAttributes));
+                    }
+                    finally
+                    {
+                        Wlan.WlanFreeMemory(valuePtr);
+                    }
+                }
+            }
+
+            /// <summary>
+            /// Requests a scan for available networks.
+            /// </summary>
+            /// <remarks>
+            /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event.
+            /// </remarks>
+            public void Scan()
+            {
+                Wlan.ThrowIfError(
+                    Wlan.WlanScan(client.clientHandle, info.interfaceGuid, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
+            }
+
+            /// <summary>
+            /// Converts a pointer to a available networks list (header + entries) to an array of available network entries.
+            /// </summary>
+            /// <param name="availNetListPtr">A pointer to an available networks list's header.</param>
+            /// <returns>An array of available network entries.</returns>
+            private static Wlan.WlanAvailableNetwork[] ConvertAvailableNetworkListPtr(IntPtr availNetListPtr)
+            {
+                Wlan.WlanAvailableNetworkListHeader availNetListHeader = (Wlan.WlanAvailableNetworkListHeader)Marshal.PtrToStructure(availNetListPtr, typeof(Wlan.WlanAvailableNetworkListHeader));
+                long availNetListIt = availNetListPtr.ToInt64() + Marshal.SizeOf(typeof(Wlan.WlanAvailableNetworkListHeader));
+                Wlan.WlanAvailableNetwork[] availNets = new Wlan.WlanAvailableNetwork[availNetListHeader.numberOfItems];
+                for (int i = 0; i < availNetListHeader.numberOfItems; ++i)
+                {
+                    availNets[i] = (Wlan.WlanAvailableNetwork)Marshal.PtrToStructure(new IntPtr(availNetListIt), typeof(Wlan.WlanAvailableNetwork));
+                    availNets[i].profileName = WlanTool.GetStringForSSID(availNets[i].dot11Ssid);
+                    availNetListIt += Marshal.SizeOf(typeof(Wlan.WlanAvailableNetwork));
+                }
+                return availNets;
+            }
+
+            /// <summary>
+            /// Retrieves the list of available networks.
+            /// </summary>
+            /// <param name="flags">Controls the type of networks returned.</param>
+            /// <returns>A list of the available networks.</returns>
+            public Wlan.WlanAvailableNetwork[] GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags flags)
+            {
+                IntPtr availNetListPtr;
+                Wlan.ThrowIfError(
+                    Wlan.WlanGetAvailableNetworkList(client.clientHandle, info.interfaceGuid, flags, IntPtr.Zero, out availNetListPtr));
+                try
+                {
+                    return ConvertAvailableNetworkListPtr(availNetListPtr);
+                }
+                finally
+                {
+                    Wlan.WlanFreeMemory(availNetListPtr);
+                }
+            }
+
+            /// <summary>
+            /// Converts a pointer to a BSS list (header + entries) to an array of BSS entries.
+            /// </summary>
+            /// <param name="bssListPtr">A pointer to a BSS list's header.</param>
+            /// <returns>An array of BSS entries.</returns>
+            private static Wlan.WlanBssEntry[] ConvertBssListPtr(IntPtr bssListPtr)
+            {
+                Wlan.WlanBssListHeader bssListHeader = (Wlan.WlanBssListHeader)Marshal.PtrToStructure(bssListPtr, typeof(Wlan.WlanBssListHeader));
+                long bssListIt = bssListPtr.ToInt64() + Marshal.SizeOf(typeof(Wlan.WlanBssListHeader));
+                Wlan.WlanBssEntry[] bssEntries = new Wlan.WlanBssEntry[bssListHeader.numberOfItems];
+                for (int i = 0; i < bssListHeader.numberOfItems; ++i)
+                {
+                    bssEntries[i] = (Wlan.WlanBssEntry)Marshal.PtrToStructure(new IntPtr(bssListIt), typeof(Wlan.WlanBssEntry));
+                    bssListIt += Marshal.SizeOf(typeof(Wlan.WlanBssEntry));
+                }
+                return bssEntries;
+            }
+
+            /// <summary>
+            /// Retrieves the basic service sets (BSS) list of all available networks.
+            /// </summary>
+            public Wlan.WlanBssEntry[] GetNetworkBssList()
+            {
+                IntPtr bssListPtr;
+                Wlan.ThrowIfError(
+                    Wlan.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, IntPtr.Zero, Wlan.Dot11BssType.Any, false, IntPtr.Zero, out bssListPtr));
+                try
+                {
+                    return ConvertBssListPtr(bssListPtr);
+                }
+                finally
+                {
+                    Wlan.WlanFreeMemory(bssListPtr);
+                }
+            }
+
+            /// <summary>
+            /// Retrieves the basic service sets (BSS) list of the specified network.
+            /// </summary>
+            /// <param name="ssid">Specifies the SSID of the network from which the BSS list is requested.</param>
+            /// <param name="bssType">Indicates the BSS type of the network.</param>
+            /// <param name="securityEnabled">Indicates whether security is enabled on the network.</param>
+            public Wlan.WlanBssEntry[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType, bool securityEnabled)
+            {
+                IntPtr ssidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));
+                Marshal.StructureToPtr(ssid, ssidPtr, false);
+                try
+                {
+                    IntPtr bssListPtr;
+                    Wlan.ThrowIfError(
+                        Wlan.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, ssidPtr, bssType, securityEnabled, IntPtr.Zero, out bssListPtr));
+                    try
+                    {
+                        return ConvertBssListPtr(bssListPtr);
+                    }
+                    finally
+                    {
+                        Wlan.WlanFreeMemory(bssListPtr);
+                    }
+                }
+                finally
+                {
+                    Marshal.FreeHGlobal(ssidPtr);
+                }
+            }
+
+            /// <summary>
+            /// Connects to a network defined by a connection parameters structure.
+            /// </summary>
+            /// <param name="connectionParams">The connection paramters.</param>
+            protected void Connect(Wlan.WlanConnectionParameters connectionParams)
+            {
+                Wlan.ThrowIfError(
+                    Wlan.WlanConnect(client.clientHandle, info.interfaceGuid, ref connectionParams, IntPtr.Zero));
+            }
+
+            /// <summary>
+            /// Requests a connection (association) to the specified wireless network.
+            /// </summary>
+            /// <remarks>
+            /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event.
+            /// </remarks>
+            public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile)
+            {
+                Wlan.WlanConnectionParameters connectionParams = new Wlan.WlanConnectionParameters();
+                connectionParams.wlanConnectionMode = connectionMode;
+                connectionParams.profile = profile;
+                connectionParams.dot11BssType = bssType;
+                connectionParams.flags = 0;
+                Connect(connectionParams);
+            }
+
+            /// <summary>
+            /// Connects (associates) to the specified wireless network, returning either on a success to connect
+            /// or a failure.
+            /// </summary>
+            /// <param name="connectionMode"></param>
+            /// <param name="bssType"></param>
+            /// <param name="profile"></param>
+            /// <param name="connectTimeout"></param>
+            /// <returns></returns>
+            public bool ConnectSynchronously(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile, int connectTimeout)
+            {
+                queueEvents = true;
+                try
+                {
+                    Connect(connectionMode, bssType, profile);
+                    while (queueEvents && eventQueueFilled.WaitOne(connectTimeout, true))
+                    {
+                        lock (eventQueue)
+                        {
+                            while (eventQueue.Count != 0)
+                            {
+                                object e = eventQueue.Dequeue();
+                                if (e is WlanConnectionNotificationEventData)
+                                {
+                                    WlanConnectionNotificationEventData wlanConnectionData = (WlanConnectionNotificationEventData)e;
+                                    // Check if the conditions are good to indicate either success or failure.
+                                    if (wlanConnectionData.notifyData.notificationSource == Wlan.WlanNotificationSource.ACM)
+                                    {
+                                        switch ((Wlan.WlanNotificationCodeAcm)wlanConnectionData.notifyData.notificationCode)
+                                        {
+                                            case Wlan.WlanNotificationCodeAcm.ConnectionComplete:
+                                                if (wlanConnectionData.connNotifyData.profileName == profile)
+                                                    return true;
+                                                break;
+                                        }
+                                    }
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+                finally
+                {
+                    queueEvents = false;
+                    eventQueue.Clear();
+                }
+                return false; // timeout expired and no "connection complete"
+            }
+
+            /// <summary>
+            /// Connects to the specified wireless network.
+            /// </summary>
+            /// <remarks>
+            /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event.
+            /// </remarks>
+            public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid, Wlan.WlanConnectionFlags flags)
+            {
+                Wlan.WlanConnectionParameters connectionParams = new Wlan.WlanConnectionParameters();
+                connectionParams.wlanConnectionMode = connectionMode;
+                connectionParams.dot11SsidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));
+                Marshal.StructureToPtr(ssid, connectionParams.dot11SsidPtr, false);
+                connectionParams.dot11BssType = bssType;
+                connectionParams.flags = flags;
+                Connect(connectionParams);
+                Marshal.DestroyStructure(connectionParams.dot11SsidPtr, ssid.GetType());
+                Marshal.FreeHGlobal(connectionParams.dot11SsidPtr);
+            }
+
+            /// <summary>
+            /// Deletes a profile.
+            /// </summary>
+            /// <param name="profileName">
+            /// The name of the profile to be deleted. Profile names are case-sensitive.
+            /// On Windows XP SP2, the supplied name must match the profile name derived automatically from the SSID of the network. For an infrastructure network profile, the SSID must be supplied for the profile name. For an ad hoc network profile, the supplied name must be the SSID of the ad hoc network followed by <c>-adhoc</c>.
+            /// </param>
+            public void DeleteProfile(string profileName)
+            {
+                Wlan.ThrowIfError(
+                    Wlan.WlanDeleteProfile(client.clientHandle, info.interfaceGuid, profileName, IntPtr.Zero));
+            }
+
+            /// <summary>
+            /// Sets the profile.
+            /// </summary>
+            /// <param name="flags">The flags to set on the profile.</param>
+            /// <param name="profileXml">The XML representation of the profile. On Windows XP SP 2, special care should be taken to adhere to its limitations.</param>
+            /// <param name="overwrite">If a profile by the given name already exists, then specifies whether to overwrite it (if <c>true</c>) or return an error (if <c>false</c>).</param>
+            /// <returns>The resulting code indicating a success or the reason why the profile wasn't valid.</returns>
+            public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite)
+            {
+                Wlan.WlanReasonCode reasonCode;
+                Wlan.ThrowIfError(
+                        Wlan.WlanSetProfile(client.clientHandle, info.interfaceGuid, flags, profileXml, null, overwrite, IntPtr.Zero, out reasonCode));
+                return reasonCode;
+            }
+
+            /// <summary>
+            /// Gets the profile's XML specification.
+            /// </summary>
+            /// <param name="profileName">The name of the profile.</param>
+            /// <returns>The XML document.</returns>
+            public string GetProfileXml(string profileName)
+            {
+                IntPtr profileXmlPtr;
+                Wlan.WlanProfileFlags flags;
+                Wlan.WlanAccess access;
+                Wlan.ThrowIfError(
+                    Wlan.WlanGetProfile(client.clientHandle, info.interfaceGuid, profileName, IntPtr.Zero, out profileXmlPtr, out flags,
+                                   out access));
+                try
+                {
+                    return Marshal.PtrToStringUni(profileXmlPtr);
+                }
+                finally
+                {
+                    Wlan.WlanFreeMemory(profileXmlPtr);
+                }
+            }
+
+            /// <summary>
+            /// Gets the information of all profiles on this interface.
+            /// </summary>
+            /// <returns>The profiles information.</returns>
+            public Wlan.WlanProfileInfo[] GetProfiles()
+            {
+                IntPtr profileListPtr;
+                Wlan.ThrowIfError(
+                    Wlan.WlanGetProfileList(client.clientHandle, info.interfaceGuid, IntPtr.Zero, out profileListPtr));
+                try
+                {
+                    Wlan.WlanProfileInfoListHeader header = (Wlan.WlanProfileInfoListHeader)Marshal.PtrToStructure(profileListPtr, typeof(Wlan.WlanProfileInfoListHeader));
+                    Wlan.WlanProfileInfo[] profileInfos = new Wlan.WlanProfileInfo[header.numberOfItems];
+                    long profileListIterator = profileListPtr.ToInt64() + Marshal.SizeOf(header);
+                    for (int i = 0; i < header.numberOfItems; ++i)
+                    {
+                        Wlan.WlanProfileInfo profileInfo = (Wlan.WlanProfileInfo)Marshal.PtrToStructure(new IntPtr(profileListIterator), typeof(Wlan.WlanProfileInfo));
+                        profileInfos[i] = profileInfo;
+                        profileListIterator += Marshal.SizeOf(profileInfo);
+                    }
+                    return profileInfos;
+                }
+                finally
+                {
+                    Wlan.WlanFreeMemory(profileListPtr);
+                }
+            }
+
+            internal void OnWlanConnection(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData)
+            {
+                if (WlanConnectionNotification != null)
+                    WlanConnectionNotification(notifyData, connNotifyData);
+
+                if (queueEvents)
+                {
+                    WlanConnectionNotificationEventData queuedEvent = new WlanConnectionNotificationEventData();
+                    queuedEvent.notifyData = notifyData;
+                    queuedEvent.connNotifyData = connNotifyData;
+                    EnqueueEvent(queuedEvent);
+                }
+            }
+
+            internal void OnWlanReason(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode)
+            {
+                if (WlanReasonNotification != null)
+                    WlanReasonNotification(notifyData, reasonCode);
+                if (queueEvents)
+                {
+                    WlanReasonNotificationData queuedEvent = new WlanReasonNotificationData();
+                    queuedEvent.notifyData = notifyData;
+                    queuedEvent.reasonCode = reasonCode;
+                    EnqueueEvent(queuedEvent);
+                }
+            }
+
+            internal void OnWlanNotification(Wlan.WlanNotificationData notifyData)
+            {
+                if (WlanNotification != null)
+                    WlanNotification(notifyData);
+            }
+
+            /// <summary>
+            /// Enqueues a notification event to be processed serially.
+            /// </summary>
+            private void EnqueueEvent(object queuedEvent)
+            {
+                lock (eventQueue)
+                    eventQueue.Enqueue(queuedEvent);
+                eventQueueFilled.Set();
+            }
+
+            /// <summary>
+            /// Gets the network interface of this wireless interface.
+            /// </summary>
+            /// <remarks>
+            /// The network interface allows querying of generic network properties such as the interface's IP address.
+            /// </remarks>
+            public NetworkInterface NetworkInterface
+            {
+                get
+                {
+                    // Do not cache the NetworkInterface; We need it fresh
+                    // each time cause otherwise it caches the IP information.
+                    foreach (NetworkInterface netIface in NetworkInterface.GetAllNetworkInterfaces())
+                    {
+                        Guid netIfaceGuid = new Guid(netIface.Id);
+                        if (netIfaceGuid.Equals(info.interfaceGuid))
+                        {
+                            return netIface;
+                        }
+                    }
+                    return null;
+                }
+            }
+
+            /// <summary>
+            /// The GUID of the interface (same content as the <see cref="System.Net.NetworkInformation.NetworkInterface.Id"/> value).
+            /// </summary>
+            public Guid InterfaceGuid
+            {
+                get { return info.interfaceGuid; }
+            }
+
+            /// <summary>
+            /// The description of the interface.
+            /// This is a user-immutable string containing the vendor and model name of the adapter.
+            /// </summary>
+            public string InterfaceDescription
+            {
+                get { return info.interfaceDescription; }
+            }
+
+            /// <summary>
+            /// The friendly name given to the interface by the user (e.g. "Local Area Network Connection").
+            /// </summary>
+            public string InterfaceName
+            {
+                get { return NetworkInterface.Name; }
+            }
+        }
+
+        private IntPtr clientHandle;
+        private uint negotiatedVersion;
+        private readonly Wlan.WlanNotificationCallbackDelegate wlanNotificationCallback;
+        private readonly Dictionary<Guid, WlanInterface> ifaces = new Dictionary<Guid, WlanInterface>();
+
+        /// <summary>
+        /// Creates a new instance of a Native Wifi service client.
+        /// </summary>
+        public WlanClient()
+        {
+            Wlan.ThrowIfError(
+                Wlan.WlanOpenHandle(Wlan.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle));
+            try
+            {
+                Wlan.WlanNotificationSource prevSrc;
+                wlanNotificationCallback = OnWlanNotification;
+                Wlan.ThrowIfError(
+                    Wlan.WlanRegisterNotification(clientHandle, Wlan.WlanNotificationSource.All, false, wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevSrc));
+            }
+            catch
+            {
+                Close();
+                throw;
+            }
+        }
+
+        void IDisposable.Dispose()
+        {
+            GC.SuppressFinalize(this);
+            Close();
+        }
+
+        ~WlanClient()
+        {
+            Close();
+        }
+
+        /// <summary>
+        /// Closes the handle.
+        /// </summary>
+        private void Close()
+        {
+            if (clientHandle != IntPtr.Zero)
+            {
+                Wlan.WlanCloseHandle(clientHandle, IntPtr.Zero);
+                clientHandle = IntPtr.Zero;
+            }
+        }
+
+        private static Wlan.WlanConnectionNotificationData? ParseWlanConnectionNotification(ref Wlan.WlanNotificationData notifyData)
+        {
+            int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanConnectionNotificationData));
+            if (notifyData.dataSize < expectedSize)
+                return null;
+
+            Wlan.WlanConnectionNotificationData connNotifyData =
+                (Wlan.WlanConnectionNotificationData)
+                Marshal.PtrToStructure(notifyData.dataPtr, typeof(Wlan.WlanConnectionNotificationData));
+            if (connNotifyData.wlanReasonCode == Wlan.WlanReasonCode.Success)
+            {
+                IntPtr profileXmlPtr = new IntPtr(
+                    notifyData.dataPtr.ToInt64() +
+                    Marshal.OffsetOf(typeof(Wlan.WlanConnectionNotificationData), "profileXml").ToInt64());
+                connNotifyData.profileXml = Marshal.PtrToStringUni(profileXmlPtr);
+            }
+
+            return connNotifyData;
+        }
+
+        private void OnWlanNotification(ref Wlan.WlanNotificationData notifyData, IntPtr context)
+        {
+            WlanInterface wlanIface;
+            ifaces.TryGetValue(notifyData.interfaceGuid, out wlanIface);
+
+            switch (notifyData.notificationSource)
+            {
+                case Wlan.WlanNotificationSource.ACM:
+                    switch ((Wlan.WlanNotificationCodeAcm)notifyData.notificationCode)
+                    {
+                        case Wlan.WlanNotificationCodeAcm.ConnectionStart:
+                        case Wlan.WlanNotificationCodeAcm.ConnectionComplete:
+                        case Wlan.WlanNotificationCodeAcm.ConnectionAttemptFail:
+                        case Wlan.WlanNotificationCodeAcm.Disconnecting:
+                        case Wlan.WlanNotificationCodeAcm.Disconnected:
+                            Wlan.WlanConnectionNotificationData? connNotifyData = ParseWlanConnectionNotification(ref notifyData);
+                            if (connNotifyData.HasValue)
+                                if (wlanIface != null)
+                                    wlanIface.OnWlanConnection(notifyData, connNotifyData.Value);
+                            break;
+                        case Wlan.WlanNotificationCodeAcm.ScanFail:
+                            {
+                                int expectedSize = Marshal.SizeOf(typeof(int));
+                                if (notifyData.dataSize >= expectedSize)
+                                {
+                                    Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr);
+                                    if (wlanIface != null)
+                                        wlanIface.OnWlanReason(notifyData, reasonCode);
+                                }
+                            }
+                            break;
+                    }
+                    break;
+                case Wlan.WlanNotificationSource.MSM:
+                    switch ((Wlan.WlanNotificationCodeMsm)notifyData.notificationCode)
+                    {
+                        case Wlan.WlanNotificationCodeMsm.Associating:
+                        case Wlan.WlanNotificationCodeMsm.Associated:
+                        case Wlan.WlanNotificationCodeMsm.Authenticating:
+                        case Wlan.WlanNotificationCodeMsm.Connected:
+                        case Wlan.WlanNotificationCodeMsm.RoamingStart:
+                        case Wlan.WlanNotificationCodeMsm.RoamingEnd:
+                        case Wlan.WlanNotificationCodeMsm.Disassociating:
+                        case Wlan.WlanNotificationCodeMsm.Disconnected:
+                        case Wlan.WlanNotificationCodeMsm.PeerJoin:
+                        case Wlan.WlanNotificationCodeMsm.PeerLeave:
+                        case Wlan.WlanNotificationCodeMsm.AdapterRemoval:
+                            Wlan.WlanConnectionNotificationData? connNotifyData = ParseWlanConnectionNotification(ref notifyData);
+                            if (connNotifyData.HasValue)
+                                if (wlanIface != null)
+                                    wlanIface.OnWlanConnection(notifyData, connNotifyData.Value);
+                            break;
+                    }
+                    break;
+            }
+
+            if (wlanIface != null)
+                wlanIface.OnWlanNotification(notifyData);
+        }
+
+        /// <summary>
+        /// Gets the WLAN interfaces.
+        /// </summary>
+        /// <value>The WLAN interfaces.</value>
+        public WlanInterface[] Interfaces
+        {
+            get
+            {
+                IntPtr ifaceList;
+                Wlan.ThrowIfError(
+                    Wlan.WlanEnumInterfaces(clientHandle, IntPtr.Zero, out ifaceList));
+                try
+                {
+                    Wlan.WlanInterfaceInfoListHeader header =
+                        (Wlan.WlanInterfaceInfoListHeader)Marshal.PtrToStructure(ifaceList, typeof(Wlan.WlanInterfaceInfoListHeader));
+                    Int64 listIterator = ifaceList.ToInt64() + Marshal.SizeOf(header);
+                    WlanInterface[] interfaces = new WlanInterface[header.numberOfItems];
+                    List<Guid> currentIfaceGuids = new List<Guid>();
+                    for (int i = 0; i < header.numberOfItems; ++i)
+                    {
+                        Wlan.WlanInterfaceInfo info =
+                            (Wlan.WlanInterfaceInfo)Marshal.PtrToStructure(new IntPtr(listIterator), typeof(Wlan.WlanInterfaceInfo));
+                        listIterator += Marshal.SizeOf(info);
+                        currentIfaceGuids.Add(info.interfaceGuid);
+
+                        WlanInterface wlanIface;
+                        if (!ifaces.TryGetValue(info.interfaceGuid, out wlanIface))
+                        {
+                            wlanIface = new WlanInterface(this, info);
+                            ifaces[info.interfaceGuid] = wlanIface;
+                        }
+
+                        interfaces[i] = wlanIface;
+                    }
+
+                    // Remove stale interfaces
+                    Queue<Guid> deadIfacesGuids = new Queue<Guid>();
+                    foreach (Guid ifaceGuid in ifaces.Keys)
+                    {
+                        if (!currentIfaceGuids.Contains(ifaceGuid))
+                            deadIfacesGuids.Enqueue(ifaceGuid);
+                    }
+                    while (deadIfacesGuids.Count != 0)
+                    {
+                        Guid deadIfaceGuid = deadIfacesGuids.Dequeue();
+                        ifaces.Remove(deadIfaceGuid);
+                    }
+
+                    return interfaces;
+                }
+                finally
+                {
+                    Wlan.WlanFreeMemory(ifaceList);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Gets a string that describes a specified reason code.
+        /// </summary>
+        /// <param name="reasonCode">The reason code.</param>
+        /// <returns>The string.</returns>
+        public string GetStringForReasonCode(Wlan.WlanReasonCode reasonCode)
+        {
+            StringBuilder sb = new StringBuilder(1024); // the 1024 size here is arbitrary; the WlanReasonCodeToString docs fail to specify a recommended size
+            Wlan.ThrowIfError(
+                Wlan.WlanReasonCodeToString(reasonCode, sb.Capacity, sb, IntPtr.Zero));
+            return sb.ToString();
+        }
+    }
+}

文件差异内容过多而无法显示
+ 303 - 0
Azylee.Utils/Azylee.Core/NetUtils/WifiManUtils/WlanTool.cs


+ 7 - 0
Azylee.Utils/Azylee.Utils.sln

@@ -43,6 +43,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exts", "Exts", "{618CFF8A-0
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azylee.Ext.NetworkX", "Azylee.Ext.NetworkX\Azylee.Ext.NetworkX.csproj", "{A320E11D-D771-4BBD-913F-DD0E87090943}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.WifiManTest", "Tests\Test.WifiManTest\Test.WifiManTest.csproj", "{A5702F35-A589-4F03-9468-72BD4A6B57A9}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -117,6 +119,10 @@ Global
 		{A320E11D-D771-4BBD-913F-DD0E87090943}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{A320E11D-D771-4BBD-913F-DD0E87090943}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{A320E11D-D771-4BBD-913F-DD0E87090943}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A5702F35-A589-4F03-9468-72BD4A6B57A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A5702F35-A589-4F03-9468-72BD4A6B57A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A5702F35-A589-4F03-9468-72BD4A6B57A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A5702F35-A589-4F03-9468-72BD4A6B57A9}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -138,6 +144,7 @@ Global
 		{37995B05-DB66-499F-B861-FB5451172E58} = {9351FC10-E8D0-41BB-A813-0B5B3EA90605}
 		{0497D55F-332B-40CC-A8C6-8D3AF98FEBAD} = {9351FC10-E8D0-41BB-A813-0B5B3EA90605}
 		{A320E11D-D771-4BBD-913F-DD0E87090943} = {618CFF8A-0137-4E15-BC07-4E172B7FC5DA}
+		{A5702F35-A589-4F03-9468-72BD4A6B57A9} = {9351FC10-E8D0-41BB-A813-0B5B3EA90605}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {3A021A3E-4C98-47CD-B4E8-912E12611C2E}

+ 48 - 0
Azylee.Utils/Tests/Test.WifiManTest/Form1.Designer.cs

@@ -0,0 +1,48 @@
+namespace Test.WifiManTest
+{
+    partial class Form1
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.SuspendLayout();
+            // 
+            // Form1
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(284, 261);
+            this.Name = "Form1";
+            this.Text = "Form1";
+            this.Load += new System.EventHandler(this.Form1_Load);
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+    }
+}
+

+ 28 - 0
Azylee.Utils/Tests/Test.WifiManTest/Form1.cs

@@ -0,0 +1,28 @@
+using Azylee.Core.NetUtils.WifiManUtils;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Test.WifiManTest
+{
+    public partial class Form1 : Form
+    {
+        public Form1()
+        {
+            InitializeComponent();
+        }
+
+        private void Form1_Load(object sender, EventArgs e)
+        {
+            WlanTool wlan = new WlanTool();
+            var isconn = wlan.IsConnect("lala");
+            var result = wlan.Connect("lala", "12345678a");
+            //var result = wlan.Connect("pppppp", "123123123");
+        }
+    }
+}

+ 120 - 0
Azylee.Utils/Tests/Test.WifiManTest/Form1.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 21 - 0
Azylee.Utils/Tests/Test.WifiManTest/Program.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace Test.WifiManTest
+{
+    static class Program
+    {
+        /// <summary>
+        /// 应用程序的主入口点。
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new Form1());
+        }
+    }
+}

+ 36 - 0
Azylee.Utils/Tests/Test.WifiManTest/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Test.WifiManTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Test.WifiManTest")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("a5702f35-a589-4f03-9468-72bd4a6b57a9")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 71 - 0
Azylee.Utils/Tests/Test.WifiManTest/Properties/Resources.Designer.cs

@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本: 4.0.30319.42000
+//
+//     对此文件的更改可能导致不正确的行为,如果
+//     重新生成代码,则所做更改将丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Test.WifiManTest.Properties
+{
+
+
+    /// <summary>
+    ///   强类型资源类,用于查找本地化字符串等。
+    /// </summary>
+    // 此类是由 StronglyTypedResourceBuilder
+    // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+    // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // (以 /str 作为命令选项),或重新生成 VS 项目。
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resources
+    {
+
+        private static global::System.Resources.ResourceManager resourceMan;
+
+        private static global::System.Globalization.CultureInfo resourceCulture;
+
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resources()
+        {
+        }
+
+        /// <summary>
+        ///   返回此类使用的缓存 ResourceManager 实例。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager
+        {
+            get
+            {
+                if ((resourceMan == null))
+                {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test.WifiManTest.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+
+        /// <summary>
+        ///   覆盖当前线程的 CurrentUICulture 属性
+        ///   使用此强类型的资源类的资源查找。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture
+        {
+            get
+            {
+                return resourceCulture;
+            }
+            set
+            {
+                resourceCulture = value;
+            }
+        }
+    }
+}

+ 117 - 0
Azylee.Utils/Tests/Test.WifiManTest/Properties/Resources.resx

@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 30 - 0
Azylee.Utils/Tests/Test.WifiManTest/Properties/Settings.Designer.cs

@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.42000
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Test.WifiManTest.Properties
+{
+
+
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+    {
+
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+        public static Settings Default
+        {
+            get
+            {
+                return defaultInstance;
+            }
+        }
+    }
+}

+ 7 - 0
Azylee.Utils/Tests/Test.WifiManTest/Properties/Settings.settings

@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+  <Settings />
+</SettingsFile>

+ 83 - 0
Azylee.Utils/Tests/Test.WifiManTest/Test.WifiManTest.csproj

@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{A5702F35-A589-4F03-9468-72BD4A6B57A9}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <RootNamespace>Test.WifiManTest</RootNamespace>
+    <AssemblyName>Test.WifiManTest</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Form1.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Form1.Designer.cs">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <EmbeddedResource Include="Form1.resx">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resources.resx</DependentUpon>
+    </Compile>
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\Azylee.Core\Azylee.Core.csproj">
+      <Project>{88DC61FA-95F0-41B7-9D7D-AB0F3CBD169C}</Project>
+      <Name>Azylee.Core</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>