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);
        }
Exemple #3
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);
            });
        }
Exemple #4
0
        public DeviceSelectDialogViewModel()
        {
            _disposables = new CompositeDisposable();

            LocalAddress = SwMainApi.GetAllLocalIPv4Addresses().FirstOrDefault();
            var ver = Assembly.GetCallingAssembly().GetName().Version;

            AppVersion = $"{ver.Major}.{ver.Minor}.{ver.Build}";

            _devices = new ObservableCollection <DiscoverResult>();
            Devices  = _devices.ToReadOnlyReactiveCollection().AddTo(_disposables);

            _discoverBusy         = new BusyNotifier();
            DiscoverDeviceCommand = _discoverBusy.Inverse().ToReactiveCommand().AddTo(_disposables);
            DiscoverDeviceCommand.Delay(new TimeSpan(100)).Subscribe(_ => DiscoverDevice()).AddTo(_disposables);

            IsSearchIpMode = new ReactiveProperty <bool>(false).AddTo(_disposables);
            IsSearchIpMode.Subscribe(b => {
                if (b)
                {
                    // Enter mode: clear fail flag.
                    _searchFailed.OnNext(false);
                }
                else if (DiscoverDeviceCommand.CanExecute())
                {
                    // Exit mode: rescan devices.
                    DiscoverDeviceCommand.Execute();
                }
            }).AddTo(_disposables);

            _searchFailed   = new BehaviorSubject <bool>(false).AddTo(_disposables);
            SearchFailed    = _searchFailed.ToReadOnlyReactiveProperty().AddTo(_disposables);
            SearchIpAddr    = new ReactiveProperty <string>().SetValidateAttribute(() => SearchIpAddr).AddTo(_disposables);
            SearchIpCommand = Observable.CombineLatest(SearchIpAddr.ObserveHasErrors, _discoverBusy, (e, c) => !e && !c)
                              .ToReactiveCommand().AddTo(_disposables);
            SearchIpCommand.Subscribe(_ => SearchIp()).AddTo(_disposables);
        }
Exemple #5
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);
        }