Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Do.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
7
9{
13 public class Do : ActionContainer
14 {
15 private ExpressionAttribute @while;
16
20 public Do()
21 : base()
22 {
23 }
24
28 [DefaultValueNull]
29 public string While
30 {
31 get => this.@while?.Expression;
32 set => this.@while = new ExpressionAttribute(value, false, this);
33 }
34
38 public override string LocalName => nameof(Do);
39
44 public override IStateMachineNode Create()
45 {
46 return new Do();
47 }
48
53 public override Task Parse(XmlElement Xml)
54 {
55 this.@while = new ExpressionAttribute(XML.Attribute(Xml, "while"), true, this);
56
57 return base.Parse(Xml);
58 }
59
64 public override async Task Execute(EvaluationArguments Arguments)
65 {
66 while (true)
67 {
68 await base.Execute(Arguments);
69
70 if (!(await this.@while.Evaluate(Arguments.Variables) is bool Result))
71 throw new Exception("Conditions must return boolean values.");
72
73 if (!Result)
74 break;
75 }
76 }
77 }
78}
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:914
Abstract base class for action nodes that contain other action nodes.
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
Definition: Do.cs:64
override Task Parse(XmlElement Xml)
Parses the State-machine node.
Definition: Do.cs:53
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: Do.cs:44
Contains information required for evaluating script in a state-machine.