-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathDummyRecipe.cs
More file actions
107 lines (90 loc) · 3.32 KB
/
Copy pathDummyRecipe.cs
File metadata and controls
107 lines (90 loc) · 3.32 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2026 Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using Moryx.AbstractionLayer.Recipes;
using Moryx.AbstractionLayer.TestTools;
using Moryx.ControlSystem.TestTools.Tasks;
using Moryx.Workplans;
namespace Moryx.ControlSystem.TestTools;
/// <summary>
/// Implementation of a recipe for testing purposes
/// </summary>
public class DummyRecipe : ProductionRecipe
{
/// <summary>
/// Creates a new instances of the <see cref="DummyResult"/>
/// </summary>
public DummyRecipe()
{
}
/// <summary>
/// Creates a new instances of the <see cref="DummyResult"/> forwarding the constructor to the base class
/// </summary>
protected DummyRecipe(DummyRecipe source) : base(source)
{
}
/// <summary>
/// Creates a <see cref="ProductionRecipe"/> and fills the properties with reasonable values
/// </summary>
/// <param name="id">The id of the created recipe</param>
/// <returns>The created recipe</returns>
public static ProductionRecipe BuildRecipe(long id = 1)
{
var workplan = BuildWorkplan();
var recipe = new ProductionRecipe
{
Id = id,
Name = workplan.Name,
Revision = 1,
State = RecipeState.Released,
Workplan = workplan,
Product = new DummyProductType()
};
return recipe;
}
/// <summary>
/// Creates a <see cref="Workplan"/> and fills the properties with reasonable values
/// </summary>
/// <returns>The created workplan</returns>
public static Workplan BuildWorkplan()
{
var workplan = new Workplan
{
Name = "DummyWorkplan"
};
// Workplan boundaries
var start = WorkplanInstance.CreateConnector("StartNode", NodeClassification.Start);
var mounted = WorkplanInstance.CreateConnector("MountedNode", NodeClassification.Intermediate);
var done = WorkplanInstance.CreateConnector("DoneNode", NodeClassification.Intermediate);
var end = WorkplanInstance.CreateConnector("EndNode", NodeClassification.End);
var failed = WorkplanInstance.CreateConnector("Failed", NodeClassification.Failed);
workplan.Add(start, mounted, done, end, failed);
// Mount task
var mount = BuildTaskStep(new MountTask(), start, mounted);
// The really important task
var task = BuildTaskStep(new AssignIdentityTask(), mounted, done, failed);
// Unmount of successful article
var unmount = BuildTaskStep(new UnmountTask(), done, end);
workplan.Add(mount, task, unmount);
return workplan;
}
private static IWorkplanStep BuildTaskStep(IWorkplanStep task, IConnector input, params IConnector[] outputs)
{
task.Inputs[0] = input;
for (var i = 0; i < task.Outputs.Length; i++)
{
if (outputs.Length > i)
task.Outputs[i] = outputs[i];
else
task.Outputs[i] = outputs[outputs.Length - 1]; // Use last for all missing
}
return task;
}
/// <summary>
/// Creates a new <see cref="DummyRecipe"/> that is a clone of this one
/// </summary>
/// <returns>A clone of this recipe</returns>
public override IRecipe Clone()
{
return new DummyRecipe(this);
}
}