예제 #1
0
        public async Task <IEnumerable <ProfileItem> > GetProfilesAsync(bool isLatest, TimeSpan timeoutDuration)
        {
            var interfacePacks = (await Netsh.GetInterfacesAsync().ConfigureAwait(false))
                                 .ToArray(); // ToArray method is necessary.

            var networkPacks = (await Netsh.GetNetworksAsync().ConfigureAwait(false))
                               .ToArray();  // ToArray method is necessary.

            var profilePacks = await Netsh.GetProfilesAsync().ConfigureAwait(false);

            return(from profilePack in profilePacks
                   let networkPack = networkPacks.FirstOrDefault(x =>
                                                                 x.InterfaceName.Equals(profilePack.InterfaceName, StringComparison.Ordinal) &&
                                                                 x.Ssid.Equals(profilePack.Ssid, StringComparison.Ordinal))
                                     from interfacePack in interfacePacks
                                     where profilePack.InterfaceName.Equals(interfacePack.Name, StringComparison.Ordinal)
                                     select new ProfileItem(
                       name: profilePack.Name,
                       interfaceGuid: interfacePack.Guid,
                       interfaceName: profilePack.InterfaceName,
                       interfaceDescription: interfacePack.Description,
                       authentication: ConvertToAuthentication(profilePack.Authentication),
                       encryption: ConvertToEncryption(profilePack.Encryption),
                       position: profilePack.Position,
                       isAutomatic: profilePack.IsAutomatic,
                       signal: (networkPack?.Signal ?? 0),
                       isConnected: (interfacePack.IsConnected && profilePack.Name.Equals(interfacePack.ProfileName, StringComparison.Ordinal))));
        }
예제 #2
0
        public async Task <bool> DisconnectAsync(ProfileItem profileItem, TimeSpan timeoutDuration)
        {
            if (profileItem == null)
            {
                throw new ArgumentNullException(nameof(profileItem));
            }

            return(await Netsh.DisconnectAsync(profileItem.InterfaceName));
        }
예제 #3
0
        public async Task <bool> DeleteProfileAsync(ProfileItem profileItem)
        {
            if (profileItem == null)
            {
                throw new ArgumentNullException(nameof(profileItem));
            }

            return(await Netsh.DeleteProfileAsync(profileItem.Name, profileItem.InterfaceName));
        }
예제 #4
0
        public async Task <bool> SetProfileParameterAsync(ProfileItem profileItem)
        {
            if (profileItem == null)
            {
                throw new ArgumentNullException(nameof(profileItem));
            }

            return(await Netsh.SetProfileParameterAsync(profileItem.InterfaceName, profileItem.Name, profileItem.IsAutoConnectionEnabled, profileItem.IsAutoSwitchEnabled));
        }
예제 #5
0
        public async Task <bool> ConnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout)
        {
            if (profileItem == null)
            {
                throw new ArgumentNullException(nameof(profileItem));
            }

            return(await Netsh.ConnectNetworkAsync(profileItem.InterfaceName, profileItem.Name));
        }
예제 #6
0
        public async Task <bool> SetProfilePositionAsync(ProfileItem profileItem, int position)
        {
            if (profileItem == null)
            {
                throw new ArgumentNullException(nameof(profileItem));
            }

            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position));
            }

            return(await Netsh.SetProfilePositionAync(profileItem.Name, profileItem.InterfaceName, position));
        }