-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGadgetStepsFeature.cs
51 lines (41 loc) · 1.39 KB
/
GadgetStepsFeature.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
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace Gadgetry.Steps;
/// <summary>
/// A feature used to interact with the <b>workers</b> associated with an <see cref="Gadget"/>.
/// </summary>
public class GadgetStepsFeature : IGadgetInitFeature, IGadgetRunFeature
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal readonly List<GadgetStep> steps = new();
/// <summary>
/// A collection of all steps associated with the <see cref="Gadget"/>
/// </summary>
public IReadOnlyList<GadgetStep> Steps => steps;
/// <summary>
/// Creates a new instance of the <see cref="GadgetStepsFeature"/> class.
/// </summary>
public GadgetStepsFeature()
{
}
void IGadgetInitFeature.Init(GadgetRuntime gadgetRuntime)
{
var runtimeFeature = gadgetRuntime.Features.GetOrCreateFeature<GadgetRuntimeStepsFeature>();
foreach (var step in Steps)
{
var stepRuntime = gadgetRuntime.ExtendWith(step.StepGadget);
runtimeFeature.steps.Add(stepRuntime);
}
}
async Task IGadgetRunFeature.RunAsync(GadgetRuntime gadgetRuntime, CancellationToken cancellationToken)
{
var runtimeFeature = gadgetRuntime.Features.GetOrCreateFeature<GadgetRuntimeStepsFeature>();
for (int i = 0; i < runtimeFeature.steps.Count; i++)
{
var stepRuntime = runtimeFeature.steps[i];
await stepRuntime.RunAsync(cancellationToken);
}
}
}