-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionScheduler.cs
55 lines (48 loc) · 1.4 KB
/
ActionScheduler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace cake
{
public class ActionScheduler
{
private readonly Dictionary<TargetGenerateSettings, HashSet<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, HashSet<string>>();
public bool AnyJobsLeft
{
get { return _scheduledActions.Any(); }
}
public void Add(SchedulableAction schedulableAction)
{
_scheduledActions.Add(schedulableAction.Settings, new HashSet<string>(schedulableAction.InputFilesRequiringGeneration));
}
public TargetGenerateSettings FindJobToRun()
{
var findJobToRun = _scheduledActions.Where(kvp => kvp.Value.Count == 0).Select(kvp=>kvp.Key).FirstOrDefault();
if (findJobToRun!=null)
_scheduledActions.Remove(findJobToRun);
return findJobToRun;
}
public void JobFinished(TargetGenerateSettings finishedJob)
{
foreach(var outputFile in finishedJob.OutputFiles)
{
foreach (var deps in _scheduledActions.Values)
deps.Remove(outputFile);
}
}
public void VerifyAllInputFilesArePresentOrWillBeGenerated()
{
foreach(var scheduledAction in _scheduledActions.Keys)
{
foreach(var inputFile in scheduledAction.InputFiles)
{
if (File.Exists(inputFile))
continue;
if (_scheduledActions.Keys.Any(sa=>sa.OutputFiles.Contains(inputFile)))
continue;
throw new MissingDependencyException();
}
}
}
}
}