Пример #1
0
		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));
		}
Пример #3
0
        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)));
        }
Пример #6
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));
        }
Пример #7
0
        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)));
        }
Пример #9
0
        public async Task <bool> DeleteProfileAsync(ProfileItem profileItem)
        {
            if (profileItem == null)
            {
                throw new ArgumentNullException(nameof(profileItem));
            }

            return(await Netsh.DeleteProfileAsync(profileItem.Name, profileItem.InterfaceName));
        }
Пример #10
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));
        }
Пример #11
0
        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));
		}
Пример #13
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);
		}
Пример #14
0
		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;
		}
Пример #15
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));
        }
Пример #16
0
        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)));
        }
Пример #18
0
        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);
        }
Пример #20
0
		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);
		}
Пример #22
0
		public async Task<bool> DisconnectAsync(ProfileItem profileItem, TimeSpan timeoutDuration)
		{
			if (profileItem == null)
				throw new ArgumentNullException(nameof(profileItem));

			return await Netsh.DisconnectAsync(profileItem.InterfaceName);
		}
Пример #23
0
		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();
			}
		}
Пример #24
0
        public async Task <bool> DeleteProfileAsync(ProfileItem profileItem)
        {
            await WaitAsync();

            return(_sourceProfiles.Remove(profileItem));
        }
Пример #25
0
		public async Task<bool> DeleteProfileAsync(ProfileItem profileItem)
		{
			await WaitAsync();

			return _sourceProfiles.Remove(profileItem);
		}