public RepoClonesValidStateVm(
     IDriverRepositoryPreparationFollower driverRepositoryPreparation,
     IRunnerRepositoryPreparation runnerRepositoryPreparation)
 {
     _Valid = Observable.CombineLatest(
         driverRepositoryPreparation.DriverInfo,
         runnerRepositoryPreparation.State,
         (driver, runner) => driver.RunnableState.Succeeded && runner.RunnableState.Succeeded)
              .ToGuiProperty(this, nameof(Valid), deferSubscription: true);
 }
Exemple #2
0
 public AvailableProjects(
     IDriverRepositoryPreparationFollower driverRepositoryPreparation)
 {
     Projects = driverRepositoryPreparation.DriverInfo
                .Select(x => x.Item?.AvailableProjects ?? Enumerable.Empty <string>())
                .Select(x => x.AsObservableChangeSet <string>())
                .Switch()
                .ObserveOn(RxApp.MainThreadScheduler)
                .ToObservableCollection(this);
 }
Exemple #3
0
        public AvailableTags(
            ISelectedProjectInputVm selectedProjectInput,
            IDriverRepositoryPreparationFollower driverRepositoryPreparation,
            IAvailableProjects availableProjects)
        {
            var tagInput = Observable.CombineLatest(
                selectedProjectInput.Picker.WhenAnyValue(x => x.TargetPath),
                availableProjects.Projects.WhenAnyValue(x => x.Count),
                (targetPath, count) => (targetPath, count));

            Tags = driverRepositoryPreparation.DriverInfo
                   .Select(x => x.Item?.Tags ?? Enumerable.Empty <DriverTag>())
                   .Select(x => x.AsObservableChangeSet())
                   .Switch()
                   .Filter(
                tagInput.Select(x =>
            {
                if (x.count == 0)
                {
                    return(new Func <DriverTag, bool>(_ => false));
                }
                if (x.count == 1)
                {
                    return(new Func <DriverTag, bool>(_ => true));
                }
                if (!x.targetPath.EndsWith(".csproj"))
                {
                    return(new Func <DriverTag, bool>(_ => false));
                }
                var projName = Path.GetFileName(x.targetPath);
                return(new Func <DriverTag, bool>(i =>
                                                  i.Name.StartsWith(projName, StringComparison.OrdinalIgnoreCase)));
            }))
                   .Sort(SortExpressionComparer <DriverTag> .Descending(x => x.Index))
                   .Transform(x => x.Name)
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .ToObservableCollection(this);
        }
