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;
8
10{
14 public class OnCondition : EventNode
15 {
16 private ExpressionAttribute condition;
17
21 public OnCondition()
22 : base()
23 {
24 }
25
29 [DefaultValueNull]
30 public string Condition
31 {
32 get => this.condition?.Expression;
33 set => this.condition = new ExpressionAttribute(value, false, this);
34 }
35
39 public override string LocalName => nameof(OnCondition);
40
45 public override IStateMachineNode Create()
46 {
47 return new OnCondition();
48 }
49
54 public override Task Parse(XmlElement Xml)
55 {
56 this.condition = new ExpressionAttribute(Xml.InnerText, true, this);
57
58 return base.Parse(Xml);
59 }
60
69 public override Task<EventHandlerReference> Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
70 {
71 return this.StateUpdated(Arguments);
72 }
73
79 public override Task Unregister(int EventIndex, EvaluationArguments Arguments)
80 {
81 return Task.CompletedTask;
82 }
83
91 public override async Task<EventHandlerReference> StateUpdated(EvaluationArguments Arguments)
92 {
93 if (this.condition is null)
94 return null;
95
96 if (await this.condition.Evaluate(Arguments.Variables) is bool b && b)
97 return new EventHandlerReference(null, true);
98
99 return null;
100 }
101
105 public override string Label
106 {
107 get
108 {
109 StringBuilder sb = new StringBuilder();
110
111 sb.Append('[');
112 sb.Append(this.condition.Expression);
113 sb.Append(']');
114
115 return sb.ToString();
116 }
117 }
118 }
119}
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:11
Event raised when a condition becomes true
Definition: OnCondition.cs:15
override Task< EventHandlerReference > Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
Registers the event
Definition: OnCondition.cs:69
OnCondition()
Event raised when a condition becomes true
Definition: OnCondition.cs:21
override async Task< EventHandlerReference > StateUpdated(EvaluationArguments Arguments)
Method called when the internal state of the state-machine has been updated.
Definition: OnCondition.cs:91
override Task Parse(XmlElement Xml)
Parses the State-machine node.
Definition: OnCondition.cs:54
override Task Unregister(int EventIndex, EvaluationArguments Arguments)
Registers the event
Definition: OnCondition.cs:79
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: OnCondition.cs:45
Action executed when entering a state.
Definition: OnEvent.cs:19