Exemplo n.º 1
0
 public GroupRunVmFactory(
     RunDisplayControllerVm runDisplayControllerVm,
     IPatcherRunnerFactory runnerFactory,
     IPrepPatcherForRun prepPatcherForRun)
 {
     _runDisplayControllerVm = runDisplayControllerVm;
     _runnerFactory          = runnerFactory;
     _prepPatcherForRun      = prepPatcherForRun;
 }
Exemplo n.º 2
0
        public GroupRunVm(
            GroupVm groupVm,
            IGroupRun run,
            RunDisplayControllerVm runDisplayControllerVm,
            IEnumerable <PatcherRunVm> runVms)
        {
            SourceVm = groupVm;
            GroupVm  = groupVm;
            Run      = run;
            RunDisplayControllerVm = runDisplayControllerVm;

            Patchers = runVms;

            _hasStarted = runVms.AsObservableChangeSet()
                          .FilterOnObservable(x => x.WhenAnyValue(x => x.State.Value)
                                              .Select(x => x != RunState.NotStarted))
                          .QueryWhenChanged(q => q.Count > 0)
                          .ToGuiProperty(this, nameof(HasStarted), deferSubscription: true);

            _runTimeString = runVms.AsObservableChangeSet()
                             .AutoRefresh(x => x.RunTime)
                             .Transform(x => x.RunTime, transformOnRefresh: true)
                             .QueryWhenChanged(q =>
            {
                TimeSpan span = new();
                foreach (var s in q)
                {
                    span += s;
                }
                return(span);
            })
                             .Select(time =>
            {
                if (time == new TimeSpan())
                {
                    return(string.Empty);
                }
                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, deferSubscription: true);
        }