public Task <byte[]> InvokeAsync(TParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, nameof(parameters)); var command = _commandFactory(parameters); var stdInReceiver = new AsyncBytesReader(); var stdErrReceiver = new AsyncTextReader(); return(_commandExecutor .ExecuteCommandAsync( command, stdInReceiver, stdErrReceiver, CommandExecutionFlags.None, cancellationToken) .ContinueWith( t => { var exitCode = TaskUtility.UnwrapResult(t); if (exitCode != 0) { throw new GitException(stdErrReceiver.GetText()); } return stdInReceiver.GetBytes(); }, cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)); }
/// <summary>Clone existing repository.</summary> /// <param name="parameters"><see cref="CloneRepositoryParameters"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="parameters"/> == <c>null</c>.</exception> public Task InvokeAsync(CloneRepositoryParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, nameof(parameters)); var command = _commandFactory(parameters, true); if (!Directory.Exists(parameters.Path)) { Directory.CreateDirectory(parameters.Path); } progress?.Report(new OperationProgress(Resources.StrsConnectingToRemoteHost.AddEllipsis())); var errorMessages = default(List <string>); var stdOutReceiver = new NullReader(); var stdErrReceiver = new NotifyingAsyncTextReader(); stdErrReceiver.TextLineReceived += (s, e) => { if (!string.IsNullOrWhiteSpace(e.Text)) { var parser = new GitParser(e.Text); var operationProgress = parser.ParseProgress(); progress?.Report(operationProgress); if (operationProgress.IsIndeterminate) { if (!string.IsNullOrWhiteSpace(operationProgress.ActionName)) { if (errorMessages == null) { errorMessages = new List <string>(); } errorMessages.Add(operationProgress.ActionName); } } else { errorMessages?.Clear(); } } }; return(_commandExecutor .ExecuteCommandAsync(command, stdOutReceiver, stdErrReceiver, CommandExecutionFlags.None, cancellationToken) .ContinueWith( t => { var exitCode = TaskUtility.UnwrapResult(t); if (exitCode != 0) { var errorMessage = errorMessages != null && errorMessages.Count != 0 ? string.Join(Environment.NewLine, errorMessages) : string.Format(CultureInfo.InvariantCulture, "git process exited with code {0}", exitCode); throw new GitException(errorMessage); } }, cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)); }
public async Task <string> InvokeAsync(QueryTagMessageParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, nameof(parameters)); var command = _commandFactory(parameters); var output = await _commandExecutor .ExecuteCommandAsync(command, CommandExecutionFlags.None, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return(ParseTagMessage(command, output)); }
public async Task <IList <ReferencePushResult> > InvokeAsync(PushParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, nameof(parameters)); var command = _commandFactory(parameters, true); progress?.Report(new OperationProgress(Resources.StrsConnectingToRemoteHost.AddEllipsis())); var errorMessages = default(List <string>); var stdOutReceiver = new AsyncTextReader(); var stdErrReceiver = new NotifyingAsyncTextReader(); stdErrReceiver.TextLineReceived += (s, e) => { if (!string.IsNullOrWhiteSpace(e.Text)) { var parser = new GitParser(e.Text); var operationProgress = parser.ParseProgress(); progress?.Report(operationProgress); if (operationProgress.IsIndeterminate) { if (errorMessages == null) { errorMessages = new List <string>(); } errorMessages.Add(operationProgress.ActionName); } else { errorMessages?.Clear(); } } }; var processExitCode = await _commandExecutor .ExecuteCommandAsync( command, stdOutReceiver, stdErrReceiver, CommandExecutionFlags.None, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); if (processExitCode != 0) { var errorMessage = errorMessages != null && errorMessages.Count != 0 ? string.Join(Environment.NewLine, errorMessages) : string.Format(CultureInfo.InvariantCulture, "git process exited with code {0}", processExitCode); throw new GitException(errorMessage); } return(_resultsParser(stdOutReceiver.GetText())); }
public Task InvokeAsync(TParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, nameof(parameters)); var command = _commandFactory(parameters); return(_commandExecutor .ExecuteCommandAsync(command, _flags, cancellationToken) .ContinueWith( t => TaskUtility.UnwrapResult(t).ThrowOnBadReturnCode(), cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)); }
public Task <string> InvokeAsync(QueryTagMessageParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, "parameters"); var command = _commandFactory(parameters); return(_commandExecutor .ExecuteCommandAsync(command, CommandExecutionFlags.None, cancellationToken) .ContinueWith( t => { var output = TaskUtility.UnwrapResult(t); return ParseTagMessage(command, output); }, cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)); }
public async Task <TOutput> InvokeAsync(TParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, nameof(parameters)); var command = CreateCommand(parameters); var parser = CreateParser(); var stdOutReceiver = new AsyncTextParser(parser); var stdErrReceiver = new AsyncTextReader(); var processExitCode = await _commandExecutor .ExecuteCommandAsync(command, stdOutReceiver, stdErrReceiver, GetExecutionFlags(), cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); if (processExitCode != 0) { HandleNonZeroExitCode(stdErrReceiver, processExitCode); } return(parser.GetResult()); }
public async Task ExecuteCommandAsync(ICommand command) { await commandExecutor.ExecuteCommandAsync(command); }
public Task <IList <ReflogRecordData> > InvokeAsync(QueryReflogParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, "parameters"); var command1 = _commandFactory(parameters); var command2 = GetCommand2(parameters); var tcs = new TaskCompletionSource <object>(); if (cancellationToken.CanBeCanceled) { cancellationToken.Register(() => tcs.TrySetCanceled()); } int completedTasks = 0; var task1 = _commandExecutor.ExecuteCommandAsync(command1, CommandExecutionFlags.None, cancellationToken); var task2 = _commandExecutor.ExecuteCommandAsync(command2, CommandExecutionFlags.None, cancellationToken); task1.ContinueWith( t => tcs.TrySetCanceled(), cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnCanceled, TaskScheduler.Default); task2.ContinueWith( t => tcs.TrySetCanceled(), cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnCanceled, TaskScheduler.Default); task1.ContinueWith( t => tcs.TrySetException(t.Exception), cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default); task2.ContinueWith( t => tcs.TrySetException(t.Exception), cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default); task1.ContinueWith( t => { if (Interlocked.Increment(ref completedTasks) == 2) { tcs.TrySetResult(null); } }, cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); task2.ContinueWith( t => { if (Interlocked.Increment(ref completedTasks) == 2) { tcs.TrySetResult(null); } }, cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); return(tcs.Task. ContinueWith( t => { TaskUtility.PropagateFaultedStates(t); var output1 = TaskUtility.UnwrapResult(task1); output1.ThrowOnBadReturnCode(); var output2 = TaskUtility.UnwrapResult(task2); output2.ThrowOnBadReturnCode(); var cache = new Dictionary <Hash, RevisionData>(Hash.EqualityComparer); var list = ParseResult1(output1, cache); var parser = new GitParser(output2.Output); parser.ParseCommitParentsFromRaw(list.Select(rrd => rrd.Revision), cache); return list; }, cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)); }