Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmlNote.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
6
8{
12 public class XmlNote : Note
13 {
17 public XmlNote()
18 : base()
19 {
20 }
21
25 public override string LocalName => nameof(XmlNote);
26
31 public override IStateMachineNode Create()
32 {
33 return new XmlNote();
34 }
35
40 public override async Task Execute(EvaluationArguments Arguments)
41 {
42 object Content = await this.Content.Evaluate(Arguments);
43 string XmlContent;
44
45 if (Content is XmlNode N)
46 XmlContent = N.OuterXml;
47 else
48 throw new Exception("Expected XML content.");
49
50 bool Personal = false;
51 if (!(this.Personal is null))
52 {
53 if (await this.Personal.Evaluate(Arguments) is bool b)
54 Personal = b;
55 else
56 throw new Exception("Personal must be a boolean value.");
57 }
58
59 NoteXml Event = new NoteXml()
60 {
61 ArchiveOptional = Arguments.Token?.ArchiveOptional ?? Arguments.Machine?.ArchiveOptional,
62 ArchiveRequired = Arguments.Token?.ArchiveRequired ?? Arguments.Machine?.ArchiveRequired,
63 Expires = Arguments.Token?.Expires ?? Arguments.Machine?.Expires ?? DateTime.MaxValue,
64 Note = XmlContent,
65 LocalName = N.LocalName,
66 Namespace = N.NamespaceURI,
68 Timestamp = DateTime.UtcNow,
69 TokenId = Arguments.Token?.TokenId ?? Arguments.Machine?.StateMachineId
70 };
71
72 await Database.Insert(Event);
73
74 if (Arguments.Token is null)
75 await StateMachineProcessor.EventGenerated(Arguments.Machine?.StateMachineId, Event);
76 else
77 await StateMachineProcessor.EventGenerated(Arguments.Token, Event);
78 }
79 }
80}
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
Definition: Database.cs:95
An xml note logged on the token.
Definition: NoteXml.cs:9
Abstract base class for note actions.
Definition: Note.cs:10
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
Definition: XmlNote.cs:40
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: XmlNote.cs:31
Contains information required for evaluating script in a state-machine.
StateMachine Machine
Reference to state-machine definition.
Task< object > Evaluate(EvaluationArguments Arguments)
Evaluates the value node.
Definition: Value.cs:146
Duration? ArchiveRequired
Duration after which token expires, the token is required to be archived.
Definition: StateMachine.cs:92
CaseInsensitiveString StateMachineId
ID of State Machine.
Definition: StateMachine.cs:51
Duration? ArchiveOptional
Duration after which token expires, and the required archiving time, the token can optionally be arch...
Definition: StateMachine.cs:98
DateTime Expires
When state-machine expires
Definition: StateMachine.cs:66