Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TextNote.cs
1using System;
2using System.Threading.Tasks;
5
7{
11 public class TextNote : Note
12 {
16 public TextNote()
17 : base()
18 {
19 }
20
24 public override string LocalName => nameof(TextNote);
25
30 public override IStateMachineNode Create()
31 {
32 return new TextNote();
33 }
34
39 public override async Task Execute(EvaluationArguments Arguments)
40 {
41 object Content = await this.Content.Evaluate(Arguments);
42 if (!(Content is string TextContent))
43 throw new Exception("Expected text content.");
44
45 bool Personal = false;
46 if (!(this.Personal is null))
47 {
48 if (await this.Personal.Evaluate(Arguments) is bool b)
49 Personal = b;
50 else
51 throw new Exception("Personal must be a boolean value.");
52 }
53
54 NoteText Event = new NoteText()
55 {
56 ArchiveOptional = Arguments.Token?.ArchiveOptional ?? Arguments.Machine?.ArchiveOptional,
57 ArchiveRequired = Arguments.Token?.ArchiveRequired ?? Arguments.Machine?.ArchiveRequired,
58 Expires = Arguments.Token?.Expires ?? Arguments.Machine?.Expires ?? DateTime.MaxValue,
59 Note = TextContent,
61 Timestamp = DateTime.UtcNow,
62 TokenId = Arguments.Token?.TokenId ?? Arguments.Machine?.StateMachineId
63 };
64
65 await Database.Insert(Event);
66
67 if (Arguments.Token is null)
68 await StateMachineProcessor.EventGenerated(Arguments.Machine?.StateMachineId, Event);
69 else
70 await StateMachineProcessor.EventGenerated(Arguments.Token, Event);
71 }
72 }
73}
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
Abstract base class for note actions.
Definition: Note.cs:10
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: TextNote.cs:30
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
Definition: TextNote.cs:39
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