예제 #1
0
        public MainWindowViewModel()
        {
            Logger.Info("Initializing...");

            // DB Context (SQLite)
            var context = new MainDbContext();

            // Create ViewModel collection from the models
            Companies = context.Companies
                        .ToObservable()
                        .Select(x => new CompanyViewModel(x))
                        .ToReactiveCollection();
            // SelectFileCommand is fired from click event of button through EventToReactiveCommand.
            // SelectedFilename will be set after a file selected from OpenFileDialog through OpenFileDialogConverter.
            SelectedFilename = SelectFileCommand
                               .Select(filename => filename)
                               .ToReadOnlyReactiveProperty();
            // ReactiveCommand (can execute when SelectedFilename is set)
            StartCommand = SelectedFilename.Select(x => !string.IsNullOrWhiteSpace(x)).ToReactiveCommand <string>();
            StartCommand.Subscribe(async _ =>
            {
                var res = await ConfirmationRequest.RaiseAsync(new Confirmation {
                    Title = "Demo", Content = "Are you sure?"
                });
                if (res.Confirmed)
                {
                    await NotificationRequest.RaiseAsync(new Notification {
                        Title = "Demo", Content = "Done!"
                    });
                }
            });
            Logger.Info("Initialized.");
        }
예제 #2
0
        public MainWindowViewModel(IStopwatchService service)
        {
            this.service = service;

            Ellapsed = this.service.ObserveProperty(x => x.Ellapsed)
                       .ToReadOnlyReactiveProperty()
                       .AddTo(CompositeDisposable);

            LapTimes = this.service.LapTimes
                       ?.ToReadOnlyReactiveCollection(t => new LapTimeViewModel(this.service.LapTimes.Count, t));

            StartCommand = this.service.ObserveProperty(x => x.IsRunning)
                           .Inverse()
                           .ToReactiveCommand()
                           .AddTo(CompositeDisposable);
            StartCommand.Subscribe(() => this.service.Start()).AddTo(CompositeDisposable);

            StopCommand = this.service.ObserveProperty(x => x.IsRunning)
                          .ToReactiveCommand()
                          .AddTo(CompositeDisposable);
            StopCommand.Subscribe(() => this.service.Stop()).AddTo(CompositeDisposable);

            ResetCommand = new ReactiveCommand().AddTo(CompositeDisposable);
            ResetCommand.Subscribe(() => this.service.Reset()).AddTo(CompositeDisposable);

            LapCommand = this.service.ObserveProperty(x => x.IsRunning)
                         .ToReactiveCommand()
                         .AddTo(CompositeDisposable);
            LapCommand.Subscribe(() => this.service.Lap()).AddTo(CompositeDisposable);
        }
        public MainWindowViewModel()
        {
            Zero = settingModel.ToReactivePropertyAsSynchronized(x => x.Zero);

            One = settingModel.ToReactivePropertyAsSynchronized(x => x.One);

            Two = settingModel.ToReactivePropertyAsSynchronized(x => x.Two);

            Three = settingModel.ToReactivePropertyAsSynchronized(x => x.Three);

            Four = settingModel.ToReactivePropertyAsSynchronized(x => x.Four);

            Five = settingModel.ToReactivePropertyAsSynchronized(x => x.Five);

            Six = settingModel.ToReactivePropertyAsSynchronized(x => x.Six);

            Seven = settingModel.ToReactivePropertyAsSynchronized(x => x.Seven);

            Eight = settingModel.ToReactivePropertyAsSynchronized(x => x.Eight);

            Nine = settingModel.ToReactivePropertyAsSynchronized(x => x.Nine);

            Ten = settingModel.ToReactivePropertyAsSynchronized(x => x.Ten);

            Eleven = settingModel.ToReactivePropertyAsSynchronized(x => x.Eleven);

            Twelve = settingModel.ToReactivePropertyAsSynchronized(x => x.Twelve);

            Thirteen = settingModel.ToReactivePropertyAsSynchronized(x => x.Thirteen);

            Fourteen = settingModel.ToReactivePropertyAsSynchronized(x => x.Fourteen);

            Fifteen = settingModel.ToReactivePropertyAsSynchronized(x => x.Fifteen);

            Sixteen = settingModel.ToReactivePropertyAsSynchronized(x => x.Sixteen);

            Seventeen = settingModel.ToReactivePropertyAsSynchronized(x => x.Seventeen);

            Eighteen = settingModel.ToReactivePropertyAsSynchronized(x => x.Eighteen);

            Nineteen = settingModel.ToReactivePropertyAsSynchronized(x => x.Nineteen);

            Twenty = settingModel.ToReactivePropertyAsSynchronized(x => x.Twenty);

            Twentyone = settingModel.ToReactivePropertyAsSynchronized(x => x.Twentyone);

            Twentytwo = settingModel.ToReactivePropertyAsSynchronized(x => x.Twentytwo);

            Twentythree = settingModel.ToReactivePropertyAsSynchronized(x => x.Twentythree);

            OpenFileCommand.Subscribe(x => ButtonAction(x));

            PlayCommand.Subscribe(x => PlayAction(x));

            StartCommand.Subscribe(_ => StartAction());

            StopCommand.Subscribe(_ => StopAction());
        }
