public TaskResult(TaskNode task, bool success, object returnValue, Exception exception) { Task = task; Success = success; ReturnValue = returnValue; Exception = exception; }
private TaskResult ExecuteTask(TaskNode task, Func <string, bool> circularDependencyGuard) { if (!task.Dependencies.Any() && task.Definition.Implementation == null) { _log.LogTrace($"Skipping empty task: {task.Definition.Name}"); return(new TaskResult(task, success: true, returnValue: null, exception: null)); } using (var activity = _log.BeginActivity("TASK", task.Definition.Name)) { // Run dependencies TaskResult result; var dependencyResults = new Dictionary <string, TaskResult>(); foreach (var dependency in task.Dependencies) { if (circularDependencyGuard(dependency.Definition.Name)) { throw new InvalidOperationException($"Circular dependency detected at '{dependency.Definition.Name}'"); } result = ExecuteTask(dependency, ChainPredicate(circularDependencyGuard, dependency.Definition.Name)); if (!result.Success) { return(result); } dependencyResults[dependency.Definition.Name] = result; } // Run the task itself result = ExecuteTask(new TaskInvocation(task, _services, dependencyResults)); activity.Success = result.Success; if (result.Exception != null) { activity.Conclusion = $"failed with {result.Exception.GetType().Name}: {result.Exception.Message}"; } return(result); } }
public TaskInvocation(TaskNode task, IServiceProvider services, Dictionary <string, TaskResult> dependencyResults) { Task = task; Services = services; DependencyResults = dependencyResults; }