public MainViewModel()
        {
            this.text = @"The Plesiosaurus lived during the Mesozoic era, in the Jurassic period. Its named means 'near lizard', derived from the Greek words plesios (near to) and sauros (lizard). The first Plesiosaurus fossils were found in England by Mary Anning in 1821.

The Eryops was a primitive amphibian alive during the Permian period (Palaeozoic era) around 270 million years ago. It was part of the Eryopidae family. Its named means 'drawn-out face' due to the fact that most of its skull is in front of its eyes.";

            var canRemoveEras = this
                                .WhenAnyValue(x => x.Text)
                                .Select(text => text != null && eras.Any(era => text.Contains(era.ToString())));

            this.removeErasCommand = ReactiveCommand.Create(this.RemoveEras, canRemoveEras);

            var canRemovePeriods = this
                                   .WhenAnyValue(x => x.Text)
                                   .Select(text => text != null && periods.Any(period => text.Contains(period.ToString())));

            this.removePeriodsCommand = ReactiveCommand.Create(this.RemovePeriods, canRemovePeriods);

            this.removeBothCommand = ReactiveCommand.CreateCombined(
                new[]
            {
                this.removeErasCommand,
                this.removePeriodsCommand
            });
        }
Beispiel #2
0
        public SettingsViewModel(IScreen hostScreen)
            : base(hostScreen)
        {
            _settingsProvider = Locator.Current.GetRequiredService <ISettingsProvider>();
            _partsRepository  = Locator.Current.GetRequiredService <IPartRepository>();

            SaveSettings = ReactiveCommand.CreateFromTask(execute: ExecuteSaveSettings);

            var canAddCustomField = this.WhenAnyValue(vm => vm.NewCustomField, value =>
            {
                return(!string.IsNullOrWhiteSpace(value) &&
                       !CustomFields.Any(vm => vm.Value.Equals(value, StringComparison.Ordinal)));
            });

            AddCustomField = ReactiveCommand.Create(execute: ExecuteAddCustomField, canExecute: canAddCustomField);

            ImportCustomFields = ReactiveCommand.CreateCombined(new[]
            {
                SaveSettings,
                ReactiveCommand.CreateFromTask(
                    execute: ImportCustomFieldsAsync),
            });

            GoBack = ReactiveCommand.CreateFromTask(GoBackAsync);
        }
        public void ExecuteExecutesAllChildCommands()
        {
            var child1        = ReactiveCommand.Create(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var child2        = ReactiveCommand.Create(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var child3        = ReactiveCommand.Create(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var childCommands = new[] { child1, child2, child3 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands, outputScheduler: ImmediateScheduler.Instance);

            fixture.IsExecuting.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var isExecuting).Subscribe();
            child1.IsExecuting.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var child1IsExecuting).Subscribe();
            child2.IsExecuting.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var child2IsExecuting).Subscribe();
            child3.IsExecuting.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var child3IsExecuting).Subscribe();

            fixture.Execute().Subscribe();

            Assert.Equal(3, isExecuting.Count);
            Assert.False(isExecuting[0]);
            Assert.True(isExecuting[1]);
            Assert.False(isExecuting[2]);

            Assert.Equal(3, child1IsExecuting.Count);
            Assert.False(child1IsExecuting[0]);
            Assert.True(child1IsExecuting[1]);
            Assert.False(child1IsExecuting[2]);

            Assert.Equal(3, child2IsExecuting.Count);
            Assert.False(child2IsExecuting[0]);
            Assert.True(child2IsExecuting[1]);
            Assert.False(child2IsExecuting[2]);

            Assert.Equal(3, child3IsExecuting.Count);
            Assert.False(child3IsExecuting[0]);
            Assert.True(child3IsExecuting[1]);
            Assert.False(child3IsExecuting[2]);
        }
