Specifies a set of values that are used when you execute a command.
Properties of this class are passed to an instance of System.Diagnostics.ProcessStartInfo when spawning the process for this command.
Exemplo n.º 1
0
        /// <summary>
        /// Uses a <see cref="CommandStartInfo"/> object to execute this command.
        /// </summary>
        /// <param name="startInfo">Specifies how to execute this command.</param>
        /// <returns>The exit code of the process.</returns>
        public int Execute(CommandStartInfo startInfo)
        {
            this.StartProcess(startInfo);

            this.process.WaitForExit();

            return(this.CleanupProcess());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts the process with customized starting information
        /// </summary>
        /// <param name="startInfo">CommandStartInfo object that defines how this command should start</param>
        private void StartProcess(CommandStartInfo startInfo)
        {
            if (this.IsExecuting)
            {
                throw new CommandException("Cannot execute this command because it is already running.");
            }

            var commandStartingEventArgs = new CommandStartingEventArgs(startInfo);

            this.OnCommandStarting(commandStartingEventArgs);
            if (commandStartingEventArgs.Cancel)
            {
                return;
            }

            this.IsExecuting = true;

            if (this.HasExecuted)
            {
                throw new CommandException("This command has already been executed.", null, this);
            }

            if (startInfo == null)
            {
                throw new ArgumentNullException("startInfo");
            }

            var           commandSyntaxAttribute = this.GetCommandSyntaxAttribute();
            SyntaxBuilder syntaxBuilder          = new SyntaxBuilder(this);
            var           arguments = syntaxBuilder.Arguments;

            ProcessStartInfo processStartInfo = startInfo.GetProcessStartInfo(syntaxBuilder.FileName);

            processStartInfo.Arguments              = arguments;
            processStartInfo.RedirectStandardError  = true;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.UseShellExecute        = false;

            this.process.StartInfo          = processStartInfo;
            this.process.ErrorDataReceived += (s, e) =>
            {
                this.errorOutputBuilder.AppendLine(e.Data);
                this.OnErrorOutputWritten(e.Data);
            };

            this.process.OutputDataReceived += (s, e) =>
            {
                this.standardOutputBuilder.AppendLine(e.Data);
                this.OnStandardOutputWritten(e.Data);
            };

            this.process.Start();
            this.process.BeginErrorReadLine();
            this.process.BeginOutputReadLine();
            this.process.EnableRaisingEvents = true;
        }
 public CommandStartingEventArgs(CommandStartInfo startInfo)
 {
     this.startInfo = startInfo;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Executes the command with custom starting parameters.
 /// </summary>
 /// <param name="startInfo">The CommandStartInfo object that defines how the command should start</param>
 public void ExecuteAsync(CommandStartInfo startInfo)
 {
     this.process.Exited += this.ProcessExited;
     this.StartProcess(startInfo);
 }
 public CommandStartingEventArgs(CommandStartInfo startInfo)
 {
     this.startInfo = startInfo;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Starts the process with customized starting information
        /// </summary>
        /// <param name="startInfo">CommandStartInfo object that defines how this command should start</param>
        private void StartProcess(CommandStartInfo startInfo)
        {
            if (this.IsExecuting)
            {
                throw new CommandException("Cannot execute this command because it is already running.");
            }

            var commandStartingEventArgs = new CommandStartingEventArgs(startInfo);
            this.OnCommandStarting(commandStartingEventArgs);
            if (commandStartingEventArgs.Cancel)
            {
                return;
            }

            this.IsExecuting = true;

            if (this.HasExecuted)
            {
                throw new CommandException("This command has already been executed.", null, this);
            }

            if (startInfo == null)
            {
                throw new ArgumentNullException("startInfo");
            }

            var commandSyntaxAttribute = this.GetCommandSyntaxAttribute();
            SyntaxBuilder syntaxBuilder = new SyntaxBuilder(this);
            var arguments = syntaxBuilder.Arguments;

            ProcessStartInfo processStartInfo = startInfo.GetProcessStartInfo(syntaxBuilder.FileName);
            processStartInfo.Arguments = arguments;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.UseShellExecute = false;

            this.process.StartInfo = processStartInfo;
            this.process.ErrorDataReceived += (s, e) =>
                                                  {
                                                      this.errorOutputBuilder.AppendLine(e.Data);
                                                      this.OnErrorOutputWritten(e.Data);
                                                  };

            this.process.OutputDataReceived += (s, e) =>
                                                   {
                                                       this.standardOutputBuilder.AppendLine(e.Data);
                                                       this.OnStandardOutputWritten(e.Data);
                                                   };

            this.process.Start();
            this.process.BeginErrorReadLine();
            this.process.BeginOutputReadLine();
            this.process.EnableRaisingEvents = true;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Executes the command with custom starting parameters.
 /// </summary>
 /// <param name="startInfo">The CommandStartInfo object that defines how the command should start</param>
 public void ExecuteAsync(CommandStartInfo startInfo)
 {
     this.process.Exited += this.ProcessExited;
     this.StartProcess(startInfo);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Uses a <see cref="CommandStartInfo"/> object to execute this command.
        /// </summary>
        /// <param name="startInfo">Specifies how to execute this command.</param>
        /// <returns>The exit code of the process.</returns>
        public int Execute(CommandStartInfo startInfo)
        {
            this.StartProcess(startInfo);

            this.process.WaitForExit();

            return this.CleanupProcess();
        }