示例#1
0
        public PatcherRunVM(PatchersRunVM parent, PatcherVM config, IPatcherRun run)
        {
            Run    = run;
            Config = config;

            _IsSelected = parent.WhenAnyValue(x => x.SelectedPatcher)
                          .Select(x => x == this)
                          .ToGuiProperty(this, nameof(IsSelected));

            OutputLineDisplay = Observable.Merge(
                run.Output,
                run.Error,
                this.WhenAnyValue(x => x.State)
                .Where(x => x.Value == RunState.Error)
                .Select(x => x.Reason))
                                .ToObservableChangeSet()
                                .Buffer(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
                                .Where(l => l.Count > 0)
                                .FlattenBufferResult()
                                .ToObservableCollection(this);

            _IsRunning = this.WhenAnyValue(x => x.State)
                         .Select(x => x.Value == RunState.Started)
                         .ToGuiProperty(this, nameof(IsRunning));

            _IsErrored = this.WhenAnyValue(x => x.State)
                         .Select(x => x.Value == RunState.Error)
                         .ToGuiProperty(this, nameof(IsErrored));

            var runTime = Noggog.ObservableExt.TimePassed(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
                          .FilterSwitch(this.WhenAnyValue(x => x.IsRunning))
                          .Publish()
                          .RefCount();

            _RunTime = runTime
                       .ToProperty(this, nameof(RunTime));

            _RunTimeString = runTime
                             .Select(time =>
            {
                if (time.TotalDays > 1)
                {
                    return($"{time.TotalDays:n1}d");
                }
                if (time.TotalHours > 1)
                {
                    return($"{time.TotalHours:n1}h");
                }
                if (time.TotalMinutes > 1)
                {
                    return($"{time.TotalMinutes:n1}m");
                }
                return($"{time.TotalSeconds:n1}s");
            })
                             .ToGuiProperty <string>(this, nameof(RunTimeString), string.Empty);
        }
示例#2
0
 public override PatcherRunVM ToRunner(PatchersRunVM parent)
 {
     return(new PatcherRunVM(
                parent,
                this,
                new CliPatcherRun(
                    nickname: DisplayName,
                    pathToExecutable: PathToExecutable.TargetPath,
                    pathToExtra: null)));
 }
示例#3
0
 public override PatcherRunVM ToRunner(PatchersRunVM parent)
 {
     return(new PatcherRunVM(
                parent,
                this,
                new SolutionPatcherRun(
                    name: DisplayName,
                    pathToSln: SolutionPath.TargetPath,
                    pathToExtraDataBaseFolder: Execution.Constants.TypicalExtraData,
                    pathToProj: SelectedProjectPath.TargetPath)));
 }
示例#4
0
 public override PatcherRunVM ToRunner(PatchersRunVM parent)
 {
     PatcherSettings.Persist(Logger.Information);
     return(new PatcherRunVM(
                parent,
                this,
                new SolutionPatcherRun(
                    name: DisplayName,
                    pathToSln: SolutionPath.TargetPath,
                    pathToExtraDataBaseFolder: Execution.Paths.TypicalExtraData,
                    pathToProj: SelectedProjectPath.TargetPath)));
 }
示例#5
0
 public abstract PatcherRunVM ToRunner(PatchersRunVM parent);
示例#6
0
        public ConfigurationVM(MainVM mvm)
        {
            MainVM          = mvm;
            ProfilesDisplay = Profiles.Connect().ToObservableCollection(this);
            PatchersDisplay = this.WhenAnyValue(x => x.SelectedProfile)
                              .Select(p => p?.Patchers.Connect() ?? Observable.Empty <IChangeSet <PatcherVM> >())
                              .Switch()
                              .ToObservableCollection(this);

            CompleteConfiguration = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var initializer = this.NewPatcher;
                if (initializer == null)
                {
                    return;
                }
                AddNewPatchers(await initializer.Construct().ToListAsync());
            },
                canExecute: this.WhenAnyValue(x => x.NewPatcher)
                .Select(patcher =>
            {
                if (patcher == null)
                {
                    return(Observable.Return(false));
                }
                return(patcher.WhenAnyValue(x => x.CanCompleteConfiguration)
                       .Select(e => e.Succeeded));
            })
                .Switch());

            CancelConfiguration = ReactiveCommand.Create(
                () =>
            {
                NewPatcher?.Cancel();
                NewPatcher = null;
            });

            // Dispose any old patcher initializations
            this.WhenAnyValue(x => x.NewPatcher)
            .DisposePrevious()
            .Subscribe()
            .DisposeWith(this);

            _DisplayedObject = Observable.CombineLatest(
                this.WhenAnyValue(x => x.SelectedProfile !.DisplayedObject),
                this.WhenAnyValue(x => x.NewPatcher),
                (selected, newConfig) => (newConfig as object) ?? selected)
                               .ToGuiProperty(this, nameof(DisplayedObject), default);

            RunPatchers = NoggogCommand.CreateFromJob(
                extraInput: this.WhenAnyValue(x => x.SelectedProfile),
                jobCreator: (profile) =>
            {
                if (SelectedProfile == null)
                {
                    return(default(PatchersRunVM?), Observable.Return(Unit.Default));
                }
                var ret            = new PatchersRunVM(this, SelectedProfile);
                var completeSignal = ret.WhenAnyValue(x => x.Running)
                                     .TurnedOff()
                                     .FirstAsync();
                return(ret, completeSignal);
            },
                createdJobs: out var createdRuns,
                canExecute: this.WhenAnyFallback(x => x.SelectedProfile !.BlockingError, fallback: ErrorResponse.Failure)
                .Select(err => err.Succeeded))
                          .DisposeWith(this);

            _CurrentRun = createdRuns
                          .ToGuiProperty(this, nameof(CurrentRun), default);

            this.WhenAnyValue(x => x.CurrentRun)
            .NotNull()
            .Do(run => MainVM.ActivePanel = run)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(r => r.Run())
            .DisposeWith(this);

            ShowHelpToggleCommand = ReactiveCommand.Create(() => ShowHelp = !ShowHelp);
        }