Beispiel #4
0
        public SettingsViewModel(IScreen screen, ISettingsManager settingsManager, IVersionManager versionManager, IGameManager gameManager)
        {
            HostScreen       = screen;
            _settingsManager = settingsManager;
            _versionManager  = versionManager;
            _gameManager     = gameManager;

            ApiKey                      = _settingsManager.Settings.ApiKey;
            AuthUser                    = _settingsManager.Settings.AuthUser;
            AuthPass                    = _settingsManager.Settings.AuthPass;
            Endpoint                    = _settingsManager.Settings.Endpoint;
            PbxFolder                   = _settingsManager.Settings.PinballXFolder;
            SyncStarred                 = _settingsManager.Settings.SyncStarred;
            DownloadOnStartup           = _settingsManager.Settings.DownloadOnStartup;
            PatchTableScripts           = _settingsManager.Settings.PatchTableScripts;
            MinimizeToTray              = _settingsManager.Settings.MinimizeToTray;
            ReformatXml                 = _settingsManager.Settings.ReformatXml;
            XmlFileVP                   = _settingsManager.Settings.XmlFile[Platform.VP];
            StartWithWindows            = _settingsManager.Settings.StartWithWindows;
            DownloadOrientation         = _settingsManager.Settings.DownloadOrientation;
            DownloadOrientationFallback = _settingsManager.Settings.DownloadOrientationFallback;
            DownloadLighting            = _settingsManager.Settings.DownloadLighting;
            DownloadLightingFallback    = _settingsManager.Settings.DownloadLightingFallback;

            SaveSettings = ReactiveCommand.CreateFromTask(_ => Save());
            SaveSettings.IsExecuting.ToProperty(this, vm => vm.IsValidating, out _isValidating);
            SaveSettings.ThrownExceptions.Subscribe(e =>
            {
                // todo either remove or treat correctly.
                Console.WriteLine("Exception while saving settings.");
            });

            ChooseFolder  = ReactiveCommand.Create(OpenFolderDialog);
            CloseSettings = ReactiveCommand.CreateCombined(new[] { HostScreen.Router.NavigateBack });

            _settingsManager.WhenAnyValue(sm => sm.Settings.IsFirstRun).ToProperty(this, vm => vm.IsFirstRun, out _isFirstRun);
            _settingsManager.WhenAnyValue(sm => sm.CanCancel)
            .CombineLatest(screen.Router.NavigationStack.Changed, (canCancel, _) => canCancel || screen.Router.NavigationStack.Count > 1)
            .DistinctUntilChanged()
            .StartWith(true)
            .ToProperty(this, vm => vm.CanCancel, out _canCancel);

            OrientationSettings.Add(new OrientationSetting("Portrait", SettingsManager.Orientation.Portrait));
            OrientationSettings.Add(new OrientationSetting("Landscape", SettingsManager.Orientation.Landscape));
            OrientationSettings.Add(new OrientationSetting("Universal (VP10)", SettingsManager.Orientation.Universal));
            LightingSettings.Add(new LightingSetting("Day", SettingsManager.Lighting.Day));
            LightingSettings.Add(new LightingSetting("Night", SettingsManager.Lighting.Night));
            LightingSettings.Add(new LightingSetting("Universal (VP10)", SettingsManager.Lighting.Universal));
            XmlFilesVP.Add("Visual Pinball");
            XmlFilesVP.Add("Vpdb");
            OrientationFallbackSettings.Add(new OrientationSetting("Same *", SettingsManager.Orientation.Same));
            OrientationFallbackSettings.Add(new OrientationSetting("Portrait", SettingsManager.Orientation.Portrait));
            OrientationFallbackSettings.Add(new OrientationSetting("Landscape", SettingsManager.Orientation.Landscape));
            OrientationFallbackSettings.Add(new OrientationSetting("Any", SettingsManager.Orientation.Any));
            LightingFallbackSettings.Add(new LightingSetting("Same *", SettingsManager.Lighting.Same));
            LightingFallbackSettings.Add(new LightingSetting("Day", SettingsManager.Lighting.Day));
            LightingFallbackSettings.Add(new LightingSetting("Night", SettingsManager.Lighting.Night));
            LightingFallbackSettings.Add(new LightingSetting("Any", SettingsManager.Lighting.Any));
        }
