Ejemplo n.º 1
0
 private void Resolve(RegisteredTask task, List<RegisteredTask> resolved, List<RegisteredTask> unresolved)
 {
     unresolved.Add(task);
     foreach (var dependency in GetDependenciesOf(task))
     {
         if (!resolved.Contains(dependency))
             if (unresolved.Contains(dependency))
                 throw new CircularTaskDependencyDetectedException(task, dependency);
         Resolve(dependency, resolved, unresolved);
     }
     if (!resolved.Contains(task))
         resolved.Add(task);
     unresolved.Remove(task);
         
 }
Ejemplo n.º 2
0
        public void Dryrun_should_output_the_graph()
        {
            var t1 = new RegisteredTask(typeof(ExampleTask0));
            var t2 = new RegisteredTask(typeof(ExampleTask1));
            var t3 = new RegisteredTask(typeof(ExampleTask2));

            var output = new FakeConsoleOutput();
            PrepareInstance<IOutput>(new OutputService(output));
            var dryrun = CreateInstance<Dryrun>();

            A.CallTo(() => Fake<ITaskGraphResolver>().Resolve(t3)).Returns(new[] {t1, t2, t3});
            A.CallTo(() => Fake<IRequestedTask>().Current).Returns(t3);

            dryrun.Run();

            StringAssert.Contains(nameof(ExampleTask2), output.Lines.First());
            StringAssert.Contains(nameof(ExampleTask1), output.ToString());
            StringAssert.Contains(nameof(ExampleTask0), output.ToString());
        }
Ejemplo n.º 3
0
 public CircularTaskDependencyDetectedException(RegisteredTask task, RegisteredTask dependency)
 {
     Task = task;
     Dependency = dependency;
 }
Ejemplo n.º 4
0
 private IEnumerable<RegisteredTask> GetDependenciesOf(RegisteredTask task)
 {
     return task.DependsOn.Select(x => _taskRegistration.Tasks.SingleOrDefault(y => y.Name == x)).Where(x => x != null);
 }
Ejemplo n.º 5
0
 public RegisteredTask[] Resolve(RegisteredTask targetTask)
 {
     var result = new List<RegisteredTask>();
     Resolve(targetTask, result, new List<RegisteredTask>());
     return result.ToArray();
 }