Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
StateMachine.cs
1using System;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
8using Waher.Events;
16using Waher.Script;
28using Waher.Things;
29
31{
35 [CollectionName("StateMachines")]
36 [TypeName(TypeNameSerialization.FullName)]
37 [ArchivingTime(nameof(ArchiveDays))]
38 [Index("StateMachineId")]
39 [Index("CreatorTokenId")]
40 [Index("Expires", "StateMachineId")]
41 [ObsoleteMethod(nameof(SetObsoleteProperties))]
43 {
44 private Dictionary<string, Model.Actions.Action> actions;
45 private Dictionary<string, Model.Events.Event> events;
46 private Dictionary<string, State> states;
47
51 [ObjectId]
52 public string ObjectId { get; set; }
53
58
63
67 public StateMachineRoot Root { get; set; }
68
72 public DateTime Expires { get; set; }
73
77 public string XmlDefinition { get; set; }
78
83
88
93
97 [DefaultValueNull]
98 public Duration? ArchiveRequired { get; set; }
99
103 [DefaultValueNull]
104 public Duration? ArchiveOptional { get; set; }
105
110
114 public void IndexElements()
115 {
116 this.actions = new Dictionary<string, Model.Actions.Action>();
117 this.events = new Dictionary<string, Model.Events.Event>();
118 this.states = new Dictionary<string, State>();
119
120 this.Root?.ForEach((Node, State) =>
121 {
122 Node.IndexElement(this);
123 return true;
124 }, null);
125 }
126
131 public void Index(Model.Actions.Action Action)
132 {
133 if (this.actions.ContainsKey(Action.Id))
134 throw new StateMachineException(this, "Duplicate Action ID: " + Action.Id);
135
136 this.actions[Action.Id] = Action;
137 }
138
143 public void Index(Model.Events.Event Event)
144 {
145 if (this.events.ContainsKey(Event.Id))
146 throw new StateMachineException(this, "Duplicate Event ID: " + Event.Id);
147
148 this.events[Event.Id] = Event;
149 }
150
155 public void Index(State State)
156 {
157 if (this.states.ContainsKey(State.Id))
158 throw new StateMachineException(this, "Duplicate State ID: " + State.Id);
159
160 this.states[State.Id] = State;
161 }
162
168 {
169 this.IndexElements();
170
171 this.Root?.ForEach((Node, State) =>
172 {
173 Node.CheckReferences(this, Token);
174 return true;
175 }, null);
176 }
177
184 public bool TryGetAction(string Id, out Model.Actions.Action Action)
185 {
186 if (Id is null)
187 {
188 Action = null;
189 return false;
190 }
191 else
192 return this.actions.TryGetValue(Id, out Action);
193 }
194
201 public bool TryGetEvent(string Id, out Model.Events.Event Event)
202 {
203 if (Id is null)
204 {
205 Event = null;
206 return false;
207 }
208 else
209 return this.events.TryGetValue(Id, out Event);
210 }
211
218 public bool TryGetState(string Id, out State State)
219 {
220 if (Id is null)
221 {
222 State = null;
223 return false;
224 }
225 else
226 return this.states.TryGetValue(Id, out State);
227 }
228
239 {
240 List<CurrentStateVariable> VariableValues = new List<CurrentStateVariable>();
241 CurrentState CurrentState = await StateMachineProcessor.GetOrCreateCurrentState(this, false);
244 List<StateMachineSample> Samples = null;
245
246 if (!(this.Root.ChildNodes is null))
247 {
248 foreach (IStateMachineNode Node in this.Root.ChildNodes)
249 {
250 if (Node is Model.Variable Variable)
251 {
252 try
253 {
254 object Value = await Variable.Evaluate(Arguments);
255
256 Variables[Variable.Id] = Value;
257 VariableValues.Add(new CurrentStateVariable(Variable.Id, Value));
258
259 Samples ??= new List<StateMachineSample>();
260 Samples.Add(new StateMachineSample()
261 {
262 Variable = Variable.Id,
263 Timestamp = DateTime.UtcNow,
264 Value = Value,
266 Expires = this.Expires,
268 ArchiveRequired = this.ArchiveRequired
269 });
270 }
271 catch (Exception ex)
272 {
273 Log.Critical("Unable to evaluate inital value for variable " +
274 Variable.Id + " for state-machine. Error reported: " + ex.Message, this.ObjectId);
275
277 {
279 Timestamp = DateTime.UtcNow,
280 Value = ex.Message,
282 Expires = Arguments.Machine.Expires,
284 ArchiveRequired = Arguments.Machine.ArchiveRequired
285 });
286 }
287 }
288 }
289 }
290
291 CurrentState.VariableValues = VariableValues.ToArray();
292
294
295 if (!(Samples is null))
296 await Database.Insert(Samples.ToArray());
297
298 return (CurrentState, Arguments);
299 }
300
305 public async Task Start(EvaluationArguments Arguments)
306 {
307 await GoToState(this.Root.StartState, Arguments);
308 }
309
315 public static async Task GoToState(string StateId, EvaluationArguments Arguments)
316 {
317 DateTime Start = DateTime.Now;
318
319 try
320 {
321 do
322 {
323 bool NewState = StateId != Arguments.CurrentState.State;
324
325 if (!string.IsNullOrEmpty(Arguments.CurrentState.State) &&
326 Arguments.Machine.TryGetState(Arguments.CurrentState.State, out State State))
327 {
328 if (NewState)
329 await UnregisterEventHandlers(State.OnEvent, Arguments);
330
331 await ExecuteLog(State.OnLeave, Arguments, false);
332 }
333
334 State = null;
335
336 if (!string.IsNullOrEmpty(StateId) && !Arguments.Machine.TryGetState(StateId, out State))
337 throw new StateMachineException(Arguments.Machine, "State not found:" + StateId);
338
339 if (NewState)
340 {
341 Arguments.SetState(StateId);
342
344 {
346 Timestamp = DateTime.UtcNow,
347 Value = StateId,
349 Expires = Arguments.Machine.Expires,
351 ArchiveRequired = Arguments.Machine.ArchiveRequired
352 });
353
354 if (string.IsNullOrEmpty(StateId))
355 await ScheduledAction.DeleteScheduledActions(Arguments.Machine.StateMachineId);
356 }
357
358 StateId = null;
359
360 if (!(State is null))
361 {
362 ChunkedList<EventHandlerReference> EventsTriggered = null;
363
364 try
365 {
366 await ExecuteLog(State.OnEnter, Arguments, false);
367 }
368 catch (Exception ex)
369 {
370 Log.Exception(ex, Arguments.Token?.TokenId ?? Arguments.Machine.StateMachineId);
371
373 {
375 Timestamp = DateTime.UtcNow,
376 Value = ex.Message,
378 Expires = Arguments.Machine.Expires,
380 ArchiveRequired = Arguments.Machine.ArchiveRequired
381 });
382 }
383
384 if (NewState)
385 EventsTriggered = await RegisterEventHandlers(State.OnEvent, Arguments);
386
387 if (!(EventsTriggered is null))
388 {
389 foreach (EventHandlerReference Ref in EventsTriggered)
390 {
391 OnEvent EventTriggered = Ref.Event;
392 if (!(EventTriggered is null))
393 {
394 try
395 {
396 await Ref.Prepare(Arguments);
397
398 bool SuppressSamples = await EventTriggered.GetSuppressSample(Arguments);
399 await EventTriggered.ExecuteLog(Arguments, SuppressSamples);
400 StateId = await EventTriggered.GetNewState(Arguments);
401 }
402 catch (Exception ex)
403 {
404 StateId = await EventTriggered.GetFailureState(Arguments);
405
406 if (string.IsNullOrEmpty(StateId))
407 {
408 Log.Error(ex, Arguments.Machine.ObjectId);
409
411 {
413 Timestamp = DateTime.UtcNow,
414 Value = ex.Message,
416 Expires = Arguments.Machine.Expires,
418 ArchiveRequired = Arguments.Machine.ArchiveRequired
419 });
420 }
421 }
422
423 if (!string.IsNullOrEmpty(StateId))
424 break;
425 }
426 }
427
428 double ElapsedTimeSeconds = DateTime.Now.Subtract(Start).TotalMinutes;
429
430 if (ElapsedTimeSeconds > 60)
431 {
432 Log.Error("State change exceeds maximum allotted time.", Arguments.Machine.ObjectId,
433 new KeyValuePair<string, object>("StateMachineId", Arguments.Machine.StateMachineId),
434 new KeyValuePair<string, object>("ElapsedTimeSeconds", ElapsedTimeSeconds));
435
436 return;
437 }
438 }
439 }
440 }
441 while (!string.IsNullOrEmpty(StateId));
442 }
443 finally
444 {
445 await EvaluationComplete(Arguments);
446 }
447 }
448
454 public static async Task EvaluationComplete(EvaluationArguments Arguments)
455 {
456 bool StateUpdated = Arguments.StateUpdated;
457 bool VariablesUpdated = Arguments.VariablesUpdated;
458 bool AuthorizationsUpdated = Arguments.AuthorizationsUpdated;
459
460 if (StateUpdated || VariablesUpdated || AuthorizationsUpdated)
461 {
462 await Database.Update(Arguments.CurrentState);
463
464 Arguments.AuthorizationsUpdated = false;
465
466 if (StateUpdated)
467 {
468 Arguments.StateUpdated = false;
469
470 if (!(Arguments.Token is null))
471 {
472 StringBuilder Xml = new StringBuilder();
473 string OwnerJid = Arguments.Token.OwnerJid;
474
475 Xml.Append("<stateUpdated xmlns='");
477 Xml.Append("' tokenId='");
478 Xml.Append(XML.Encode(Arguments.Token.TokenId));
479 Xml.Append("' machineId='");
480 Xml.Append(XML.Encode(Arguments.Machine.StateMachineId));
481 Xml.Append("' state='");
482 Xml.Append(XML.Encode(Arguments.CurrentState.State));
483 Xml.Append("'/>");
484
485 _ = Task.Run(async () =>
486 {
487 try
488 {
489 await Arguments.EDaler.Server.SendMessage(string.Empty, string.Empty, Arguments.EDaler.MainDomain,
490 new XmppAddress(OwnerJid), string.Empty, Xml.ToString());
491 }
492 catch (Exception ex)
493 {
494 Log.Exception(ex);
495 }
496 });
497 }
498 }
499
500 if (VariablesUpdated)
501 {
502 if (Arguments.Token is null)
503 Arguments.ClearUpdatedVariables();
504 else
505 {
506 KeyValuePair<string, object>[] Variables = Arguments.PopUpdatedVariables();
507 StringBuilder Xml = new StringBuilder();
508 string OwnerJid = Arguments.Token.OwnerJid;
509
510 Xml.Append("<variablesUpdated xmlns='");
512 Xml.Append("' tokenId='");
513 Xml.Append(XML.Encode(Arguments.Token.TokenId));
514 Xml.Append("' machineId='");
515 Xml.Append(XML.Encode(Arguments.Machine.StateMachineId));
516 Xml.Append("'>");
517
518 foreach (KeyValuePair<string, object> P in Variables)
519 StateMachineProcessor.AppendVariable(Xml, P.Key, P.Value);
520
521 Xml.Append("</variablesUpdated>");
522
523 _ = Task.Run(async () =>
524 {
525 try
526 {
527 await Arguments.EDaler.Server.SendMessage(string.Empty, string.Empty, Arguments.EDaler.MainDomain,
528 new XmppAddress(OwnerJid), string.Empty, Xml.ToString());
529 }
530 catch (Exception ex)
531 {
532 Log.Exception(ex);
533 }
534 });
535 }
536 }
537
538 if (Arguments.Token?.IsPublic ?? false)
539 {
540 string[] TabIDs = ClientEvents.GetTabIDsForLocation("/NF/" + Arguments.Token.TokenId);
541
542 if ((TabIDs?.Length ?? 0) > 0)
543 await PublicTokenView.UpdatePresent(TabIDs, Arguments.Token);
544 }
545 }
546 }
547
552 public static async Task CheckConditionalEvents(EvaluationArguments Arguments)
553 {
554 if (!Arguments.Machine.TryGetState(Arguments.CurrentState.State, out State State))
555 return;
556
557 if (!(State.OnEvent is null))
558 {
559 foreach (OnEvent Event in State.OnEvent)
560 {
561 EventHandlerReference Ref = await Event.StateUpdated(Arguments);
562
563 if (Ref?.Triggered ?? false)
564 {
565 string StateId;
566
567 try
568 {
569 await Ref.Prepare(Arguments);
570
571 bool SuppressSamples = await Event.GetSuppressSample(Arguments);
572 await Event.ExecuteLog(Arguments, SuppressSamples);
573 StateId = await Event.GetNewState(Arguments);
574 }
575 catch (Exception ex)
576 {
577 StateId = await Event.GetFailureState(Arguments);
578
579 if (string.IsNullOrEmpty(StateId))
580 {
581 Log.Error(ex, Arguments.Machine.ObjectId);
582
584 {
586 Timestamp = DateTime.UtcNow,
587 Value = ex.Message,
589 Expires = Arguments.Machine.Expires,
591 ArchiveRequired = Arguments.Machine.ArchiveRequired
592 });
593 }
594 }
595
596 if (!string.IsNullOrEmpty(StateId))
597 {
598 await GoToState(StateId, Arguments);
599 break;
600 }
601 }
602 }
603 }
604 }
605
612 public static async Task ExecuteLog(ActionReference[] ActionReferences, EvaluationArguments Arguments, bool SuppressSamples)
613 {
614 if (ActionReferences is null)
615 return;
616
617 foreach (ActionReference Action in ActionReferences)
618 await Action.ExecuteLog(Arguments, SuppressSamples);
619 }
620
627 public static async Task<ChunkedList<EventHandlerReference>> RegisterEventHandlers(OnEvent[] Events, EvaluationArguments Arguments)
628 {
629 if (Events is null)
630 return null;
631
632 int i = 0;
634
635 foreach (OnEvent Event in Events)
636 {
637 try
638 {
639 EventHandlerReference Ref = await Event.Register(i++, Arguments);
640 if (Ref?.Triggered ?? false)
641 {
642 Ref.Event = Event;
643
644 Result ??= new ChunkedList<EventHandlerReference>();
645 Result.Add(Ref);
646 }
647 }
648 catch (Exception ex)
649 {
650 ex = Log.UnnestException(ex);
651
652 string MachineId = Event.StateMachine.StateMachineId;
653 string CurrentState = await StateMachineProcessor.GetCurrentState(MachineId);
654
655 Log.Error("Unable to register event handlers for state machine.",
656 new KeyValuePair<string, object>("State Machine ID", MachineId),
657 new KeyValuePair<string, object>("State", CurrentState),
658 new KeyValuePair<string, object>("Messge", ex.Message),
659 new KeyValuePair<string, object>("Event", Event.Event.Label),
660 new KeyValuePair<string, object>("Local Name", Event.Event.LocalName),
661 new KeyValuePair<string, object>("Namespace", Event.Event.Namespace));
662
664 {
666 Timestamp = DateTime.UtcNow,
667 Value = ex.Message,
668 StateMachineId = Arguments.Machine.StateMachineId,
669 Expires = Arguments.Machine.Expires,
670 ArchiveOptional = Arguments.Machine.ArchiveOptional,
671 ArchiveRequired = Arguments.Machine.ArchiveRequired
672 });
673 }
674 }
675
676 return Result;
677 }
678
684 public static async Task UnregisterEventHandlers(OnEvent[] Events, EvaluationArguments Arguments)
685 {
686 IEnumerable<EventHandlers.EventHandler> Handlers = await Database.FindDelete<EventHandlers.EventHandler>(new FilterAnd(
687 new FilterFieldEqualTo("StateMachineId", Arguments.CurrentState.StateMachineId),
688 new FilterFieldEqualTo("State", Arguments.CurrentState.State)));
689
690 foreach (EventHandlers.EventHandler Handler in Handlers)
691 {
694 }
695
696 if (Events is null)
697 return;
698
699 int i = 0;
700
701 foreach (OnEvent Event in Events)
702 await Event.Unregister(i, Arguments);
703 }
704
711 public bool TryGetVariable(string Name, out Script.Variable Variable)
712 {
713 switch (Name)
714 {
715 case "this":
716 Variable = new Script.Variable("this", this);
717 return true;
718
719 default:
720 Variable = null;
721 return false;
722 }
723 }
724
730 public bool ContainsVariable(string Name)
731 {
732 return Name == "this";
733 }
734
740 public Waher.Script.Variable Add(string Name, object Value)
741 {
742 throw new NotSupportedException("Variable collection is read-only.");
743 }
744
748 public async Task<RequestOrigin> GetOrigin()
749 {
750 Token Token = await NeuroFeaturesProcessor.GetToken(this.CreatorTokenId, true);
751 string OwnerJid = Token?.OwnerJid.Value ?? string.Empty;
752
753 return new RequestOrigin(OwnerJid, null, null, null, this);
754 }
755
761 public bool HasPrivilege(string Privilege)
762 {
763 return false;
764 }
765
769 public async Task ReparseDefinition()
770 {
771 XmlDocument Doc = XML.ParseXml(this.XmlDefinition);
772
773 this.Root = (StateMachineRoot)await StateMachineProcessor.Create(Doc.DocumentElement);
774
775 this.IndexElements();
776 }
777
782 public void SetObsoleteProperties(Dictionary<string, object> Properties)
783 {
784 foreach (KeyValuePair<string, object> Property in Properties)
785 {
786 switch (Property.Key)
787 {
788 case "XmlDefinnition":
789 if (Property.Value is string s)
790 this.XmlDefinition = s;
791 break;
792 }
793 }
794 }
795 }
796}
Helps with common XML-related tasks.
Definition: XML.cs:21
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:29
static XmlDocument ParseXml(string Xml)
Parses an XML Document from its string representation.
Definition: XML.cs:713
Class representing an event.
Definition: Event.cs:11
Event(DateTime Timestamp, EventType Type, string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Class representing an event.
Definition: Event.cs:39
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
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.
Definition: Log.cs:1657
static void Critical(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs a critical event.
Definition: Log.cs:1027
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
Definition: Log.cs:692
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:828
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
Definition: ClientEvents.cs:51
static string[] GetTabIDsForLocation(string Location)
Gets the Tab IDs of all tabs that display a particular resource.
XmppAddress MainDomain
Main/principal domain address
Definition: Component.cs:87
XmppServer Server
XMPP Server.
Definition: Component.cs:97
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
override string ToString()
object.ToString()
Definition: XmppAddress.cs:190
Task< bool > SendMessage(string Type, string Id, string From, string To, string Language, string ContentXml)
Sends a Message stanza to a recipient.
Definition: XmppServer.cs:3862
Represents a case-insensitive string.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static Task< IEnumerable< object > > FindDelete(string Collection, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
Definition: Database.cs:1442
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:1211
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
Definition: Database.cs:97
This filter selects objects that conform to all child-filters provided.
Definition: FilterAnd.cs:10
This filter selects objects that have a named field equal to a given value.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Class that keeps track of events and timing.
Definition: Profiler.cs:68
Contains information about a variable.
Definition: Variable.cs:10
Collection of variables.
Definition: Variables.cs:25
virtual Variable Add(string Name, object Value)
Adds a variable to the collection.
Definition: Variables.cs:126
Manages eDaler on accounts connected to the broker.
Marketplace processor, brokering sales of items via tenders and offers defined in smart contracts.
bool IsPublic
If the token is public.
Definition: Token.cs:181
static int CalcArchiveDays(DateTime Expires, Duration? ArchiveReq, Duration? ArchiveOpt)
Calculates the number of days an object should be archived in the ledger.
Definition: Token.cs:622
CaseInsensitiveString OwnerJid
JID of Current owner of token
Definition: Token.cs:216
CaseInsensitiveString TokenId
Token ID
Definition: Token.cs:145
Class representing the current state of a state machine.
Definition: CurrentState.cs:20
Variables GetVariables(StateMachine Machine)
Gets a new variable collection containing the current state variables.
string State
ID of current state in state-machine. Empty State = State-machine has ended.
Definition: CurrentState.cs:47
CaseInsensitiveString StateMachineId
ID of State-Machine.
Definition: CurrentState.cs:41
Class representing a persisted state-machine variable value.
async Task RemoveFromCache()
Removes the event handler from the cache.
virtual Task Prepare(EvaluationArguments Arguments)
Prepares the collection of event arguments for event handler execution.
OnEvent Event
Event that triggered the event handler, if any.
Abstract base class for nodes referencing an action.
async Task< TimeSpan > ExecuteLog(EvaluationArguments Arguments, bool SuppressSample)
Evaluates an action, and logs the time the action took as a sample value.
Contains information required for evaluating script in a state-machine.
StateMachine Machine
Reference to state-machine definition.
bool AuthorizationsUpdated
If authorizations in the state machine have been updated.
KeyValuePair< string, object >[] PopUpdatedVariables()
Gets an array of updated variables since last call.
bool StateUpdated
If the state machine has changed state during processing.
bool VariablesUpdated
If variables in the state machine have been updated.
bool ForEach(ForEachCallback Callback, object State)
Iterates through th node and all its child nodes.
IStateMachineNode[] ChildNodes
Child nodes, if available. Null if no children.
Action executed when entering a state.
Definition: OnEvent.cs:19
async Task< bool > GetSuppressSample(EvaluationArguments Arguments)
Gets a Boolean value indicating if samples should be suppressed for the event.
Definition: OnEvent.cs:151
async Task< string > GetFailureState(EvaluationArguments Arguments)
Gets the failure state ID when the event is triggered.
Definition: OnEvent.cs:138
async Task< string > GetNewState(EvaluationArguments Arguments)
Gets the new state ID when the event is triggered.
Definition: OnEvent.cs:125
OnEnter[] OnEnter
Events raised when entering the state.
Definition: State.cs:36
OnLeave[] OnLeave
Events raised when leaving the state.
Definition: State.cs:41
OnEvent[] OnEvent
Events that can be raised when in the state.
Definition: State.cs:46
Class representing a state machine.
Definition: StateMachine.cs:43
StateMachineRoot Root
Root of State-Machine model.
Definition: StateMachine.cs:67
bool TryGetAction(string Id, out Model.Actions.Action Action)
Tries to get an action.
bool TryGetState(string Id, out State State)
Tries to get a state.
Duration? ArchiveRequired
Duration after which token expires, the token is required to be archived.
Definition: StateMachine.cs:98
void IndexElements()
Indexes all elements in the state-machine.
async Task<(CurrentState, EvaluationArguments)> CreateCurrentState(Token Token, LegalComponent Legal, EDalerComponent EDaler, Profiler Profiler)
Starts processing of the state-machine.
bool TryGetVariable(string Name, out Script.Variable Variable)
Tries to get a variable object, given its name.
async Task ReparseDefinition()
Reparses the state-machine.
async Task< RequestOrigin > GetOrigin()
Origin of request.
void Index(Model.Events.Event Event)
Adds an event to the index.
static async Task< ChunkedList< EventHandlerReference > > RegisterEventHandlers(OnEvent[] Events, EvaluationArguments Arguments)
Registers a set of events.
static async Task GoToState(string StateId, EvaluationArguments Arguments)
Goes to a new state.
void SetObsoleteProperties(Dictionary< string, object > Properties)
Sets obsolete properties.
CaseInsensitiveString TrustProviderJid
JID of Trust Provider
Definition: StateMachine.cs:92
CaseInsensitiveString CreatorTokenId
ID of token that created the state-machine.
Definition: StateMachine.cs:62
bool TryGetEvent(string Id, out Model.Events.Event Event)
Tries to get an event.
async Task Start(EvaluationArguments Arguments)
Starts the processing of the state-machine.
string ObjectId
Object ID of state machine.
Definition: StateMachine.cs:52
void Index(State State)
Adds a state to the index.
CaseInsensitiveString StateMachineId
ID of State Machine.
Definition: StateMachine.cs:57
void CheckReferences(Token Token)
Indexes all elements in the state-machine.
static async Task EvaluationComplete(EvaluationArguments Arguments)
Method called when current evaluation has been completed, and new states need to be persisted.
Duration? ArchiveOptional
Duration after which token expires, and the required archiving time, the token can optionally be arch...
bool HasPrivilege(string Privilege)
If the origin has a given privilege.
CaseInsensitiveString DefinitionContractId
ID of Definition Contract
Definition: StateMachine.cs:82
void Index(Model.Actions.Action Action)
Adds an action to the index.
CaseInsensitiveString TrustProvider
ID of Trust Provider
Definition: StateMachine.cs:87
Waher.Script.Variable Add(string Name, object Value)
Adds a variable to the collection.
int ArchiveDays
Number of days to archive field.
DateTime Expires
When state-machine expires
Definition: StateMachine.cs:72
static async Task CheckConditionalEvents(EvaluationArguments Arguments)
Checks conditional events.
static async Task UnregisterEventHandlers(OnEvent[] Events, EvaluationArguments Arguments)
Unregisters event handlers for the current state.
static async Task ExecuteLog(ActionReference[] ActionReferences, EvaluationArguments Arguments, bool SuppressSamples)
Evaluates a set of actions.
bool ContainsVariable(string Name)
If the collection contains a variable with a given name.
const string StateMachineNamespace
https://paiwise.tagroot.io/Schema/StateMachines.xsd
Class representing a sample of a state machine variable over time.
const string CurrentStateVariable
Variable ID used to sample state changes.
const string ExceptionVariable
Variable ID used to sample exception messages.
Tokens available in request.
Definition: RequestOrigin.cs:9
Variables available in a specific context.
Interface for requestors that can act as an origin for distributed requests.
Definition: ImplTypes.g.cs:58
TypeNameSerialization
How the type name should be serialized.
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:14