Beispiel #5
0
        public QuestionPageViewModel(int questionId, IApplicationViewModel application = null, INetworkApi networkApi = null)
            : base(application)
        {
            NetworkApi    = networkApi ?? Api <INetworkApi>();
            LoadAnswers   = ReactiveCommand.CreateFromTask(LoadAnswersImpl, outputScheduler: RxApp.MainThreadScheduler);
            LoadQuestions = ReactiveCommand.CreateFromTask(LoadQuestionsImpl, outputScheduler: RxApp.MainThreadScheduler);
            Load          = ReactiveCommand.CreateCombined(new[] { LoadQuestions, LoadAnswers });

            Question = new QuestionDetailViewModel(questionId);
        }
Beispiel #6
0
        public TimebaseVM()
        {
            Activator = new ViewModelActivator();
            Protocol  = new TimebaseProtocol(null);

            Offset       = new ScopeCommand <double>(this, Protocol.Offset, "0.0");
            Offset.Value = SI.Parse("0V");
            Scale        = new ScopeCommand <double>(this, Protocol.Scale, "1u".ToReal()); // 1us/div
            Scale.Value  = SI.Parse("1u");
            Mode         = new ScopeCommand <string>(this, Protocol.Mode, "MAIN");

            AllCommands = new List <IScopeCommand>()
            {
                Offset, Scale, Mode,
            };

            var GetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Retrieving all TIMEBASE values from device ---------"));

            GetAll = ReactiveCommand
                     .CreateCombined(new[]
            {
                // TODO: Should also get items that are dependencies of these
                //   like sample rate, memory depth, etc.
                GetAllMessage,
                Offset.GetCommand,
                Scale.GetCommand,
                Mode.GetCommand,
            });

            var SetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Setting all TIMEBASE values on device ---------"));

            SetAll = ReactiveCommand.CreateCombined(new[]
            {
                SetAllMessage,
                Offset.SetCommand,
                Scale.SetCommand,
                Mode.SetCommand,
            });

            this.WhenActivated(disposables =>
            {
                this.HandleActivation();

                Disposable
                .Create(() => this.HandleDeactivation())
                .DisposeWith(disposables);

                foreach (var scopeCommand in AllCommands)
                {
                    scopeCommand.WhenActivated(disposables);
                }
            });
        }
        public void CanExecuteIsFalseIfParentCanExecuteIsFalse()
        {
            var child1        = ReactiveCommand.Create(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var child2        = ReactiveCommand.Create(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var childCommands = new[] { child1, child2 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands, Observables.False, ImmediateScheduler.Instance);

            fixture.CanExecute.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var canExecute).Subscribe();

            Assert.Equal(1, canExecute.Count);
            Assert.False(canExecute[0]);
        }
        public void CanExecuteIsFalseIfAnyChildCannotExecute()
        {
            var child1        = ReactiveCommand.Create(() => Observable.Return(Unit.Default));
            var child2        = ReactiveCommand.Create(() => Observable.Return(Unit.Default), Observable.Return(false));
            var childCommands = new[] { child1, child2 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands);
            var canExecute    = fixture
                                .CanExecute
                                .CreateCollection();

            Assert.Equal(1, canExecute.Count);
            Assert.False(canExecute[0]);
        }
        public void CanExecuteIsFalseIfAnyChildCannotExecute()
        {
            var child1        = ReactiveCommand.Create(() => Observables.Unit);
            var child2        = ReactiveCommand.Create(() => Observables.Unit, Observables.False);
            var childCommands = new[] { child1, child2 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands);
            var canExecute    = fixture
                                .CanExecute
                                .CreateCollection(scheduler: ImmediateScheduler.Instance);

            Assert.Equal(1, canExecute.Count);
            Assert.False(canExecute[0]);
        }
Beispiel #10
0
        public void CanExecuteIsFalseIfParentCanExecuteIsFalse()
        {
            var child1        = ReactiveCommand.Create(() => Observables.Unit);
            var child2        = ReactiveCommand.Create(() => Observables.Unit);
            var childCommands = new[] { child1, child2 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands, Observables.False);
            var canExecute    = fixture
                                .CanExecute
                                .CreateCollection();

            Assert.Equal(1, canExecute.Count);
            Assert.False(canExecute[0]);
        }
        public void ExecuteTicksErrorsInAnyChildCommandThroughThrownExceptions()
        {
            var child1        = ReactiveCommand.CreateFromObservable(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var child2        = ReactiveCommand.CreateFromObservable(() => Observable.Throw <Unit>(new InvalidOperationException("oops")), outputScheduler: ImmediateScheduler.Instance);
            var childCommands = new[] { child1, child2 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands, outputScheduler: ImmediateScheduler.Instance);

            fixture.ThrownExceptions.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var thrownExceptions).Subscribe();

            fixture.Execute().Subscribe(_ => { }, _ => { });

            Assert.Equal(1, thrownExceptions.Count);
            Assert.Equal("oops", thrownExceptions[0].Message);
        }
        public void ExceptionsAreDeliveredOnOutputScheduler() =>
        new TestScheduler().With(
            scheduler =>
        {
            var child           = ReactiveCommand.CreateFromObservable(() => Observable.Throw <Unit>(new InvalidOperationException("oops")));
            var childCommands   = new[] { child };
            var fixture         = ReactiveCommand.CreateCombined(childCommands, outputScheduler: scheduler);
            Exception?exception = null;
            fixture.ThrownExceptions.Subscribe(ex => exception = ex);
            fixture.Execute().Subscribe(_ => { }, _ => { });

            Assert.Null(exception);
            scheduler.Start();
            Assert.IsType <InvalidOperationException>(exception);
        });
        public void CanExecuteTicksFailuresThroughThrownExceptions()
        {
            var canExecuteSubject = new Subject <bool>();
            var child1            = ReactiveCommand.Create(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var child2            = ReactiveCommand.Create(() => Observables.Unit, outputScheduler: ImmediateScheduler.Instance);
            var childCommands     = new[] { child1, child2 };
            var fixture           = ReactiveCommand.CreateCombined(childCommands, canExecuteSubject, ImmediateScheduler.Instance);

            fixture.ThrownExceptions.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var thrownExceptions).Subscribe();

            canExecuteSubject.OnError(new InvalidOperationException("oops"));

            Assert.Equal(1, thrownExceptions.Count);
            Assert.Equal("oops", thrownExceptions[0].Message);
        }
        public void ExecuteTicksThroughTheResults()
        {
            var child1        = ReactiveCommand.CreateFromObservable(() => Observable.Return(1), outputScheduler: ImmediateScheduler.Instance);
            var child2        = ReactiveCommand.CreateFromObservable(() => Observable.Return(2), outputScheduler: ImmediateScheduler.Instance);
            var childCommands = new[] { child1, child2 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands, outputScheduler: ImmediateScheduler.Instance);

            fixture.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var results).Subscribe();

            fixture.Execute().Subscribe();

            Assert.Equal(1, results.Count);
            Assert.Equal(2, results[0].Count);
            Assert.Equal(1, results[0][0]);
            Assert.Equal(2, results[0][1]);
        }
