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;
3using Waher.Events;
7
9{
13 public class TextNote : Note
14 {
18 public TextNote()
19 : base()
20 {
21 }
22
26 public override string LocalName => nameof(TextNote);
27
32 public override IStateMachineNode Create()
33 {
34 return new TextNote();
35 }
36
41 public override async Task Execute(EvaluationArguments Arguments)
42 {
43 object Content = await this.Content.Evaluate(Arguments);
44 if (!(Content is string TextContent))
45 throw new StateMachineException(Arguments.Machine, "Expected text content.");
46
47 bool Personal = false;
48 if (!(this.Personal is null))
49 {
50 if (await this.Personal.Evaluate(Arguments) is bool b)
51 Personal = b;
52 else
53 throw new StateMachineException(Arguments.Machine, "Personal must be a boolean value.");
54 }
55
56 NoteText Event = new NoteText()
57 {
58 ArchiveOptional = Arguments.Token?.ArchiveOptional ?? Arguments.Machine?.ArchiveOptional,
59 ArchiveRequired = Arguments.Token?.ArchiveRequired ?? Arguments.Machine?.ArchiveRequired,
60 Expires = Arguments.Token?.Expires ?? Arguments.Machine?.Expires ?? DateTime.MaxValue,
61 Note = TextContent,
63 Timestamp = DateTime.UtcNow,
64 TokenId = Arguments.Token?.TokenId ?? Arguments.Machine?.StateMachineId
65 };
66
67 await Database.Insert(Event);
68
69 _ = Task.Run(async () =>
70 {
71 try
72 {
73 if (Arguments.Token is null)
74 await StateMachineProcessor.EventGenerated(Arguments.Machine?.StateMachineId, Event);
75 else
76 await StateMachineProcessor.EventGenerated(Arguments.Token, Event);
77 }
78 catch (Exception ex)
79 {
80 Log.Exception(ex);
81 }
82 });
83 }
84 }
85}
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
Abstract base class for note actions.
Definition: Note.cs:10
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: TextNote.cs:32
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
Definition: TextNote.cs:41
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