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;
4using Waher.Events;
8
10{
14 public class XmlNote : Note
15 {
19 public XmlNote()
20 : base()
21 {
22 }
23
27 public override string LocalName => nameof(XmlNote);
28
33 public override IStateMachineNode Create()
34 {
35 return new XmlNote();
36 }
37
42 public override async Task Execute(EvaluationArguments Arguments)
43 {
44 object Content = await this.Content.Evaluate(Arguments);
45 string XmlContent;
46
47 if (Content is XmlNode N)
48 XmlContent = N.OuterXml;
49 else
50 throw new StateMachineException(Arguments.Machine, "Expected XML content.");
51
52 bool Personal = false;
53 if (!(this.Personal is null))
54 {
55 if (await this.Personal.Evaluate(Arguments) is bool b)
56 Personal = b;
57 else
58 throw new StateMachineException(Arguments.Machine, "Personal must be a boolean value.");
59 }
60
61 NoteXml Event = new NoteXml()
62 {
63 ArchiveOptional = Arguments.Token?.ArchiveOptional ?? Arguments.Machine?.ArchiveOptional,
64 ArchiveRequired = Arguments.Token?.ArchiveRequired ?? Arguments.Machine?.ArchiveRequired,
65 Expires = Arguments.Token?.Expires ?? Arguments.Machine?.Expires ?? DateTime.MaxValue,
66 Note = XmlContent,
67 LocalName = N.LocalName,
68 Namespace = N.NamespaceURI,
70 Timestamp = DateTime.UtcNow,
71 TokenId = Arguments.Token?.TokenId ?? Arguments.Machine?.StateMachineId
72 };
73
74 await Database.Insert(Event);
75
76 _ = Task.Run(async () =>
77 {
78 try
79 {
80 if (Arguments.Token is null)
81 await StateMachineProcessor.EventGenerated(Arguments.Machine?.StateMachineId, Event);
82 else
83 await StateMachineProcessor.EventGenerated(Arguments.Token, Event);
84 }
85 catch (Exception ex)
86 {
87 Log.Exception(ex);
88 }
89 });
90 }
91 }
92}
Class representing an event.
Definition: Event.cs:11
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 interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
Definition: Database.cs:97
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:42
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: XmlNote.cs:33
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:147
Duration? ArchiveRequired
Duration after which token expires, the token is required to be archived.
Definition: StateMachine.cs:98
CaseInsensitiveString StateMachineId
ID of State Machine.
Definition: StateMachine.cs:57
Duration? ArchiveOptional
Duration after which token expires, and the required archiving time, the token can optionally be arch...
DateTime Expires
When state-machine expires
Definition: StateMachine.cs:72
Definition: ImplTypes.g.cs:58