GetProcessStartInfo() private method

Returns a System.Diagnostics.ProcessStartInfo object which has matching properties of this CommandStartInfo object.
Specifically, the returned System.Diagnostics.ProcessStartInfo object that is returned has the same properties except for CommandStartInfo.Path and CommandStartInfo.WorkingDirectory.
private GetProcessStartInfo ( string fileName ) : ProcessStartInfo
fileName string The file name to use when creating the object.
return System.Diagnostics.ProcessStartInfo
Ejemplo n.º 1
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;
        }
Ejemplo 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;
        }