Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
OnCondition.cs
1using System.Text;
2using System.Threading.Tasks;
3using System.Xml;
7
9{
13 public class OnCondition : EventNode
14 {
15 private ExpressionAttribute condition;
16
20 public OnCondition()
21 : base()
22 {
23 }
24
28 [DefaultValueNull]
29 public string Condition
30 {
31 get => this.condition?.Expression;
32 set => this.condition = new ExpressionAttribute(value, false, this);
33 }
34
38 public override string LocalName => nameof(OnCondition);
39
44 public override IStateMachineNode Create()
45 {
46 return new OnCondition();
47 }
48
53 public override Task Parse(XmlElement Xml)
54 {
55 this.condition = new ExpressionAttribute(Xml.InnerText, true, this);
56
57 return base.Parse(Xml);
58 }
59
66 public override Task<bool> Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
67 {
68 return this.StateUpdated(Arguments);
69 }
70
76 public override Task Unregister(int EventIndex, EvaluationArguments Arguments)
77 {
78 return Task.CompletedTask;
79 }
80
86 public override async Task<bool> StateUpdated(EvaluationArguments Arguments)
87 {
88 if (this.condition is null)
89 return false;
90
91 if (await this.condition.Evaluate(Arguments.Variables) is bool b)
92 return b;
93
94 return false;
95 }
96
100 public override string Label
101 {
102 get
103 {
104 StringBuilder sb = new StringBuilder();
105
106 sb.Append('[');
107 sb.Append(this.condition.Expression);
108 sb.Append(']');
109
110 return sb.ToString();
111 }
112 }
113 }
114}
async Task< object > Evaluate(Variables Variables)
Evaluates the attribute
Contains information required for evaluating script in a state-machine.
Abstract base class for State-Machine event nodes.
Definition: EventNode.cs:10
Event raised when a condition becomes true
Definition: OnCondition.cs:14
OnCondition()
Event raised when a condition becomes true
Definition: OnCondition.cs:20
override async Task< bool > StateUpdated(EvaluationArguments Arguments)
Method called when the internal state of the state-machine has been updated.
Definition: OnCondition.cs:86
override Task Parse(XmlElement Xml)
Parses the State-machine node.
Definition: OnCondition.cs:53
override Task Unregister(int EventIndex, EvaluationArguments Arguments)
Registers the event
Definition: OnCondition.cs:76
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: OnCondition.cs:44
override Task< bool > Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
Registers the event
Definition: OnCondition.cs:66
Action executed when entering a state.
Definition: OnEvent.cs:17