Ejemplo n.º 1
0
        private void DiscoverDevice()
        {
            var busy = _discoverBusy.ProcessStart();

            _devices.Clear();
            SwMainApi.Discover().Subscribe(d => _devices.Add(d), (ex) => busy.Dispose(), () => busy.Dispose());
        }
Ejemplo n.º 2
0
        public void NotifyCase()
        {
            var n = new BusyNotifier();

            var d = n.ProcessStart();

            var observeNotifyIsBusyCounter = 0;
            var latestNotifyIsBusyValue    = false;

            n.Subscribe(x =>
            {
                observeNotifyIsBusyCounter++;
                latestNotifyIsBusyValue = x;
            });

            observeNotifyIsBusyCounter.Is(1);
            latestNotifyIsBusyValue.IsTrue();
            n.IsBusy.IsTrue();

            d.Dispose();

            observeNotifyIsBusyCounter.Is(2);
            latestNotifyIsBusyValue.IsFalse();
            n.IsBusy.IsFalse();
        }
Ejemplo n.º 3
0
 private async void OtherTakeLongTimeAsync()
 {
     using (BusyNotifier.ProcessStart())
     {
         await Task.Run(() => Model.TakeLongTimeTask2());
     }
 }
Ejemplo n.º 4
0
        public void MultipleCase()
        {
            var n = new BusyNotifier();
            var notifyPropertyChangedCounter = 0;

            n.PropertyChanged += (_, e) =>
            {
                if (e.PropertyName == nameof(BusyNotifier.IsBusy))
                {
                    notifyPropertyChangedCounter++;
                }
            };
            var observeNotifyIsBusyCounter = 0;
            var latestNotifyIsBusyValue    = false;

            n.Subscribe(x =>
            {
                observeNotifyIsBusyCounter++;
                latestNotifyIsBusyValue = x;
            });

            notifyPropertyChangedCounter.Is(0);
            observeNotifyIsBusyCounter.Is(1);
            latestNotifyIsBusyValue.IsFalse();

            var d1 = n.ProcessStart();
            var d2 = n.ProcessStart();

            notifyPropertyChangedCounter.Is(1);
            observeNotifyIsBusyCounter.Is(2);
            latestNotifyIsBusyValue.IsTrue();
            n.IsBusy.IsTrue();

            d1.Dispose();

            notifyPropertyChangedCounter.Is(1);
            observeNotifyIsBusyCounter.Is(2);
            latestNotifyIsBusyValue.IsTrue();
            n.IsBusy.IsTrue();

            d2.Dispose();

            notifyPropertyChangedCounter.Is(2);
            observeNotifyIsBusyCounter.Is(3);
            latestNotifyIsBusyValue.IsFalse();
            n.IsBusy.IsFalse();
        }