Beispiel #15
0
        public void CanExecuteTicksFailuresInChildCanExecuteThroughThrownExceptions()
        {
            var canExecuteSubject = new Subject <bool>();
            var child1            = ReactiveCommand.Create(() => Observables.Unit);
            var child2            = ReactiveCommand.Create(() => Observables.Unit, canExecuteSubject);
            var childCommands     = new[] { child1, child2 };
            var fixture           = ReactiveCommand.CreateCombined(childCommands);
            var thrownExceptions  = fixture
                                    .ThrownExceptions
                                    .CreateCollection();

            canExecuteSubject.OnError(new InvalidOperationException("oops"));

            Assert.Equal(1, thrownExceptions.Count);
            Assert.Equal("oops", thrownExceptions[0].Message);
        }
        public void CombinedCommandsShouldReflectParentCanExecute()
        {
            var subj1      = new Subject <bool>();
            var cmd1       = new ReactiveCommand(subj1);
            var subj2      = new Subject <bool>();
            var cmd2       = new ReactiveCommand(subj2);
            var cmd3       = new ReactiveCommand();
            var parentSubj = new Subject <bool>();


            // Initial state for ReactiveCommands is to be executable
            var fixture          = ReactiveCommand.CreateCombined(parentSubj, cmd1, cmd2, cmd3);
            var canExecuteOutput = fixture.CanExecuteObservable.CreateCollection();

            Assert.True(fixture.CanExecute(null));
            Assert.Equal(1, canExecuteOutput.Count);

            parentSubj.OnNext(false);

            // 1 is false, 2 is true
            subj1.OnNext(false);
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(2, canExecuteOutput.Count);
            Assert.Equal(false, canExecuteOutput[1]);

            // 1 is false, 2 is false
            subj2.OnNext(false);
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(2, canExecuteOutput.Count);

            // 1 is true, 2 is false
            subj1.OnNext(true);
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(2, canExecuteOutput.Count);

            // 1 is true, 2 is true, but it doesn't matter because
            // parent is still false
            subj2.OnNext(true);
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(2, canExecuteOutput.Count);

            // Parent is finally true, mark it true
            parentSubj.OnNext(true);
            Assert.True(fixture.CanExecute(null));
            Assert.Equal(3, canExecuteOutput.Count);
            Assert.Equal(true, canExecuteOutput[2]);
        }
