/// <summary> /// Aggregates the specified result with this result and returns the aggregation. /// </summary> /// <remarks> /// The rules are: /// 1. Errors take precedence over success. /// 2. Success takes precedence over skipped. /// 3. Stop takes precedence over continue. /// 4. The first exception in the result wins. /// </remarks> internal WorkUnitResult AggregateResult(WorkUnitResult result) { WorkUnitResultCode aggregateResult = _resultCode; WorkUnitActionCode aggregateAction = _actionCode; Exception aggregateException = _exception; if (result._resultCode == WorkUnitResultCode.Canceled || result.ResultCode == WorkUnitResultCode.Failed) { // Failed and canceled take priority aggregateResult = result._resultCode; } else if (result._resultCode == WorkUnitResultCode.Success && aggregateResult == WorkUnitResultCode.Skipped) { // Success only counts if we were previously in the skipped category. aggregateResult = result._resultCode; } if (result._actionCode == WorkUnitActionCode.Stop) { aggregateAction = result.ActionCode; } if (aggregateException == null) { aggregateException = result._exception; } return(new WorkUnitResult(aggregateResult, aggregateAction, aggregateException)); }
/// <summary> /// Walks through the set of tasks for this target and processes them by handing them off to the TaskBuilder. /// </summary> /// <returns> /// The result of the tasks, based on the last task which ran. /// </returns> private async Task <WorkUnitResult> ProcessBucket(ITaskBuilder taskBuilder, TargetLoggingContext targetLoggingContext, TaskExecutionMode mode, Lookup lookupForInference, Lookup lookupForExecution) { WorkUnitResultCode aggregatedTaskResult = WorkUnitResultCode.Success; WorkUnitActionCode finalActionCode = WorkUnitActionCode.Continue; WorkUnitResult lastResult = new WorkUnitResult(WorkUnitResultCode.Success, WorkUnitActionCode.Continue, null); try { // Grab the task builder so if cancel is called it will have something to operate on. _currentTaskBuilder = taskBuilder; int currentTask = 0; // Walk through all of the tasks and execute them in order. for (; (currentTask < _target.Children.Count) && !_cancellationToken.IsCancellationRequested; ++currentTask) { ProjectTargetInstanceChild targetChildInstance = _target.Children[currentTask]; if (DebuggerManager.DebuggingEnabled) { DebuggerManager.EnterState(targetChildInstance.Location, lookupForExecution.GlobalsForDebugging /* does not matter which lookup we get this from */); } // Execute the task. lastResult = await taskBuilder.ExecuteTask(targetLoggingContext, _requestEntry, _targetBuilderCallback, targetChildInstance, mode, lookupForInference, lookupForExecution, _cancellationToken); if (DebuggerManager.DebuggingEnabled) { DebuggerManager.LeaveState(targetChildInstance.Location); } if (lastResult.ResultCode == WorkUnitResultCode.Failed) { aggregatedTaskResult = WorkUnitResultCode.Failed; } else if (lastResult.ResultCode == WorkUnitResultCode.Success && aggregatedTaskResult != WorkUnitResultCode.Failed) { aggregatedTaskResult = WorkUnitResultCode.Success; } if (lastResult.ActionCode == WorkUnitActionCode.Stop) { finalActionCode = WorkUnitActionCode.Stop; break; } } if (_cancellationToken.IsCancellationRequested) { aggregatedTaskResult = WorkUnitResultCode.Canceled; finalActionCode = WorkUnitActionCode.Stop; } } finally { _currentTaskBuilder = null; } return(new WorkUnitResult(aggregatedTaskResult, finalActionCode, lastResult.Exception)); }
/// <summary> /// Creates a work result with the specified result codes. /// </summary> internal WorkUnitResult(WorkUnitResultCode resultCode, WorkUnitActionCode actionCode, Exception e) { _resultCode = resultCode; _actionCode = actionCode; _exception = e; }
/// <summary> /// Creates a new work result ready for aggregation during batches. /// </summary> internal WorkUnitResult() { _resultCode = WorkUnitResultCode.Skipped; _actionCode = WorkUnitActionCode.Continue; _exception = null; }
/// <summary> /// Creates a work result with the specified result codes. /// </summary> internal WorkUnitResult(WorkUnitResultCode resultCode, WorkUnitActionCode actionCode, Exception e) { _resultCode = resultCode; _actionCode = actionCode; _exception = e; }
/// <summary> /// Creates a new work result ready for aggregation during batches. /// </summary> internal WorkUnitResult() { _resultCode = WorkUnitResultCode.Skipped; _actionCode = WorkUnitActionCode.Continue; _exception = null; }
/// <summary> /// Walks through the set of tasks for this target and processes them by handing them off to the TaskBuilder. /// </summary> /// <returns> /// The result of the tasks, based on the last task which ran. /// </returns> private async Task <WorkUnitResult> ProcessBucket(ITaskBuilder taskBuilder, TargetLoggingContext targetLoggingContext, TaskExecutionMode mode, Lookup lookupForInference, Lookup lookupForExecution) { WorkUnitResultCode aggregatedTaskResult = WorkUnitResultCode.Success; WorkUnitActionCode finalActionCode = WorkUnitActionCode.Continue; WorkUnitResult lastResult = new WorkUnitResult(WorkUnitResultCode.Success, WorkUnitActionCode.Continue, null); List <StaticTarget.Task> staticTasks = new List <StaticTarget.Task>(); try { // Grab the task builder so if cancel is called it will have something to operate on. _currentTaskBuilder = taskBuilder; int currentTask = 0; // Walk through all of the tasks and execute them in order. for (; (currentTask < _target.Children.Count) && !_cancellationToken.IsCancellationRequested; ++currentTask) { ProjectTargetInstanceChild targetChildInstance = _target.Children[currentTask]; // Execute the task. lastResult = await taskBuilder.ExecuteTask(targetLoggingContext, _requestEntry, _targetBuilderCallback, targetChildInstance, mode, lookupForInference, lookupForExecution, _cancellationToken, staticTasks); if (lastResult.ResultCode == WorkUnitResultCode.Failed) { aggregatedTaskResult = WorkUnitResultCode.Failed; } else if (lastResult.ResultCode == WorkUnitResultCode.Success && aggregatedTaskResult != WorkUnitResultCode.Failed) { aggregatedTaskResult = WorkUnitResultCode.Success; } if (lastResult.ActionCode == WorkUnitActionCode.Stop) { finalActionCode = WorkUnitActionCode.Stop; break; } } if (_cancellationToken.IsCancellationRequested) { aggregatedTaskResult = WorkUnitResultCode.Canceled; finalActionCode = WorkUnitActionCode.Stop; } } finally { _currentTaskBuilder = null; } StaticTarget staticTarget = null; if (staticTasks.Count > 0) { staticTarget = new StaticTarget() { Location = _target.Location, Tasks = staticTasks, Name = Name }; } return(new WorkUnitResult(aggregatedTaskResult, finalActionCode, lastResult.Exception) { GeneratedStaticTarget = staticTarget, }); }