Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
OnTime.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
4using Waher.Content;
7
9{
13 public class OnTime : TimedEventNode
14 {
15 private ScriptableTimeSpanAttribute value;
16
20 public OnTime()
21 : base()
22 {
23 }
24
28 [DefaultValueNull]
29 public string ValueDefinition
30 {
31 get => this.value?.Definition;
32 set => this.value = new ScriptableTimeSpanAttribute(value, this);
33 }
34
38 public override string LocalName => nameof(OnTime);
39
44 public override IStateMachineNode Create()
45 {
46 return new OnTime();
47 }
48
53 public override Task Parse(XmlElement Xml)
54 {
55 this.value = new ScriptableTimeSpanAttribute(Xml.InnerText, this);
56
57 return base.Parse(Xml);
58 }
59
65 public override async Task<EventTimepoint> GetEventTimepoint(EvaluationArguments Arguments)
66 {
67 if (this.value is null)
68 return new EventTimepoint();
69 else
70 {
71 TimeSpan TS = await this.value.Evaluate(Arguments.Variables);
72 DateTime Now = DateTime.Now;
73 DateTime TP = Now.Date.Add(TS);
74
75 if (TP < Now)
76 TP = TP.AddDays(Math.Ceiling(Now.Subtract(TP).TotalDays));
77
78 return new EventTimepoint(Now, TP, everyDay);
79 }
80 }
81
82 private static readonly Duration everyDay = Duration.FromDays(1);
83
87 public override string Label => this.value.Definition;
88 }
89}
async Task< T > Evaluate(Variables Variables)
Evaluates the attribute
Contains information required for evaluating script in a state-machine.
override string Label
UML Label for event.
Definition: OnTime.cs:87
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: OnTime.cs:44
override Task Parse(XmlElement Xml)
Parses the State-machine node.
Definition: OnTime.cs:53
override async Task< EventTimepoint > GetEventTimepoint(EvaluationArguments Arguments)
Gets the timepoint for when the event elapses.
Definition: OnTime.cs:65
OnTime()
Event raised at a certain time.
Definition: OnTime.cs:20
Abstract base class for timed State-Machine event nodes.
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:13
static Duration FromDays(int Days)
Creates a Duration object from a given number of days.
Definition: Duration.cs:559