Beispiel #1
0
        public int ExecuteCommand(Command command, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags)
        {
            OnCommandExecuting(command);

            var executor = CreateProcessExecutor();
            var exitCode = executor.Execute(PrepareInput(command, GitProcess.DefaultEncoding), stdOutReceiver, stdErrReceiver);
            return exitCode;
        }
Beispiel #2
0
 public GitActionImpl0(
     ICommandExecutor commandExecutor,
     Func <TParameters, Command> commandFactory,
     CommandExecutionFlags flags)
 {
     _commandExecutor = commandExecutor;
     _commandFactory  = commandFactory;
     _flags           = flags;
 }
Beispiel #3
0
        public GitOutput ExecuteCommand(Command command, Encoding encoding, CommandExecutionFlags flags)
        {
            OnCommandExecuting(command);

            var stdOutReceiver = new AsyncTextReader();
            var stdErrReceiver = new AsyncTextReader();
            var executor = CreateProcessExecutor();
            var exitCode = executor.Execute(PrepareInput(command, encoding), stdOutReceiver, stdErrReceiver);
            return new GitOutput(stdOutReceiver.GetText(), stdErrReceiver.GetText(), exitCode);
        }
Beispiel #4
0
 public static void Create <TParameters>(
     out IGitFunction <TParameters, byte[]> function,
     ICommandExecutor commandExecutor,
     Func <TParameters, Command> commandFactory,
     CommandExecutionFlags flags = CommandExecutionFlags.None)
     where TParameters : class
 {
     function = new GitFunctionImpl2 <TParameters>(
         commandExecutor, commandFactory, flags);
 }
Beispiel #5
0
 public GitActionImpl2(
     ICommandExecutor commandExecutor,
     Func <TParameters, Command> commandFactory,
     Action <TParameters, GitOutput> resultHandler,
     CommandExecutionFlags flags)
 {
     _commandExecutor = commandExecutor;
     _commandFactory  = commandFactory;
     _resultHandler   = resultHandler;
     _flags           = flags;
 }
Beispiel #6
0
 private static Action <Process> GetCancellationMethod(CommandExecutionFlags flags)
 {
     if ((flags & CommandExecutionFlags.DoNotKillProcess) == CommandExecutionFlags.DoNotKillProcess)
     {
         return(ProcessExecutor.CancellationMethods.AllowToExecute);
     }
     else
     {
         return(ProcessExecutor.CancellationMethods.KillProcess);
     }
 }
Beispiel #7
0
 public static void Create <TParameters, TOutput>(
     out IGitFunction <TParameters, TOutput> function,
     ICommandExecutor commandExecutor,
     Func <TParameters, Command> commandFactory,
     Func <TParameters, GitOutput, TOutput> resultParser,
     CommandExecutionFlags flags = CommandExecutionFlags.None)
     where TParameters : class
 {
     function = new GitFunctionImpl1 <TParameters, TOutput>(
         commandExecutor, commandFactory, resultParser, flags);
 }
Beispiel #8
0
 public static void Create <TParameters>(
     out IGitAction <TParameters> action,
     ICommandExecutor commandExecutor,
     Func <TParameters, Command> commandFactory,
     Action <TParameters, GitOutput> resultHandler,
     CommandExecutionFlags flags = CommandExecutionFlags.None)
     where TParameters : class
 {
     action = new GitActionImpl2 <TParameters>(
         commandExecutor, commandFactory, resultHandler, flags);
 }
Beispiel #9
0
 public GitFunctionImpl1(
     ICommandExecutor commandExecutor,
     Func <TParameters, Command> commandFactory,
     Func <TParameters, GitOutput, TOutput> resultParser,
     CommandExecutionFlags flags)
 {
     _commandExecutor = commandExecutor;
     _commandFactory  = commandFactory;
     _resultParser    = resultParser;
     _flags           = flags;
 }
Beispiel #10
0
        public GitOutput ExecuteCommand(Command command, Encoding encoding, CommandExecutionFlags flags)
        {
            OnCommandExecuting(command);

            var stdOutReceiver = new AsyncTextReader();
            var stdErrReceiver = new AsyncTextReader();
            var executor       = CreateProcessExecutor();
            var exitCode       = executor.Execute(PrepareInput(command, encoding), stdOutReceiver, stdErrReceiver);

            return(new GitOutput(stdOutReceiver.GetText(), stdErrReceiver.GetText(), exitCode));
        }
Beispiel #11
0
        public int ExecuteCommand(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags)
        {
            OnCommandExecuting(command);

            var executor = CreateProcessExecutor();
            var exitCode = executor.Execute(PrepareInput(command, encoding), stdOutReceiver, stdErrReceiver);

            return(exitCode);
        }
        public Task <int> ExecuteCommandAsync(Command command, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            Verify.Argument.IsNotNull(command, nameof(command));

            return(ExecuteCommandAsyncCore(command, GitProcess.DefaultEncoding, stdOutReceiver, stdErrReceiver, flags, cancellationToken));
        }
Beispiel #13
0
        public Task <GitOutput> ExecuteCommandAsync(Command command, Encoding encoding, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            Verify.Argument.IsNotNull(command, "command");

            return(ExecuteCommandAsyncCore(command, encoding, flags, cancellationToken));
        }
