2using System.Collections.Generic;
4using System.Reflection;
5using System.Threading.Tasks;
21 private static readonly Dictionary<string, DateTime> lastExecuted =
new Dictionary<string, DateTime>();
72 if (
string.IsNullOrEmpty(Source))
75 Source = Path.Combine(Source,
Argument);
95 DateTime Timestamp = File.GetLastWriteTime(FileName);
96 DateTime? LastExecuted;
97 Type RuntimeSettings =
null;
103 if (lastExecuted.TryGetValue(FileName, out DateTime TP))
109 if (LastExecuted.HasValue && LastExecuted.Value >= Timestamp)
112 if (!LastExecuted.HasValue &&
113 !((RuntimeSettings =
Types.
GetType(
"Waher.Runtime.Settings.RuntimeSettings")) is
null) &&
114 !((GetAsync = RuntimeSettings.GetRuntimeMethod(
"GetAsync",
new Type[] { typeof(string), typeof(DateTime) })) is
null) &&
115 GetAsync.ReturnType == typeof(Task<DateTime>))
117 LastExecuted = await (Task<DateTime>)GetAsync.Invoke(
null,
new object[] { FileName, DateTime.MinValue });
119 if (LastExecuted.HasValue && LastExecuted.Value >= Timestamp)
123 lastExecuted[FileName] = LastExecuted.Value;
132 lastExecuted[FileName] = Timestamp;
135 if (RuntimeSettings is
null)
136 RuntimeSettings =
Types.
GetType(
"Waher.Runtime.Settings.RuntimeSettings");
138 if (!(RuntimeSettings is
null) &&
139 !((SetAsync = RuntimeSettings.GetRuntimeMethod(
"SetAsync",
new Type[] { typeof(string), typeof(DateTime) })) is
null) &&
140 SetAsync.ReturnType == typeof(Task<bool>))
142 Task<bool> Result = (Task<bool>)SetAsync.Invoke(
null,
new object[] { FileName, Timestamp });
Executes script from a file, if not executed before, or if file timestamp has changed....
override string FunctionName
Name of the function
static async Task< bool > NeedsExecution(string FileName)
Checks if an init-file needs to be executed.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
InitScriptFile(ScriptNode Argument, int Start, int Length, Expression Expression)
Executes script from a file, if not executed before, or if file timestamp has changed....
override string[] DefaultArgumentNames
Default Argument names
override IElement EvaluateScalar(string Argument, Variables Variables)
Evaluates the function on a scalar argument.
override async Task< IElement > EvaluateScalarAsync(string Argument, Variables Variables)
Evaluates the function on a scalar argument.
Static class managing loading of resources stored as embedded resources or in content files.
static async Task< string > ReadAllTextAsync(string FileName)
Reads a text file asynchronously.
Static class that dynamically manages types and interfaces available in the runtime environment.
static Type GetType(string FullName)
Gets a type, given its full name.
Script runtime exception.
Class managing a script expression.
ScriptNode Root
Root script node.
string Source
Source of script, or null if not defined.
Base class for funcions of one scalar string variable.
ScriptNode Argument
Function argument.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
Expression Expression
Expression of which the node is a part.
int Start
Start position in script expression.
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
static readonly ObjectValue Null
Null value.
Basic interface for all types of elements.