4using System.Reflection;
5using System.Threading.Tasks;
22 private static readonly Dictionary<string, DateTime> lastExecuted =
new Dictionary<string, DateTime>();
73 if (
string.IsNullOrEmpty(Source))
76 Source = Path.Combine(Source,
Argument);
96 DateTime Timestamp = File.GetLastWriteTimeUtc(FileName);
97 DateTime? LastExecuted;
98 Type RuntimeSettings =
null;
104 if (lastExecuted.TryGetValue(FileName, out DateTime TP))
110 if (LastExecuted.HasValue && LastExecuted.Value >= Timestamp)
113 if (!LastExecuted.HasValue &&
114 !((RuntimeSettings =
Types.
GetType(
"Waher.Runtime.Settings.RuntimeSettings")) is
null) &&
115 !((GetAsync = RuntimeSettings.GetRuntimeMethod(
"GetAsync",
new Type[] { typeof(string), typeof(DateTime) })) is
null) &&
116 GetAsync.ReturnType == typeof(Task<DateTime>))
118 LastExecuted = await (Task<DateTime>)GetAsync.Invoke(
null,
new object[] { FileName, DateTime.MinValue });
120 if (LastExecuted.HasValue && LastExecuted.Value >= Timestamp)
124 lastExecuted[FileName] = LastExecuted.Value;
133 lastExecuted[FileName] = Timestamp;
136 if (RuntimeSettings is
null)
137 RuntimeSettings =
Types.
GetType(
"Waher.Runtime.Settings.RuntimeSettings");
139 if (!(RuntimeSettings is
null) &&
140 !((SetAsync = RuntimeSettings.GetRuntimeMethod(
"SetAsync",
new Type[] { typeof(string), typeof(DateTime) })) is
null) &&
141 SetAsync.ReturnType == typeof(Task<bool>))
143 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 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.