3using System.Threading.Tasks;
21 private DateTime timepointUtc = DateTime.MaxValue;
49 this.CurrentUtc = DateTime.UtcNow;
50 this.NextUtc = DateTime.MaxValue;
60 this.CurrentUtc = DateTime.UtcNow;
61 this.NextUtc = Next.Kind == DateTimeKind.Utc ? Next : Next.ToUniversalTime();
71 this.CurrentUtc = DateTime.UtcNow;
72 this.NextUtc = this.CurrentUtc +
Duration;
83 this.CurrentUtc = DateTime.UtcNow;
84 this.NextUtc = Next.Kind == DateTimeKind.Utc ? Next : Next.ToUniversalTime();
96 this.CurrentUtc = Current.Kind == DateTimeKind.Utc ? Current : Current.ToUniversalTime();
97 this.NextUtc = Next.Kind == DateTimeKind.Utc ? Next : Next.ToUniversalTime();
126 public override async Task<EventHandlerReference>
Register(
int EventIndex,
131 this.timepointUtc = TP.
NextUtc;
132 this.recurrence = Event.HasNewState ? Duration.Zero : TP.
Duration;
134 if (this.timepointUtc == DateTime.MaxValue)
137 if (this.timepointUtc <= DateTime.UtcNow)
143 this.timepointUtc = pendingEvents.Add(this.timepointUtc, this.EventElapsed, Handler);
145 bool SuppressSamples;
149 SuppressSamples = await
Event.GetSuppressSample(Arguments);
154 SuppressSamples =
false;
157 if (!SuppressSamples)
158 this.AddIntervalToProfiler(TP, Arguments.
Profiler);
174 if (this.timepointUtc <= DateTime.UtcNow)
175 await this.EventElapsed(Handler);
176 else if (this.timepointUtc < DateTime.MaxValue)
177 this.timepointUtc = pendingEvents.Add(this.timepointUtc, this.EventElapsed, Handler);
188 Label = TP.Duration.ToString();
191 TimeSpan TS = TP.NextUtc - TP.CurrentUtc;
192 double d = TS.TotalDays;
194 Label = d.ToString(
"F2") +
" days";
199 Label = d.ToString(
"F2") +
" h";
204 Label = d.ToString(
"F2") +
" min";
209 Label = d.ToString(
"F2") +
" s";
212 d = TS.TotalMilliseconds;
213 Label = d.ToString(
"F2") +
" ms";
220 if (TP.NextUtc != DateTime.MaxValue)
231 this.timepointUtc = pendingEvents.Add(Handler.
Timepoint,
this.EventElapsed, Handler);
241 if (this.timepointUtc != DateTime.MaxValue)
243 pendingEvents.Remove(this.timepointUtc);
244 this.timepointUtc = DateTime.MaxValue;
248 return Task.CompletedTask;
251 private Task EventElapsed(
object State)
262 StateMachineProcessor.EventRecord Record =
null;
271 if (Recurring && !(Record is
null))
273 DateTime UtcNow = DateTime.UtcNow;
277 Handler.Timepoint += Recurrence;
281 this.recurrence = Recurrence;
282 this.timepointUtc = pendingEvents.Add(Handler.
Timepoint,
this.EventElapsed, Handler);
284 if (!Record.SuppressSamples)
292 catch (KeyNotFoundException)
300 if (!(Record.CacheRecord.Profiler is
null) && !Record.SuppressSamples)
302 int NoteNr = Record.CacheRecord.Profiler.AddNote(ex);
303 Record.CacheRecord.Profiler?.Exception(ex,
"Note" + NoteNr);
311 internal static void ClearPendingEvents()
313 pendingEvents.Clear();
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
static async Task Delete(object Object)
Deletes an object in the database.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
Class that keeps track of events and timing.
void Interval(DateTime From, DateTime To, string Label)
Records an interval in the main thread.
Class that can be used to schedule events in time. It uses a timer to execute tasks at the appointed ...
Contains information about an event handler reference
Event handler for timepoint events.
Duration Recurrence
Recurrence
DateTime Timepoint
Timepoint (in UTC time coordinates).
Contains information required for evaluating script in a state-machine.
Profiler Profiler
State-Machine profiler.
Represents an event definition.
Abstract base class for State-Machine event nodes.
abstract string Label
UML Label for event.
Contains information about when a timed event elapses, in UTC time coordinates.
EventTimepointUtc()
No next timepoint
EventTimepointUtc(Duration Duration)
Contains information about when a timed event elapses.
DateTime CurrentUtc
Current timepoint
DateTime NextUtc
Next timepoint
EventTimepointUtc(DateTime Next, Duration Duration)
Contains information about when a timed event elapses.
EventTimepointUtc(DateTime Next)
Contains information about when a timed event elapses.
Duration Duration
Duration of recurring events.
EventTimepointUtc(DateTime Current, DateTime Next, Duration Duration)
Contains information about when a timed event elapses.
Abstract base class for timed State-Machine event nodes.
abstract Task< EventTimepointUtc > GetEventTimepointUtc(EvaluationArguments Arguments)
Gets the timepoint for when the event elapses.
TimedEventNode()
Abstract base class for timed State-Machine event nodes.
override async Task< EventHandlerReference > Register(int EventIndex, EvaluationArguments Arguments, OnEvent Event)
Registers the event
async Task EventElapsed(TimepointEventHandler Handler)
Method called when event elapses.
async Task ReregisterOnStart(TimepointEventHandler Handler)
Re-registers the event on module start.
override Task Unregister(int EventIndex, EvaluationArguments Arguments)
Registers the event
void Register(TimepointEventHandler Handler)
Registers an existing event handler.
Action executed when entering a state.
Represents an action definition.
Represents a duration value, as defined by the xsd:duration data type: http://www....
static readonly Duration Zero
Zero value