Beispiel #17
0
        public void CombinedCommandsShouldFireChildCommands()
        {
            var cmd1 = ReactiveCommand.Create();
            var cmd2 = ReactiveCommand.Create();
            var cmd3 = ReactiveCommand.Create();

            var output = new[] { cmd1, cmd2, cmd3, }.Merge().CreateCollection();

            var fixture = ReactiveCommand.CreateCombined(cmd1, cmd2, cmd3);

            Assert.True(fixture.CanExecute(null));
            Assert.Equal(0, output.Count);

            fixture.Execute(42);

            Assert.Equal(3, output.Count);
        }
Beispiel #18
0
        public void CombinedCommandsShouldBeInactiveOnAsyncInflightOps()
        {
            (new TestScheduler()).With(sched => {
                var cmd1 = ReactiveCommand.CreateAsyncObservable(Observable.Return(true),
                                                                 x => Observable.Return(x).Delay(TimeSpan.FromMilliseconds(100), sched));
                var cmd2 = ReactiveCommand.CreateAsyncObservable(Observable.Return(true),
                                                                 x => Observable.Return(x).Delay(TimeSpan.FromMilliseconds(300), sched));

                var cmd3 = ReactiveCommand.Create();

                var result1 = cmd1.CreateCollection();

                var result2 = cmd2.CreateCollection();

                var fixture          = ReactiveCommand.CreateCombined(cmd1, cmd2, cmd3);
                var canExecuteOutput = fixture.CanExecuteObservable.CreateCollection();

                Assert.True(fixture.CanExecute(null));
                Assert.Equal(0, canExecuteOutput.Count);

                fixture.Execute(42);

                // NB: The first two canExecuteOutputs are because of the initial value
                // that shows up because we finally ran the scheduler
                sched.AdvanceToMs(50.0);
                Assert.Equal(3, canExecuteOutput.Count);
                Assert.Equal(true, canExecuteOutput[1]);
                Assert.Equal(false, canExecuteOutput[2]);
                Assert.Equal(false, fixture.CanExecute(null));
                Assert.Equal(0, result1.Count);
                Assert.Equal(0, result2.Count);

                sched.AdvanceToMs(250.0);
                Assert.Equal(3, canExecuteOutput.Count);
                Assert.Equal(false, fixture.CanExecute(null));
                Assert.Equal(1, result1.Count);
                Assert.Equal(0, result2.Count);

                sched.AdvanceToMs(500.0);
                Assert.Equal(4, canExecuteOutput.Count);
                Assert.Equal(true, canExecuteOutput[3]);
                Assert.Equal(true, fixture.CanExecute(null));
                Assert.Equal(1, result1.Count);
                Assert.Equal(1, result2.Count);
            });
        }
