public async Task <IEnumerable <ProfileItem> > GetProfilesAsync() { 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, interfaceId: interfacePack.Id, interfaceName: profilePack.InterfaceName, interfaceDescription: interfacePack.Description, authentication: ConvertToAuthenticationMethod(profilePack.Authentication), encryption: ConvertToEncryptionType(profilePack.Encryption), isAutoConnectEnabled: profilePack.IsAutoConnectEnabled, isAutoSwitchEnabled: profilePack.IsAutoSwitchEnabled, position: profilePack.Position, isRadioOn: interfacePack.IsRadioOn, isConnected: (interfacePack.IsConnected && profilePack.Name.Equals(interfacePack.ProfileName, StringComparison.Ordinal)), signal: (networkPack?.Signal ?? 0), band: (networkPack?.Band ?? 0), channel: (networkPack?.Channel ?? 0))); }
public async Task <bool> DisconnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout) { var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem)); if (!await Netsh.DisconnectNetworkAsync(item.InterfaceName)) { return(false); } await DeferAsync(() => ConnectionChanged?.Invoke(this, EventArgs.Empty)); return(true); }
public async Task <bool> DeleteProfileAsync(ProfileItem profileItem) { var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem)); if (!await Netsh.DeleteProfileAsync(item.InterfaceName, item.Name)) { return(false); } await DeferAsync(() => ProfileChanged?.Invoke(this, EventArgs.Empty)); return(true); }
public async Task <bool> SetProfileOptionAsync(ProfileItem profileItem) { var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem)); if (!await Netsh.SetProfileParameterAsync(item.InterfaceName, item.Name, item.IsAutoConnectEnabled, item.IsAutoSwitchEnabled)) { return(false); } await DeferAsync(() => ProfileChanged?.Invoke(this, EventArgs.Empty)); return(true); }
public async Task <bool> SetProfilePositionAsync(ProfileItem profileItem, int position) { var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem)); if (position < 0) { throw new ArgumentOutOfRangeException(nameof(position)); } if (!await Netsh.SetProfilePositionAsync(item.InterfaceName, item.Name, position)) { return(false); } await DeferAsync(() => ProfileChanged?.Invoke(this, EventArgs.Empty)); return(true); }