예제 #1
0
        public Operation(IWlanWorker worker)
        {
            this._worker = worker;

            IsLoading = new BooleanNotifier();
            IsWorking = new BooleanNotifier();

            ShowLoadingTime();             // For debug
            ShowWorkingTime();             // For debug

            ReloadTimer = new ReactiveTimer(TimeSpan.FromSeconds(Settings.Current.AutoReloadInterval))
                          .AddTo(this.Subscription);
            ReloadTimer
            .Subscribe(async _ => await LoadProfilesAsync(true))
            .AddTo(this.Subscription);

            Settings.Current
            .ObserveProperty(x => x.AutoReloadInterval)
            .Throttle(TimeSpan.FromMilliseconds(100))
            .Subscribe(x => ReloadTimer.Interval = TimeSpan.FromSeconds(x))
            .AddTo(this.Subscription);

            this.ObserveProperty(x => x.IsAutoReloadEnabled)
            .Subscribe(isEnabled =>
            {
                if (isEnabled)
                {
                    ReloadTimer.Start();
                }
                else
                {
                    ReloadTimer.Stop();
                }
            })
            .AddTo(this.Subscription);

            this.ObserveProperty(x => x.IsSuspended, false)
            .Subscribe(async isSuspended =>
            {
                if (isSuspended)
                {
                    ReloadTimer.Stop();
                }
                else
                {
                    if (IsAutoReloadEnabled)
                    {
                        ReloadTimer.Start();
                    }
                    else
                    {
                        await LoadProfilesAsync(false);
                    }
                }
            })
            .AddTo(this.Subscription);

            var initialTask = LoadProfilesAsync(false);
        }
예제 #2
0
		public Operation(IWlanWorker worker)
		{
			this._worker = worker;

			IsLoading = new BooleanNotifier();
			IsWorking = new BooleanNotifier();

			ShowLoadingTime(); // For debug
			ShowWorkingTime(); // For debug

			ReloadTimer = new ReactiveTimer(TimeSpan.FromSeconds(Settings.Current.AutoReloadInterval))
				.AddTo(this.Subscription);
			ReloadTimer
				.Subscribe(async _ => await LoadProfilesAsync(true))
				.AddTo(this.Subscription);

			Settings.Current
				.ObserveProperty(x => x.AutoReloadInterval)
				.Throttle(TimeSpan.FromMilliseconds(100))
				.Subscribe(x => ReloadTimer.Interval = TimeSpan.FromSeconds(x))
				.AddTo(this.Subscription);

			this.ObserveProperty(x => x.IsAutoReloadEnabled)
				.Subscribe(isEnabled =>
				{
					if (isEnabled)
						ReloadTimer.Start();
					else
						ReloadTimer.Stop();
				})
				.AddTo(this.Subscription);

			this.ObserveProperty(x => x.IsSuspended, false)
				.Subscribe(async isSuspended =>
				{
					if (isSuspended)
					{
						ReloadTimer.Stop();
					}
					else
					{
						if (IsAutoReloadEnabled)
							ReloadTimer.Start();
						else
							await LoadProfilesAsync(false);
					}
				})
				.AddTo(this.Subscription);

			var initialTask = LoadProfilesAsync(false);
		}
예제 #3
0
        public MainController(StartupAgent agent, IWlanWorker worker)
        {
            StartupAgent = agent ?? throw new ArgumentNullException(nameof(agent));

            Profiles = new ObservableCollection <ProfileItem>();
            BindingOperations.EnableCollectionSynchronization(Profiles, _profilesLock);

            NotifyIconContainer = new NotifyIconContainer();
            NotifyIconContainer.MouseLeftButtonClick  += OnMainWindowShowRequested;
            NotifyIconContainer.MouseRightButtonClick += OnMenuWindowShowRequested;

            this._worker = worker;

            IsUpdating = new BooleanNotifier();
            IsWorking  = new BooleanNotifier();

            ShowUpdatingTime();            // For debug
            ShowWorkingTime();             // For debug

            RushesRescan = new ReactiveProperty <bool>()
                           .AddTo(this.Subscription);

            EngagesPriority = new ReactiveProperty <bool>()
                              .AddTo(this.Subscription);
            EngagesPriority
            .Subscribe(_ => SetNotifyIconText())
            .AddTo(this.Subscription);

            #region Update

            RescanTimer = new ReactiveTimer(TimeSpan.FromSeconds(Settings.Current.RescanInterval))
                          .AddTo(this.Subscription);

            RescanCommand = IsUpdating
                            .Inverse()
                            .ObserveOnUIDispatcher()     // This is for thread access by ReactiveCommand.
                            .ToReactiveCommand();
            RescanCommand
            .Merge(EngagesPriority.Where(x => x).Select(x => x as object))
            .Merge(RescanTimer.Select(x => x as object))
            .Subscribe(async _ => await ScanNetworkAsync())
            .AddTo(this.Subscription);

            Settings.Current
            .ObserveProperty(x => x.RescanInterval)
            .Subscribe(rescanInterval => RescanTimer.Interval = TimeSpan.FromSeconds(rescanInterval))
            .AddTo(this.Subscription);

            RushesRescan
            .Subscribe(rushesRescan =>
            {
                if (rushesRescan)
                {
                    RescanTimer.Start();
                }
                else
                {
                    RescanTimer.Stop();
                }

                SetNotifyIconText();
            })
            .AddTo(this.Subscription);

            var networkRefreshed = Observable.FromEventPattern(
                h => _worker.NetworkRefreshed += h,
                h => _worker.NetworkRefreshed -= h);
            var availabilityChanged = Observable.FromEventPattern(
                h => _worker.AvailabilityChanged += h,
                h => _worker.AvailabilityChanged -= h);
            var interfaceChanged = Observable.FromEventPattern(
                h => _worker.InterfaceChanged += h,
                h => _worker.InterfaceChanged -= h);
            var connectionChanged = Observable.FromEventPattern(
                h => _worker.ConnectionChanged += h,
                h => _worker.ConnectionChanged -= h);
            var profileChanged = Observable.FromEventPattern(
                h => _worker.ProfileChanged += h,
                h => _worker.ProfileChanged -= h);
            Observable.Merge(networkRefreshed, availabilityChanged, interfaceChanged, connectionChanged, profileChanged)
            .Throttle(TimeSpan.FromMilliseconds(100))
            .Subscribe(async _ =>
            {
                if (RushesRescan.Value)
                {
                    RescanTimer.Start(TimeSpan.FromSeconds(Settings.Current.RescanInterval));                             // Wait for due time.
                }
                await LoadProfilesAsync();
            })
            .AddTo(this.Subscription);

            #endregion

            #region Close

            CloseCommand = new ReactiveProperty <bool>(true)
                           .ToReactiveCommand();
            CloseCommand
            .Subscribe(_ => _current.Shutdown())
            .AddTo(this.Subscription);

            #endregion
        }