Beispiel #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExportImageViewModel"/> class.
        /// </summary>
        /// <param name="dialogService">Dialog service for opening dialogs from view model.</param>
        /// <param name="height">Default height of the image.</param>
        /// <param name="width">Default width of the image.</param>
        /// <param name="dpi">Default DPI of the image.</param>
        /// <param name="plotModel">Plot model to export</param>
        public ExportImageViewModel(IDialogService dialogService, int height = 0, int width = 0, int dpi = 0, PlotModel plotModel = null)
        {
            this.dialogService = dialogService;
            Height             = height;
            Width = width;
            Dpi   = dpi;

            ExportCommand = ReactiveCommand.CreateCombined(new [] { SuccessCommand },
                                                           this.WhenAnyValue(x => x.FilePath, x => x.Height, x => x.Width, x => x.Dpi)
                                                           .Select(
                                                               x => !string.IsNullOrWhiteSpace(x.Item1) &&
                                                               x.Item2 >= 0 && x.Item3 >= 0 && x.Item4 >= 0));

            BrowseFilesCommand = ReactiveCommand.Create(() => FilePath = this.dialogService.SaveFile(".png", @"Png Files (*.png)|*.png"));

            SuccessCommand.Where(_ => plotModel != null).Subscribe(_ => ExportPlotModel(plotModel));
        }
Beispiel #20
0
        public void ResultIsTickedThroughSpecifiedScheduler()
        {
            (new TestScheduler()).With(sched => {
                var child1        = ReactiveCommand.Create(() => Observable.Return(1));
                var child2        = ReactiveCommand.Create(() => Observable.Return(2));
                var childCommands = new[] { child1, child2 };
                var fixture       = ReactiveCommand.CreateCombined(childCommands, outputScheduler: sched);
                var results       = fixture
                                    .CreateCollection();

                fixture.Execute().Subscribe();
                Assert.Empty(results);

                sched.AdvanceByMs(1);
                Assert.Equal(1, results.Count);
            });
        }
Beispiel #21
0
        public void ExecuteTicksThroughTheResults()
        {
            var child1        = ReactiveCommand.CreateFromObservable(() => Observable.Return(1));
            var child2        = ReactiveCommand.CreateFromObservable(() => Observable.Return(2));
            var childCommands = new[] { child1, child2 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands);

            var results = fixture
                          .CreateCollection();

            fixture.Execute().Subscribe();

            Assert.Equal(1, results.Count);
            Assert.Equal(2, results[0].Count);
            Assert.Equal(1, results[0][0]);
            Assert.Equal(2, results[0][1]);
        }
