コード例 #1
0
        async Task <ProcessExitResult> LaunchAndWaitForExitAsync(ReactiveProcess process, TimeSpan?monitorOutput,
                                                                 TimeSpan?monitorResponding)
        {
            var task = process.StartAsync();

            _launched.OnNext(Tuple.Create(process.StartInfo, process.Id));

            using (SetupMonitoringDisposable(process, monitorOutput, monitorResponding))
                await task.ConfigureAwait(false);
            _terminated.OnNext(Tuple.Create(process.StartInfo, process.ExitCode, process.Id));
            return(new ProcessExitResult(process.ExitCode, process.Id, process.StartInfo));
        }
コード例 #2
0
 public async Task <ProcessExitResult> LaunchAsync(BasicLaunchInfo info)
 {
     ProcessBLI(info);
     using (var process = new ReactiveProcess {
         StartInfo = info.StartInfo
     }) {
         return
             (await
              LaunchAndWaitForExitAsync(process, info.MonitorOutput, info.MonitorResponding,
                                        info.CancellationToken)
              .ConfigureAwait(false));
     }
 }
コード例 #3
0
        async Task <ProcessExitResult> LaunchAndWaitForExitAsync(ReactiveProcess process, TimeSpan?monitorOutput,
                                                                 TimeSpan?monitorResponding, CancellationToken token)
        {
            var task = process.StartAsync();

            _launched.OnNext(Tuple.Create(process.StartInfo, process.Id));

            using (SetupMonitoringDisposable(process, monitorOutput, monitorResponding))
                using (token.Register(process.TryKill))
                    await task.ConfigureAwait(false);
            _terminated.OnNext(Tuple.Create(process.StartInfo, process.ExitCode, process.Id));
            token.ThrowIfCancellationRequested();
            return(new ProcessExitResult(process.ExitCode, process.Id, process.StartInfo));
        }
コード例 #4
0
 public async Task <ProcessExitResult> LaunchAndProcessAsync(LaunchAndProcessInfo info)
 {
     using (var process = new ReactiveProcess {
         StartInfo = info.StartInfo.EnableRedirect()
     }) {
         using (SetupStandardOutput(info, process))
             using (SetupStandardError(info, process))
                 return
                     (await
                      LaunchAndWaitForExitAsync(process, info.MonitorOutput, info.MonitorResponding,
                                                info.CancellationToken)
                      .ConfigureAwait(false));
     }
 }
コード例 #5
0
        CompositeDisposable SetupMonitoringDisposable(ReactiveProcess process, TimeSpan?monitorOutput,
                                                      TimeSpan?monitorResponding)
        {
            var disposable = new CompositeDisposable();

            if (monitorOutput.HasValue)
            {
                disposable.Add(MonitorProcessOutput(process, monitorOutput.Value));
            }
            //if (monitorResponding.HasValue)
            //disposable.Add(MonitorProcessResponding(process, monitorResponding.Value));

            return(disposable);
        }
コード例 #6
0
        static IDisposable SetupStandardOutput(LaunchAndProcessInfo info, ReactiveProcess process)
        {
            if (!info.StartInfo.RedirectStandardOutput)
            {
                throw new InvalidOperationException("Not redirected output");
            }
            var dsp = new CompositeDisposable();

            if (info.StandardOutputObs != null)
            {
                dsp.Add(info.StandardOutputObs(process.StandardOutputObservable));
            }
            if (info.StandardOutputAction != null)
            {
                dsp.Add(process.StandardOutputObservable.Subscribe(data => info.StandardOutputAction(process, data)));
            }
            return(dsp);
        }
コード例 #7
0
        Timer MonitorProcessOutput(ReactiveProcess process, TimeSpan timeout)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            if (timeout == null)
            {
                throw new ArgumentNullException(nameof(timeout));
            }

            var state = process.MonitorProcessOutput();

            _monitorStarted.OnNext(Tuple.Create(process.StartInfo, process.Id, "Output"));
            return(new TimerWithElapsedCancellation(monitorInterval,
                                                    () => OnOutputMonitorElapsed(process, state, timeout),
                                                    () => _monitorStopped.OnNext(Tuple.Create(process.StartInfo, process.Id, "Output"))));
        }
コード例 #8
0
        public static ProcessManager.ProcessState MonitorProcessOutput(this ReactiveProcess process)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            var state = new ProcessManager.ProcessState();

            if (!process.StartInfo.RedirectStandardOutput)
            {
                throw new InvalidOperationException("Not redirected output");
            }
            if (!process.StartInfo.RedirectStandardError)
            {
                throw new InvalidOperationException("Not redirected error");
            }

            // we terminate the observables so we dont have to dispose these subscriptions
            process.StandardOutputObservable.Subscribe(_ => state.UpdateStamp());
            process.StandardErrorObservable.Subscribe(_ => state.UpdateStamp());
            return(state);
        }