/// <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 <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 <IList <ReferencePushResult> > InvokeAsync(PushParameters parameters, IProgress <OperationProgress> progress, CancellationToken cancellationToken) { Verify.Argument.IsNotNull(parameters, "parameters"); var command = _commandFactory(parameters, true); if (progress != null) { progress.Report(new OperationProgress(Resources.StrsConnectingToRemoteHost.AddEllipsis())); } List <string> errorMessages = null; 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(); if (progress != null) { progress.Report(operationProgress); } if (operationProgress.IsIndeterminate) { if (errorMessages == null) { errorMessages = new List <string>(); } errorMessages.Add(operationProgress.ActionName); } else { if (errorMessages != null) { errorMessages.Clear(); } } } }; return(_commandExecutor .ExecuteCommandAsync( command, stdOutReceiver, stdErrReceiver, CommandExecutionFlags.None, cancellationToken) .ContinueWith(task => { int exitCode = TaskUtility.UnwrapResult(task); if (exitCode != 0) { string errorMessage; if (errorMessages != null && errorMessages.Count != 0) { errorMessage = string.Join(Environment.NewLine, errorMessages); } else { errorMessage = string.Format(CultureInfo.InvariantCulture, "git process exited with code {0}", exitCode); } throw new GitException(errorMessage); } else { return _resultsParser(stdOutReceiver.GetText()); } }, cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)); }