private CompilerResult CreateCompilerResult()
 {
     return(new CompilerResult {
         StandardOutput = StandardOutput.ReadToEnd(),
         StandardError = StandardError.ReadToEnd(),
         CompilationTime = (int)ExitTime.Subtract(StartTime).TotalMilliseconds
     });
 }
Пример #2
0
 private RunResult CreateRunResult()
 {
     return(new RunResult {
         Output = StandardOutput.ReadToEnd(),
         Error = StandardError.ReadToEnd(),
         RunTime = (int)ExitTime.Subtract(StartTime).TotalMilliseconds
     });
 }
Пример #3
0
        /// <summary>
        /// Waits for process to exit or to get killed due to timed out.
        /// </summary>
        /// <remarks>
        /// After this task completes, stdout and stderr of <see cref="Process"/> are not necessarily flushed
        /// yet. If you care about those tasks completing, call <see cref="WaitForStdOutAndStdErrAsync"/>.
        /// </remarks>
        public async Task WaitForExitAsync()
        {
            Log($"waiting to exit");
            var finishedTask = await Task.WhenAny(Task.Delay(m_timeout), WhenExited);

            ExitTime = DateTime.UtcNow;

            var timedOut = finishedTask != WhenExited;

            if (timedOut)
            {
                Log($"timed out after {ExitTime.Subtract(StartTime)} (timeout: {m_timeout})");
                TimedOut = true;
                await KillAsync();
            }
            else
            {
                Log($"exited at {ExitTime}");
            }
        }
Пример #4
0
 public override string ToString()
 {
     return(direction + "," + entryPrice + "," + EntryTime.ToString(TIMEFORMAT) + "," +
            exitPrice + "," + ExitTime.ToString(TIMEFORMAT));
 }
Пример #5
0
        protected sealed override bool run()
        {
            var startInfo = StartInfo.GetValue();

            using (var process = new Process()
            {
                StartInfo = startInfo
            })
            {
                if (DataReceiveAction != null)
                {
                    process.OutputDataReceived += (_, e) => DataReceiveAction.GetValue()(e);
                }

                if (ErrorReceiveAction != null)
                {
                    process.ErrorDataReceived += (_, e) => ErrorReceiveAction.GetValue()(e);
                }

                if (!process.Start())
                {
                    return(false);
                }

                if (startInfo.RedirectStandardOutput)
                {
                    process.BeginOutputReadLine();
                }

                if (startInfo.RedirectStandardError)
                {
                    process.BeginErrorReadLine();
                }

                if (Timeout == null)
                {
                    process.WaitForExit();
                }
                else
                {
                    process.WaitForExit(Timeout.GetValue());
                }

                if (startInfo.RedirectStandardInput)
                {
                    process.CancelOutputRead();
                }

                if (startInfo.RedirectStandardError)
                {
                    process.CancelErrorRead();
                }

                var exitCode = process.ExitCode;

                if (ExitCode != null)
                {
                    ExitCode.SetValue <int>(exitCode);
                }

                if (StartTime != null)
                {
                    StartTime.SetValue <DateTime>(process.StartTime);
                }

                if (ExitTime != null)
                {
                    ExitTime.SetValue <DateTime>(process.ExitTime);
                }

                if (ResultConverter == null)
                {
                    return(exitCode == 0);
                }
                else
                {
                    return(ResultConverter.Convert(exitCode));
                }
            }
        }