Esempio n. 1
0
        public Task <bool> RenameProfileAsync(ProfileItem profileItem, string profileName)
        {
            var targetProfile = _sourceProfiles.FirstOrDefault(x => x.Id == profileItem.Id);

            if (targetProfile == null)
            {
                return(Task.FromResult(false));
            }

            var renamedProfile = new ProfileItem(
                name: profileName,
                interfaceId: targetProfile.InterfaceId,
                interfaceName: targetProfile.InterfaceName,
                interfaceDescription: targetProfile.InterfaceDescription,
                authentication: targetProfile.Authentication,
                encryption: targetProfile.Encryption,
                isAutoConnectEnabled: targetProfile.IsAutoConnectEnabled,
                isAutoSwitchEnabled: targetProfile.IsAutoSwitchEnabled,
                position: targetProfile.Position,
                isRadioOn: targetProfile.IsRadioOn,
                isConnected: targetProfile.IsConnected,
                signal: targetProfile.Signal,
                band: targetProfile.Band,
                channel: targetProfile.Channel);

            _sourceProfiles.Remove(targetProfile);
            _sourceProfiles.Add(renamedProfile);

            deferTask = DeferAsync(() => ProfileChanged?.Invoke(this, EventArgs.Empty));
            return(Task.FromResult(true));
        }
Esempio n. 2
0
        public Task <bool> SetProfilePositionAsync(ProfileItem profileItem, int position)
        {
            var targetProfiles = _sourceProfiles
                                 .Where(x => x.InterfaceId == profileItem.InterfaceId)
                                 .OrderBy(x => x.Position)
                                 .ToList();

            if ((targetProfiles.Count == 0) || (targetProfiles.Count - 1 < position))
            {
                return(Task.FromResult(false));
            }

            var targetProfile = targetProfiles.FirstOrDefault(x => x.Id == profileItem.Id);

            if (targetProfile == null)
            {
                return(Task.FromResult(false));
            }

            if (targetProfile.Position == position)
            {
                return(Task.FromResult(false));
            }

            targetProfiles.Remove(targetProfile);
            targetProfiles.Insert(position, targetProfile);

            int index = 0;

            targetProfiles.ForEach(x => x.Position = index++);

            deferTask = DeferAsync(() => ProfileChanged?.Invoke(this, EventArgs.Empty));
            return(Task.FromResult(true));
        }
Esempio n. 3
0
        public Task <bool> DeleteProfileAsync(ProfileItem profileItem)
        {
            if (!_sourceProfiles.Remove(profileItem))
            {
                return(Task.FromResult(false));
            }

            deferTask = DeferAsync(() => ProfileChanged?.Invoke(this, EventArgs.Empty));
            return(Task.FromResult(true));
        }
Esempio n. 4
0
        public Task <bool> DisconnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout)
        {
            var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem));

            if (!IsWorkable)
            {
                return(Task.FromResult(false));
            }

            return(_player.DisconnectNetworkAsync(item.InterfaceId, timeout, CancellationToken.None));
        }
Esempio n. 5
0
        public Task <bool> DeleteProfileAsync(ProfileItem profileItem)
        {
            var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem));

            if (!IsWorkable)
            {
                return(Task.FromResult(false));
            }

            return(Task.Run(() => _player.DeleteProfile(item.InterfaceId, item.Name)));
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        public Task <bool> ConnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout)
        {
            if (!(profileItem is NativeWifiProfileItem item))
            {
                throw new ArgumentException(nameof(profileItem));
            }

            if (!IsWorkable)
            {
                return(Task.FromResult(false));
            }

            return(_player.ConnectNetworkAsync(item.InterfaceId, item.Name, item.BssType, timeout, CancellationToken.None));
        }
Esempio n. 10
0
        public Task <bool> SetProfileOptionAsync(ProfileItem profileItem)
        {
            if (!(profileItem is NativeWifiProfileItem item))
            {
                throw new ArgumentException(nameof(profileItem));
            }

            if (!IsWorkable)
            {
                return(Task.FromResult(false));
            }

            return(Task.Run(() => _player.SetProfile(item.InterfaceId, item.ProfileType, item.Xml, null, true)));
        }
Esempio n. 11
0
        public Task <bool> DisconnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout)
        {
            var targetProfile = _sourceProfiles.FirstOrDefault(x => x.Id == profileItem.Id);

            if (targetProfile == null)
            {
                return(Task.FromResult(false));
            }

            targetProfile.IsConnected = false;

            deferTask = DeferAsync(() => ConnectionChanged?.Invoke(this, EventArgs.Empty));
            return(Task.FromResult(true));
        }
Esempio n. 12
0
        public Task <bool> SetProfileOptionAsync(ProfileItem profileItem)
        {
            var targetProfile = _sourceProfiles.FirstOrDefault(x => x.Id == profileItem.Id);

            if (targetProfile == null)
            {
                return(Task.FromResult(false));
            }

            targetProfile.IsAutoConnectEnabled = profileItem.IsAutoConnectEnabled;
            targetProfile.IsAutoSwitchEnabled  = profileItem.IsAutoSwitchEnabled;

            deferTask = DeferAsync(() => ProfileChanged?.Invoke(this, EventArgs.Empty));
            return(Task.FromResult(true));
        }
Esempio n. 13
0
        public Task <bool> RenameProfileAsync(ProfileItem profileItem, string profileName)
        {
            var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem));

            if (string.IsNullOrWhiteSpace(profileName))
            {
                throw new ArgumentNullException(nameof(profileName));
            }

            if (!IsWorkable)
            {
                return(Task.FromResult(false));
            }

            return(Task.Run(() => _player.RenameProfile(item.InterfaceId, item.Name, profileName)));
        }
Esempio n. 14
0
        public Task <bool> SetProfilePositionAsync(ProfileItem profileItem, int position)
        {
            var item = profileItem ?? throw new ArgumentNullException(nameof(profileItem));

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

            if (!IsWorkable)
            {
                return(Task.FromResult(false));
            }

            return(Task.Run(() => _player.SetProfilePosition(item.InterfaceId, item.Name, position)));
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        public Task <bool> ConnectNetworkAsync(ProfileItem profileItem, TimeSpan timeout)
        {
            var targetProfiles = _sourceProfiles
                                 .Where(x => x.InterfaceId == profileItem.InterfaceId)
                                 .ToList();

            var targetProfile = targetProfiles.FirstOrDefault(x => x.Id == profileItem.Id);

            if (targetProfile == null)
            {
                return(Task.FromResult(false));
            }

            targetProfile.IsConnected = true;
            targetProfiles.Remove(targetProfile);

            targetProfiles.ForEach(x => x.IsConnected = false);

            deferTask = DeferAsync(() => ConnectionChanged?.Invoke(this, EventArgs.Empty));
            return(Task.FromResult(true));
        }
Esempio n. 17
0
 public Task <bool> RenameProfileAsync(ProfileItem profileItem, string profileName)
 {
     // Netsh has no function to directly rename a wireless profile.
     return(Task.FromResult(false));
 }