예제 #1
0
        public MainVM(Window window)
        {
            _window = window;
            var dotNet = Observable.Interval(TimeSpan.FromSeconds(10), RxApp.TaskpoolScheduler)
                         .StartWith(0)
                         .SelectTask(async i =>
            {
                try
                {
                    var ret = await DotNetCommands.DotNetSdkVersion(CancellationToken.None);
                    Log.Logger.Information($"dotnet SDK: {ret}");
                    return(ret);
                }
                catch (Exception ex)
                {
                    Log.Logger.Error(ex, $"Error retrieving dotnet SDK version");
                    return(default(Version?));
                }
            });

            DotNetSdkInstalled = dotNet
                                 .Take(1)
                                 .Merge(dotNet
                                        .FirstAsync(v => v != null))
                                 .DistinctUntilChanged()
                                 .Replay(1)
                                 .RefCount();

            Configuration        = new ConfigurationVM(this);
            ActivePanel          = Configuration;
            DiscardActionCommand = NoggogCommand.CreateFromObject(
                objectSource: this.WhenAnyValue(x => x.TargetConfirmation),
                canExecute: target => target != null,
                execute: (_) =>
            {
                TargetConfirmation = null;
            },
                disposable: this.CompositeDisposable);
            ConfirmActionCommand = NoggogCommand.CreateFromObject(
                objectSource: this.WhenAnyFallback(x => x.TargetConfirmation !.ToDo),
                canExecute: toDo => toDo != null,
                execute: toDo =>
            {
                toDo?.Invoke();
                TargetConfirmation = null;
            },
                disposable: this.CompositeDisposable);

            _Hot = this.WhenAnyValue(x => x.ActivePanel)
                   .Select(x =>
            {
                switch (x)
                {
                case ConfigurationVM config:
                    return(config.WhenAnyFallback(x => x.CurrentRun !.Running, fallback: false));

                case PatchersRunVM running:
                    return(running.WhenAnyValue(x => x.Running));

                default:
                    break;
                }
                return(Observable.Return(false));
            })
                   .Switch()
                   .DistinctUntilChanged()
                   .ToGuiProperty(this, nameof(Hot));

            OpenProfilesPageCommand = ReactiveCommand.Create(() =>
            {
                ActivePanel = new ProfilesDisplayVM(Configuration, ActivePanel);
            },
                                                             canExecute: Observable.CombineLatest(
                                                                 this.WhenAnyFallback(x => x.Configuration.CurrentRun !.Running, fallback: false),
                                                                 this.WhenAnyValue(x => x.ActivePanel)
                                                                 .Select(x => x is ProfilesDisplayVM),
                                                                 (running, isProfile) => !running && !isProfile));

            IdeOptions.AddRange(EnumExt.GetValues <IDE>());

            Task.Run(() => Mutagen.Bethesda.WarmupAll.Init()).FireAndForget();

            SynthesisVersion = Mutagen.Bethesda.Synthesis.Versions.SynthesisVersion;
            MutagenVersion   = Mutagen.Bethesda.Synthesis.Versions.MutagenVersion;

            var latestVersions = Observable.Return(Unit.Default)
                                 .ObserveOn(RxApp.TaskpoolScheduler)
                                 .CombineLatest(
                DotNetSdkInstalled,
                (_, v) => v)
                                 .SelectTask(async v =>
            {
                var normalUpdateTask     = GetLatestVersions(v, includePrerelease: false);
                var prereleaseUpdateTask = GetLatestVersions(v, includePrerelease: true);
                await Task.WhenAll(normalUpdateTask, prereleaseUpdateTask);
                return(Normal: await normalUpdateTask, Prerelease: await prereleaseUpdateTask);
            })
                                 .Replay(1)
                                 .RefCount();

            NewestMutagenVersion = Observable.CombineLatest(
                latestVersions,
                this.WhenAnyFallback(x => x.Configuration.SelectedProfile !.ConsiderPrereleaseNugets),
                (vers, prereleases) => prereleases ? vers.Prerelease.MutagenVersion : vers.Normal.MutagenVersion)
                                   .Replay(1)
                                   .RefCount();
            NewestSynthesisVersion = Observable.CombineLatest(
                latestVersions,
                this.WhenAnyFallback(x => x.Configuration.SelectedProfile !.ConsiderPrereleaseNugets),
                (vers, prereleases) => prereleases ? vers.Prerelease.SynthesisVersion : vers.Normal.SynthesisVersion)
                                     .Replay(1)
                                     .RefCount();

            // Switch to DotNet screen if missing
            DotNetSdkInstalled
            .Subscribe(v =>
            {
                if (v == null)
                {
                    ActivePanel = new DotNetNotInstalledVM(this, this.ActivePanel, DotNetSdkInstalled);
                }
            });

            _ActiveConfirmation = Observable.CombineLatest(
                this.WhenAnyFallback(x => x.Configuration.SelectedProfile !.SelectedPatcher)
                .Select(x =>
            {
                if (x is not GitPatcherVM gitPatcher)
                {
                    return(Observable.Return(default(GitPatcherVM?)));
                }
                return(gitPatcher.WhenAnyValue(x => x.PatcherSettings.SettingsOpen)
                       .Select(open => open ? (GitPatcherVM?)gitPatcher : null));
            })
                .Switch(),
                this.WhenAnyValue(x => x.TargetConfirmation),
                (openPatcher, target) =>
            {
                if (target != null)
                {
                    return(target);
                }
                if (openPatcher == null)
                {
                    return(default(ConfirmationActionVM?));
                }
                return(new ConfirmationActionVM(
                           "External Patcher Settings Open",
                           $"{openPatcher.Nickname} is open for settings manipulation.",
                           toDo: null));
            })
                                  .ToGuiProperty(this, nameof(ActiveConfirmation), default(ConfirmationActionVM?));

            _InModal = this.WhenAnyValue(x => x.ActiveConfirmation)
                       .Select(x => x != null)
                       .ToGuiProperty(this, nameof(InModal));
        }
