Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Eval.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Script;
7
9{
13 public class Eval : ActivityNode
14 {
15 private string script;
16 private Expression expression;
17
24 : base(Parent, Model)
25 {
26 }
27
31 public string Script => this.script;
32
36 public Expression Expression => this.expression;
37
41 public override string LocalName => nameof(Eval);
42
50 {
51 return new Eval(Parent, Model);
52 }
53
58 public override Task FromXml(XmlElement Definition)
59 {
60 this.script = Values.Script.RemoveIndent(Definition.InnerText);
61 this.expression = new Expression(this.script);
62
63 return base.FromXml(Definition);
64 }
65
69 public override bool ParseChildren => false;
70
76 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
77 {
78 await this.expression.EvaluateAsync(Variables);
79 return null;
80 }
81
88 public override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
89 {
90 ExportPlantUml(this.script, Output, Indentation, QuoteChar, true);
91 }
92
101 public static void ExportPlantUml(string Script, StreamWriter Output, int Indentation, char QuoteChar, bool Delimiters)
102 {
103 bool First = true;
104
105 if (QuoteChar != '"')
106 Script = Script.Replace('"', QuoteChar);
107
108 foreach (string Row in Script.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'))
109 {
110 if (First)
111 {
112 if (Delimiters)
113 {
114 Indent(Output, Indentation);
115 Output.Write(':');
116 }
117
118 First = false;
119 }
120 else
121 Output.Write("\\n");
122
123 if (!string.IsNullOrEmpty(Row))
124 Output.Write(Row.Replace("\t", "\\t"));
125 }
126
127 if (!First && Delimiters)
128 Output.WriteLine(";");
129 }
130 }
131}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for activity nodes
Definition: ActivityNode.cs:15
Executes script in an activity.
Definition: Eval.cs:14
override string LocalName
Local name of XML element defining contents of class.
Definition: Eval.cs:41
override bool ParseChildren
If children are to be parsed by FromXml(XmlElement)
Definition: Eval.cs:69
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Definition: Eval.cs:88
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: Eval.cs:76
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: Eval.cs:49
static void ExportPlantUml(string Script, StreamWriter Output, int Indentation, char QuoteChar, bool Delimiters)
Exports PlantUML
Definition: Eval.cs:101
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: Eval.cs:58
Eval(ISimulationNode Parent, Model Model)
Represents a delay in an activity.
Definition: Eval.cs:23
Expression Expression
Parsed expression
Definition: Eval.cs:36
static void Indent(StreamWriter Output, int Indentation)
Adds indentation to the current row.
Class managing a script expression.
Definition: Expression.cs:39
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
Definition: Expression.cs:4275
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.