Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetHashObject.cs
1using System.Threading.Tasks;
7
9{
14 {
23 : base(new ScriptNode[] { Hash }, argumentTypes1Normal, Start, Length, Expression)
24 {
25 }
26
36 : base(new ScriptNode[] { Realm, Hash },
37 new ArgumentType[] { ArgumentType.Scalar, ArgumentType.Normal },
39 {
40 }
41
45 public override string FunctionName => nameof(GetHashObject);
46
50 public override string[] DefaultArgumentNames => new string[] { "Realm", "Hash" };
51
56 public override bool IsAsynchronous => true;
57
65 {
66 return this.EvaluateAsync(Arguments, Variables).Result;
67 }
68
75 public override async Task<IElement> EvaluateAsync(IElement[] Arguments, Variables Variables)
76 {
77 int c = Arguments.Length;
78 object Result;
79
80 if (!(Arguments[c - 1].AssociatedObjectValue is byte[] Hash))
81 throw new ScriptRuntimeException("Expected last argument to be a hash digest.", this);
82
83 if (Arguments.Length > 1)
84 {
85 if (!(Arguments[0].AssociatedObjectValue is string Realm))
86 throw new ScriptRuntimeException("Expected first argument to be string.", this);
87
88 Result = await PersistedHashes.TryGetAssociatedObject(Realm, Hash);
89 }
90 else
91 Result = await PersistedHashes.TryGetAssociatedObject(Hash);
92
93 return new ObjectValue(Result);
94 }
95 }
96}
Static class managing persistent counters.
static Task< object > TryGetAssociatedObject(byte[] Hash)
Tries to get the associated object of a hash value that has been persisted in the database,...
Class managing a script expression.
Definition: Expression.cs:41
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes1Normal
One scalar parameter.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Tries to get the associated object value from a persisted hash value
GetHashObject(ScriptNode Realm, ScriptNode Hash, int Start, int Length, Expression Expression)
Tries to get the associated object value from a persisted hash value
override string FunctionName
Name of the function
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
override string[] DefaultArgumentNames
Default Argument names
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
GetHashObject(ScriptNode Hash, int Start, int Length, Expression Expression)
Tries to get the associated object value from a persisted hash value
override async Task< IElement > EvaluateAsync(IElement[] Arguments, Variables Variables)
Evaluates the function.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21
ArgumentType
Type of parameter used in a function definition or a lambda definition.
Definition: IFunction.cs:9