Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Conditional.cs
1using System.Collections.Generic;
2using System.IO;
3using System.Threading.Tasks;
4using Waher.Script;
5
7{
12 {
13 private readonly LinkedList<IConditionNode> conditions = new LinkedList<IConditionNode>();
14
21 : base(Parent, Model)
22 {
23 }
24
28 public override string LocalName => nameof(Conditional);
29
37 {
38 return new Conditional(Parent, Model);
39 }
40
45 public void Register(IConditionNode Node)
46 {
47 this.conditions.AddLast(Node);
48 }
49
55 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
56 {
57 foreach (IConditionNode Condition in this.conditions)
58 {
59 if (await Condition.IsTrue(Variables))
60 return await Condition.Execute(Variables);
61 }
62
63 return null;
64 }
65
72 public override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
73 {
74 bool First = true;
75
76 foreach (IConditionNode Node in this.conditions)
77 {
78 Node.ExportPlantUml(Output, Indentation, First, QuoteChar);
79 First = false;
80 }
81
82 if (!First)
83 {
84 Indent(Output, Indentation);
85 Output.WriteLine("endif");
86 }
87 }
88
89 }
90}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for activity nodes
Definition: ActivityNode.cs:15
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: Condition.cs:84
async Task< bool > IsTrue(Variables Variables)
If the node condition is true.
Definition: Condition.cs:95
Conditional execution in an activity.
Definition: Conditional.cs:12
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: Conditional.cs:55
void Register(IConditionNode Node)
Register a conditional node.
Definition: Conditional.cs:45
override string LocalName
Local name of XML element defining contents of class.
Definition: Conditional.cs:28
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Definition: Conditional.cs:72
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: Conditional.cs:36
Conditional(ISimulationNode Parent, Model Model)
Conditional execution in an activity.
Definition: Conditional.cs:20
static void Indent(StreamWriter Output, int Indentation)
Adds indentation to the current row.
Collection of variables.
Definition: Variables.cs:25
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.
void ExportPlantUml(StreamWriter Output, int Indentation, bool First, char QuoteChar)
Exports PlantUML
Interface for elements taking Condition nodes.
Definition: IConditional.cs:9