Exemplo n.º 1
0
        public ErrorDisplayVm(
            ISelected parent,
            IObservable <IConfigurationState> state)
        {
            DisplayedObject = parent;

            _state = state
                     .ToGuiProperty(this, nameof(State), ConfigurationState.Success, deferSubscription: true);

            ErrorVM = new ErrorVM("Error", backAction: () =>
            {
                DisplayedObject = parent;
            });

            GoToErrorCommand = NoggogCommand.CreateFromObject(
                objectSource: state.Select(x => x.RunnableState),
                canExecute: x => x.Failed,
                execute: x => DisplayedObject = ErrorVM,
                disposable: this);

            parent.WhenAnyValue(x => x.IsSelected)
            .DistinctUntilChanged()
            .Where(x => x)
            .Subscribe(_ =>
            {
                DisplayedObject = parent;
            })
            .DisposeWith(this);

            state.Select(x => x.RunnableState)
            .Subscribe(state =>
            {
                if (state.Failed)
                {
                    ErrorVM.String = state.Reason;
                }
                else
                {
                    ErrorVM.String = null;
                }
            })
            .DisposeWith(this);
        }
 public ConfirmationPanelControllerVm()
 {
     DiscardActionCommand = NoggogCommand.CreateFromObjectz(
         objectSource: this.WhenAnyValue(x => x.TargetConfirmation),
         canExecute: target =>
     {
         if (target == null)
         {
             return(Observable.Return(false));
         }
         if (target.DiscardActionCommand == null)
         {
             return(Observable.Return(true));
         }
         return(target.DiscardActionCommand.CanExecute);
     },
         execute: x =>
     {
         (x?.DiscardActionCommand as ICommand)?.Execute(Unit.Default);
         TargetConfirmation = null;
     },
         disposable: this);
     ConfirmActionCommand = NoggogCommand.CreateFromObjectz(
         objectSource: this.WhenAnyValue(x => x.TargetConfirmation),
         canExecute: target =>
     {
         if (target == null)
         {
             return(Observable.Return(false));
         }
         return(target.ConfirmActionCommand.CanExecute);
     },
         execute: x =>
     {
         (x?.ConfirmActionCommand as ICommand)?.Execute(Unit.Default);
         TargetConfirmation = null;
     },
         disposable: this);
 }
Exemplo n.º 3
0
        public ErrorVM(string title, string?str = null, Action?backAction = null)
        {
            Title       = title;
            String      = str;
            BackAction  = backAction;
            BackCommand = NoggogCommand.CreateFromObject(
                objectSource: this.WhenAnyValue(x => x.BackAction),
                canExecute: x => x != null,
                execute: x =>
            {
                x?.Invoke();
            },
                disposable: this);

            // Go back automatically if things no longer apply
            this.WhenAnyValue(x => x.String)
            .DistinctUntilChanged()
            .Where(x => x.IsNullOrWhitespace())
            .Subscribe(_ =>
            {
                BackAction?.Invoke();
            })
            .DisposeWith(this);
        }
Exemplo n.º 4
0
        public ProfileVersioning(
            ILogger logger,
            IProfileNameProvider nameProvider,
            INewestProfileLibraryVersionsVm libs)
        {
            ActiveVersioning = Observable.CombineLatest(
                this.WhenAnyValue(x => x.MutagenVersioning),
                this.WhenAnyValue(x => x.ManualMutagenVersion),
                libs.WhenAnyValue(x => x.NewestMutagenVersion),
                this.WhenAnyValue(x => x.SynthesisVersioning),
                this.WhenAnyValue(x => x.ManualSynthesisVersion),
                libs.WhenAnyValue(x => x.NewestSynthesisVersion),
                (mutaVersioning, mutaManual, newestMuta, synthVersioning, synthManual, newestSynth) =>
            {
                return(new ActiveNugetVersioning(
                           new NugetsToUse("Mutagen", mutaVersioning, mutaManual ?? newestMuta ?? string.Empty, newestMuta),
                           new NugetsToUse("Synthesis", synthVersioning, synthManual ?? newestSynth ?? string.Empty, newestSynth)));
            })
                               .Do(x => logger.Information("Swapped profile {Nickname} to {Versioning}", nameProvider.Name, x))
                               .ObserveOnGui()
                               .Replay(1)
                               .RefCount();

            // Set manual if empty
            libs.WhenAnyValue(x => x.NewestMutagenVersion)
            .Subscribe(x =>
            {
                if (ManualMutagenVersion == null)
                {
                    ManualMutagenVersion = x;
                }
            })
            .DisposeWith(this);
            libs.WhenAnyValue(x => x.NewestSynthesisVersion)
            .Subscribe(x =>
            {
                if (ManualSynthesisVersion == null)
                {
                    ManualSynthesisVersion = x;
                }
            })
            .DisposeWith(this);

            UpdateMutagenManualToLatestCommand = NoggogCommand.CreateFromObject(
                objectSource: libs.WhenAnyValue(x => x.NewestMutagenVersion)
                .ObserveOnGui(),
                canExecute: v =>
            {
                return(Observable.CombineLatest(
                           this.WhenAnyValue(x => x.MutagenVersioning),
                           this.WhenAnyValue(x => x.ManualMutagenVersion),
                           v,
                           (versioning, manual, latest) =>
                {
                    if (versioning != NugetVersioningEnum.Manual)
                    {
                        return false;
                    }
                    return latest != null && latest != manual;
                })
                       .ObserveOnGui());
            },
                execute: v => ManualMutagenVersion = v ?? string.Empty,
                disposable: this);
            UpdateSynthesisManualToLatestCommand = NoggogCommand.CreateFromObject(
                objectSource: libs.WhenAnyValue(x => x.NewestSynthesisVersion)
                .ObserveOnGui(),
                canExecute: v =>
            {
                return(Observable.CombineLatest(
                           this.WhenAnyValue(x => x.SynthesisVersioning),
                           this.WhenAnyValue(x => x.ManualSynthesisVersion),
                           v,
                           (versioning, manual, latest) =>
                {
                    if (versioning != NugetVersioningEnum.Manual)
                    {
                        return false;
                    }
                    return latest != null && latest != manual;
                })
                       .ObserveOnGui());
            },
                execute: v => ManualSynthesisVersion = v ?? string.Empty,
                disposable: this);

            UpdateProfileNugetVersionCommand = CommandExt.CreateCombinedAny(
                this.UpdateMutagenManualToLatestCommand,
                this.UpdateSynthesisManualToLatestCommand);
        }
