public async Task<bool> SetProfilePositionAsync(ProfileItem profileItem, int position) { await WaitAsync(); var targetProfiles = _sourceProfiles .Where(x => x.InterfaceGuid == profileItem.InterfaceGuid) .OrderBy(x => x.Position) .ToList(); if ((targetProfiles.Count == 0) || (targetProfiles.Count - 1 < position)) return false; var targetProfile = targetProfiles.FirstOrDefault(x => x.Id == profileItem.Id); if (targetProfile == null) return false; if (targetProfile.Position == position) return true; targetProfiles.Remove(targetProfile); targetProfiles.Insert(position, targetProfile); int index = 0; targetProfiles.ForEach(x => x.Position = index++); return true; }
public async Task<bool> DeleteProfileAsync(ProfileItem profileItem) { if (profileItem == null) throw new ArgumentNullException(nameof(profileItem)); return await Task.Run(() => NativeWifi.DeleteProfile(profileItem.Name, profileItem.InterfaceGuid)); }
public async Task <bool> SetProfilePositionAsync(ProfileItem profileItem, int position) { await WaitAsync(); var targetProfiles = _sourceProfiles .Where(x => x.InterfaceId == profileItem.InterfaceId) .OrderBy(x => x.Position) .ToList(); if ((targetProfiles.Count == 0) || (targetProfiles.Count - 1 < position)) { return(false); } var targetProfile = targetProfiles.FirstOrDefault(x => x.Id == profileItem.Id); if (targetProfile == null) { return(false); } if (targetProfile.Position == position) { return(true); } targetProfiles.Remove(targetProfile); targetProfiles.Insert(position, targetProfile); int index = 0; targetProfiles.ForEach(x => x.Position = index++); return(true); }
public async Task <bool> DisconnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout) { if (profileItem == null) { throw new ArgumentNullException(nameof(profileItem)); } return(await NativeWifi.DisconnectNetworkAsync(profileItem.InterfaceId, timeout)); }
public async Task <bool> SetProfileParameterAsync(ProfileItem profileItem) { if (!(profileItem is NativeWifiProfileItem item)) { throw new ArgumentException(nameof(profileItem)); } return(await Task.Run(() => NativeWifi.SetProfile(item.InterfaceId, item.ProfileType, item.Xml, null, true))); }
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)); }
public async Task <bool> DisconnectAsync(ProfileItem profileItem, TimeSpan timeoutDuration) { if (profileItem == null) { throw new ArgumentNullException(nameof(profileItem)); } return(await Netsh.DisconnectAsync(profileItem.InterfaceName)); }
public async Task <bool> DeleteProfileAsync(ProfileItem profileItem) { if (profileItem == null) { throw new ArgumentNullException(nameof(profileItem)); } return(await Task.Run(() => NativeWifi.DeleteProfile(profileItem.InterfaceId, profileItem.Name))); }
public async Task <bool> DeleteProfileAsync(ProfileItem profileItem) { if (profileItem == null) { throw new ArgumentNullException(nameof(profileItem)); } return(await Netsh.DeleteProfileAsync(profileItem.Name, profileItem.InterfaceName)); }
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)); }
public async Task <bool> ConnectAsync(ProfileItem profileItem, TimeSpan timeoutDuration) { if (profileItem == null) { throw new ArgumentNullException(nameof(profileItem)); } return(await NativeWifi.ConnectAsync(profileItem.Name, profileItem.InterfaceGuid, NativeWifi.BssType.Any, timeoutDuration)); }
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 Task.Run(() => NativeWifi.SetProfilePosition(profileItem.Name, profileItem.InterfaceGuid, position)); }
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); }
public async Task<bool> DisconnectAsync(ProfileItem profileItem, TimeSpan timeoutDuration) { await WaitAsync(); var targetProfile = _sourceProfiles.FirstOrDefault(x => x.Id == profileItem.Id); if (targetProfile == null) return false; targetProfile.IsConnected = false; return true; }
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)); }
public async Task <bool> DisconnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout) { await WaitAsync(); var targetProfile = _sourceProfiles.FirstOrDefault(x => x.Id == profileItem.Id); if (targetProfile == null) { return(false); } targetProfile.IsConnected = false; return(true); }
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 Task.Run(() => NativeWifi.SetProfilePosition(profileItem.InterfaceId, profileItem.Name, position))); }
public async Task <bool> SetProfileParameterAsync(ProfileItem profileItem) { await WaitAsync(); var targetProfile = _sourceProfiles.FirstOrDefault(x => x.Id == profileItem.Id); if (targetProfile == null) { return(false); } targetProfile.IsAutoConnectionEnabled = profileItem.IsAutoConnectionEnabled; targetProfile.IsAutoSwitchEnabled = profileItem.IsAutoSwitchEnabled; return(true); }
public ProfileItemViewModel(ProfileItem profileItem) { Name = profileItem.Name; InterfaceDescription = profileItem.InterfaceDescription; Authentication = profileItem.Authentication.ToString().Replace("_", "-"); Encryption = profileItem.Encryption.ToString(); Position = profileItem .ObserveProperty(x => x.Position) .ToReadOnlyReactiveProperty() .AddTo(this.Subscription); PositionCount = profileItem .ObserveProperty(x => x.PositionCount) .ToReadOnlyReactiveProperty() .AddTo(this.Subscription); IsAutomatic = profileItem .ObserveProperty(x => x.IsAutomatic) .Select(x => x ? "Automatic" : string.Empty) .ToReadOnlyReactiveProperty() .AddTo(this.Subscription); Signal = profileItem .ObserveProperty(x => x.Signal) .ToReadOnlyReactiveProperty() .AddTo(this.Subscription); IsAvailable = Signal .Select(x => 0 < x) .ToReadOnlyReactiveProperty() .AddTo(this.Subscription); IsConnected = profileItem .ObserveProperty(x => x.IsConnected) .ToReadOnlyReactiveProperty() .AddTo(this.Subscription); IsSelected = ReactiveProperty.FromObject(profileItem, x => x.IsTarget) .AddTo(this.Subscription); }
public async Task<bool> DeleteProfileAsync(ProfileItem profileItem) { if (profileItem == null) throw new ArgumentNullException(nameof(profileItem)); return await Netsh.DeleteProfileAsync(profileItem.Name, profileItem.InterfaceName); }
public async Task<bool> ConnectAsync(ProfileItem profileItem, TimeSpan timeoutDuration) { if (profileItem == null) throw new ArgumentNullException(nameof(profileItem)); return await NativeWifi.ConnectAsync(profileItem.Name, profileItem.InterfaceGuid, NativeWifi.BssType.Any, timeoutDuration); }
public async Task<bool> DisconnectAsync(ProfileItem profileItem, TimeSpan timeoutDuration) { if (profileItem == null) throw new ArgumentNullException(nameof(profileItem)); return await Netsh.DisconnectAsync(profileItem.InterfaceName); }
private async Task<bool> WorkAsync(Func<ProfileItem, Task<bool>> perform, Func<ProfileItem, bool> judge, ProfileItem targetProfile = null) { var targetProfileCopy = targetProfile ?? Profiles.FirstOrDefault(x => x.IsTarget); if (targetProfileCopy == null) return false; IsWorking.TurnOn(); try { var timeoutTime = DateTime.Now.Add(_workingTimeoutDuration); if (!await perform(targetProfileCopy)) return false; await Task.Delay(_workingFirstInterval); using (var cts = new CancellationTokenSource()) { while (timeoutTime > DateTime.Now) { try { await Task.WhenAll( Task.Run(async () => { await LoadProfilesAsync(false); if (judge(targetProfileCopy)) cts.Cancel(); }), Task.Delay(_workingSecondInterval, cts.Token)); } catch (TaskCanceledException) { } if (cts.IsCancellationRequested) return true; } return false; } } finally { IsWorking.TurnOff(); } }
public async Task <bool> DeleteProfileAsync(ProfileItem profileItem) { await WaitAsync(); return(_sourceProfiles.Remove(profileItem)); }
public async Task<bool> DeleteProfileAsync(ProfileItem profileItem) { await WaitAsync(); return _sourceProfiles.Remove(profileItem); }