Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SetVariable.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 IValue value = null;
18 private string name;
19
26 : base(Parent, Model)
27 {
28 }
29
33 public override string LocalName => nameof(SetVariable);
34
38 public string Name => this.name;
39
47 {
48 return new SetVariable(Parent, Model);
49 }
50
55 public override Task FromXml(XmlElement Definition)
56 {
57 this.name = XML.Attribute(Definition, "name");
58
59 return base.FromXml(Definition);
60 }
61
66 public void Register(IValue Value)
67 {
68 if (this.value is null)
69 this.value = Value;
70 else
71 throw new Exception("SetVariable node already has a value defined.");
72 }
73
79 public override async Task Prepare(Variables Variables, List<KeyValuePair<string, object>> Tags)
80 {
81 Variables[this.name] = this.value is null ? null : await this.value.EvaluateAsync(Variables);
82 }
83
88 public override void Release(Variables Variables)
89 {
90 Variables.Remove(this.name);
91 }
92
99 public override void ExportPlantUml(StreamWriter Output, string Name, int Index)
100 {
101 string s = Index.ToString();
102
103 Output.Write("note \"");
104 Output.Write(this.name);
105 Output.Write('=');
106 this.value?.ExportPlantUml(Output, 0, '\'');
107 Output.Write("\" as N");
108 Output.Write(this.name);
109 Output.WriteLine(s);
110
111 Output.Write("UC");
112 Output.Write(s);
113 Output.Write(" .. N");
114 Output.Write(this.name);
115 Output.WriteLine(s);
116 }
117 }
118}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for event preparation nodes (with children).
Sets a variable value when an event is triggered.
Definition: SetVariable.cs:16
SetVariable(ISimulationNode Parent, Model Model)
Sets a variable value when an event is triggered.
Definition: SetVariable.cs:25
string Name
Name of variable within the scope of the event.
Definition: SetVariable.cs:38
override void ExportPlantUml(StreamWriter Output, string Name, int Index)
Exports the node to PlantUML script in a markdown document.
Definition: SetVariable.cs:99
override string LocalName
Local name of XML element defining contents of class.
Definition: SetVariable.cs:33
override async Task Prepare(Variables Variables, List< KeyValuePair< string, object > > Tags)
Prepares Variables for the execution of an event.
Definition: SetVariable.cs:79
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: SetVariable.cs:46
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: SetVariable.cs:55
void Register(IValue Value)
Registers a value for the argument.
Definition: SetVariable.cs:66
override void Release(Variables Variables)
Releases resources at the end of an event.
Definition: SetVariable.cs:88
Abstract base class for values
Definition: Value.cs:11
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
virtual bool Remove(string VariableName)
Removes a varaiable from the collection.
Definition: Variables.cs:147
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.
void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Task< object > EvaluateAsync(Variables Variables)
Evaluates the value.
Interface for nodes holding a value node