示例#1
0
        private void ReceiveStandardErrorData(object sender, DataReceivedEventArgs e)
        {
            if (e.Data == null)
            {
                return;
            }

            StandardErrorWriter.WriteLine(e.Data);
        }
示例#2
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (StandardErrorWriter != null)
                {
                    StandardErrorWriter.Dispose();
                }

                if (StandardOutputWriter != null)
                {
                    StandardOutputWriter.Dispose();
                }

                if (_toolTimer != null)
                {
                    _toolTimer.Dispose();
                }
            }
        }
示例#3
0
 /// <summary>
 /// Appends to the standard error writer.
 /// </summary>
 /// <param name="message">The message to write.</param>
 protected virtual void AppendStandardError(string message)
 {
     StandardErrorWriter.WriteLine(message);
 }
示例#4
0
        /// <summary>
        /// Runs the executable file.
        /// </summary>
        /// <param name="pathToTool">The path to tool.</param>
        /// <param name="commandLineCommands">The command line arguments.</param>
        /// <returns>The returned exit code of the executable file.</returns>
        protected virtual int ExecuteTool(string pathToTool, string commandLineCommands)
        {
            Process proc = null;

            _standardErrorData.Length  = 0;
            _standardOutputData.Length = 0;

            if (StandardErrorWriter == null)
            {
                StandardErrorWriter = TextWriter.Synchronized(new StringWriter(_standardErrorData));
            }

            if (StandardOutputWriter == null)
            {
                StandardOutputWriter = TextWriter.Synchronized(new StringWriter(_standardOutputData));
            }

            _toolExited         = new ManualResetEvent(false);
            _toolTimeoutExpired = new ManualResetEvent(false);
            _status             = ProcessStatus.Running;

            try
            {
                proc                     = new Process();
                proc.StartInfo           = GetProcessStartInfo(pathToTool, commandLineCommands);
                proc.EnableRaisingEvents = true;
                proc.Exited             += ReceiveExitNotification;
                proc.ErrorDataReceived  += ReceiveStandardErrorData;
                proc.OutputDataReceived += ReceiveStandardOutputData;

                _exitCode = -1;

                proc.Start();
                proc.StandardInput.Close();
                proc.BeginErrorReadLine();
                proc.BeginOutputReadLine();

                _toolTimer = new Timer(ReceiveTimeoutNotification);
                _toolTimer.Change(Timeout, -1);
                HandleToolNotifications(proc);
            }
            finally
            {
                if (proc != null)
                {
                    try
                    {
                        _exitCode = proc.ExitCode;
                    }
                    catch (InvalidOperationException)
                    { }

                    proc.Close();
                    proc = null;
                }

                _toolExited.Close();
                _toolTimeoutExpired.Close();

                StandardErrorWriter.Dispose();
                StandardOutputWriter.Dispose();
                if (_toolTimer != null)
                {
                    _toolTimer.Dispose();
                }
            }
            return(_exitCode);
        }