Beispiel #14
0
        public Task<int> ExecuteCommandAsync(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            Verify.Argument.IsNotNull(command, "command");

            return ExecuteCommandAsyncCore(command, encoding, stdOutReceiver, stdErrReceiver, flags, cancellationToken);
        }
Beispiel #15
0
        public Task<GitOutput> ExecuteCommandAsync(Command command, Encoding encoding, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            Verify.Argument.IsNotNull(command, "command");

            return ExecuteCommandAsyncCore(command, encoding, flags, cancellationToken);
        }
Beispiel #16
0
        private Task <int> ExecuteCommandAsyncCore(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            OnCommandExecuting(command);

            var input              = PrepareInput(command, encoding);
            var processExecutor    = CreateProcessExecutor();
            var cancellationMethod = GetCancellationMethod(flags);

            return(processExecutor.ExecuteAsync(
                       input,
                       stdOutReceiver,
                       stdErrReceiver,
                       cancellationMethod,
                       cancellationToken));
        }
Beispiel #17
0
        private Task <GitOutput> ExecuteCommandAsyncCore(Command command, Encoding encoding, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            OnCommandExecuting(command);

            var stdOutReceiver     = new AsyncTextReader();
            var stdErrReceiver     = new AsyncTextReader();
            var input              = PrepareInput(command, encoding);
            var processExecutor    = CreateProcessExecutor();
            var cancellationMethod = GetCancellationMethod(flags);

            return(processExecutor
                   .ExecuteAsync(
                       input,
                       stdOutReceiver,
                       stdErrReceiver,
                       cancellationMethod,
                       cancellationToken)
                   .ContinueWith(
                       task =>
            {
                int exitCode = TaskUtility.UnwrapResult(task);
                var stdOut = stdOutReceiver.GetText();
                var stdErr = stdErrReceiver.GetText();
                return new GitOutput(stdOut, stdErr, exitCode);
            },
                       cancellationToken,
                       TaskContinuationOptions.ExecuteSynchronously,
                       TaskScheduler.Default));
        }
Beispiel #18
0
 private static Action<Process> GetCancellationMethod(CommandExecutionFlags flags)
 {
     if((flags & CommandExecutionFlags.DoNotKillProcess) == CommandExecutionFlags.DoNotKillProcess)
     {
         return ProcessExecutor.CancellationMethods.AllowToExecute;
     }
     else
     {
         return ProcessExecutor.CancellationMethods.KillProcess;
     }
 }
Beispiel #19
0
        public Task <int> ExecuteCommandAsync(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            Verify.Argument.IsNotNull(command, "command");

            return(ExecuteCommandAsyncCore(command, encoding, stdOutReceiver, stdErrReceiver, flags, cancellationToken));
        }
Beispiel #20
0
        private Task<int> ExecuteCommandAsyncCore(Command command, Encoding encoding, IOutputReceiver stdOutReceiver, IOutputReceiver stdErrReceiver, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            OnCommandExecuting(command);

            var input              = PrepareInput(command, encoding);
            var processExecutor    = CreateProcessExecutor();
            var cancellationMethod = GetCancellationMethod(flags);
            return processExecutor.ExecuteAsync(
                input,
                stdOutReceiver,
                stdErrReceiver,
                cancellationMethod,
                cancellationToken);
        }
Beispiel #21
0
        private Task<GitOutput> ExecuteCommandAsyncCore(Command command, Encoding encoding, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            OnCommandExecuting(command);

            var stdOutReceiver     = new AsyncTextReader();
            var stdErrReceiver     = new AsyncTextReader();
            var input              = PrepareInput(command, encoding);
            var processExecutor    = CreateProcessExecutor();
            var cancellationMethod = GetCancellationMethod(flags);
            return processExecutor
                .ExecuteAsync(
                    input,
                    stdOutReceiver,
                    stdErrReceiver,
                    cancellationMethod,
                    cancellationToken)
                .ContinueWith(
                    task =>
                    {
                        int exitCode = TaskUtility.UnwrapResult(task);
                        var stdOut   = stdOutReceiver.GetText();
                        var stdErr   = stdErrReceiver.GetText();
                        return new GitOutput(stdOut, stdErr, exitCode);
                    },
                    cancellationToken,
                    TaskContinuationOptions.ExecuteSynchronously,
                    TaskScheduler.Default);
        }
Beispiel #22
0
        private async Task <GitOutput> ExecuteCommandAsyncCore(Command command, Encoding encoding, CommandExecutionFlags flags, CancellationToken cancellationToken)
        {
            OnCommandExecuting(command);

            var stdOutReceiver     = new AsyncTextReader();
            var stdErrReceiver     = new AsyncTextReader();
            var input              = PrepareInput(command, encoding);
            var processExecutor    = CreateProcessExecutor();
            var cancellationMethod = GetCancellationMethod(flags);
            var exitCode           = await processExecutor
                                     .ExecuteAsync(
                input,
                stdOutReceiver,
                stdErrReceiver,
                cancellationMethod,
                cancellationToken)
                                     .ConfigureAwait(continueOnCapturedContext: false);

            var stdOut = stdOutReceiver.GetText();
            var stdErr = stdErrReceiver.GetText();

            return(new GitOutput(stdOut, stdErr, exitCode));
        }