Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EventReference.cs
1using System.Threading.Tasks;
2using System.Xml;
10
12{
17 {
18 private ScriptableStringAttribute eventRef;
19
24 : base()
25 {
26 }
27
31 [DefaultValueNull]
33 {
34 get => this.eventRef?.Definition;
35 set => this.eventRef = new ScriptableStringAttribute(value, this);
36 }
37
42 public override Task Parse(XmlElement Xml)
43 {
44 this.eventRef = new ScriptableStringAttribute(XML.Attribute(Xml, "eventRef"), this);
45
46 return base.Parse(Xml);
47 }
48
52 public override string LocalName => nameof(EventReference);
53
58 public override IStateMachineNode Create()
59 {
60 return new EventReference();
61 }
62
68 public override void CheckReferences(StateMachine Machine, Token Token)
69 {
70 if (this.eventRef.IsConstant && !Machine.TryGetEvent(this.eventRef.Definition, out _))
71 throw new StateMachineException(Machine, "Event not found: " + this.eventRef.Definition);
72
73 base.CheckReferences(Machine, Token);
74 }
75
81 public async Task<Event> GetReference(EvaluationArguments Arguments)
82 {
83 if (this.eventRef is null)
84 throw new StateMachineException(Arguments.Machine, "No event id defined.");
85
86 string EventId = await this.eventRef.Evaluate(Arguments.Variables);
87 if (!Arguments.Machine.TryGetEvent(EventId, out Event Event))
88 throw new StateMachineException(Arguments.Machine, "Event not found: " + Event.Id);
89
90 return Event;
91 }
92
102 public override async Task<EventHandlerReference> Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
103 {
104 Event Event2 = await this.GetReference(Arguments);
105 return await Event2.Register(EventIndex, Arguments, Event);
106 }
107
113 public override async Task Unregister(int EventIndex, EvaluationArguments Arguments)
114 {
115 Event Event = await this.GetReference(Arguments);
116 await Event.Unregister(EventIndex, Arguments);
117 }
118
122 public override string Label => this.eventRef.Definition;
123
124 }
125}
Helps with common XML-related tasks.
Definition: XML.cs:21
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:1062
async Task< T > Evaluate(Variables Variables)
Evaluates the attribute
Contains information required for evaluating script in a state-machine.
StateMachine Machine
Reference to state-machine definition.
async Task< EventHandlerReference > Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
Registers the event
Definition: Event.cs:91
Task Unregister(int EventIndex, EvaluationArguments Arguments)
Registers the event
Definition: Event.cs:104
Abstract base class for State-Machine event nodes.
Definition: EventNode.cs:11
override async Task< EventHandlerReference > Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
Registers the event
override void CheckReferences(StateMachine Machine, Token Token)
Checks references in the node.
override Task Parse(XmlElement Xml)
Parses the State-machine node.
override async Task Unregister(int EventIndex, EvaluationArguments Arguments)
Registers the event
override IStateMachineNode Create()
Creates a new node of the corresponding type.
async Task< Event > GetReference(EvaluationArguments Arguments)
Evaluates the reference.
Action executed when entering a state.
Definition: OnEvent.cs:19
Class representing a state machine.
Definition: StateMachine.cs:43
bool TryGetEvent(string Id, out Model.Events.Event Event)
Tries to get an event.
Definition: ImplTypes.g.cs:58