Exemplo n.º 5
0
        public GitNugetTargetingVm(
            ILogger logger,
            INewestProfileLibraryVersionsVm newest,
            IProfileVersioning versioning)
        {
            UpdateMutagenManualToLatestCommand = NoggogCommand.CreateFromObject(
                objectSource: newest.WhenAnyValue(x => x.NewestMutagenVersion),
                canExecute: v =>
            {
                return(Observable.CombineLatest(
                           this.WhenAnyValue(x => x.ManualMutagenVersion),
                           v,
                           (manual, latest) => latest != null && latest != manual));
            },
                execute: v => ManualMutagenVersion = v ?? string.Empty,
                extraCanExecute: this.WhenAnyValue(x => x.MutagenVersioning)
                .Select(vers => vers == PatcherNugetVersioningEnum.Manual),
                disposable: this);
            UpdateSynthesisManualToLatestCommand = NoggogCommand.CreateFromObject(
                objectSource: newest.WhenAnyValue(x => x.NewestSynthesisVersion),
                canExecute: v =>
            {
                return(Observable.CombineLatest(
                           this.WhenAnyValue(x => x.ManualSynthesisVersion),
                           v,
                           (manual, latest) => latest != null && latest != manual));
            },
                execute: v => ManualSynthesisVersion = v ?? string.Empty,
                extraCanExecute: this.WhenAnyValue(x => x.SynthesisVersioning)
                .Select(vers => vers == PatcherNugetVersioningEnum.Manual),
                disposable: this);

            ActiveNugetVersion = Observable.CombineLatest(
                versioning.WhenAnyValue(x => x.ActiveVersioning)
                .Switch(),
                this.WhenAnyValue(x => x.MutagenVersioning),
                this.WhenAnyValue(x => x.ManualMutagenVersion),
                newest.WhenAnyValue(x => x.NewestMutagenVersion),
                this.WhenAnyValue(x => x.SynthesisVersioning),
                this.WhenAnyValue(x => x.ManualSynthesisVersion),
                newest.WhenAnyValue(x => x.NewestSynthesisVersion),
                (profile, mutaVersioning, mutaManual, newestMuta, synthVersioning, synthManual, newestSynth) =>
            {
                var sb = new StringBuilder("Switching nuget targets");
                NugetsToUse mutagen, synthesis;
                if (mutaVersioning == PatcherNugetVersioningEnum.Profile)
                {
                    sb.Append($"  Mutagen following profile: {profile.Mutagen}");
                    mutagen = profile.Mutagen;
                }
                else
                {
                    mutagen = new NugetsToUse("Mutagen", mutaVersioning.ToNugetVersioningEnum(), mutaManual,
                                              newestMuta);
                    sb.Append($"  {mutagen}");
                }

                if (synthVersioning == PatcherNugetVersioningEnum.Profile)
                {
                    sb.Append($"  Synthesis following profile: {profile.Synthesis}");
                    synthesis = profile.Synthesis;
                }
                else
                {
                    synthesis = new NugetsToUse("Synthesis", synthVersioning.ToNugetVersioningEnum(),
                                                synthManual, newestSynth);
                    sb.Append($"  {synthesis}");
                }

                logger.Information(sb.ToString());
                return(new ActiveNugetVersioning(
                           Mutagen: mutagen,
                           Synthesis: synthesis));
            })
                                 .Select(nuget => nuget.TryGetTarget())
                                 .Replay(1)
                                 .RefCount();
        }