本文整理汇总了C#中IExecutionContext.Progress方法的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext.Progress方法的具体用法?C# IExecutionContext.Progress怎么用?C# IExecutionContext.Progress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExecutionContext
的用法示例。
在下文中一共展示了IExecutionContext.Progress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessTaskProgressCommand
private void ProcessTaskProgressCommand(IExecutionContext context, Dictionary<string, string> eventProperties, string data)
{
Int32 percentComplete = 0;
String processValue;
if (eventProperties.TryGetValue("value", out processValue))
{
Int32 progress;
if (Int32.TryParse(processValue, out progress))
{
percentComplete = (Int32)Math.Min(Math.Max(progress, 0), 100);
}
}
context.Progress(percentComplete, data);
}
示例2: RunAsync
public async Task RunAsync(IExecutionContext jobContext, IList<IStep> steps)
{
ArgUtil.NotNull(jobContext, nameof(jobContext));
ArgUtil.NotNull(steps, nameof(steps));
// TaskResult:
// Abandoned
// Canceled
// Failed
// Skipped
// Succeeded
// SucceededWithIssues
bool stepFailed = false;
bool criticalStepFailed = false;
int stepCount = 0;
jobContext.Variables.Agent_JobStatus = TaskResult.Succeeded;
foreach (IStep step in steps)
{
Trace.Info($"Processing step: DisplayName='{step.DisplayName}', AlwaysRun={step.AlwaysRun}, ContinueOnError={step.ContinueOnError}, Critical={step.Critical}, Enabled={step.Enabled}, Finally={step.Finally}");
ArgUtil.Equal(true, step.Enabled, nameof(step.Enabled));
ArgUtil.NotNull(step.ExecutionContext, nameof(step.ExecutionContext));
ArgUtil.NotNull(step.ExecutionContext.Variables, nameof(step.ExecutionContext.Variables));
jobContext.Progress(stepCount++ * 100 / steps.Count);
// TODO: Run finally even if canceled?
// Skip if a previous step failed and the current step is not AlwaysRun.
if ((stepFailed && !step.AlwaysRun && !step.Finally)
// Or if a previous Critical step failed and the current step is not Finally.
|| (criticalStepFailed && !step.Finally))
{
Trace.Info("Skipping step.");
step.ExecutionContext.Result = TaskResult.Skipped;
continue;
}
// Run the step.
Trace.Info("Starting the step.");
step.ExecutionContext.Start();
List<string> expansionWarnings;
step.ExecutionContext.Variables.RecalculateExpanded(out expansionWarnings);
expansionWarnings?.ForEach(x => step.ExecutionContext.Warning(x));
List<OperationCanceledException> allCancelExceptions = new List<OperationCanceledException>();
try
{
await step.RunAsync();
}
catch (OperationCanceledException ex)
{
if (step.ExecutionContext.TimeoutExceeded)
{
Trace.Error($"Caught timeout exception from step: {ex.Message}");
step.ExecutionContext.Error(StringUtil.Loc("StepTimedOut"));
step.ExecutionContext.Result = TaskResult.Failed;
}
else
{
// Log the exception and cancel the step.
Trace.Error($"Caught cancellation exception from step: {ex}");
step.ExecutionContext.Error(ex);
step.ExecutionContext.Result = TaskResult.Canceled;
}
//save the OperationCanceledException, merge with OperationCanceledException throw from Async Commands.
allCancelExceptions.Add(ex);
}
catch (Exception ex)
{
// Log the error and fail the step.
Trace.Error($"Caught exception from step: {ex}");
step.ExecutionContext.Error(ex);
step.ExecutionContext.Result = TaskResult.Failed;
}
// Wait till all async commands finish.
foreach (var command in step.ExecutionContext.AsyncCommands ?? new List<IAsyncCommandContext>())
{
try
{
// wait async command to finish.
await command.WaitAsync();
}
catch (OperationCanceledException ex)
{
if (step.ExecutionContext.TimeoutExceeded)
{
// Log the timeout error, set step result to falied if the current result is not canceled.
Trace.Error($"Caught timeout exception from async command {command.Name}: {ex}");
step.ExecutionContext.Error(StringUtil.Loc("StepTimedOut"));
// if the step already canceled, don't set it to failed.
step.ExecutionContext.CommandResult = TaskResultUtil.MergeTaskResults(step.ExecutionContext.CommandResult, TaskResult.Failed);
}
else
{
// log and save the OperationCanceledException, set step result to canceled if the current result is not failed.
Trace.Error($"Caught cancellation exception from async command {command.Name}: {ex}");
step.ExecutionContext.Error(ex);
// if the step already failed, don't set it to canceled.
//.........这里部分代码省略.........
示例3: ProcessTaskCompleteCommand
private void ProcessTaskCompleteCommand(IExecutionContext context, Dictionary<string, string> eventProperties, String data)
{
string resultText;
TaskResult result;
if (!eventProperties.TryGetValue(TaskCompleteEventProperties.Result, out resultText) ||
String.IsNullOrEmpty(resultText) ||
!Enum.TryParse<TaskResult>(resultText, out result))
{
throw new Exception(StringUtil.Loc("InvalidCommandResult"));
}
context.Result = TaskResultUtil.MergeTaskResults(context.Result, result);
context.Progress(100, data);
}
示例4: GetSourceAsync
//.........这里部分代码省略.........
{
//fall back
executionContext.Warning("Unable to run \"git clean -fdx\" and \"git reset --hard HEAD\" successfully, delete source folder instead.");
IOUtil.DeleteDirectory(targetPath, cancellationToken);
}
}
}
// if the folder is missing, create it
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
// if the folder contains a .git folder, it means the folder contains a git repo that matches the remote url and in a clean state.
// we will run git fetch to update the repo.
if (!Directory.Exists(Path.Combine(targetPath, ".git")))
{
// init git repository
int exitCode_init = await _gitCommandManager.GitInit(executionContext, targetPath);
if (exitCode_init != 0)
{
throw new InvalidOperationException($"Unable to use git.exe init repository under {targetPath}, 'git init' failed with exit code: {exitCode_init}");
}
int exitCode_addremote = await _gitCommandManager.GitRemoteAdd(executionContext, targetPath, "origin", repositoryUrl.AbsoluteUri);
if (exitCode_addremote != 0)
{
throw new InvalidOperationException($"Unable to use git.exe add remote 'origin', 'git remote add' failed with exit code: {exitCode_addremote}");
}
}
cancellationToken.ThrowIfCancellationRequested();
executionContext.Progress(0, "Starting fetch...");
// disable git auto gc
int exitCode_disableGC = await _gitCommandManager.GitDisableAutoGC(executionContext, targetPath);
if (exitCode_disableGC != 0)
{
executionContext.Warning("Unable turn off git auto garbage collection, git fetch operation may trigger auto garbage collection which will affect the performence of fetching.");
}
// inject credential into fetch url
executionContext.Debug("Inject credential into git remote url.");
Uri urlWithCred = null;
urlWithCred = GetCredentialEmbeddedRepoUrl(repositoryUrl, username, password);
// inject credential into fetch url
executionContext.Debug("Inject credential into git remote fetch url.");
int exitCode_seturl = await _gitCommandManager.GitRemoteSetUrl(executionContext, targetPath, "origin", urlWithCred.AbsoluteUri);
if (exitCode_seturl != 0)
{
throw new InvalidOperationException($"Unable to use git.exe inject credential to git remote fetch url, 'git remote set-url' failed with exit code: {exitCode_seturl}");
}
// inject credential into push url
executionContext.Debug("Inject credential into git remote push url.");
exitCode_seturl = await _gitCommandManager.GitRemoteSetPushUrl(executionContext, targetPath, "origin", urlWithCred.AbsoluteUri);
if (exitCode_seturl != 0)
{
throw new InvalidOperationException($"Unable to use git.exe inject credential to git remote push url, 'git remote set-url --push' failed with exit code: {exitCode_seturl}");
}
// If this is a build for a pull request, then include
// the pull request reference as an additional ref.
string fetchSpec = IsPullRequest(sourceBranch) ? StringUtil.Format("+{0}:{1}", sourceBranch, GetRemoteRefName(sourceBranch)) : null;