Beispiel #22
0
        public PullRequestDiffViewController(
            string username,
            string repository,
            int pullRequestId,
            string path,
            string patch,
            string commit,
            IApplicationService applicationService         = null,
            INetworkActivityService networkActivityService = null,
            IMarkdownService markdownService = null)
            : base(false)
        {
            _applicationService     = applicationService ?? Locator.Current.GetService <IApplicationService>();
            _networkActivityService = networkActivityService ?? Locator.Current.GetService <INetworkActivityService>();
            _markdownService        = markdownService ?? Locator.Current.GetService <IMarkdownService>();
            _username      = username;
            _repository    = repository;
            _pullRequestId = pullRequestId;
            _path          = path;
            _patch         = patch;
            _commit        = commit;

            Title = string.IsNullOrEmpty(_path) ? "Diff" : System.IO.Path.GetFileName(_path);

            var loadComments = ReactiveCommand.CreateFromTask(
                _ => _applicationService.GitHubClient.PullRequest.ReviewComment.GetAll(_username, _repository, _pullRequestId));

            loadComments
            .ThrownExceptions
            .Select(error => new UserError("Unable to load comments.", error))
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            loadComments
            .Subscribe(comments => _comments.Reset(comments));

            var loadAll = ReactiveCommand.CreateCombined(new[] { loadComments });

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeReactiveCommand(loadAll);
        }
Beispiel #23
0
        public void ExecuteTicksErrorsInAnyChildCommandThroughThrownExceptions()
        {
            var child1           = ReactiveCommand.CreateFromObservable(() => Observables.Unit);
            var child2           = ReactiveCommand.CreateFromObservable(() => Observable.Throw <Unit>(new InvalidOperationException("oops")));
            var childCommands    = new[] { child1, child2 };
            var fixture          = ReactiveCommand.CreateCombined(childCommands);
            var thrownExceptions = fixture
                                   .ThrownExceptions
                                   .CreateCollection();

            fixture
            .Execute()
            .Subscribe(
                _ => { },
                _ => { });

            Assert.Equal(1, thrownExceptions.Count);
            Assert.Equal("oops", thrownExceptions[0].Message);
        }
Beispiel #24
0
        public void ExecuteExecutesAllChildCommands()
        {
            var child1        = ReactiveCommand.Create(() => Observables.Unit);
            var child2        = ReactiveCommand.Create(() => Observables.Unit);
            var child3        = ReactiveCommand.Create(() => Observables.Unit);
            var childCommands = new[] { child1, child2, child3 };
            var fixture       = ReactiveCommand.CreateCombined(childCommands);

            var isExecuting = fixture
                              .IsExecuting
                              .CreateCollection();
            var child1IsExecuting = child1
                                    .IsExecuting
                                    .CreateCollection();
            var child2IsExecuting = child2
                                    .IsExecuting
                                    .CreateCollection();
            var child3IsExecuting = child3
                                    .IsExecuting
                                    .CreateCollection();

            fixture.Execute().Subscribe();

            Assert.Equal(3, isExecuting.Count);
            Assert.False(isExecuting[0]);
            Assert.True(isExecuting[1]);
            Assert.False(isExecuting[2]);

            Assert.Equal(3, child1IsExecuting.Count);
            Assert.False(child1IsExecuting[0]);
            Assert.True(child1IsExecuting[1]);
            Assert.False(child1IsExecuting[2]);

            Assert.Equal(3, child2IsExecuting.Count);
            Assert.False(child2IsExecuting[0]);
            Assert.True(child2IsExecuting[1]);
            Assert.False(child2IsExecuting[2]);

            Assert.Equal(3, child3IsExecuting.Count);
            Assert.False(child3IsExecuting[0]);
            Assert.True(child3IsExecuting[1]);
            Assert.False(child3IsExecuting[2]);
        }
