Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Delay.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
8using Waher.Script;
9
11{
15 public class Delay : ActivityNode
16 {
17 private Duration duration;
18
25 : base(Parent, Model)
26 {
27 }
28
32 public Duration Duration => this.duration;
33
37 public override string LocalName => nameof(Delay);
38
46 {
47 return new Delay(Parent, Model);
48 }
49
54 public override Task FromXml(XmlElement Definition)
55 {
56 this.duration = XML.Attribute(Definition, "duration", Duration.Zero);
57
58 return Task.CompletedTask;
59 }
60
66 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
67 {
68 DateTime Now = DateTime.Now;
69 DateTime TP = Now + this.duration;
70 TimeSpan TS = TP - Now;
71
72 if (TS > TimeSpan.Zero)
73 await Task.Delay(TS);
74
75 return null;
76 }
77
84 public override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
85 {
86 Indent(Output, Indentation);
87 Output.Write(":Delay(");
88
89 Values.Duration.ExportText(this.duration, Output);
90
91 Output.WriteLine(");");
92 }
93 }
94}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for activity nodes
Definition: ActivityNode.cs:15
Represents a delay in an activity.
Definition: Delay.cs:16
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: Delay.cs:45
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Definition: Delay.cs:84
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: Delay.cs:54
Delay(ISimulationNode Parent, Model Model)
Represents a delay in an activity.
Definition: Delay.cs:24
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: Delay.cs:66
override string LocalName
Local name of XML element defining contents of class.
Definition: Delay.cs:37
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.
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:13
static readonly Duration Zero
Zero value
Definition: Duration.cs:532