Ejemplo n.º 1
0
        public static void ReceiveErrorData(this ProcessOutputCollector collector, object sender, DataReceivedEventArgs e)
        {
            if (e.Data is null)
            {
                return;
            }

            collector.AddError(e.Data);
        }
Ejemplo n.º 2
0
 public static IEnumerable <string> GetErrorLines(this ProcessOutputCollector collector)
 {
     using (var reader = collector.GetErrorReader())
     {
         while (!reader.ReadLineIsEnd(out var line))
         {
             yield return(line);
         }
     }
 }
Ejemplo n.º 3
0
        public static ProcessOutputCollector Run(string command, string arguments, bool throwIfAnyError = true)
        {
            var outputCollector = new ProcessOutputCollector();
            var runOptions      = new ProcessRunOptions
            {
                Command           = command,
                Arguments         = arguments,
                ReceiveOutputData = outputCollector.ReceiveOutputData,
                ReceiveErrorData  = outputCollector.ReceiveErrorData,
            };

            ProcessRunner.Run(runOptions);

            if (throwIfAnyError && outputCollector.AnyError)
            {
                var commandLineIncantation = ProcessRunner.GetCommandLineIncantation(command, arguments);

                throw new Exception($"Automation failure.\nCommand:\n{commandLineIncantation}\nReceived:\n{outputCollector.GetErrorText()}");
            }

            return(outputCollector);
        }
Ejemplo n.º 4
0
        public static StringReader GetErrorReader(this ProcessOutputCollector collector)
        {
            var reader = new StringReader(collector.GetErrorText());

            return(reader);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Trims the output text (including any ending \r\n from the output).
        /// </summary>
        public static string GetOutputTextTrimmed(this ProcessOutputCollector collector)
        {
            var output = collector.GetOutputText().Trim();

            return(output);
        }