Beispiel #25
0
        public void CombinedCommandsShouldReflectCanExecuteOfChildren()
        {
            var subj1 = new Subject <bool>();
            var cmd1  = ReactiveCommand.Create(subj1);
            var subj2 = new Subject <bool>();
            var cmd2  = ReactiveCommand.Create(subj2);
            var cmd3  = ReactiveCommand.Create();

            // Initial state for ReactiveCommands is to be executable
            var fixture          = ReactiveCommand.CreateCombined(cmd1, cmd2, cmd3);
            var canExecuteOutput = fixture.CanExecuteObservable.CreateCollection();

            // cmd1 and cmd2 are ??? so, result is false
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(1, canExecuteOutput.Count);

            // 1 is false, 2 is true
            subj1.OnNext(false);
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(1, canExecuteOutput.Count);
            Assert.Equal(false, canExecuteOutput[0]);

            // 1 is false, 2 is false
            subj2.OnNext(false);
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(1, canExecuteOutput.Count);

            // 1 is true, 2 is false
            subj1.OnNext(true);
            Assert.False(fixture.CanExecute(null));
            Assert.Equal(1, canExecuteOutput.Count);

            // 1 is true, 2 is true
            subj2.OnNext(true);
            Assert.True(fixture.CanExecute(null));
            Assert.Equal(2, canExecuteOutput.Count);
            Assert.Equal(true, canExecuteOutput[1]);
        }
        public ScoreBoardViewModel()
        {
            this.WhenInitialized(disposables =>
            {
                var canStartNewGame =
                    Observable.CombineLatest(
                        ScoreHomeTeam.CanDecrement,
                        ScoreVisitors.CanDecrement,
                        (canHomeDecr, canVisitorsDecr) => canHomeDecr || canVisitorsDecr);

                NewGameCommand =
                    ReactiveCommand.CreateCombined(
                        new[]
                {
                    ScoreHomeTeam.ResetScoreCommand,
                    ScoreVisitors.ResetScoreCommand
                },
                        canStartNewGame)
                    .DisposeWith(disposables);

                CloseCommand = ReactiveCommand.Create(() => Unit.Default).DisposeWith(disposables);
            });
        }
Beispiel #27
0
        public TriggerVM()
        {
            Activator = new ViewModelActivator();
            Protocol  = new TriggerProtocol(null);

            Sweep      = new ScopeCommand <string>(this, Protocol.Sweep, "AUTO");
            Mode       = new ScopeCommand <string>(this, Protocol.Mode, nameof(ModeStringOptions.Edge));
            EdgeSource = new ScopeCommand <string>(this, Protocol.Edge.Source, "CHAN1");
            EdgeSlope  = new ScopeCommand <string>(this, Protocol.Edge.Slope, "POS");
            EdgeLevel  = new ScopeCommand <double>(this, Protocol.Edge.Level, "0");

            AllScopeCommands = new List <IScopeCommand>()
            {
                Sweep, Mode, EdgeSource, EdgeSlope, EdgeLevel,
            };

            var GetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Retrieving all TRIGGER values from device ---------"));

            GetAll = ReactiveCommand.CreateCombined(new[]
            {
                GetAllMessage,
                Sweep.GetCommand,
                Mode.GetCommand,
                EdgeSource.GetCommand,
                EdgeSlope.GetCommand,
                EdgeLevel.GetCommand,
            });

            var SetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Setting all TRIGGER values on device ---------"));

            SetAll = ReactiveCommand.CreateCombined(new[]
            {
                SetAllMessage,
                Sweep.SetCommand,
                Mode.SetCommand,
                EdgeSource.SetCommand,
                EdgeSlope.SetCommand,
                EdgeLevel.SetCommand,
            });


            this.WhenActivated(disposables =>
            {
                this.HandleActivation();

                Disposable
                .Create(() => this.HandleDeactivation())
                .DisposeWith(disposables);

                foreach (var scopeCommand in AllScopeCommands)
                {
                    scopeCommand.WhenActivated(disposables);
                }

                // Make visible the panel that corresponds to the selected trigger mode
                this.WhenAnyValue(
                    x => x.Mode.Value,
                    x => x == nameof(ModeStringOptions.Edge))
                .ToPropertyEx(this, x => x.IsEdgeMode);

                // Range of edge level trigger is:
                //   (-5x Vertical Scale - Offset) to (+5x Vertical Scale - Offset)
                Timebase.WhenAnyValue(
                    vm => vm.Scale.Value,
                    vm => vm.Offset.Value,
                    (x, y) => {
                    Protocol.Edge.SetLevelRange(x, y);
                    return(0.0);
                });
            });
        }