예제 #2
0
파일: MainVM.cs 프로젝트: Deigue/Synthesis
        public MainVM()
        {
            var dotNet = Observable.Interval(TimeSpan.FromSeconds(10), RxApp.TaskpoolScheduler)
                         .StartWith(0)
                         .SelectTask(async i =>
            {
                try
                {
                    var ret = await DotNetQueries.DotNetSdkVersion();
                    Log.Logger.Information($"dotnet SDK: {ret}");
                    return(ret);
                }
                catch (Exception ex)
                {
                    Log.Logger.Error(ex, $"Error retrieving dotnet SDK version");
                    return(default(Version?));
                }
            });

            DotNetSdkInstalled = dotNet
                                 .Take(1)
                                 .Merge(dotNet
                                        .FirstAsync(v => v != null))
                                 .DistinctUntilChanged()
                                 .Replay(1)
                                 .RefCount();

            Configuration        = new ConfigurationVM(this);
            ActivePanel          = Configuration;
            DiscardActionCommand = ReactiveCommand.Create(() => ActiveConfirmation = null);
            ConfirmActionCommand = ReactiveCommand.Create(
                () =>
            {
                if (ActiveConfirmation == null)
                {
                    return;
                }
                ActiveConfirmation.ToDo();
                ActiveConfirmation = null;
            });

            _Hot = this.WhenAnyValue(x => x.ActivePanel)
                   .Select(x =>
            {
                switch (x)
                {
                case ConfigurationVM config:
                    return(config.WhenAnyFallback(x => x.CurrentRun !.Running, fallback: false));

                case PatchersRunVM running:
                    return(running.WhenAnyValue(x => x.Running));

                default:
                    break;
                }
                return(Observable.Return(false));
            })
                   .Switch()
                   .DistinctUntilChanged()
                   .ToGuiProperty(this, nameof(Hot));

            OpenProfilesPageCommand = ReactiveCommand.Create(() =>
            {
                ActivePanel = new ProfilesDisplayVM(Configuration, ActivePanel);
            },
                                                             canExecute: Observable.CombineLatest(
                                                                 this.WhenAnyFallback(x => x.Configuration.CurrentRun !.Running, fallback: false),
                                                                 this.WhenAnyValue(x => x.ActivePanel)
                                                                 .Select(x => x is ProfilesDisplayVM),
                                                                 (running, isProfile) => !running && !isProfile));

            IdeOptions.AddRange(EnumExt.GetValues <IDE>());

            Task.Run(() => Mutagen.Bethesda.WarmupAll.Init()).FireAndForget();

            SynthesisVersion = Mutagen.Bethesda.Synthesis.Versions.SynthesisVersion;
            MutagenVersion   = Mutagen.Bethesda.Synthesis.Versions.MutagenVersion;

            var latestVersions = Observable.Return(Unit.Default)
                                 .ObserveOn(RxApp.TaskpoolScheduler)
                                 .CombineLatest(
                DotNetSdkInstalled,
                (_, v) => v)
                                 .SelectTask(GetLatestVersions)
                                 .Replay(1)
                                 .RefCount();

            NewestMutagenVersion = latestVersions
                                   .Select(x => x.MutagenVersion);
            NewestSynthesisVersion = latestVersions
                                     .Select(x => x.SynthesisVersion);

            // Switch to DotNet screen if missing
            DotNetSdkInstalled
            .Subscribe(v =>
            {
                if (v == null)
                {
                    ActivePanel = new DotNetNotInstalledVM(this, this.ActivePanel, DotNetSdkInstalled);
                }
            });
        }