Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CreateEntry.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
6
8{
12 public class CreateEntry : ActionNode
13 {
14 private Collection collection;
15 private Type type;
16 private Property[] properties;
17
21 public CreateEntry()
22 : base()
23 {
24 }
25
29 public Collection Collection => this.collection;
30
34 public Type Type => this.type;
35
39 public Property[] Properties => this.properties;
40
44 public override string LocalName => nameof(CreateEntry);
45
50 public override IStateMachineNode Create()
51 {
52 return new CreateEntry();
53 }
54
59 public override async Task Parse(XmlElement Xml)
60 {
61 await base.Parse(Xml);
62
64 new System.Type[]
65 {
66 typeof(Collection),
67 typeof(Type)
68 },
69 new bool[]
70 {
71 true,
72 true
73 });
74 }
75
79 protected override void OnChildNodesUpdated()
80 {
81 base.OnChildNodesUpdated();
82
83 this.collection = this.GetValueElement<Collection>();
84 this.type = this.GetValueElement<Type>();
85 this.properties = this.GetChildElements<Property>();
86 }
87
92 public override async Task Execute(EvaluationArguments Arguments)
93 {
94 string Collection = (await this.collection.Evaluate(Arguments))?.ToString();
95 string Type = (await this.type.Evaluate(Arguments))?.ToString();
96 List<KeyValuePair<string, object>> Properties = new List<KeyValuePair<string, object>>();
97
98 foreach (Property Property in this.properties)
99 {
100 Properties.Add(new KeyValuePair<string, object>(
101 (await Property.Key.Evaluate(Arguments))?.ToString(),
102 await Property.Value.Evaluate(Arguments)));
103 }
104
105 await Persistence.Ledger.NewEntry(new GenericObject(Collection, Type, Guid.NewGuid(), Properties.ToArray()));
106 }
107 }
108}
Generic object. Contains a sequence of properties.
Abstract base class for State-Machine action nodes.
Definition: ActionNode.cs:9
Creates an entry in the ledger.
Definition: CreateEntry.cs:13
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
Definition: CreateEntry.cs:92
Property[] Properties
Entry properties
Definition: CreateEntry.cs:39
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: CreateEntry.cs:50
override string LocalName
Local name
Definition: CreateEntry.cs:44
CreateEntry()
Creates an entry in the ledger.
Definition: CreateEntry.cs:21
override void OnChildNodesUpdated()
Method called whenever ChildNodes is updated.
Definition: CreateEntry.cs:79
override async Task Parse(XmlElement Xml)
Parses the State-machine node.
Definition: CreateEntry.cs:59
Contains information required for evaluating script in a state-machine.
void ConvertValueAttributesToElements(XmlElement Xml, Type[] ValueTypes, bool[] Required)
Converts value attributes to parsed elements. The XML definition has to be parsed before,...
Task< object > Evaluate(EvaluationArguments Arguments)
Evaluates the value node.
Definition: Value.cs:146