예제 #4
0
 /// <summary>
 /// コンストラクタで処理を購読
 /// </summary>
 public MainWindowViewModel()
 {
     StartCommand.Subscribe(async() => await StartPreview());
     StopCommand.Subscribe(_ => StopPreview());
     PhotoCommand = IsStop.ObserveHasErrors.CombineLatest(
         InputText.ObserveHasErrors, (x, y) => !x && !y).ToReactiveCommand();
     OptionCommand.Subscribe(_ => IsOption.Value = !IsOption.Value);
     PhotoCommand.Subscribe(_ => Photo());
     IsPhoto = InputText.Select(x => x.Length != 0).ToReactiveProperty();
 }
예제 #5
0
        public AutoTestViewModel(INavigationService navigationService)
        {
            StartCommand.Subscribe(async _ =>
            {
                await ToastTest();
                await LoadingTest();
                await DialogTest();

                await navigationService.NavigateAsync("ResultPage", new NavigationParameters {
                    { "item", TestResults }
                });
            });
        }
예제 #6
0
        internal IoWindowViewModel(ProcessFilesApp context, Action <IApp> work, Action <IApp, Exception> onFailure)
        {
            this.context = context;
            var isInProgress = this.WhenAnyValue(me => me.TokenSource).Select(source => source != null).ObserveOn(Dispatcher.CurrentDispatcher);

            isInProgressHelper = this.WhenAnyValue(me => me.TokenSource).Select(source => source != null).ToProperty(this, me => me.IsInProgress, true);
            OpenFile           = new InputFileBrowseViewModel(isInProgress.Select(f => !f));
            SaveFile           = new OutputFileBrowseViewModel(isInProgress.Select(f => !f), OpenFile);
            worker.DoWork     += (o, e) =>
            {
                work(this);
                e.Result = 0;
            };
            worker.RunWorkerCompleted += (o, e) =>
            {
                if (TokenSource.IsCancellationRequested)
                {
                    Progress = 0;
                }
                else if (e.Error != null)
                {
                    MessageBox.Show(Owner, e.Error.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error);
                    Progress = 0;
                }
                else
                {
                    new ExportCompletedWindow(new ExportCompletedViewModel(Title, SaveFile.File))
                    {
                        Owner = Owner,
                        WindowStartupLocation = WindowStartupLocation.CenterOwner
                    }.ShowDialog();
                }
                TokenSource = null;
                if (e.Error != null)
                {
                    onFailure?.Invoke(this, e.Error);
                }
            };
            worker.ProgressChanged += (o, e) => Progress = e.ProgressPercentage;
            StartCommand            = ReactiveCommand.Create(this.WhenAnyValue(me => me.OpenFile.File, me => me.SaveFile.File, me => me.TokenSource)
                                                             .Select(CanStart).ObserveOn(Dispatcher.CurrentDispatcher));
            CancelCommand = ReactiveCommand.Create(isInProgress);
            StartCommand.Subscribe(_ =>
            {
                TokenSource = new CancellationTokenSource();
                worker.RunWorkerAsync();
            });
            CancelCommand.Subscribe(_ => Cancel());
            isInProgress.Where(f => f).Subscribe(source => CancellationToken = TokenSource.Token);
            this.WhenAnyValue(me => me.Title).Where(title => !string.IsNullOrEmpty(title)).Subscribe(title => Owner.Title = title);
        }
        public ReactiveTimerViewModel(ReactiveTimerModel _model)
        {
            Model = _model.AddTo(DisposeCollection);

            ReadOnlyReactiveTimer =
                Observable.Merge(
                    Model.ReactiveTimer,
                    Model.ChangeStop().Select(_ => (long)0)
                    ).ToReadOnlyReactivePropertySlim()
                .AddTo(DisposeCollection);

            StartCommand = Model.CanStart().ToReactiveCommand().AddTo(DisposeCollection);
            StartCommand.Subscribe(start).AddTo(DisposeCollection);

            PauseCommand = Model.CanPause().ToReactiveCommand().AddTo(DisposeCollection);
            PauseCommand.Subscribe(pause).AddTo(DisposeCollection);

            StopCommand = Model.CanStop().ToReactiveCommand().AddTo(DisposeCollection);
            StopCommand.Subscribe(stop).AddTo(DisposeCollection);
        }