Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScriptResource.cs
1using System.Threading.Tasks;
2using Waher.Script;
7
9{
17 {
30 : base(Resource, Exp, Start, Length, Expression)
31 {
32 }
33
37 public override string FunctionName => nameof(ScriptResource);
38
42 public override string[] DefaultArgumentNames => new string[] { "Resource", "Expression" };
43
48 public override bool IsAsynchronous => true;
49
56 {
57 return this.EvaluateAsync(Variables).Result;
58 }
59
65 public override async Task<IElement> EvaluateAsync(Variables Variables)
66 {
67 IElement E;
68
70 E = await this.Argument1.EvaluateAsync(Variables);
71 else
72 E = this.Argument1.Evaluate(Variables);
73
74 if (!(E is StringValue S))
75 throw new ScriptRuntimeException("Expected string resource name.", this);
76
77 string ResourceName = S.Value;
78
79 return new BooleanValue(await Gateway.AddScriptResource(ResourceName, this.Argument2, this.Expression.Source ?? string.Empty));
80 }
81
90 {
91 return BooleanValue.False;
92 }
93
94 }
95}
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static async Task< bool > AddScriptResource(string ResourceName, Expression Expression, string ReferenceFileName)
Adds a script resource to the web server hosted by the gateway.
Definition: Gateway.cs:5033
Defines a script resource on the web server hosted by the gateway. Script resources are persisted,...
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override string[] DefaultArgumentNames
Default Argument names
ScriptResource(ScriptNode Resource, ScriptNode Exp, int Start, int Length, Expression Expression)
Defines a script resource on the web server hosted by the gateway. Script resources are persisted,...
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
override IElement Evaluate(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Class managing a script expression.
Definition: Expression.cs:39
Base class for funcions of one variable.
ScriptNode Argument2
Function argument 2.
ScriptNode Argument1
Function argument 1.
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
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
virtual bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: ScriptNode.cs:142
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20