Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ControlParameterNode.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading.Tasks;
5using System.Xml;
10using Waher.Script;
12
14{
19 {
20 private IValue value = null;
21 private string name;
22 private string page;
23 private string label;
24 private string description;
25 private string variable;
26 private string actor;
27 private string setEventId;
28 private IEvent setEvent;
29
36 : base(Parent, Model)
37 {
38 }
39
43 public IValue Value => this.value;
44
48 public string Name => this.name;
49
53 public string Page => this.page;
54
58 public string Label => this.label;
59
63 public string Description => this.description;
64
68 public string Variable => this.variable;
69
73 public string Actor => this.actor;
74
78 public IEvent SetEvent => this.setEvent;
79
83 public string SetEventId => this.setEventId;
84
89 public override Task FromXml(XmlElement Definition)
90 {
91 this.name = XML.Attribute(Definition, "name");
92 this.page = XML.Attribute(Definition, "page");
93 this.label = XML.Attribute(Definition, "label");
94 this.description = XML.Attribute(Definition, "description");
95 this.variable = XML.Attribute(Definition, "variable");
96 this.actor = XML.Attribute(Definition, "actor");
97 this.setEventId = XML.Attribute(Definition, "setEvent");
98
99 return base.FromXml(Definition);
100 }
101
106 public void Register(IValue Value)
107 {
108 if (this.value is null)
109 this.value = Value;
110 else
111 throw new Exception("Field node already has a value defined.");
112 }
113
117 public override Task Start()
118 {
119 if (!this.Model.TryGetEvent(this.setEventId, out this.setEvent))
120 throw new Exception("Event not found: " + this.setEventId);
121
122 this.setEvent.Register(this);
123
124 return base.Start();
125 }
126
132 public abstract void AddParameters(List<ControlParameter> Parameters, IActor Actor);
133
139 public Task Prepare(Variables Variables, List<KeyValuePair<string, object>> Tags)
140 {
141 return Task.CompletedTask; // Do nothing.
142 }
143
149 {
150 // Do nothing.
151 }
152
159 public void ExportPlantUml(StreamWriter Output, string Name, int Index)
160 {
161 Output.Write("actor \"");
162 Output.Write(this.actor);
163 Output.Write("\" as A");
164 Output.Write(" <<");
165 Output.Write(this.actor);
166 Output.WriteLine(">>");
167 Output.WriteLine("note right of A : Triggered when external\\ncontrol client sets parameter");
168 Output.Write("A --> UC1 : ");
169 Output.WriteLine(this.name);
170 }
171 }
172}
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
Abstract base class for actors
Definition: Actor.cs:15
Abstract base class for values
Definition: Value.cs:11
Value defined by variable.
Definition: Variable.cs:14
void Register(IValue Value)
Registers a value for the argument.
Task Prepare(Variables Variables, List< KeyValuePair< string, object > > Tags)
Prepares Variables for the execution of an event.
abstract void AddParameters(List< ControlParameter > Parameters, IActor Actor)
Adds control parameters.
ControlParameterNode(ISimulationNode Parent, Model Model)
Abstract base class for control parameter nodes.
void Release(Variables Variables)
Releases resources at the end of an event.
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
void ExportPlantUml(StreamWriter Output, string Name, int Index)
Exports the node to PlantUML script in a markdown document.
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.
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
Definition: IActor.cs:11
void Register(IEventPreparation PreparationNode)
Registers an event preparation node.
Interface for event preparation nodes
Interface for nodes holding a value node