示例#7
0
        public PatcherRunVM(PatchersRunVM parent, PatcherVM config, IPatcherRun run)
        {
            Run    = run;
            Config = config;

            _IsSelected = parent.WhenAnyValue(x => x.SelectedPatcher)
                          .Select(x => x == this)
                          .ToGuiProperty(this, nameof(IsSelected));

            Observable.Merge(
                run.Output,
                run.Error,
                this.WhenAnyValue(x => x.State)
                .Where(x => x.Value == RunState.Error)
                .Select(x => x.Reason))
            .Buffer(TimeSpan.FromMilliseconds(250), count: 1000, RxApp.TaskpoolScheduler)
            .Where(b => b.Count > 0)
            .ObserveOnGui()
            .Subscribe(output =>
            {
                StringBuilder sb = new();
                foreach (var line in output)
                {
                    sb.AppendLine(line);
                }
                OutputDisplay.Insert(OutputDisplay.TextLength, sb.ToString());
            })
            .DisposeWith(this);

            _IsRunning = this.WhenAnyValue(x => x.State)
                         .Select(x => x.Value == RunState.Started)
                         .ToGuiProperty(this, nameof(IsRunning));

            _IsErrored = this.WhenAnyValue(x => x.State)
                         .Select(x => x.Value == RunState.Error)
                         .ToGuiProperty(this, nameof(IsErrored));

            var runTime = Noggog.ObservableExt.TimePassed(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
                          .FilterSwitch(this.WhenAnyValue(x => x.IsRunning))
                          .Publish()
                          .RefCount();

            _RunTime = runTime
                       .ToProperty(this, nameof(RunTime));

            _RunTimeString = runTime
                             .Select(time =>
            {
                if (time.TotalDays > 1)
                {
                    return($"{time.TotalDays:n1}d");
                }
                if (time.TotalHours > 1)
                {
                    return($"{time.TotalHours:n1}h");
                }
                if (time.TotalMinutes > 1)
                {
                    return($"{time.TotalMinutes:n1}m");
                }
                return($"{time.TotalSeconds:n1}s");
            })
                             .ToGuiProperty <string>(this, nameof(RunTimeString), string.Empty);

            this.WhenAnyValue(x => x.State)
            .Where(x => x.Succeeded && x.Value == RunState.Finished)
            .Subscribe(_ => config.SuccessfulRunCompleted())
            .DisposeWith(this);
        }