Exemple #4
0
        public GitPatcherState(
            IDriverRepositoryPreparationFollower driverRepositoryPreparation,
            IRunnerRepositoryPreparation runnerRepositoryState,
            IRunnableStateProvider runnableStateProvider,
            IPatcherRunnabilityCliState runnabilityCliState,
            IInstalledSdkFollower dotNetInstalled,
            IEnvironmentErrorsVm envErrors,
            IMissingMods missingMods,
            ILogger logger)
        {
            State = Observable.CombineLatest(
                driverRepositoryPreparation.DriverInfo
                .Select(x => x.ToUnit()),
                runnerRepositoryState.State,
                runnableStateProvider.WhenAnyValue(x => x.State)
                .Select(x => x.ToUnit()),
                runnabilityCliState.Runnable,
                dotNetInstalled.DotNetSdkInstalled
                .Select(x => (x, true))
                .StartWith((new DotNetVersion(string.Empty, false), false)),
                envErrors.WhenAnyFallback(x => x.ActiveError !.ErrorString),
                missingMods.Missing
                .QueryWhenChanged()
                .Throttle(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler)
                .StartWith(ListExt.Empty <ModKey>()),
                (driver, runner, checkout, runnability, dotnet, envError, reqModsMissing) =>
            {
                if (driver.IsHaltingError)
                {
                    return(driver);
                }
                if (runner.IsHaltingError)
                {
                    return(runner);
                }
                if (!dotnet.Item2)
                {
                    return(new ConfigurationState(ErrorResponse.Fail("Determining DotNet SDK installed"))
                    {
                        IsHaltingError = false
                    });
                }

                if (!dotnet.Item1.Acceptable)
                {
                    return(new ConfigurationState(ErrorResponse.Fail("No DotNet SDK installed")));
                }
                if (envError != null)
                {
                    return(new ConfigurationState(ErrorResponse.Fail(envError)));
                }

                if (reqModsMissing.Count > 0)
                {
                    return(new ConfigurationState(ErrorResponse.Fail(
                                                      $"Required mods missing from load order:{Environment.NewLine}{string.Join(Environment.NewLine, reqModsMissing)}")));
                }

                if (runnability.RunnableState.Failed)
                {
                    return(runnability.BubbleError());
                }

                if (checkout.RunnableState.Failed)
                {
                    return(checkout.BubbleError());
                }

                logger.Information("State returned success!");
                return(ConfigurationState.Success);
            })
                    .Replay(1)
                    .RefCount();
        }
        public GitStatusDisplay(
            IRunnableStateProvider runnableStateProvider,
            ICompilationProvider compilationProvider,
            IPatcherRunnabilityCliState runnabilityCliState,
            IDriverRepositoryPreparationFollower driverRepositoryPreparation)
        {
            StatusDisplay = Observable.CombineLatest(
                driverRepositoryPreparation.DriverInfo,
                runnableStateProvider.WhenAnyValue(x => x.State),
                compilationProvider.State,
                runnabilityCliState.Runnable,
                (driver, runnable, comp, runnability) =>
            {
                if (driver.RunnableState.Failed)
                {
                    if (driver.IsHaltingError)
                    {
                        return(new StatusRecord(
                                   Text: "Blocking Error",
                                   Processing: false,
                                   Blocking: true,
                                   Command: null));
                    }

                    return(new StatusRecord(
                               Text: "Analyzing repository",
                               Processing: true,
                               Blocking: false,
                               Command: null));
                }

                if (runnable.RunnableState.Failed)
                {
                    if (runnable.IsHaltingError)
                    {
                        return(new StatusRecord(
                                   Text: "Blocking Error",
                                   Processing: false,
                                   Blocking: true,
                                   Command: null));
                    }

                    return(new StatusRecord(
                               Text: "Checking out desired state",
                               Processing: true,
                               Blocking: false,
                               Command: null));
                }

                if (comp.RunnableState.Failed)
                {
                    if (comp.IsHaltingError)
                    {
                        return(new StatusRecord(
                                   Text: "Blocking Error",
                                   Processing: false,
                                   Blocking: true,
                                   Command: null));
                    }

                    return(new StatusRecord(
                               Text: "Compiling",
                               Processing: true,
                               Blocking: false,
                               Command: null));
                }

                if (runnability.RunnableState.Failed)
                {
                    if (runnability.IsHaltingError)
                    {
                        return(new StatusRecord(
                                   Text: "Blocking Error",
                                   Processing: false,
                                   Blocking: true,
                                   Command: null));
                    }

                    return(new StatusRecord(
                               Text: "Checking runnability",
                               Processing: true,
                               Blocking: false,
                               Command: null));
                }

                return(new StatusRecord(
                           Text: "Ready",
                           Processing: false,
                           Blocking: false,
                           Command: null));
            })
                            .Replay(1)
                            .RefCount();
        }
        public GitPatcherTargetingVm(
            ILockToCurrentVersioning lockToCurrentVersioning,
            IDriverRepositoryPreparationFollower driverRepositoryPreparation)
        {
            var targetOriginBranchName = this.WhenAnyValue(x => x.TargetBranchName)
                                         .Select(x => $"origin/{x}")
                                         .Replay(1).RefCount();

            // Set latest checkboxes to drive user input
            driverRepositoryPreparation.DriverInfo
            .FlowSwitch(this.WhenAnyValue(x => x.BranchFollowMain))
            .Throttle(TimeSpan.FromMilliseconds(150), RxApp.MainThreadScheduler)
            .Subscribe(state =>
            {
                if (state.RunnableState.Succeeded)
                {
                    this.TargetBranchName = state.Item.MasterBranchName;
                }
            })
            .DisposeWith(this);

            Observable.CombineLatest(
                driverRepositoryPreparation.DriverInfo,
                targetOriginBranchName,
                (Driver, TargetBranch) => (Driver, TargetBranch))
            .FlowSwitch(
                Observable.CombineLatest(
                    this.WhenAnyValue(x => x.BranchAutoUpdate),
                    this.WhenAnyValue(x => x.PatcherVersioning),
                    (autoBranch, versioning) => autoBranch && versioning == PatcherVersioningEnum.Branch))
            .Throttle(TimeSpan.FromMilliseconds(150), RxApp.MainThreadScheduler)
            .Subscribe(x =>
            {
                if (x.Driver.RunnableState.Succeeded &&
                    x.Driver.Item.BranchShas.TryGetValue(x.TargetBranch, out var sha))
                {
                    this.TargetCommit = sha;
                }
            })
            .DisposeWith(this);

            driverRepositoryPreparation.DriverInfo
            .Select(x =>
                    x.RunnableState.Failed ? default : x.Item.Tags.OrderByDescending(x => x.Index).FirstOrDefault())
            .FlowSwitch(
                Observable.CombineLatest(
                    this.WhenAnyValue(x => x.TagAutoUpdate),
                    lockToCurrentVersioning.WhenAnyValue(x => x.Lock),
                    this.WhenAnyValue(x => x.PatcherVersioning),
                    (autoTag, locked, versioning) => !locked && autoTag && versioning == PatcherVersioningEnum.Tag))
            .Throttle(TimeSpan.FromMilliseconds(150), RxApp.MainThreadScheduler)
            .Subscribe(x =>
            {
                this.TargetTag    = x?.Name ?? string.Empty;
                this.TargetCommit = x?.Sha ?? string.Empty;
            })
            .DisposeWith(this);

            var targetBranchSha = Observable.CombineLatest(
                driverRepositoryPreparation.DriverInfo
                .Select(x => x.RunnableState.Failed ? default : x.Item.BranchShas),
                targetOriginBranchName,
                (dict, branch) => dict?.GetOrDefault(branch))
                                  .Replay(1)
                                  .RefCount();

            var targetTag = Observable.CombineLatest(
                driverRepositoryPreparation.DriverInfo
                .Select(x => x.RunnableState.Failed ? default : x.Item.Tags),
                this.WhenAnyValue(x => x.TargetTag),
                (tags, tag) => tags?
                .Where(tagItem => tagItem.Name == tag)
                .FirstOrDefault())
                            .Replay(1)
                            .RefCount();

            // Set up empty target autofill
            // Usually for initial bootstrapping
            Observable.CombineLatest(
                targetBranchSha,
                this.WhenAnyValue(x => x.TargetCommit),
                (targetBranchSha, targetCommit) => (targetBranchSha, targetCommit))
            .Throttle(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler)
            .Where(x => x.targetBranchSha != null && TargetCommit.IsNullOrWhitespace())
            .Subscribe(x => { this.TargetCommit = x.targetBranchSha ?? string.Empty; })
            .DisposeWith(this);
            Observable.CombineLatest(
                targetTag,
                this.WhenAnyValue(x => x.TargetCommit),
                (targetTagSha, targetCommit) => (targetTagSha, targetCommit))
            .Throttle(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler)
            .Where(x => x.targetTagSha != null && TargetCommit.IsNullOrWhitespace())
            .Subscribe(x => { this.TargetCommit = x.targetTagSha?.Sha ?? string.Empty; })
            .DisposeWith(this);

            // Set up update available systems
            UpdateToBranchCommand = NoggogCommand.CreateFromObject(
                objectSource: Observable.CombineLatest(
                    targetBranchSha,
                    this.WhenAnyValue(x => x.TargetCommit),
                    (branch, target) => (BranchSha: branch, Current: target)),
                canExecute: o => o.BranchSha != null && o.BranchSha != o.Current,
                extraCanExecute: this.WhenAnyValue(x => x.PatcherVersioning)
                .Select(vers => vers == PatcherVersioningEnum.Branch),
                execute: o => { this.TargetCommit = o.BranchSha !; },
                this);

            UpdateToTagCommand = NoggogCommand.CreateFromObject(
                objectSource: Observable.CombineLatest(
                    targetTag,
                    Observable.CombineLatest(
                        this.WhenAnyValue(x => x.TargetCommit),
                        this.WhenAnyValue(x => x.TargetTag),
                        (TargetSha, TargetTag) => (TargetSha, TargetTag)),
                    (tag, target) => (TagSha: tag?.Sha, Tag: tag?.Name, Current: target)),
                canExecute: o => (o.TagSha != null && o.Tag != null) &&
                (o.TagSha != o.Current.TargetSha || o.Tag != o.Current.TargetTag),
                extraCanExecute: this.WhenAnyValue(x => x.PatcherVersioning)
                .Select(vers => vers == PatcherVersioningEnum.Tag),
                execute: o =>
            {
                this.TargetTag    = o.Tag !;
                this.TargetCommit = o.TagSha !;
            },
                this);

            ActivePatcherVersion = Observable.CombineLatest(
                this.WhenAnyValue(x => x.PatcherVersioning),
                this.WhenAnyValue(x => x.TargetTag),
                this.WhenAnyValue(x => x.TargetCommit),
                targetOriginBranchName,
                Observable.CombineLatest(
                    this.WhenAnyValue(x => x.TagAutoUpdate),
                    lockToCurrentVersioning.WhenAnyValue(x => x.Lock),
                    (auto, locked) => !locked && auto),
                Observable.CombineLatest(
                    this.WhenAnyValue(x => x.BranchAutoUpdate),
                    lockToCurrentVersioning.WhenAnyValue(x => x.Lock),
                    (auto, locked) => !locked && auto),
                (versioning, tag, commit, branch, tagAuto, branchAuto) =>
            {
                return(GitPatcherVersioning.Factory(
                           versioning: versioning,
                           tag: tag,
                           commit: commit,
                           branch: branch,
                           autoTag: tagAuto,
                           autoBranch: branchAuto));
            })
                                   .DistinctUntilChanged()
                                   .Replay(1)
                                   .RefCount();
        }