Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Triggered.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading.Tasks;
5using System.Xml;
8using Waher.Script;
9
11{
16 {
17 private string @event;
18 private IEvent eventRef;
19
26 : base(Parent, Model)
27 {
28 }
29
33 public string Event => this.@event;
34
38 public override string LocalName => nameof(Triggered);
39
47 {
48 return new Triggered(Parent, Model);
49 }
50
55 public override Task FromXml(XmlElement Definition)
56 {
57 this.@event = XML.Attribute(Definition, "event");
58
59 return base.FromXml(Definition);
60 }
61
65 public override Task Initialize()
66 {
67 if (this.Parent is Wait Wait)
68 Wait.Register(this);
69
70 if (!this.Model.TryGetEvent(this.@event, out this.eventRef))
71 throw new Exception("Event " + this.@event + " not found.");
72
73 return base.Initialize();
74 }
75
81 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
82 {
84 return null;
85 }
86
91 public Task GetTask()
92 {
93 return this.eventRef.GetTrigger();
94 }
95
103 public void ExportPlantUml(StreamWriter Output, int Indentation, bool First, char QuoteChar)
104 {
105 Indent(Output, Indentation);
106
107 if (First)
108 Output.WriteLine("split");
109 else
110 Output.WriteLine("split again");
111
112 Indentation++;
113 Indent(Output, Indentation);
114
115 Output.Write("#FireBrick:");
116 Output.Write(this.@event);
117 Output.WriteLine("<");
118
119 base.ExportPlantUml(Output, Indentation + 1, QuoteChar);
120 }
121
122 }
123}
Root node of a simulation model
Definition: Model.cs:49
bool TryGetEvent(string Id, out IEvent Event)
Tries to get a registered event from the model.
Definition: Model.cs:365
Represents an activity that can be executed as the result of triggered events.
Definition: Activity.cs:17
static async Task ExecuteActivity(Variables Variables, LinkedListNode< IActivityNode > Start)
Executes an activity by executing a possibly branching sequence of nodes.
Definition: Activity.cs:143
Abstract base class for activity nodes
Definition: ActivityNode.cs:15
LinkedListNode< IActivityNode > FirstNode
First child activity node.
Definition: ActivityNode.cs:75
Waits for an event to be triggered
Definition: Triggered.cs:16
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: Triggered.cs:46
override Task Initialize()
Initialized the node before simulation.
Definition: Triggered.cs:65
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: Triggered.cs:81
override string LocalName
Local name of XML element defining contents of class.
Definition: Triggered.cs:38
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: Triggered.cs:55
Triggered(ISimulationNode Parent, Model Model)
Waits for an event to be triggered
Definition: Triggered.cs:25
void ExportPlantUml(StreamWriter Output, int Indentation, bool First, char QuoteChar)
Exports PlantUML
Definition: Triggered.cs:103
Conditional execution in an activity, based on external events.
Definition: Wait.cs:13
void Register(ITriggerNode Node)
Register a trigger node.
Definition: Wait.cs:47
Abstract base class for events
Definition: Event.cs:19
static void Indent(StreamWriter Output, int Indentation)
Adds indentation to the current row.
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
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.
Task GetTrigger()
Gets a Task object, that will be completed when the event is triggered.