Ejemplo n.º 5
0
        public void MultipleCase()
        {
            var n = new BusyNotifier();
            var notifyPropertyChangedCounter = 0;
            n.PropertyChanged += (_, e) =>
            {
                if (e.PropertyName == nameof(BusyNotifier.IsBusy))
                {
                    notifyPropertyChangedCounter++;
                }
            };
            var observeNotifyIsBusyCounter = 0;
            var latestNotifyIsBusyValue = false;
            n.Subscribe(x =>
            {
                observeNotifyIsBusyCounter++;
                latestNotifyIsBusyValue = x;
            });

            notifyPropertyChangedCounter.Is(0);
            observeNotifyIsBusyCounter.Is(1);
            latestNotifyIsBusyValue.IsFalse();

            var d1 = n.ProcessStart();
            var d2 = n.ProcessStart();

            notifyPropertyChangedCounter.Is(1);
            observeNotifyIsBusyCounter.Is(2);
            latestNotifyIsBusyValue.IsTrue();
            n.IsBusy.IsTrue();

            d1.Dispose();

            notifyPropertyChangedCounter.Is(1);
            observeNotifyIsBusyCounter.Is(2);
            latestNotifyIsBusyValue.IsTrue();
            n.IsBusy.IsTrue();

            d2.Dispose();

            notifyPropertyChangedCounter.Is(2);
            observeNotifyIsBusyCounter.Is(3);
            latestNotifyIsBusyValue.IsFalse();
            n.IsBusy.IsFalse();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public DataExportViewModel(string inDirPath, string outFilePath)
        {
            InDirPath = new ReactiveProperty <string>(inDirPath,
                                                      mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);
            _UnableToGetLanguages = new ReactivePropertySlim <bool>(false);
            InDirPath.SetValidateNotifyError(
                _ => _UnableToGetLanguages.Select(isError => isError ? "Error" : null));
            _OutFilePath = outFilePath;

            Languages        = new ReactiveCollection <LangComboboxItem>();
            SelectedLanguage = new ReactivePropertySlim <LangComboboxItem?>();

            MaxSteps    = new ReactivePropertySlim <int>(1);
            CurrentStep = new ReactivePropertySlim <int>(0);

            CanOperation = _BusyNotifier.Inverse().ToReadOnlyReactivePropertySlim();

            // 操作可能かつ入力項目に不備がない場合に true にする
            var canExport = new[] {
                CanOperation,
                InDirPath.Select(p => !string.IsNullOrEmpty(p)),
                SelectedLanguage.Select(l => l != null),
            }.CombineLatestValuesAreAllTrue();

            SelectInDirCommand = new ReactiveCommand(CanOperation).WithSubscribe(SelectInDir);
            ExportCommand      = new AsyncReactiveCommand(canExport).WithSubscribe(Export);
            ClosingCommand     = new ReactiveCommand <CancelEventArgs>().WithSubscribe(Closing);

            // 入力元フォルダパスに値が代入された時、言語一覧を更新する
            InDirPath.ObserveOn(ThreadPoolScheduler.Instance).Subscribe(path =>
            {
                using var _ = _BusyNotifier.ProcessStart();
                _UnableToGetLanguages.Value = false;
                Languages.ClearOnScheduler();

                var(success, languages)     = _Model.GetLanguages(path);
                _UnableToGetLanguages.Value = !success;
                Languages.AddRangeOnScheduler(languages);
            });
        }
        public ScheduledNotifierViewModel()
        {
            ProcessingProgress = ScheduledNotifier
                                 .ToReadOnlyReactiveProperty()
                                 .AddTo(CompositeDisposable);

            HeavyProcessCommand1 = _busyNotifier.Inverse()
                                   .ToAsyncReactiveCommand()
                                   .WithSubscribe(async() =>
            {
                using (_busyNotifier.ProcessStart())
                {
                    await HeavyProcessAsync(null);
                }
            },
                                                  CompositeDisposable.Add);

            HeavyProcessCommand2 = _busyNotifier.Inverse()
                                   .ToAsyncReactiveCommand()
                                   .WithSubscribe(async() =>
            {
                using (_busyNotifier.ProcessStart())
                {
                    await HeavyProcessAsync(ScheduledNotifier);
                }
            },
                                                  CompositeDisposable.Add);

#if false
            var scheduledNotifier = new ScheduledNotifier <int>();
            var progress          = scheduledNotifier as IProgress <int>;

            scheduledNotifier.Report(10);
            scheduledNotifier.Report(100, TimeSpan.FromSeconds(3));
            progress.Report(22);
#endif
        }
        public BusyNotifierViewModel()
        {
            LightProcessCommand = _busyNotifier
                                  .Inverse()
                                  .ToReactiveCommand()
                                  .WithSubscribe(async() =>
            {
                // Viewボタンが無効になるので来ないが勉強のため
                if (_busyNotifier.IsBusy)
                {
                    throw new Exception();
                }

                using (_busyNotifier.ProcessStart())
                {
                    await Task.Delay(500);
                }
            }, CompositeDisposable.Add);

            HeavyProcessCommand = _busyNotifier
                                  .Inverse()
                                  .ToReactiveCommand()
                                  .WithSubscribe(async() =>
            {
                // Viewボタンが無効になるので来ないが勉強のため
                if (_busyNotifier.IsBusy)
                {
                    throw new Exception();
                }

                using (_busyNotifier.ProcessStart())
                {
                    await Task.Delay(2000);
                }
            }, CompositeDisposable.Add);
        }
Ejemplo n.º 9
0
        public RegisterPageViewModel(INavigationService navigationService, IUserUsecase userUsecase, IUserDialogs userDialogs) : base(navigationService)
        {
            _userUsecase = userUsecase;
            _userDialogs = userDialogs;

            Name.SetValidateAttribute(() => Name);

            RegisterCommand = new[]
            {
                Name.ObserveHasErrors,
                _busyNotifier,
            }
            .CombineLatestValuesAreAllFalse()
            .ObserveOn(SynchronizationContext.Current)
            .ToReactiveCommand()
            .WithSubscribe(() =>
            {
                _registerRequested.OnNext(Unit.Default);
                _userUsecase.Register(Name.Value);
            })
            .AddTo(_disposables);

            _registerRequested.SelectMany(_ => Observable.Using(() =>
            {
                return(new CompositeDisposable()
                {
                    _busyNotifier.ProcessStart(),
                    _userDialogs.Loading(""),
                });
            }, _ => Observable.Amb(
                                                                    _userUsecase.UserRegistered.Select <User, (User?user, Exception?error)>(user => (user, null)),
                                                                    _userUsecase.ErrorOccurred.Select <Exception, (User?user, Exception?error)>(ex => (null, ex)))
                                                                .Take(1)))
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(async t =>
            {
                if (t.user is not null)
                {
                    await _userDialogs.AlertAsync("登録が完了しました", "確認");
                    await navigationService.NavigateAsync("/MainPage");
                }
                else
                {
                    await _userDialogs.AlertAsync("登録に失敗しました", "エラー");
                }
            })
            .AddTo(_disposables);
        }
Ejemplo n.º 10
0
        public async Task DeleteAsync()
        {
            try
            {
                using (_deletingNotifier.ProcessStart())
                {
                    await _firestore.GetCollection(Models.Item.CollectionPath)
                    .GetDocument(Item.Value.Id)
                    .DeleteDocumentAsync();

                    await _accountService.IncrementContributionCountAsync(-1);
                }
                _deleteCompletedNotifier.OnNext(Unit.Default);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                _deleteErrorNotifier.OnNext(e.Message);
            }
        }
        public async Task Login()
        {
            if (!CanLogin.Value)
            {
                return;
            }

            try
            {
                using (_loggingInNotifier.ProcessStart())
                {
                    await _accountService.LoginWithEmailAndPasswordAsync(Email.Value, Password.Value);
                }
                _loginCompletedNotifier.OnNext(Unit.Default);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                _loginErrorNotifier.OnNext(e.Message);
            }
        }
        public async Task Signup()
        {
            if (!CanSignup.Value)
            {
                return;
            }

            try
            {
                using (_signingUpNotifier.ProcessStart())
                {
                    await _accountService.SignupAsync(Email.Value, Password.Value, Name.Value, Image.Value);
                }
                _signupCompletedNotifier.OnNext(Unit.Default);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                _signupErrorNotifier.OnNext(e.Message);
            }
        }
Ejemplo n.º 13
0
        public async Task Login()
        {
            try
            {
                var(idToken, accessToken) = await _authService.LoginWithGoogle().ConfigureAwait(false);

                if (idToken != null)
                {
                    using (_loggingInNotifier.ProcessStart())
                    {
                        await _accountService.LoginWithGoogleAsync(idToken, accessToken);
                    }
                    _loginCompletedNotifier.OnNext(Unit.Default);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                _loginErrorNotifier.OnNext(e.Message);
            }
        }
Ejemplo n.º 14
0
        public async Task Contribute()
        {
            if (!CanContribute.Value)
            {
                return;
            }

            try
            {
                using (_contributingNotifier.ProcessStart())
                {
                    var id = Guid.NewGuid().ToString();

                    var uri = await _storageService.UploadImage(ItemImage.Value, $"items/{id}/image.jpg").ConfigureAwait(false);

                    var item = new Item
                    {
                        Title     = ItemTitle.Value,
                        Image     = uri.AbsoluteUri,
                        Comment   = ItemComment.Value,
                        OwnerId   = _accountService.UserId.Value,
                        Timestamp = DateTime.Now.Ticks
                    };

                    await _firestore.GetCollection(Item.CollectionPath)
                    .GetDocument(id)
                    .SetDataAsync(item)
                    .ConfigureAwait(false);

                    await _accountService.IncrementContributionCountAsync(1);
                }
                _contributeCompletedNotifier.OnNext(Unit.Default);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                _contributeErrorNotifier.OnNext(e.Message);
            }
        }
Ejemplo n.º 15
0
        public void NotifyCase()
        {
            var n = new BusyNotifier();

            var d = n.ProcessStart();

            var observeNotifyIsBusyCounter = 0;
            var latestNotifyIsBusyValue = false;
            n.Subscribe(x =>
            {
                observeNotifyIsBusyCounter++;
                latestNotifyIsBusyValue = x;
            });

            observeNotifyIsBusyCounter.Is(1);
            latestNotifyIsBusyValue.IsTrue();
            n.IsBusy.IsTrue();

            d.Dispose();

            observeNotifyIsBusyCounter.Is(2);
            latestNotifyIsBusyValue.IsFalse();
            n.IsBusy.IsFalse();
        }
Ejemplo n.º 16
0
        public MainPageViewModel(INavigationService navigationService, IGameUsecase gameUsecase, IUserDialogs userDialogs) : base(navigationService)
        {
            _gameUsecase = gameUsecase;
            _userDialogs = userDialogs;

            CreateCommand = _busyNotifier
                            .Inverse()
                            .ObserveOn(SynchronizationContext.Current)
                            .ToAsyncReactiveCommand()
                            .WithSubscribe(() => NavigationService.NavigateAsync("CreatePage"))
                            .AddTo(_disposables);

            JoinCommand = _busyNotifier
                          .Inverse()
                          .ObserveOn(SynchronizationContext.Current)
                          .ToAsyncReactiveCommand()
                          .WithSubscribe(() => NavigationService.NavigateAsync("JoinPage"))
                          .AddTo(_disposables);

            _gameUsecase.PhaseChanged
            .Subscribe(info => _gameInfo.Value = info)
            .AddTo(_disposables);

            _createRequested.SelectMany(_ => Observable.Using(() =>
            {
                return(new CompositeDisposable()
                {
                    _busyNotifier.ProcessStart(),
                    _userDialogs.Loading(""),
                });
            }, _ => Observable.Amb(
                                                                  _gameUsecase.StartNewGameResponsed.Select(_ => true),
                                                                  _gameUsecase.ErrorOccurred.Select(_ => false))
                                                              .Take(1)
                                                              .SelectMany(b => b ?
                                                                          _gameInfo.Where(info => info is not null)
                                                                          .Select <GameInfo, (GameInfo?info, bool success)>(info => (info, b)) :
                                                                          Observable.Return <(GameInfo?info, bool success)>((null, b)))
                                                              .Take(1)))
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(async t =>
            {
                if (!t.success)
                {
                    _userDialogs.Alert("ゲーム開始に失敗しました", "エラー");
                }
                else
                {
                    await _userDialogs.AlertAsync($"ゲームID: {t.info!.GameId}", "確認");
                    _waitRequested.OnNext(t.info);
                }
            })
            .AddTo(_disposables);

            _joinRequested.SelectMany(_ => Observable.Using(() =>
            {
                return(new CompositeDisposable()
                {
                    _busyNotifier.ProcessStart(),
                    _userDialogs.Loading(""),
                });
            }, _ => Observable.Amb(
                                                                _gameUsecase.JoinResponsed.Select(_ => true),
                                                                _gameUsecase.ErrorOccurred.Select(_ => false))
                                                            .Take(1)
                                                            .SelectMany(b => b ?
                                                                        _gameInfo.Where(info => info is not null && info.Phase == Phase.Night && info.Day == 1)
                                                                        .Select <GameInfo, (GameInfo?info, bool success)>(info => (info, b)) :
                                                                        Observable.Return <(GameInfo?info, bool success)>((null, b)))
                                                            .Take(1)))
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(t =>
            {
                if (!t.success)
                {
                    _userDialogs.Alert("ゲーム参加に失敗しました", "エラー");
                }
                else
                {
                    NavigationService.NavigateAsync("/GamePage",
                                                    (GamePageViewModel.GameInfoParameterKey, t.info));
                }
            })
            .AddTo(_disposables);

            _waitRequested.SelectMany(info => Observable.Using(() =>
            {
                return(new CompositeDisposable()
                {
                    _busyNotifier.ProcessStart(),
                    _userDialogs.Loading($"ゲームID: {info.GameId}"),
                });
            }, _ => _gameInfo.Where(info => info is not null && info.Phase == Phase.Night && info.Day == 1)
                                                               .Take(1)))
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(info =>
            {
                NavigationService.NavigateAsync("/GamePage",
                                                (GamePageViewModel.GameInfoParameterKey, info));
            })
            .AddTo(_disposables);
        }