diff --git a/Library/BlocklyNet.csproj b/Library/BlocklyNet.csproj index 708b45a..85d313f 100644 --- a/Library/BlocklyNet.csproj +++ b/Library/BlocklyNet.csproj @@ -14,6 +14,7 @@ + diff --git a/Library/BlocklyUtils.cs b/Library/BlocklyUtils.cs new file mode 100644 index 0000000..333b51b --- /dev/null +++ b/Library/BlocklyUtils.cs @@ -0,0 +1,11 @@ +/// +/// Some implementation helpers. +/// +public static class BlockyUtils +{ + /// + /// Simulate task access to avoid warnings. + /// + /// Some task. + public static void Touch(this Task task) { } +} \ No newline at end of file diff --git a/Library/Core/Blocks/Colour/ColourBlend.cs b/Library/Core/Blocks/Colour/ColourBlend.cs index faf9db6..a1033dc 100644 --- a/Library/Core/Blocks/Colour/ColourBlend.cs +++ b/Library/Core/Blocks/Colour/ColourBlend.cs @@ -10,12 +10,12 @@ namespace BlocklyNet.Core.Blocks.Text; public class ColourBlend : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var colour1 = (await Values.Evaluate("COLOUR1", context) ?? "").ToString(); - var colour2 = (await Values.Evaluate("COLOUR2", context) ?? "").ToString(); + var colour1 = (await Values.EvaluateAsync("COLOUR1", context) ?? "").ToString(); + var colour2 = (await Values.EvaluateAsync("COLOUR2", context) ?? "").ToString(); - var ratio = System.Math.Min(System.Math.Max(await Values.Evaluate("RATIO", context), 0), 1); + var ratio = System.Math.Min(System.Math.Max(await Values.EvaluateAsync("RATIO", context), 0), 1); if (string.IsNullOrWhiteSpace(colour1) || colour1.Length != 7) return null!; diff --git a/Library/Core/Blocks/Colour/ColourPicker.cs b/Library/Core/Blocks/Colour/ColourPicker.cs index a61a848..4aa1b78 100644 --- a/Library/Core/Blocks/Colour/ColourPicker.cs +++ b/Library/Core/Blocks/Colour/ColourPicker.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Text; public class ColourPicker : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { return Task.FromResult((object?)(Fields["COLOUR"] ?? "#000000")); } diff --git a/Library/Core/Blocks/Colour/ColourRandom.cs b/Library/Core/Blocks/Colour/ColourRandom.cs index 8f939c6..89e30d2 100644 --- a/Library/Core/Blocks/Colour/ColourRandom.cs +++ b/Library/Core/Blocks/Colour/ColourRandom.cs @@ -12,7 +12,7 @@ public class ColourRandom : Block private readonly Random random = new Random(); /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { var bytes = new byte[3]; diff --git a/Library/Core/Blocks/Colour/ColourRgb.cs b/Library/Core/Blocks/Colour/ColourRgb.cs index 7b0ff91..228957c 100644 --- a/Library/Core/Blocks/Colour/ColourRgb.cs +++ b/Library/Core/Blocks/Colour/ColourRgb.cs @@ -10,11 +10,11 @@ namespace BlocklyNet.Core.Blocks.Text; public class ColourRgb : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var red = Convert.ToByte(await Values.Evaluate("RED", context)); - var green = Convert.ToByte(await Values.Evaluate("GREEN", context)); - var blue = Convert.ToByte(await Values.Evaluate("BLUE", context)); + var red = Convert.ToByte(await Values.EvaluateAsync("RED", context)); + var green = Convert.ToByte(await Values.EvaluateAsync("GREEN", context)); + var blue = Convert.ToByte(await Values.EvaluateAsync("BLUE", context)); return $"#{red:x2}{green:x2}{blue:x2}"; } diff --git a/Library/Core/Blocks/Controls/ControlsFlowStatement.cs b/Library/Core/Blocks/Controls/ControlsFlowStatement.cs index 8956332..329cd96 100644 --- a/Library/Core/Blocks/Controls/ControlsFlowStatement.cs +++ b/Library/Core/Blocks/Controls/ControlsFlowStatement.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Controls; public class ControlsFlowStatement : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { var flow = Fields["FLOW"]; diff --git a/Library/Core/Blocks/Controls/ControlsFor.cs b/Library/Core/Blocks/Controls/ControlsFor.cs index ad22cf4..36e4a75 100644 --- a/Library/Core/Blocks/Controls/ControlsFor.cs +++ b/Library/Core/Blocks/Controls/ControlsFor.cs @@ -10,13 +10,13 @@ namespace BlocklyNet.Core.Blocks.Controls; public class ControlsFor : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var variableName = Fields["VAR"]; - var fromValue = await Values.Evaluate("FROM", context); - var toValue = await Values.Evaluate("TO", context); - var byValue = await Values.Evaluate("BY", context); + var fromValue = await Values.EvaluateAsync("FROM", context); + var toValue = await Values.EvaluateAsync("TO", context); + var byValue = await Values.EvaluateAsync("BY", context); var statement = Statements.TryGet("DO"); @@ -26,11 +26,11 @@ public class ControlsFor : Block { context.Cancellation.ThrowIfCancellationRequested(); - await statement!.Evaluate(context); + await statement!.EvaluateAsync(context); context.Variables[variableName] = (double)context.Variables[variableName]! + byValue; } - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Controls/ControlsForEach.cs b/Library/Core/Blocks/Controls/ControlsForEach.cs index b83cc5b..08b9a5b 100644 --- a/Library/Core/Blocks/Controls/ControlsForEach.cs +++ b/Library/Core/Blocks/Controls/ControlsForEach.cs @@ -10,15 +10,15 @@ namespace BlocklyNet.Core.Blocks.Controls; public class ControlsForEach : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var variableName = Fields["VAR"]; - var list = await Values.Evaluate>("LIST", context); + var list = await Values.EvaluateAsync>("LIST", context); var statement = Statements.TryGet("DO"); if (null == statement) - return await base.Evaluate(context); + return await base.EvaluateAsync(context); foreach (var item in list) { @@ -29,9 +29,9 @@ public class ControlsForEach : Block else context.Variables.Add(variableName, item); - await statement.Evaluate(context); + await statement.EvaluateAsync(context); } - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Controls/ControlsIf.cs b/Library/Core/Blocks/Controls/ControlsIf.cs index 13f4e75..acec2df 100644 --- a/Library/Core/Blocks/Controls/ControlsIf.cs +++ b/Library/Core/Blocks/Controls/ControlsIf.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Controls; public class ControlsIf : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var ifCount = 1; if (null != Mutations.GetValue("elseif")) @@ -22,11 +22,11 @@ public class ControlsIf : Block var done = false; for (var i = 0; i < ifCount; i++) { - if (await Values.Evaluate($"IF{i}", context)) + if (await Values.EvaluateAsync($"IF{i}", context)) { context.Cancellation.ThrowIfCancellationRequested(); - await Statements[$"DO{i}"].Evaluate(context); + await Statements[$"DO{i}"].EvaluateAsync(context); done = true; break; @@ -43,11 +43,11 @@ public class ControlsIf : Block { context.Cancellation.ThrowIfCancellationRequested(); - await Statements["ELSE"].Evaluate(context); + await Statements["ELSE"].EvaluateAsync(context); } } } - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Controls/ControlsRepeatExt.cs b/Library/Core/Blocks/Controls/ControlsRepeatExt.cs index 6454642..a7628b8 100644 --- a/Library/Core/Blocks/Controls/ControlsRepeatExt.cs +++ b/Library/Core/Blocks/Controls/ControlsRepeatExt.cs @@ -8,21 +8,21 @@ namespace BlocklyNet.Core.Blocks.Controls; public class ControlsRepeatExt : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { /* See if there is a inner block we can execute. */ var statement = Statements.TryGet("DO"); if (statement == null) - return await base.Evaluate(context); + return await base.EvaluateAsync(context); /* Number of times to execute the inner block. */ - for (var i = await Values.Evaluate("TIMES", context); i-- > 0;) + for (var i = await Values.EvaluateAsync("TIMES", context); i-- > 0;) { /* Execute the inner block. */ context.Cancellation.ThrowIfCancellationRequested(); - await statement.Evaluate(context); + await statement.EvaluateAsync(context); try { @@ -40,6 +40,6 @@ public class ControlsRepeatExt : Block context.EscapeMode = EscapeMode.None; /* Continue with the next block. */ - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } diff --git a/Library/Core/Blocks/Controls/ControlsWhileUntil.cs b/Library/Core/Blocks/Controls/ControlsWhileUntil.cs index ee09a79..d017aa8 100644 --- a/Library/Core/Blocks/Controls/ControlsWhileUntil.cs +++ b/Library/Core/Blocks/Controls/ControlsWhileUntil.cs @@ -10,19 +10,19 @@ namespace BlocklyNet.Core.Blocks.Controls; public class ControlsWhileUntil : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var mode = Fields["MODE"]; var value = Values.TryGet("BOOL"); if (!Statements.Has("DO") || null == value) - return await base.Evaluate(context); + return await base.EvaluateAsync(context); var statement = Statements["DO"]; if (mode == "WHILE") { - while ((bool)(await value.Evaluate(context))!) + while ((bool)(await value.EvaluateAsync(context))!) { context.Cancellation.ThrowIfCancellationRequested(); @@ -32,17 +32,17 @@ public class ControlsWhileUntil : Block break; } - await statement.Evaluate(context); + await statement.EvaluateAsync(context); } } else - while (!(bool)(await value.Evaluate(context))!) + while (!(bool)(await value.EvaluateAsync(context))!) { context.Cancellation.ThrowIfCancellationRequested(); - await statement.Evaluate(context); + await statement.EvaluateAsync(context); } - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Lists/ListsCreateWith.cs b/Library/Core/Blocks/Lists/ListsCreateWith.cs index 347c986..026299e 100644 --- a/Library/Core/Blocks/Lists/ListsCreateWith.cs +++ b/Library/Core/Blocks/Lists/ListsCreateWith.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Lists; public class ListsCreateWith : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var list = new List(); @@ -18,7 +18,7 @@ public class ListsCreateWith : Block { context.Cancellation.ThrowIfCancellationRequested(); - list.Add((await value.Evaluate(context))!); + list.Add((await value.EvaluateAsync(context))!); } return list; diff --git a/Library/Core/Blocks/Lists/ListsGetIndex.cs b/Library/Core/Blocks/Lists/ListsGetIndex.cs index caa17b8..f27c0b7 100644 --- a/Library/Core/Blocks/Lists/ListsGetIndex.cs +++ b/Library/Core/Blocks/Lists/ListsGetIndex.cs @@ -12,9 +12,9 @@ public class ListsGetIndex : Block private static readonly Random rnd = new Random(); /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var values = new ListWrapper(await Values.Evaluate("VALUE", context)); + var values = new ListWrapper(await Values.EvaluateAsync("VALUE", context)); var mode = Fields["MODE"]; var where = Fields["WHERE"]; @@ -22,8 +22,8 @@ public class ListsGetIndex : Block var index = where switch { "FIRST" => 0, - "FROM_END" => values.Count - Convert.ToInt32(await Values.Evaluate("AT", context)), - "FROM_START" => Convert.ToInt32(await Values.Evaluate("AT", context)) - 1, + "FROM_END" => values.Count - Convert.ToInt32(await Values.EvaluateAsync("AT", context)), + "FROM_START" => Convert.ToInt32(await Values.EvaluateAsync("AT", context)) - 1, "LAST" => values.Count - 1, "RANDOM" => rnd.Next(values.Count), _ => throw new NotSupportedException($"unsupported where ({where})"), diff --git a/Library/Core/Blocks/Lists/ListsIndexOf.cs b/Library/Core/Blocks/Lists/ListsIndexOf.cs index 1c4051f..5c678fb 100644 --- a/Library/Core/Blocks/Lists/ListsIndexOf.cs +++ b/Library/Core/Blocks/Lists/ListsIndexOf.cs @@ -10,11 +10,11 @@ namespace BlocklyNet.Core.Blocks.Lists; public class ListsIndexOf : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var direction = Fields["END"]; - var value = await Values.Evaluate>("VALUE", context); - var find = await Values.Evaluate("FIND", context); + var value = await Values.EvaluateAsync>("VALUE", context); + var find = await Values.EvaluateAsync("FIND", context); switch (direction) { diff --git a/Library/Core/Blocks/Lists/ListsIsEmpty.cs b/Library/Core/Blocks/Lists/ListsIsEmpty.cs index 5887405..c696320 100644 --- a/Library/Core/Blocks/Lists/ListsIsEmpty.cs +++ b/Library/Core/Blocks/Lists/ListsIsEmpty.cs @@ -10,9 +10,9 @@ namespace BlocklyNet.Core.Blocks.Lists; public class ListsIsEmpty : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - if (await Values.Evaluate("VALUE", context) is not IEnumerable value) + if (await Values.EvaluateAsync("VALUE", context) is not IEnumerable value) return true; return !value.Any(); diff --git a/Library/Core/Blocks/Lists/ListsLength.cs b/Library/Core/Blocks/Lists/ListsLength.cs index 72db919..7ce9340 100644 --- a/Library/Core/Blocks/Lists/ListsLength.cs +++ b/Library/Core/Blocks/Lists/ListsLength.cs @@ -10,9 +10,9 @@ namespace BlocklyNet.Core.Blocks.Lists; public class ListsLength : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - if (await Values.Evaluate("VALUE", context) is not IEnumerable value) + if (await Values.EvaluateAsync("VALUE", context) is not IEnumerable value) return 0.0; return (double)value.Count(); diff --git a/Library/Core/Blocks/Lists/ListsRepeat.cs b/Library/Core/Blocks/Lists/ListsRepeat.cs index 8e2483a..2356998 100644 --- a/Library/Core/Blocks/Lists/ListsRepeat.cs +++ b/Library/Core/Blocks/Lists/ListsRepeat.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Lists; public class ListsRepeat : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var item = await Values.Evaluate("ITEM", context); - var num = await Values.Evaluate("NUM", context); + var item = await Values.EvaluateAsync("ITEM", context); + var num = await Values.EvaluateAsync("NUM", context); var list = new List(); diff --git a/Library/Core/Blocks/Lists/ListsSetIndex.cs b/Library/Core/Blocks/Lists/ListsSetIndex.cs index b55cc60..cfbfed3 100644 --- a/Library/Core/Blocks/Lists/ListsSetIndex.cs +++ b/Library/Core/Blocks/Lists/ListsSetIndex.cs @@ -10,23 +10,23 @@ public class ListsSetIndex : Block private static readonly Random rnd = new(); /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var list = new ListWrapper(await Values.Evaluate("LIST", context)); + var list = new ListWrapper(await Values.EvaluateAsync("LIST", context)); var where = Fields["WHERE"]; var index = where switch { "FIRST" => 0, - "FROM_END" => list.Count - Convert.ToInt32(await Values.Evaluate("AT", context)), - "FROM_START" => Convert.ToInt32(await Values.Evaluate("AT", context)) - 1, + "FROM_END" => list.Count - Convert.ToInt32(await Values.EvaluateAsync("AT", context)), + "FROM_START" => Convert.ToInt32(await Values.EvaluateAsync("AT", context)) - 1, "LAST" => list.Count - 1, "RANDOM" => rnd.Next(list.Count), _ => throw new NotSupportedException($"unsupported where ({where})"), }; - var value = await Values.Evaluate("TO", context); + var value = await Values.EvaluateAsync("TO", context); var mode = Fields["MODE"]; switch (mode) @@ -43,6 +43,6 @@ public class ListsSetIndex : Block throw new NotSupportedException($"unsupported mode ({mode})"); } - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } diff --git a/Library/Core/Blocks/Lists/ListsSplit.cs b/Library/Core/Blocks/Lists/ListsSplit.cs index db6d517..d7da829 100644 --- a/Library/Core/Blocks/Lists/ListsSplit.cs +++ b/Library/Core/Blocks/Lists/ListsSplit.cs @@ -10,11 +10,11 @@ namespace BlocklyNet.Core.Blocks.Lists; public class ListsSplit : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var mode = Fields["MODE"]; - var input = await Values.Evaluate("INPUT", context)!; - var delim = await Values.Evaluate("DELIM", context)!; + var input = await Values.EvaluateAsync("INPUT", context)!; + var delim = await Values.EvaluateAsync("DELIM", context)!; switch (mode) { diff --git a/Library/Core/Blocks/Logic/LogicBoolean.cs b/Library/Core/Blocks/Logic/LogicBoolean.cs index 1e8141b..c657fc5 100644 --- a/Library/Core/Blocks/Logic/LogicBoolean.cs +++ b/Library/Core/Blocks/Logic/LogicBoolean.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Logic; public class LogicBoolean : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { return Task.FromResult((object?)bool.Parse(Fields["BOOL"])); } diff --git a/Library/Core/Blocks/Logic/LogicCompare.cs b/Library/Core/Blocks/Logic/LogicCompare.cs index 6ac66e5..5ae6630 100644 --- a/Library/Core/Blocks/Logic/LogicCompare.cs +++ b/Library/Core/Blocks/Logic/LogicCompare.cs @@ -10,12 +10,12 @@ namespace BlocklyNet.Core.Blocks.Logic; public class LogicCompare : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var opValue = Fields["OP"]; - var a = await Values.Evaluate("A", context); - var b = await Values.Evaluate("B", context); + var a = await Values.EvaluateAsync("A", context); + var b = await Values.EvaluateAsync("B", context); if (a == null || b == null) return Compare(opValue, a == null, b == null); diff --git a/Library/Core/Blocks/Logic/LogicNegate.cs b/Library/Core/Blocks/Logic/LogicNegate.cs index 3e3660f..1fc678a 100644 --- a/Library/Core/Blocks/Logic/LogicNegate.cs +++ b/Library/Core/Blocks/Logic/LogicNegate.cs @@ -10,8 +10,8 @@ namespace BlocklyNet.Core.Blocks.Logic; public class LogicNegate : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - return !(await Values.Evaluate("BOOL", context) ?? false); + return !(await Values.EvaluateAsync("BOOL", context) ?? false); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Logic/LogicNull.cs b/Library/Core/Blocks/Logic/LogicNull.cs index b245917..247ed96 100644 --- a/Library/Core/Blocks/Logic/LogicNull.cs +++ b/Library/Core/Blocks/Logic/LogicNull.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Logic; public class LogicNull : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { return Task.FromResult((object?)null); } diff --git a/Library/Core/Blocks/Logic/LogicOperation.cs b/Library/Core/Blocks/Logic/LogicOperation.cs index 3f759f8..5b4f207 100644 --- a/Library/Core/Blocks/Logic/LogicOperation.cs +++ b/Library/Core/Blocks/Logic/LogicOperation.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Logic; public class LogicOperation : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var a = await Values.Evaluate("A", context) ?? false; - var b = await Values.Evaluate("B", context) ?? false; + var a = await Values.EvaluateAsync("A", context) ?? false; + var b = await Values.EvaluateAsync("B", context) ?? false; var op = Fields["OP"]; diff --git a/Library/Core/Blocks/Logic/LogicTernary.cs b/Library/Core/Blocks/Logic/LogicTernary.cs index b1c75bb..193b53f 100644 --- a/Library/Core/Blocks/Logic/LogicTernary.cs +++ b/Library/Core/Blocks/Logic/LogicTernary.cs @@ -10,19 +10,19 @@ namespace BlocklyNet.Core.Blocks.Logic; public class LogicTernary : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var ifValue = await Values.Evaluate("IF", context); + var ifValue = await Values.EvaluateAsync("IF", context); if (ifValue) { if (Values.Has("THEN")) - return await Values.Evaluate("THEN", context); + return await Values.EvaluateAsync("THEN", context); } else { if (Values.Has("ELSE")) - return await Values.Evaluate("ELSE", context); + return await Values.EvaluateAsync("ELSE", context); } return null; diff --git a/Library/Core/Blocks/Math/MathArithmetic.cs b/Library/Core/Blocks/Math/MathArithmetic.cs index db93b73..f909e24 100644 --- a/Library/Core/Blocks/Math/MathArithmetic.cs +++ b/Library/Core/Blocks/Math/MathArithmetic.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathArithmetic : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var a = await Values.Evaluate("A", context); - var b = await Values.Evaluate("B", context); + var a = await Values.EvaluateAsync("A", context); + var b = await Values.EvaluateAsync("B", context); var opValue = Fields["OP"]; diff --git a/Library/Core/Blocks/Math/MathChange.cs b/Library/Core/Blocks/Math/MathChange.cs index 6449d45..836a4a4 100644 --- a/Library/Core/Blocks/Math/MathChange.cs +++ b/Library/Core/Blocks/Math/MathChange.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathChange : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var variableName = Fields["VAR"]; - var delta = await Values.Evaluate("DELTA", context); + var delta = await Values.EvaluateAsync("DELTA", context); if (!context.Variables.ContainsKey(variableName)) throw new ApplicationException($"variable {variableName} not declared"); @@ -22,6 +22,6 @@ public class MathChange : Block value += delta; context.Variables[variableName] = value; - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Math/MathConstant.cs b/Library/Core/Blocks/Math/MathConstant.cs index 804205d..e6db277 100644 --- a/Library/Core/Blocks/Math/MathConstant.cs +++ b/Library/Core/Blocks/Math/MathConstant.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathConstant : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { var constant = Fields["CONSTANT"]; diff --git a/Library/Core/Blocks/Math/MathConstrain.cs b/Library/Core/Blocks/Math/MathConstrain.cs index 71082c2..e315183 100644 --- a/Library/Core/Blocks/Math/MathConstrain.cs +++ b/Library/Core/Blocks/Math/MathConstrain.cs @@ -10,11 +10,11 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathConstrain : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var value = await Values.Evaluate("VALUE", context); - var low = await Values.Evaluate("LOW", context); - var high = await Values.Evaluate("HIGH", context); + var value = await Values.EvaluateAsync("VALUE", context); + var low = await Values.EvaluateAsync("LOW", context); + var high = await Values.EvaluateAsync("HIGH", context); return System.Math.Min(System.Math.Max(value, low), high); } diff --git a/Library/Core/Blocks/Math/MathModulo.cs b/Library/Core/Blocks/Math/MathModulo.cs index 7f62b71..50e07b4 100644 --- a/Library/Core/Blocks/Math/MathModulo.cs +++ b/Library/Core/Blocks/Math/MathModulo.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathModulo : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var dividend = await Values.Evaluate("DIVIDEND", context); - var divisor = await Values.Evaluate("DIVISOR", context); + var dividend = await Values.EvaluateAsync("DIVIDEND", context); + var divisor = await Values.EvaluateAsync("DIVISOR", context); return dividend % divisor; } diff --git a/Library/Core/Blocks/Math/MathNumber.cs b/Library/Core/Blocks/Math/MathNumber.cs index 3c332a3..7539ff8 100644 --- a/Library/Core/Blocks/Math/MathNumber.cs +++ b/Library/Core/Blocks/Math/MathNumber.cs @@ -11,7 +11,7 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathNumber : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { return Task.FromResult((object?)double.Parse(Fields["NUM"], CultureInfo.InvariantCulture)); } diff --git a/Library/Core/Blocks/Math/MathNumberProperty.cs b/Library/Core/Blocks/Math/MathNumberProperty.cs index 64196ed..0faa353 100644 --- a/Library/Core/Blocks/Math/MathNumberProperty.cs +++ b/Library/Core/Blocks/Math/MathNumberProperty.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathNumberProperty : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var op = Fields["PROPERTY"]; - var number = await Values.Evaluate("NUMBER_TO_CHECK", context); + var number = await Values.EvaluateAsync("NUMBER_TO_CHECK", context); switch (op) { @@ -23,7 +23,7 @@ public class MathNumberProperty : Block case "WHOLE": return 0 == number % 1.0; case "POSITIVE": return number > 0; case "NEGATIVE": return number < 0; - case "DIVISIBLE_BY": return 0 == number % await Values.Evaluate("DIVISOR", context); + case "DIVISIBLE_BY": return 0 == number % await Values.EvaluateAsync("DIVISOR", context); default: throw new ApplicationException($"Unknown PROPERTY {op}"); } } diff --git a/Library/Core/Blocks/Math/MathOnList.cs b/Library/Core/Blocks/Math/MathOnList.cs index 8ae46b3..6b44ccd 100644 --- a/Library/Core/Blocks/Math/MathOnList.cs +++ b/Library/Core/Blocks/Math/MathOnList.cs @@ -12,10 +12,10 @@ public class MathOnList : Block private static readonly Random rnd = new Random(); /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var op = Fields["OP"]; - var list = await Values.Evaluate>("LIST", context); + var list = await Values.EvaluateAsync>("LIST", context); var doubleList = list.Select(x => (double)x).ToArray(); diff --git a/Library/Core/Blocks/Math/MathRandomFloat.cs b/Library/Core/Blocks/Math/MathRandomFloat.cs index 0a1a0da..9cba639 100644 --- a/Library/Core/Blocks/Math/MathRandomFloat.cs +++ b/Library/Core/Blocks/Math/MathRandomFloat.cs @@ -12,7 +12,7 @@ public class MathRandomFloat : Block private static readonly Random rand = new Random(); /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { return Task.FromResult((object?)rand.NextDouble()); } diff --git a/Library/Core/Blocks/Math/MathRandomInt.cs b/Library/Core/Blocks/Math/MathRandomInt.cs index ebb21b2..feb929a 100644 --- a/Library/Core/Blocks/Math/MathRandomInt.cs +++ b/Library/Core/Blocks/Math/MathRandomInt.cs @@ -12,10 +12,10 @@ public class MathRandomInt : Block private static readonly Random rand = new Random(); /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var from = await Values.Evaluate("FROM", context); - var to = await Values.Evaluate("TO", context); + var from = await Values.EvaluateAsync("FROM", context); + var to = await Values.EvaluateAsync("TO", context); return (double)rand.Next((int)System.Math.Min(from, to), (int)System.Math.Max(from, to)); } diff --git a/Library/Core/Blocks/Math/MathRound.cs b/Library/Core/Blocks/Math/MathRound.cs index 1d0489b..00d386b 100644 --- a/Library/Core/Blocks/Math/MathRound.cs +++ b/Library/Core/Blocks/Math/MathRound.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathRound : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var op = Fields["OP"]; - var number = await Values.Evaluate("NUM", context); + var number = await Values.EvaluateAsync("NUM", context); switch (op) { diff --git a/Library/Core/Blocks/Math/MathSingle.cs b/Library/Core/Blocks/Math/MathSingle.cs index f04a215..cf1b7c9 100644 --- a/Library/Core/Blocks/Math/MathSingle.cs +++ b/Library/Core/Blocks/Math/MathSingle.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Math; public class MathSingle : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var op = Fields["OP"]; - var number = await Values.Evaluate("NUM", context); + var number = await Values.EvaluateAsync("NUM", context); switch (op) { diff --git a/Library/Core/Blocks/Procedures/ProceduresCallNoReturn.cs b/Library/Core/Blocks/Procedures/ProceduresCallNoReturn.cs index 916df58..6d3101b 100644 --- a/Library/Core/Blocks/Procedures/ProceduresCallNoReturn.cs +++ b/Library/Core/Blocks/Procedures/ProceduresCallNoReturn.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Text; public class ProceduresCallNoReturn : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { // todo: add guard for missing name @@ -29,7 +29,7 @@ public class ProceduresCallNoReturn : Block { context.Cancellation.ThrowIfCancellationRequested(); - var value = await Values.Evaluate($"ARG{counter}", context); + var value = await Values.EvaluateAsync($"ARG{counter}", context); funcContext.Variables.Add(mutation.Value, value!); @@ -38,8 +38,8 @@ public class ProceduresCallNoReturn : Block context.Cancellation.ThrowIfCancellationRequested(); - await statement.Evaluate(funcContext); + await statement.EvaluateAsync(funcContext); - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Procedures/ProceduresCallReturn.cs b/Library/Core/Blocks/Procedures/ProceduresCallReturn.cs index 923ca30..f56eac8 100644 --- a/Library/Core/Blocks/Procedures/ProceduresCallReturn.cs +++ b/Library/Core/Blocks/Procedures/ProceduresCallReturn.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Text; public class ProceduresCallReturn : ProceduresCallNoReturn { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { // todo: add guard for missing name @@ -29,7 +29,7 @@ public class ProceduresCallReturn : ProceduresCallNoReturn { context.Cancellation.ThrowIfCancellationRequested(); - var value = await Values.Evaluate($"ARG{counter}", context); + var value = await Values.EvaluateAsync($"ARG{counter}", context); funcContext.Variables.Add(mutation.Value, value!); @@ -38,6 +38,6 @@ public class ProceduresCallReturn : ProceduresCallNoReturn context.Cancellation.ThrowIfCancellationRequested(); - return await statement.Evaluate(funcContext); + return await statement.EvaluateAsync(funcContext); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Procedures/ProceduresDef.cs b/Library/Core/Blocks/Procedures/ProceduresDef.cs index 23d6cb6..d141bb8 100644 --- a/Library/Core/Blocks/Procedures/ProceduresDef.cs +++ b/Library/Core/Blocks/Procedures/ProceduresDef.cs @@ -12,7 +12,7 @@ public class ProceduresDef : Block /// /// Current execution context. /// Always null. - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { /* Retrieve the name and the content of the function. */ var name = Fields["NAME"]; @@ -74,6 +74,6 @@ private class ValueBlock(Value value) : Block /// /// /// - public override Task Evaluate(Context context) => value.Evaluate(context); + public override Task EvaluateAsync(Context context) => value.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Procedures/ProceduresIfReturn.cs b/Library/Core/Blocks/Procedures/ProceduresIfReturn.cs index b93604f..8a9a845 100644 --- a/Library/Core/Blocks/Procedures/ProceduresIfReturn.cs +++ b/Library/Core/Blocks/Procedures/ProceduresIfReturn.cs @@ -10,13 +10,13 @@ namespace BlocklyNet.Core.Blocks.Text; public class ProceduresIfReturn : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var condition = await Values.Evaluate("CONDITION", context); + var condition = await Values.EvaluateAsync("CONDITION", context); if (condition) - return await Values.Evaluate("VALUE", context); + return await Values.EvaluateAsync("VALUE", context); - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Text/Text.cs b/Library/Core/Blocks/Text/Text.cs index 057d2f9..1621b87 100644 --- a/Library/Core/Blocks/Text/Text.cs +++ b/Library/Core/Blocks/Text/Text.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextBlock : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { return Task.FromResult((object?)Fields["TEXT"]); } diff --git a/Library/Core/Blocks/Text/TextAppend.cs b/Library/Core/Blocks/Text/TextAppend.cs index 197b83e..c2b3996 100644 --- a/Library/Core/Blocks/Text/TextAppend.cs +++ b/Library/Core/Blocks/Text/TextAppend.cs @@ -10,12 +10,12 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextAppend : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var variables = context.Variables; var variableName = Fields["VAR"]; - var textToAppend = (await Values.Evaluate("TEXT", context) ?? "").ToString(); + var textToAppend = (await Values.EvaluateAsync("TEXT", context) ?? "").ToString(); if (!variables.ContainsKey(variableName)) variables.Add(variableName, ""); @@ -24,6 +24,6 @@ public class TextAppend : Block variables[variableName] = value + textToAppend; - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Text/TextChangeCase.cs b/Library/Core/Blocks/Text/TextChangeCase.cs index efd6317..521bb8d 100644 --- a/Library/Core/Blocks/Text/TextChangeCase.cs +++ b/Library/Core/Blocks/Text/TextChangeCase.cs @@ -11,10 +11,10 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextCaseChange : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var toCase = Fields["CASE"].ToString(); - var text = (await Values.Evaluate("TEXT", context) ?? "").ToString(); + var text = (await Values.EvaluateAsync("TEXT", context) ?? "").ToString(); switch (toCase) { diff --git a/Library/Core/Blocks/Text/TextIndexOf.cs b/Library/Core/Blocks/Text/TextIndexOf.cs index 3477bc2..6dae038 100644 --- a/Library/Core/Blocks/Text/TextIndexOf.cs +++ b/Library/Core/Blocks/Text/TextIndexOf.cs @@ -10,12 +10,12 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextIndexOf : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var mode = Fields["END"]; - var text = (await Values.Evaluate("VALUE", context) ?? "").ToString(); - var term = (await Values.Evaluate("FIND", context) ?? "").ToString(); + var text = (await Values.EvaluateAsync("VALUE", context) ?? "").ToString(); + var term = (await Values.EvaluateAsync("FIND", context) ?? "").ToString(); switch (mode) { diff --git a/Library/Core/Blocks/Text/TextIsEmpty.cs b/Library/Core/Blocks/Text/TextIsEmpty.cs index 2451717..1a6b45a 100644 --- a/Library/Core/Blocks/Text/TextIsEmpty.cs +++ b/Library/Core/Blocks/Text/TextIsEmpty.cs @@ -10,9 +10,9 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextIsEmpty : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var text = (await Values.Evaluate("VALUE", context) ?? "").ToString(); + var text = (await Values.EvaluateAsync("VALUE", context) ?? "").ToString(); return string.IsNullOrEmpty(text); } diff --git a/Library/Core/Blocks/Text/TextJoin.cs b/Library/Core/Blocks/Text/TextJoin.cs index b85b58a..5270578 100644 --- a/Library/Core/Blocks/Text/TextJoin.cs +++ b/Library/Core/Blocks/Text/TextJoin.cs @@ -11,7 +11,7 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextJoin : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var items = int.Parse(Mutations.GetValue("items")); @@ -24,7 +24,7 @@ public class TextJoin : Block context.Cancellation.ThrowIfCancellationRequested(); - sb.Append(await Values.Evaluate($"ADD{i}", context)); + sb.Append(await Values.EvaluateAsync($"ADD{i}", context)); } return sb.ToString(); diff --git a/Library/Core/Blocks/Text/TextLength.cs b/Library/Core/Blocks/Text/TextLength.cs index 9e847da..212d8cd 100644 --- a/Library/Core/Blocks/Text/TextLength.cs +++ b/Library/Core/Blocks/Text/TextLength.cs @@ -10,9 +10,9 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextLength : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var text = (await Values.Evaluate("VALUE", context) ?? "").ToString(); + var text = (await Values.EvaluateAsync("VALUE", context) ?? "").ToString(); return (double)text!.Length; } diff --git a/Library/Core/Blocks/Text/TextTrim.cs b/Library/Core/Blocks/Text/TextTrim.cs index f6c64d7..b42a18c 100644 --- a/Library/Core/Blocks/Text/TextTrim.cs +++ b/Library/Core/Blocks/Text/TextTrim.cs @@ -10,11 +10,11 @@ namespace BlocklyNet.Core.Blocks.Text; public class TextTrim : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var mode = Fields["MODE"]; - var text = (await Values.Evaluate("TEXT", context) ?? "").ToString(); + var text = (await Values.EvaluateAsync("TEXT", context) ?? "").ToString(); switch (mode) { diff --git a/Library/Core/Blocks/Variables/GlobalVariableSet.cs b/Library/Core/Blocks/Variables/GlobalVariableSet.cs index 369ac8c..01c676c 100644 --- a/Library/Core/Blocks/Variables/GlobalVariableSet.cs +++ b/Library/Core/Blocks/Variables/GlobalVariableSet.cs @@ -10,9 +10,9 @@ namespace BlocklyNet.Core.Blocks.Variables; public class GlobalVariablesSet : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var value = await Values.Evaluate("VALUE", context); + var value = await Values.EvaluateAsync("VALUE", context); var variableName = Fields["VAR"]; var rootContext = context.GetRootContext(); @@ -22,6 +22,6 @@ public class GlobalVariablesSet : Block else if (value != null) rootContext.Variables[variableName] = value; - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Blocks/Variables/VariablesGet.cs b/Library/Core/Blocks/Variables/VariablesGet.cs index 5fcd56f..748822a 100644 --- a/Library/Core/Blocks/Variables/VariablesGet.cs +++ b/Library/Core/Blocks/Variables/VariablesGet.cs @@ -10,7 +10,7 @@ namespace BlocklyNet.Core.Blocks.Variables; public class VariablesGet : Block { /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { var variableName = Fields["VAR"]; diff --git a/Library/Core/Blocks/Variables/VariablesSet.cs b/Library/Core/Blocks/Variables/VariablesSet.cs index b4ab75d..af84f21 100644 --- a/Library/Core/Blocks/Variables/VariablesSet.cs +++ b/Library/Core/Blocks/Variables/VariablesSet.cs @@ -10,10 +10,10 @@ namespace BlocklyNet.Core.Blocks.Variables; public class VariablesSet : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var variables = context.Variables; - var value = await Values.Evaluate("VALUE", context); + var value = await Values.EvaluateAsync("VALUE", context); var variableName = Fields["VAR"]; // Fast-Solution @@ -29,6 +29,6 @@ public class VariablesSet : Block variables.Add(variableName, value!); } - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } \ No newline at end of file diff --git a/Library/Core/Model/Block.cs b/Library/Core/Model/Block.cs index d491e66..3bcfae6 100644 --- a/Library/Core/Model/Block.cs +++ b/Library/Core/Model/Block.cs @@ -49,10 +49,10 @@ public abstract class Block : IFragment public IList Comments { get; } = []; /// - public virtual async Task Evaluate(Context context) + public virtual async Task EvaluateAsync(Context context) { /* Wait for debugger to allow execution. */ - await context.Engine.SingleStep(this); + await context.Engine.SingleStepAsync(this); /* Always check for cancel before proceeding with the execution of the next block in chain. */ context.Cancellation.ThrowIfCancellationRequested(); @@ -63,7 +63,7 @@ public abstract class Block : IFragment /* Run the next block if we are not forcefully exiting a loop. */ if (Next != null && context.EscapeMode == EscapeMode.None) - return await Next.Evaluate(context); + return await Next.EvaluateAsync(context); return null; } diff --git a/Library/Core/Model/Executable.cs b/Library/Core/Model/Executable.cs index aadce2f..ef307b7 100644 --- a/Library/Core/Model/Executable.cs +++ b/Library/Core/Model/Executable.cs @@ -20,7 +20,7 @@ public abstract class Executable : IFragment /// /// Current execution context. /// The value. - public Task Evaluate(Context context) + public Task EvaluateAsync(Context context) { /* See if script should be terminated. */ context.Cancellation.ThrowIfCancellationRequested(); @@ -30,7 +30,7 @@ public abstract class Executable : IFragment return Task.FromResult((object?)null); /* Use the block to get the current value. */ - return Block.Evaluate(context); + return Block.EvaluateAsync(context); } } diff --git a/Library/Core/Model/IFragment.cs b/Library/Core/Model/IFragment.cs index 0df31fd..2f1c16d 100644 --- a/Library/Core/Model/IFragment.cs +++ b/Library/Core/Model/IFragment.cs @@ -10,6 +10,6 @@ public interface IFragment /// /// Current exewcution context. /// Result of the execution. - Task Evaluate(Context context); + Task EvaluateAsync(Context context); } diff --git a/Library/Core/Model/Values.cs b/Library/Core/Model/Values.cs index 30bf1b0..95e30e3 100644 --- a/Library/Core/Model/Values.cs +++ b/Library/Core/Model/Values.cs @@ -20,7 +20,7 @@ public class Values : Entities /// If set the indicated value must exist. /// Current result of the value. /// Value does not exist. - public Task Evaluate(string name, Context context, bool required = true) + public Task EvaluateAsync(string name, Context context, bool required = true) { /* See if the value is known */ var value = TryGet(name); @@ -38,7 +38,7 @@ public class Values : Entities context.Cancellation.ThrowIfCancellationRequested(); /* Try to evaluate the value. */ - return value.Evaluate(context); + return value.EvaluateAsync(context); } /// @@ -50,10 +50,10 @@ public class Values : Entities /// Expected result type. /// Current result of the value. /// Value does not exist. - public async Task Evaluate(string name, Context context, bool required = true) + public async Task EvaluateAsync(string name, Context context, bool required = true) { /* Execute the script. */ - var result = await Evaluate(name, context, required); + var result = await EvaluateAsync(name, context, required); /* Try to change type of result if possible. */ return result == null ? default! : (T)result; diff --git a/Library/Core/Model/Workspace.cs b/Library/Core/Model/Workspace.cs index bef46ef..64dc8fe 100644 --- a/Library/Core/Model/Workspace.cs +++ b/Library/Core/Model/Workspace.cs @@ -17,7 +17,7 @@ public class Workspace : IFragment /// /// Execution context. /// Result of the final block in the workspace. - public async Task Evaluate(Context context) + public async Task EvaluateAsync(Context context) { /* No result at all. */ object? returnValue = null; @@ -30,7 +30,7 @@ public class Workspace : IFragment /* Create the function itself and remember it. */ context.Cancellation.ThrowIfCancellationRequested(); - await block.Evaluate(context); + await block.EvaluateAsync(context); functions.Add(block); } @@ -42,7 +42,7 @@ public class Workspace : IFragment /* Remember the result and report the last result afterwards. */ context.Cancellation.ThrowIfCancellationRequested(); - returnValue = await block.Evaluate(context); + returnValue = await block.EvaluateAsync(context); } return returnValue; diff --git a/Library/Core/Parser.cs b/Library/Core/Parser.cs index fd06395..5c2a3ad 100644 --- a/Library/Core/Parser.cs +++ b/Library/Core/Parser.cs @@ -29,9 +29,9 @@ private class ParsedScript(Workspace workspace) : IParsedScript { private readonly Workspace _workspace = workspace; - public Task Run(IScriptSite engine) => _workspace.Evaluate(new Context(engine)); + public Task RunAsync(IScriptSite engine) => _workspace.EvaluateAsync(new Context(engine)); - public async Task Evaluate(Dictionary presets, IScriptSite engine) + public async Task EvaluateAsync(Dictionary presets, IScriptSite engine) { var ctx = new Context(engine); @@ -40,7 +40,7 @@ private class ParsedScript(Workspace workspace) : IParsedScript try { - await _workspace.Evaluate(ctx); + await _workspace.EvaluateAsync(ctx); } catch (ScriptStoppedEarlyException) { diff --git a/Library/Extensions/Builder/EnumBlock.cs b/Library/Extensions/Builder/EnumBlock.cs index 8db0304..9ddd1e7 100644 --- a/Library/Extensions/Builder/EnumBlock.cs +++ b/Library/Extensions/Builder/EnumBlock.cs @@ -86,7 +86,7 @@ private static JsonObject CreateToolboxEntry() } /// - public override Task Evaluate(Context context) + public override Task EvaluateAsync(Context context) { /* Just report the value. */ return Task.FromResult((object?)Enum.Parse(typeof(T), Fields["VALUE"])); diff --git a/Library/Extensions/Builder/ModelBlock.cs b/Library/Extensions/Builder/ModelBlock.cs index 2584b0b..d3e4bd9 100644 --- a/Library/Extensions/Builder/ModelBlock.cs +++ b/Library/Extensions/Builder/ModelBlock.cs @@ -341,7 +341,7 @@ private static JsonObject CreateToolboxEntry(ModelCache models) } /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { /* Create a new model instance. */ var model = new T(); @@ -350,7 +350,7 @@ private static JsonObject CreateToolboxEntry(ModelCache models) foreach (var prop in _props) { /* Get the raw value from the script. This may be untyped which especially for lists can be quite a problem. */ - var blocklyData = await Values.Evaluate(prop.Name, context, false); + var blocklyData = await Values.EvaluateAsync(prop.Name, context, false); if (blocklyData == null) continue; diff --git a/Library/Extensions/CreateRunScriptParameter.cs b/Library/Extensions/CreateRunScriptParameter.cs index e0cb556..c4c6b9b 100644 --- a/Library/Extensions/CreateRunScriptParameter.cs +++ b/Library/Extensions/CreateRunScriptParameter.cs @@ -72,12 +72,12 @@ public class RunScriptParameter public class CreateRunScriptParameter : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { return new RunScriptParameter { - VariableName = await Values.Evaluate("NAME", context), - Value = await Values.Evaluate("VALUE", context) + VariableName = await Values.EvaluateAsync("NAME", context), + Value = await Values.EvaluateAsync("VALUE", context) }; } } \ No newline at end of file diff --git a/Library/Extensions/Delay.cs b/Library/Extensions/Delay.cs index 4136e7b..e664839 100644 --- a/Library/Extensions/Delay.cs +++ b/Library/Extensions/Delay.cs @@ -48,12 +48,12 @@ namespace BlocklyNet.Extensions; public class Delay : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var delay = (int)await Values.Evaluate("DELAY", context); + var delay = (int)await Values.EvaluateAsync("DELAY", context); if (delay > 0) await Task.Delay(delay, context.Cancellation); - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } diff --git a/Library/Extensions/ExtractProperty.cs b/Library/Extensions/ExtractProperty.cs index b65a66e..62c225b 100644 --- a/Library/Extensions/ExtractProperty.cs +++ b/Library/Extensions/ExtractProperty.cs @@ -57,11 +57,11 @@ namespace BlocklyNet.Extensions; public class ExtractProperty : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { /* Get the object and the property. */ - var json = await Values.Evaluate("JSON", context); - var property = await Values.Evaluate("PROPERTY", context); + var json = await Values.EvaluateAsync("JSON", context); + var property = await Values.EvaluateAsync("PROPERTY", context); try { diff --git a/Library/Extensions/HttpRequest.cs b/Library/Extensions/HttpRequest.cs index 69142e0..2d7c4f1 100644 --- a/Library/Extensions/HttpRequest.cs +++ b/Library/Extensions/HttpRequest.cs @@ -108,13 +108,13 @@ namespace BlocklyNet.Extensions; public class HttpRequest : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { /* Get the endpoint. */ - var uri = await Values.Evaluate("URI", context); + var uri = await Values.EvaluateAsync("URI", context); /* The body is optional and if given is expected to be in JSON string representation, */ - var body = await Values.Evaluate("BODY", context, false); + var body = await Values.EvaluateAsync("BODY", context, false); var payload = body == null ? null : new StringContent(body, Encoding.UTF8, "application/json"); /* Get a client to process the request. */ @@ -128,12 +128,12 @@ public class HttpRequest : Block if (!string.IsNullOrEmpty(auth)) { - var header = await Values.Evaluate("AUTHHEADER", context, false); + var header = await Values.EvaluateAsync("AUTHHEADER", context, false); if (string.IsNullOrEmpty(header) || header == "Authorization") - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(auth, await Values.Evaluate("AUTHTOKEN", context)); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(auth, await Values.EvaluateAsync("AUTHTOKEN", context)); else - client.DefaultRequestHeaders.Add(header, $"{auth} {await Values.Evaluate("AUTHTOKEN", context)}"); + client.DefaultRequestHeaders.Add(header, $"{auth} {await Values.EvaluateAsync("AUTHTOKEN", context)}"); } /* Generate the request from the configuration of the block. */ diff --git a/Library/Extensions/Now.cs b/Library/Extensions/Now.cs index a2ec49c..5dd12fe 100644 --- a/Library/Extensions/Now.cs +++ b/Library/Extensions/Now.cs @@ -48,9 +48,9 @@ namespace BlocklyNet.Extensions; public class Now : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var format = await Values.Evaluate("FORMAT", context); + var format = await Values.EvaluateAsync("FORMAT", context); return string.IsNullOrWhiteSpace(format) ? (double)DateTime.Now.Ticks diff --git a/Library/Extensions/ParseJson.cs b/Library/Extensions/ParseJson.cs index 44ed378..ede04f6 100644 --- a/Library/Extensions/ParseJson.cs +++ b/Library/Extensions/ParseJson.cs @@ -49,9 +49,9 @@ namespace BlocklyNet.Extensions; public class ParseJson : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { /* Currently (.NET 8) rely on Newtonsoft.JSON since System.Text.Json will not handle ExpandoObject correctly: fields values will be JsonElement. */ - return JsonConvert.DeserializeObject(await Values.Evaluate("JSON", context)); + return JsonConvert.DeserializeObject(await Values.EvaluateAsync("JSON", context)); } } diff --git a/Library/Extensions/ReadFromModel.cs b/Library/Extensions/ReadFromModel.cs index 3fc458d..dc09920 100644 --- a/Library/Extensions/ReadFromModel.cs +++ b/Library/Extensions/ReadFromModel.cs @@ -65,11 +65,11 @@ namespace BlocklyNet.Extensions; public class ReadFromModel : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var data = context.Variables[Fields["VAR"]]; - var path = await Values.Evaluate("PATH", context) ?? ""; - var rawIndexes = await Values.Evaluate("INDEXES", context, false); + var path = await Values.EvaluateAsync("PATH", context) ?? ""; + var rawIndexes = await Values.EvaluateAsync("INDEXES", context, false); var indexes = rawIndexes?.Cast().ToArray() ?? []; var parts = path.Split("."); diff --git a/Library/Extensions/RequestUserInput.cs b/Library/Extensions/RequestUserInput.cs index 3e68a02..86c1646 100644 --- a/Library/Extensions/RequestUserInput.cs +++ b/Library/Extensions/RequestUserInput.cs @@ -85,35 +85,37 @@ namespace BlocklyNet.Extensions; public class RequestUserInput : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - var key = await Values.Evaluate("KEY", context); - var type = await Values.Evaluate("TYPE", context, false); - var delay = await Values.Evaluate("DELAY", context, false); + var key = await Values.EvaluateAsync("KEY", context); + var type = await Values.EvaluateAsync("TYPE", context, false); + var delay = await Values.EvaluateAsync("DELAY", context, false); var secs = delay.GetValueOrDefault(0); /* No delay necessary - just wait for the reply to be available. */ - if (secs <= 0) return await context.Engine.GetUserInput(key, type); + if (secs <= 0) return await context.Engine.GetUserInputAsync(key, type); var cancel = new CancellationTokenSource(); var delayTask = Task.Delay(TimeSpan.FromSeconds(secs), cancel.Token); - var inputTask = context.Engine.GetUserInput(key, type, delay); + var inputTask = context.Engine.GetUserInputAsync(key, type, delay); /* User has terminated the task. */ +#pragma warning disable VSTHRD103 // Call async methods when in an async method if (Task.WaitAny(inputTask, delayTask) == 0) { /* Cancel timer. */ - cancel.Cancel(); + await cancel.CancelAsync(); /* Report result. */ - return inputTask.Result; + return await inputTask; } +#pragma warning restore VSTHRD103 // Call async methods when in an async method /* Simulate user input. */ context.Engine.Engine.SetUserInput(null); /* May want to throw an exception. */ - var message = await Values.Evaluate("THROWMESSAGE", context, false); + var message = await Values.EvaluateAsync("THROWMESSAGE", context, false); if (message != null) throw new TimeoutException(message); diff --git a/Library/Extensions/RunParallel.cs b/Library/Extensions/RunParallel.cs index 02ecf8e..2656f62 100644 --- a/Library/Extensions/RunParallel.cs +++ b/Library/Extensions/RunParallel.cs @@ -49,7 +49,7 @@ namespace BlocklyNet.Extensions; public class RunParallel : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { /* Request the script blocks in configuration mode - will not execute on this thread. */ context.ParallelMode++; @@ -57,21 +57,21 @@ public class RunParallel : Block try { /* Load array of scripts. */ - var scripts = await Values.Evaluate("SCRIPTS", context); - var leading = await Values.Evaluate("LEADINGSCRIPT", context, false); + var scripts = await Values.EvaluateAsync("SCRIPTS", context); + var leading = await Values.EvaluateAsync("LEADINGSCRIPT", context, false); /* Request configuration for all scripts - allow empty array elements. */ var configs = new List(); foreach (RunScript script in scripts) - configs.Add(await script.ReadConfiguration(context)); + configs.Add(await script.ReadConfigurationAsync(context)); /* Lifetime control. */ var leadingDone = false; /* Create separate tasks for each script. */ var options = new StartScriptOptions { ShouldStopNow = () => leadingDone }; - var tasks = configs.Select(config => context.Engine.Run(config, options)).ToArray(); + var tasks = configs.Select(config => context.Engine.RunAsync(config, options)).ToArray(); /* Wait for the leading task to finish. */ if (leading is double) diff --git a/Library/Extensions/RunScript.cs b/Library/Extensions/RunScript.cs index 98dc5dc..6e06d62 100644 --- a/Library/Extensions/RunScript.cs +++ b/Library/Extensions/RunScript.cs @@ -66,12 +66,12 @@ public class RunScript : Block /// /// /// - public async Task ReadConfiguration(Context context) + public async Task ReadConfigurationAsync(Context context) { /* Find the script by its name - character casing is ignored. */ var store = context.ServiceProvider.GetRequiredService(); - var byName = await Values.Evaluate("NAME", context); - var script = await store.Find(byName) ?? throw new ArgumentException($"script '{byName}' not found"); + var byName = await Values.EvaluateAsync("NAME", context); + var script = await store.FindAsync(byName) ?? throw new ArgumentException($"script '{byName}' not found"); /* Prepare to run generic script. */ var config = context.ServiceProvider.GetService()?.Create() ?? new StartGenericScript(); @@ -81,7 +81,7 @@ public async Task ReadConfiguration(Context context) config.ResultType = script.ResultType; /* Fill presets - just copy indicated variables with the same name. */ - var copies = await Values.Evaluate("ARGS", context, false); + var copies = await Values.EvaluateAsync("ARGS", context, false); if (copies != null) foreach (RunScriptParameter parameter in copies) @@ -91,13 +91,13 @@ public async Task ReadConfiguration(Context context) } /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { /* We are prepared to be run in parallel to other scripts. */ if (context.ParallelMode > 0) return this; /* Run the script and report the result - in a new isolated environment. */ - var result = await context.Engine.Run(await ReadConfiguration(context)); + var result = await context.Engine.RunAsync(await ReadConfigurationAsync(context)); return result.Result; } diff --git a/Library/Extensions/SetProgress.cs b/Library/Extensions/SetProgress.cs index 6337161..448237d 100644 --- a/Library/Extensions/SetProgress.cs +++ b/Library/Extensions/SetProgress.cs @@ -94,20 +94,20 @@ namespace BlocklyNet.Extensions; public class SetProgress : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var script = context.Engine.MainScript as IGenericScript; - var progress = await Values.Evaluate("PROGRESS", context); - var name = await Values.Evaluate("NAME", context, false); + var progress = await Values.EvaluateAsync("PROGRESS", context); + var name = await Values.EvaluateAsync("NAME", context, false); context.Engine.ReportProgress(new GenericProgress { - Payload = await Values.Evaluate("PAYLOAD", context, false), - PayloadType = await Values.Evaluate("PAYLOADTYPE", context, false), + Payload = await Values.EvaluateAsync("PAYLOAD", context, false), + PayloadType = await Values.EvaluateAsync("PAYLOADTYPE", context, false), Percentage = progress, ScriptId = script?.Request.ScriptId }, progress / 100d, name); - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } diff --git a/Library/Extensions/Throw.cs b/Library/Extensions/Throw.cs index 63918f3..d443d3a 100644 --- a/Library/Extensions/Throw.cs +++ b/Library/Extensions/Throw.cs @@ -47,8 +47,8 @@ namespace BlocklyNet.Extensions; public class Throw : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { - throw new Exception(await Values.Evaluate("MESSAGE", context)); + throw new Exception(await Values.EvaluateAsync("MESSAGE", context)); } } diff --git a/Library/Extensions/TryCatchFinally.cs b/Library/Extensions/TryCatchFinally.cs index f4a0781..a99aee1 100644 --- a/Library/Extensions/TryCatchFinally.cs +++ b/Library/Extensions/TryCatchFinally.cs @@ -39,31 +39,31 @@ namespace BlocklyNet.Extensions; public class TryCatchFinally : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { try { /* Fetch the block to run. */ var exec = Statements.TryGet("TRY"); - if (exec != null) await exec.Evaluate(context); + if (exec != null) await exec.EvaluateAsync(context); } catch (Exception) { /* Fetch the block to run. */ var report = Statements.TryGet("CATCH"); - if (report != null) await report.Evaluate(context); + if (report != null) await report.EvaluateAsync(context); } finally { /* Fetch the block to run. */ var cleanup = Statements.TryGet("FINALLY"); - if (cleanup != null) await cleanup.Evaluate(context); + if (cleanup != null) await cleanup.EvaluateAsync(context); } /* Proceed with next block in chain. */ - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } diff --git a/Library/Extensions/UpdateModel.cs b/Library/Extensions/UpdateModel.cs index 29c6825..a434fd2 100644 --- a/Library/Extensions/UpdateModel.cs +++ b/Library/Extensions/UpdateModel.cs @@ -75,12 +75,12 @@ namespace BlocklyNet.Extensions; public class UpdateModelProperty : Block { /// - public override async Task Evaluate(Context context) + public override async Task EvaluateAsync(Context context) { var data = context.Variables[Fields["VAR"]]; - var value = await Values.Evaluate("VALUE", context); - var path = await Values.Evaluate("PATH", context) ?? ""; - var rawIndexes = await Values.Evaluate("INDEXES", context, false); + var value = await Values.EvaluateAsync("VALUE", context); + var path = await Values.EvaluateAsync("PATH", context) ?? ""; + var rawIndexes = await Values.EvaluateAsync("INDEXES", context, false); var indexes = rawIndexes?.Cast().ToArray() ?? []; var parts = path.Split("."); @@ -132,6 +132,6 @@ public class UpdateModelProperty : Block else data!.GetType().InvokeMember(leaf, BindingFlags.SetProperty | BindingFlags.SetField, null, data, [value]); - return await base.Evaluate(context); + return await base.EvaluateAsync(context); } } diff --git a/Library/Scripting/Definition/IScriptDefinitionStorage.cs b/Library/Scripting/Definition/IScriptDefinitionStorage.cs index 4cedc53..f930613 100644 --- a/Library/Scripting/Definition/IScriptDefinitionStorage.cs +++ b/Library/Scripting/Definition/IScriptDefinitionStorage.cs @@ -10,12 +10,12 @@ public interface IScriptDefinitionStorage /// /// /// - Task Get(string id); + Task GetAsync(string id); /// /// /// /// /// - Task Find(string name); + Task FindAsync(string name); } diff --git a/Library/Scripting/Engine/IScriptEngineNotifySink.cs b/Library/Scripting/Engine/IScriptEngineNotifySink.cs index f26aaaf..63361f1 100644 --- a/Library/Scripting/Engine/IScriptEngineNotifySink.cs +++ b/Library/Scripting/Engine/IScriptEngineNotifySink.cs @@ -11,5 +11,5 @@ public interface IScriptEngineNotifySink /// /// /// - Task Send(ScriptEngineNotifyMethods method, object? arg1); + Task SendAsync(ScriptEngineNotifyMethods method, object? arg1); } diff --git a/Library/Scripting/Engine/IScriptSite.cs b/Library/Scripting/Engine/IScriptSite.cs index c46b063..94a52c4 100644 --- a/Library/Scripting/Engine/IScriptSite.cs +++ b/Library/Scripting/Engine/IScriptSite.cs @@ -52,7 +52,7 @@ public interface IScriptSite /// Blockly XML representation of a workspace. /// Preset variables. /// Variables after execution. - Task Evaluate(string scriptAsXml, Dictionary presets); + Task EvaluateAsync(string scriptAsXml, Dictionary presets); /// /// Start a nested script. @@ -61,7 +61,7 @@ public interface IScriptSite /// Detailed configuration. /// Result of the script. /// Type of the result. - Task Run(StartScript request, StartScriptOptions? options = null); + Task RunAsync(StartScript request, StartScriptOptions? options = null); /// /// @@ -72,11 +72,11 @@ public interface IScriptSite /// Expected type of the response. /// /// - Task GetUserInput(string key, string? type = null, double? delay = null); + Task GetUserInputAsync(string key, string? type = null, double? delay = null); /// /// Call just before a block is executed. /// /// The block to execute. - Task SingleStep(Block block); + Task SingleStepAsync(Block block); } \ No newline at end of file diff --git a/Library/Scripting/Engine/ScriptEngine.Input.cs b/Library/Scripting/Engine/ScriptEngine.Input.cs index e271f40..8c3696e 100644 --- a/Library/Scripting/Engine/ScriptEngine.Input.cs +++ b/Library/Scripting/Engine/ScriptEngine.Input.cs @@ -66,7 +66,7 @@ private void SetUserInput(UserInputResponse? response, bool mustLock) } /// - public Task GetUserInput(string key, string? type = null, double? delay = null) + public Task GetUserInputAsync(string key, string? type = null, double? delay = null) { using (Lock.Wait()) { @@ -93,8 +93,13 @@ private void SetUserInput(UserInputResponse? response, bool mustLock) }; context? - .Send(ScriptEngineNotifyMethods.InputRequest, _inputRequest = inputRequest) - .ContinueWith(t => Logger.LogError("Failed to request user input for script {JobId}: {Exception}", inputRequest.JobId, t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.InputRequest, _inputRequest = inputRequest) + .ContinueWith( + t => Logger.LogError("Failed to request user input for script {JobId}: {Exception}", inputRequest.JobId, t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); } /* Report a promise on the result. */ @@ -122,7 +127,7 @@ private void SetUserInput(UserInputResponse? response, bool mustLock) } return value == null ? default : (T?)value; - }, TaskContinuationOptions.OnlyOnRanToCompletion); + }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current); } } } diff --git a/Library/Scripting/Engine/ScriptEngine.Nested.cs b/Library/Scripting/Engine/ScriptEngine.Nested.cs index e1177b0..18466dd 100644 --- a/Library/Scripting/Engine/ScriptEngine.Nested.cs +++ b/Library/Scripting/Engine/ScriptEngine.Nested.cs @@ -69,16 +69,16 @@ protected class ScriptSite(ScriptEngine engine, IScript? parent, int depth) : IS public IScript? MainScript => _engine.MainScript; /// - public Task Evaluate(string scriptAsXml, Dictionary presets) => - _engine.Parser.Parse(scriptAsXml).Evaluate(presets, this); + public Task EvaluateAsync(string scriptAsXml, Dictionary presets) => + _engine.Parser.Parse(scriptAsXml).EvaluateAsync(presets, this); /// - public Task Run(StartScript request, StartScriptOptions? options = null) - => _engine.StartChild(request, CurrentScript, options, depth); + public Task RunAsync(StartScript request, StartScriptOptions? options = null) + => _engine.StartChildAsync(request, CurrentScript, options, depth); /// - public Task GetUserInput(string key, string? type = null, double? delay = null) - => _engine.GetUserInput(key, type, delay); + public Task GetUserInputAsync(string key, string? type = null, double? delay = null) + => _engine.GetUserInputAsync(key, type, delay); /// public void ReportProgress(object info, double? progress, string? name) @@ -94,7 +94,7 @@ public void ReportProgress(object info, double? progress, string? name) /// or the exception observed. /// /// Result of the script. - public Task WaitForResult() + public Task WaitForResultAsync() { return Task.Run(() => { @@ -150,7 +150,9 @@ private void RunScript(object? state) CurrentScript = script; /* Run the script and remember the result. */ - script.Execute().Wait(); +#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits + script.ExecuteAsync().Wait(); +#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits _result = script.Result; } @@ -183,7 +185,7 @@ private void RunScript(object? state) } /// - public Task SingleStep(Block block) => Task.CompletedTask; + public Task SingleStepAsync(Block block) => Task.CompletedTask; } /// @@ -203,7 +205,7 @@ private void RunScript(object? state) /// Detailed configuration of the new script. /// Nestring depth of the child. /// Task on the result. - protected virtual async Task StartChild(StartScript request, IScript? parent, StartScriptOptions? options, int depth) + protected virtual async Task StartChildAsync(StartScript request, IScript? parent, StartScriptOptions? options, int depth) { /* Create execution context. */ var site = CreateSite(parent, depth + 1); @@ -222,7 +224,7 @@ protected virtual async Task StartChild(StartScript request, I site.Start(request, options); /* Execute the script and report the result - or exception. */ - return (TResult)(await site.WaitForResult())!; + return (TResult)(await site.WaitForResultAsync())!; } finally { diff --git a/Library/Scripting/Engine/ScriptEngine.Progress.cs b/Library/Scripting/Engine/ScriptEngine.Progress.cs index 1dc03e6..283a0eb 100644 --- a/Library/Scripting/Engine/ScriptEngine.Progress.cs +++ b/Library/Scripting/Engine/ScriptEngine.Progress.cs @@ -52,8 +52,13 @@ private void ReportProgress(object info, int depth) _lastProgress = nextProgress; context? - .Send(ScriptEngineNotifyMethods.Progress, _lastProgress) - .ContinueWith(t => Logger.LogError("Failed to forward progress: {Exception}", t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.Progress, _lastProgress) + .ContinueWith( + t => Logger.LogError("Failed to forward progress: {Exception}", t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); } } } diff --git a/Library/Scripting/Engine/ScriptEngine.cs b/Library/Scripting/Engine/ScriptEngine.cs index 20e5216..96bab68 100644 --- a/Library/Scripting/Engine/ScriptEngine.cs +++ b/Library/Scripting/Engine/ScriptEngine.cs @@ -112,8 +112,13 @@ public string Start(StartScript request, string userToken, StartScriptOptions? o /* Inform all. */ context? - .Send(ScriptEngineNotifyMethods.Started, CreateStartNotification(script)) - .ContinueWith(t => Logger.LogError("Failed to report active script: {Exception}", t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.Started, CreateStartNotification(script)) + .ContinueWith( + t => Logger.LogError("Failed to report active script: {Exception}", t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); return script.JobId; } @@ -181,7 +186,9 @@ private void RunScript(object? state) try { /* Now we can synchronously execute the script. */ - script.Execute().Wait(); +#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits + script.ExecuteAsync().Wait(); +#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits /* Check for cancel. */ _cancel.Token.ThrowIfCancellationRequested(); @@ -208,11 +215,16 @@ private void RunScript(object? state) /* Forward the information on the now terminated script. */ var task = error == null - ? context?.Send(ScriptEngineNotifyMethods.Done, CreateDoneNotification(script)) - : context?.Send(ScriptEngineNotifyMethods.Error, CreateErrorNotification(script, error)); + ? context?.SendAsync(ScriptEngineNotifyMethods.Done, CreateDoneNotification(script)) + : context?.SendAsync(ScriptEngineNotifyMethods.Error, CreateErrorNotification(script, error)); /* In case of any error just log - actually this could be quite a problem. */ - task?.ContinueWith(t => Logger.LogError("Failed to finish script: {Exception}", t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + task?.ContinueWith( + t => Logger.LogError("Failed to finish script: {Exception}", t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); /* Customize. */ OnScriptDone(script, null); @@ -260,20 +272,25 @@ protected virtual void OnScriptDone(IScriptInstance script, IScript? parent) /* Inform all. */ context? - .Send(ScriptEngineNotifyMethods.Finished, CreateFinishNotification(script)) - .ContinueWith(t => Logger.LogError("Failed to report active script: {Exception}", t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.Finished, CreateFinishNotification(script)) + .ContinueWith( + t => Logger.LogError("Failed to report active script: {Exception}", t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); return script.Result; } } /// - public Task Evaluate(string scriptAsXml, Dictionary presets) => - Parser.Parse(scriptAsXml).Evaluate(presets, this); + public Task EvaluateAsync(string scriptAsXml, Dictionary presets) => + Parser.Parse(scriptAsXml).EvaluateAsync(presets, this); /// - public Task Run(StartScript request, StartScriptOptions? options = null) - => StartChild(request, _active, options, 0); + public Task RunAsync(StartScript request, StartScriptOptions? options = null) + => StartChildAsync(request, _active, options, 0); /// /// Finish using this instance. @@ -294,26 +311,46 @@ public void Reconnect(IScriptEngineNotifySink client) /* Has been started. */ client - .Send(ScriptEngineNotifyMethods.Current, CreateCurrentNotification(_active)) - .ContinueWith(t => Logger.LogError("Failed to report active script: {Exception}", t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.Current, CreateCurrentNotification(_active)) + .ContinueWith( + t => Logger.LogError("Failed to report active script: {Exception}", t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); /* Has some last progress. */ if (_lastProgress != null) client - .Send(ScriptEngineNotifyMethods.Progress, _lastProgress) - .ContinueWith(t => Logger.LogError("Failed to forward progress: {Exception}", t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.Progress, _lastProgress) + .ContinueWith( + t => Logger.LogError("Failed to forward progress: {Exception}", t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); /* Is waiting for input. */ if (_inputRequest != null) client - .Send(ScriptEngineNotifyMethods.InputRequest, _inputRequest) - .ContinueWith(t => Logger.LogError("Failed to request user input for script {JobId}: {Exception}", _inputRequest.JobId, t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.InputRequest, _inputRequest) + .ContinueWith( + t => Logger.LogError("Failed to request user input for script {JobId}: {Exception}", _inputRequest.JobId, t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); /* Script is completed. */ if (_done) client - .Send(ScriptEngineNotifyMethods.Done, CreateDoneNotification(_active)) - .ContinueWith(t => Logger.LogError("Failed to finish script: {Exception}", t.Exception?.Message), TaskContinuationOptions.NotOnRanToCompletion); + .SendAsync(ScriptEngineNotifyMethods.Done, CreateDoneNotification(_active)) + .ContinueWith( + t => Logger.LogError("Failed to finish script: {Exception}", t.Exception?.Message), + CancellationToken.None, + TaskContinuationOptions.NotOnRanToCompletion, + TaskScheduler.Current) + .Touch(); } } @@ -359,5 +396,5 @@ protected virtual ScriptFinished CreateFinishNotification(IScriptInstance script => new() { JobId = script.JobId, ModelType = script.GetRequest().ModelType, Name = script.GetRequest().Name }; /// - public Task SingleStep(Block block) => Task.CompletedTask; + public Task SingleStepAsync(Block block) => Task.CompletedTask; } diff --git a/Library/Scripting/Generic/GenericScript.cs b/Library/Scripting/Generic/GenericScript.cs index d5d63c9..cfe2e63 100644 --- a/Library/Scripting/Generic/GenericScript.cs +++ b/Library/Scripting/Generic/GenericScript.cs @@ -29,7 +29,7 @@ public class GenericScript(StartGenericScript request, IScriptSite engine, Start IStartGenericScript IGenericScript.Request => Request; /// - protected override Task OnExecute() => Execute(this); + protected override Task OnExecuteAsync() => ExecuteAsync(this); /// /// @@ -40,7 +40,7 @@ public class GenericScript(StartGenericScript request, IScriptSite engine, Start /// /// /// - public static async Task Execute(Script script, Action? afterPresets = null) + public static async Task ExecuteAsync(Script script, Action? afterPresets = null) where TRequest : StartScript, IStartGenericScript where TResult : GenericResult, new() where TOptions : StartScriptOptions @@ -50,7 +50,7 @@ public static async Task Execute(Script().Get(script.Request.ScriptId) ?? throw new ArgumentException("Script not found."); + var def = await di.GetRequiredService().GetAsync(script.Request.ScriptId) ?? throw new ArgumentException("Script not found."); /* Prepare for logging. */ script.Request.Presets = presets.Select(d => new GenericScriptPreset { Key = d.Key, Value = d.Value }).ToList(); @@ -86,7 +86,7 @@ public static async Task Execute(Script /// - Task Execute(); + Task ExecuteAsync(); /// /// diff --git a/Library/Scripting/Parsing/IParsedScript.cs b/Library/Scripting/Parsing/IParsedScript.cs index fc59fe4..f9ffa44 100644 --- a/Library/Scripting/Parsing/IParsedScript.cs +++ b/Library/Scripting/Parsing/IParsedScript.cs @@ -13,12 +13,12 @@ public interface IParsedScript /// /// /// - Task Evaluate(Dictionary presets, IScriptSite engine); + Task EvaluateAsync(Dictionary presets, IScriptSite engine); /// /// /// /// /// - Task Run(IScriptSite engine); + Task RunAsync(IScriptSite engine); } diff --git a/Library/Scripting/Script.cs b/Library/Scripting/Script.cs index 44e2b51..0c4ce24 100644 --- a/Library/Scripting/Script.cs +++ b/Library/Scripting/Script.cs @@ -22,7 +22,7 @@ public abstract class Script : IScriptInstance /// /// /// - public abstract Task Execute(); + public abstract Task ExecuteAsync(); /// /// @@ -85,8 +85,8 @@ public abstract class Script(TRequest request, IScri /// /// Execute the script. /// - protected abstract Task OnExecute(); + protected abstract Task OnExecuteAsync(); /// - public sealed override Task Execute() => OnExecute(); + public sealed override Task ExecuteAsync() => OnExecuteAsync(); } diff --git a/Tests/BlocklyNetTests.csproj b/Tests/BlocklyNetTests.csproj index 0a04c93..696216c 100644 --- a/Tests/BlocklyNetTests.csproj +++ b/Tests/BlocklyNetTests.csproj @@ -18,6 +18,7 @@ + diff --git a/Tests/Core/ColorTests.cs b/Tests/Core/ColorTests.cs index 7dae651..299d1a0 100644 --- a/Tests/Core/ColorTests.cs +++ b/Tests/Core/ColorTests.cs @@ -6,7 +6,7 @@ namespace BlocklyNetTests.Core; public class ColorTests : TestEnvironment { [Test] - public async Task Can_Parse_Color() + public async Task Can_Parse_Color_Async() { var script = Engine.Parser.Parse(@" @@ -15,11 +15,11 @@ public async Task Can_Parse_Color() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("#ff0000")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("#ff0000")); } [Test] - public async Task Can_Get_Random_Color() + public async Task Can_Get_Random_Color_Async() { var script = Engine.Parser.Parse(@" @@ -27,16 +27,16 @@ public async Task Can_Get_Random_Color() "); - var output = (string)(await script.Run(Site.Object))!; + var output = (string)(await script.RunAsync(Site.Object))!; Assert.That(output, Has.Length.EqualTo(7)); Assert.That(output[0], Is.EqualTo('#')); - Assert.That(await script.Run(Site.Object), Is.Not.EqualTo(output)); + Assert.That(await script.RunAsync(Site.Object), Is.Not.EqualTo(output)); } [Test] - public async Task Can_Create_From_RGB() + public async Task Can_Create_From_RGB_Async() { var script = Engine.Parser.Parse(@" @@ -59,11 +59,11 @@ public async Task Can_Create_From_RGB() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("#ff0001")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("#ff0001")); } [Test] - public async Task Can_Blend() + public async Task Can_Blend_Async() { var script = Engine.Parser.Parse(@" @@ -86,6 +86,6 @@ public async Task Can_Blend() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("#d60a33")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("#d60a33")); } } \ No newline at end of file diff --git a/Tests/Core/ControlTests.cs b/Tests/Core/ControlTests.cs index 18e7a50..412009d 100644 --- a/Tests/Core/ControlTests.cs +++ b/Tests/Core/ControlTests.cs @@ -6,7 +6,7 @@ namespace BlocklyNetTests.Core; public class ControlTests : TestEnvironment { [Test] - public async Task Can_Execute_Simple_If() + public async Task Can_Execute_Simple_If_Async() { var script = Engine.Parser.Parse(@" @@ -37,11 +37,11 @@ public async Task Can_Execute_Simple_If() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(1)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(1)); } [Test] - public async Task Can_Execute_WhileUntil() + public async Task Can_Execute_WhileUntil_Async() { var script = Engine.Parser.Parse(@" @@ -93,11 +93,11 @@ public async Task Can_Execute_WhileUntil() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(1d)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(1d)); } [Test] - public async Task Can_Continue_In_Lopp() + public async Task Can_Continue_In_Loop_Async() { var script = Engine.Parser.Parse(@" @@ -152,11 +152,11 @@ public async Task Can_Continue_In_Lopp() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(0d)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(0d)); } [Test] - public async Task Can_Break_Loop() + public async Task Can_Break_Loop_Async() { var script = Engine.Parser.Parse(@" @@ -211,12 +211,12 @@ public async Task Can_Break_Loop() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(0d)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(0d)); } [Test] - public async Task Can_Execute_For_Each() + public async Task Can_Execute_For_Each_Async() { var script = Engine.Parser.Parse(@" @@ -270,11 +270,11 @@ public async Task Can_Execute_For_Each() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("abc")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("abc")); } [Test] - public async Task Can_Loop() + public async Task Can_Loop_Async() { var script = Engine.Parser.Parse(@" @@ -311,6 +311,6 @@ public async Task Can_Loop() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(4)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(4)); } } \ No newline at end of file diff --git a/Tests/Core/ListTests.cs b/Tests/Core/ListTests.cs index e4d0b2b..c1a8863 100644 --- a/Tests/Core/ListTests.cs +++ b/Tests/Core/ListTests.cs @@ -6,7 +6,7 @@ namespace BlocklyNetTests.Core; public class ListTests : TestEnvironment { [Test] - public async Task Can_Create_List() + public async Task Can_Create_List_Async() { var script = Engine.Parser.Parse(@" @@ -30,11 +30,11 @@ public async Task Can_Create_List() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(new string[] { "x", "y", "z" })); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(new string[] { "x", "y", "z" })); } [Test] - public async Task Can_Split_List() + public async Task Can_Split_List_Async() { var script = Engine.Parser.Parse(@" @@ -54,11 +54,11 @@ public async Task Can_Split_List() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(new string[] { "x", "y", "z" })); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(new string[] { "x", "y", "z" })); } [Test] - public async Task Can_Join_Lists() + public async Task Can_Join_Lists_Async() { var script = Engine.Parser.Parse(@" @@ -93,11 +93,11 @@ public async Task Can_Join_Lists() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("x,y,z")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("x,y,z")); } [Test] - public async Task Can_Get_Length() + public async Task Can_Get_Length_Async() { var script = Engine.Parser.Parse(@" @@ -121,11 +121,11 @@ public async Task Can_Get_Length() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(3)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(3)); } [Test] - public async Task Can_Repeat() + public async Task Can_Repeat_Async() { var script = Engine.Parser.Parse(@" @@ -143,11 +143,11 @@ public async Task Can_Repeat() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(new string[] { "hello", "hello", "hello" })); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(new string[] { "hello", "hello", "hello" })); } [Test] - public async Task Can_Test_For_Empty() + public async Task Can_Test_For_Empty_Async() { var script = Engine.Parser.Parse(@" @@ -160,11 +160,11 @@ public async Task Can_Test_For_Empty() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_Find_Index() + public async Task Can_Find_Index_Async() { var script = Engine.Parser.Parse(@" @@ -195,11 +195,11 @@ public async Task Can_Find_Index() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(2)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(2)); } [Test] - public async Task Can_Get_Element() + public async Task Can_Get_Element_Async() { var script = Engine.Parser.Parse(@" @@ -231,6 +231,6 @@ public async Task Can_Get_Element() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("bar")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("bar")); } } \ No newline at end of file diff --git a/Tests/Core/LogicTests.cs b/Tests/Core/LogicTests.cs index 13692a4..72e92f0 100644 --- a/Tests/Core/LogicTests.cs +++ b/Tests/Core/LogicTests.cs @@ -6,7 +6,7 @@ namespace BlocklyNetTests.Core; public class LogicTests : TestEnvironment { [Test] - public async Task Can_Report_True() + public async Task Can_Report_True_Async() { var script = Engine.Parser.Parse(@" @@ -15,11 +15,11 @@ public async Task Can_Report_True() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_Or() + public async Task Can_Or_Async() { var script = Engine.Parser.Parse(@" @@ -38,11 +38,11 @@ public async Task Can_Or() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_And() + public async Task Can_And_Async() { var script = Engine.Parser.Parse(@" @@ -61,11 +61,11 @@ public async Task Can_And() "); - Assert.That(await script.Run(Site.Object), Is.False); + Assert.That(await script.RunAsync(Site.Object), Is.False); } [Test] - public async Task Can_Not() + public async Task Can_Not_Async() { var script = Engine.Parser.Parse(@" @@ -78,22 +78,22 @@ public async Task Can_Not() "); - Assert.That(await script.Run(Site.Object), Is.False); + Assert.That(await script.RunAsync(Site.Object), Is.False); } [Test] - public async Task Can_Report_Null() + public async Task Can_Report_Null_Async() { var script = Engine.Parser.Parse(@" "); - Assert.That(await script.Run(Site.Object), Is.Null); + Assert.That(await script.RunAsync(Site.Object), Is.Null); } [Test] - public async Task Can_Switch_Ternary() + public async Task Can_Switch_Ternary_Async() { var script = Engine.Parser.Parse(@" @@ -116,6 +116,6 @@ public async Task Can_Switch_Ternary() "); - Assert.That(await script.Run(Site.Object), Is.False); + Assert.That(await script.RunAsync(Site.Object), Is.False); } } \ No newline at end of file diff --git a/Tests/Core/MathBlockTests.cs b/Tests/Core/MathBlockTests.cs index 9bc4b2c..5b4be97 100644 --- a/Tests/Core/MathBlockTests.cs +++ b/Tests/Core/MathBlockTests.cs @@ -11,7 +11,7 @@ public class MathBlockTests : TestEnvironment /// See if we can run the square root block from the XML representation. /// [Test] - public async Task Can_Get_Square_Root_From_Xml() + public async Task Can_Get_Square_Root_From_Xml_Async() { /* Parse string to block tree. */ var script = Engine.Parser.Parse(@" @@ -27,14 +27,14 @@ public async Task Can_Get_Square_Root_From_Xml() "); /* Execute the block tree. */ - Assert.That(await script.Run(Site.Object), Is.EqualTo(3)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(3)); } /// /// See if we can execute a manually created block tree for a square root. /// [Test] - public async Task Can_Get_Square_Root_As_Block() + public async Task Can_Get_Square_Root_As_Block_Async() { /* Manually create the block tree. */ var block = new MathSingle @@ -44,11 +44,11 @@ public async Task Can_Get_Square_Root_As_Block() }; /* Execute the block tree. */ - Assert.That(await block.Evaluate(new Context(Site.Object)), Is.EqualTo(3)); + Assert.That(await block.EvaluateAsync(new Context(Site.Object)), Is.EqualTo(3)); } [Test] - public async Task Can_Calculate_Sin() + public async Task Can_Calculate_Sin_Async() { var script = Engine.Parser.Parse(@" @@ -62,13 +62,13 @@ public async Task Can_Calculate_Sin() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(Math.Sin(Math.PI / 4))); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(Math.Sin(Math.PI / 4))); } [TestCase("E", Math.E)] [TestCase("INFINITY", double.PositiveInfinity)] [TestCase("PI", Math.PI)] - public async Task Can_Supply_Constant(string name, double expected) + public async Task Can_Supply_Constant_Async(string name, double expected) { var script = Engine.Parser.Parse(@" @@ -78,11 +78,11 @@ public async Task Can_Supply_Constant(string name, double expected) ".Replace("$$CONSTANT$$", name)); - Assert.That(await script.Run(Site.Object), Is.EqualTo(expected)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(expected)); } [Test] - public async Task Can_Detect_Even_Number() + public async Task Can_Detect_Even_Number_Async() { var script = Engine.Parser.Parse(@" @@ -97,11 +97,11 @@ public async Task Can_Detect_Even_Number() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_Detect_Odd_Number() + public async Task Can_Detect_Odd_Number_Async() { var script = Engine.Parser.Parse(@" @@ -116,11 +116,11 @@ public async Task Can_Detect_Odd_Number() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_Detect_Prime() + public async Task Can_Detect_Prime_Async() { var script = Engine.Parser.Parse(@" @@ -135,12 +135,12 @@ public async Task Can_Detect_Prime() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [TestCase("7", true)] [TestCase("7.1", false)] - public async Task Can_Detect_Whole_Number(string number, bool expected) + public async Task Can_Detect_Whole_Number_Async(string number, bool expected) { var script = Engine.Parser.Parse(@" @@ -156,11 +156,11 @@ public async Task Can_Detect_Whole_Number(string number, bool expected) ".Replace("$$NUMBER$$", number)); - Assert.That(await script.Run(Site.Object), Is.EqualTo(expected)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(expected)); } [Test] - public async Task Can_Detect_Positive_Number() + public async Task Can_Detect_Positive_Number_Async() { var script = Engine.Parser.Parse(@" @@ -175,11 +175,11 @@ public async Task Can_Detect_Positive_Number() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_Detect_Negative_Number() + public async Task Can_Detect_Negative_Number_Async() { var script = Engine.Parser.Parse(@" @@ -194,11 +194,11 @@ public async Task Can_Detect_Negative_Number() "); - Assert.That(await script.Run(Site.Object), Is.False); + Assert.That(await script.RunAsync(Site.Object), Is.False); } [Test] - public async Task Can_Test_For_Divisible_By() + public async Task Can_Test_For_Divisible_By_Async() { var script = Engine.Parser.Parse(@" @@ -218,11 +218,11 @@ public async Task Can_Test_For_Divisible_By() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_Round() + public async Task Can_Round_Async() { var script = Engine.Parser.Parse(@" @@ -236,11 +236,11 @@ public async Task Can_Round() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(3.0)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(3.0)); } [Test] - public async Task Can_Round_Up() + public async Task Can_Round_Up_Async() { var script = Engine.Parser.Parse(@" @@ -254,11 +254,11 @@ public async Task Can_Round_Up() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(4.0)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(4.0)); } [Test] - public async Task Can_Round_Down() + public async Task Can_Round_Down_Async() { var script = Engine.Parser.Parse(@" @@ -272,11 +272,11 @@ public async Task Can_Round_Down() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(3.0)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(3.0)); } [Test] - public async Task Can_Sum_List() + public async Task Can_Sum_List_Async() { var script = Engine.Parser.Parse(@" @@ -300,11 +300,11 @@ public async Task Can_Sum_List() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(15)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(15)); } [Test] - public async Task Can_Choose_Random_List_Element() + public async Task Can_Choose_Random_List_Element_Async() { var script = Engine.Parser.Parse(@" @@ -328,11 +328,11 @@ public async Task Can_Choose_Random_List_Element() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(3)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(3)); } [Test] - public async Task Can_Group_On_List() + public async Task Can_Group_On_List_Async() { var script = Engine.Parser.Parse(@" @@ -356,11 +356,11 @@ public async Task Can_Group_On_List() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(3)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(3)); } [Test] - public async Task Can_Contrain() + public async Task Can_Contrain_Async() { var script = Engine.Parser.Parse(@" @@ -383,11 +383,11 @@ public async Task Can_Contrain() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(100)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(100)); } [Test] - public async Task Can_Get_Modulo() + public async Task Can_Get_Modulo_Async() { var script = Engine.Parser.Parse(@" @@ -406,11 +406,11 @@ public async Task Can_Get_Modulo() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(4)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(4)); } [Test] - public async Task Can_Generate_Random_Number() + public async Task Can_Generate_Random_Number_Async() { var script = Engine.Parser.Parse(@" @@ -418,11 +418,11 @@ public async Task Can_Generate_Random_Number() "); - Assert.That(await script.Run(Site.Object), Is.GreaterThanOrEqualTo(0d).And.LessThanOrEqualTo(1d)); + Assert.That(await script.RunAsync(Site.Object), Is.GreaterThanOrEqualTo(0d).And.LessThanOrEqualTo(1d)); } [Test] - public async Task Can_Generate_Integral_Random_Number() + public async Task Can_Generate_Integral_Random_Number_Async() { var script = Engine.Parser.Parse(@" @@ -440,11 +440,11 @@ public async Task Can_Generate_Integral_Random_Number() "); - Assert.That(await script.Run(Site.Object), Is.GreaterThanOrEqualTo(1).And.LessThanOrEqualTo(100)); + Assert.That(await script.RunAsync(Site.Object), Is.GreaterThanOrEqualTo(1).And.LessThanOrEqualTo(100)); } [Test] - public async Task Can_Change_Number_Variable() + public async Task Can_Change_Number_Variable_Async() { var script = Engine.Parser.Parse(@" @@ -476,6 +476,6 @@ public async Task Can_Change_Number_Variable() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(2d)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(2d)); } } \ No newline at end of file diff --git a/Tests/Core/ProcedureTests.cs b/Tests/Core/ProcedureTests.cs index 764d8f6..bd701c5 100644 --- a/Tests/Core/ProcedureTests.cs +++ b/Tests/Core/ProcedureTests.cs @@ -6,7 +6,7 @@ namespace BlocklyNetTests.Core; public class ProcedureTests : TestEnvironment { [Test] - public async Task Can_Execute_Procedure() + public async Task Can_Execute_Procedure_Async() { var script = Engine.Parser.Parse(@" @@ -82,11 +82,11 @@ public async Task Can_Execute_Procedure() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(",hello world,hello world,hello world")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(",hello world,hello world,hello world")); } [Test] - public async Task Can_Return() + public async Task Can_Return_Async() { var script = Engine.Parser.Parse(@" @@ -104,11 +104,11 @@ public async Task Can_Return() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("hello world")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("hello world")); } [Test] - public async Task Can_If_Return() + public async Task Can_If_Return_Async() { var script = Engine.Parser.Parse(@" @@ -141,6 +141,6 @@ public async Task Can_If_Return() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("hello world")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("hello world")); } } diff --git a/Tests/Core/TextTests.cs b/Tests/Core/TextTests.cs index 91f96be..946b39c 100644 --- a/Tests/Core/TextTests.cs +++ b/Tests/Core/TextTests.cs @@ -6,7 +6,7 @@ namespace BlocklyNetTests.Core; public class TextTests : TestEnvironment { [Test] - public async Task Can_Get_Length() + public async Task Can_Get_Length_Async() { var script = Engine.Parser.Parse(@" @@ -19,11 +19,11 @@ public async Task Can_Get_Length() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(3)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(3)); } [Test] - public async Task Can_Test_On_Empty() + public async Task Can_Test_On_Empty_Async() { var script = Engine.Parser.Parse(@" @@ -36,11 +36,11 @@ public async Task Can_Test_On_Empty() "); - Assert.That(await script.Run(Site.Object), Is.True); + Assert.That(await script.RunAsync(Site.Object), Is.True); } [Test] - public async Task Can_Trim() + public async Task Can_Trim_Async() { var script = Engine.Parser.Parse(@" @@ -54,11 +54,11 @@ public async Task Can_Trim() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("ab c")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("ab c")); } [Test] - public async Task Can_Convert_To_Title_Case() + public async Task Can_Convert_To_Title_Case_Async() { var script = Engine.Parser.Parse(@" @@ -72,11 +72,11 @@ public async Task Can_Convert_To_Title_Case() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("Hello World")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("Hello World")); } [Test] - public async Task Can_Append() + public async Task Can_Append_Async() { var script = Engine.Parser.Parse(@" @@ -108,11 +108,11 @@ public async Task Can_Append() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("foobar")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("foobar")); } [Test] - public async Task Can_Join() + public async Task Can_Join_Async() { var script = Engine.Parser.Parse(@" @@ -144,11 +144,11 @@ public async Task Can_Join() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo("foobar")); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo("foobar")); } [Test] - public async Task Can_Find_Index() + public async Task Can_Find_Index_Async() { var script = Engine.Parser.Parse(@" @@ -167,6 +167,6 @@ public async Task Can_Find_Index() "); - Assert.That(await script.Run(Site.Object), Is.EqualTo(5)); + Assert.That(await script.RunAsync(Site.Object), Is.EqualTo(5)); } } \ No newline at end of file diff --git a/Tests/CoreEx/DelayTests.cs b/Tests/CoreEx/DelayTests.cs index 97ec286..57d71a1 100644 --- a/Tests/CoreEx/DelayTests.cs +++ b/Tests/CoreEx/DelayTests.cs @@ -11,7 +11,7 @@ public class DelayTests : TestEnvironment /// See if the execution of a script can stall for a while. /// [Test] - public async Task Can_Delay_Execution() + public async Task Can_Delay_Execution_Async() { /* Build block tree. */ var block = new Delay @@ -22,7 +22,7 @@ public async Task Can_Delay_Execution() /* Run test and see if time advances for at least the given amount. */ var start = DateTime.Now; - await block.Evaluate(new Context(Site.Object)); + await block.EvaluateAsync(new Context(Site.Object)); Assert.That((DateTime.Now - start).TotalMilliseconds, Is.GreaterThanOrEqualTo(490)); } diff --git a/Tests/CoreEx/ExtractPropertyTests.cs b/Tests/CoreEx/ExtractPropertyTests.cs index 7ab7537..5c68e5e 100644 --- a/Tests/CoreEx/ExtractPropertyTests.cs +++ b/Tests/CoreEx/ExtractPropertyTests.cs @@ -16,7 +16,7 @@ public class SomeClass } [Test] - public async Task ExtractProperty_Parsed() + public async Task ExtractProperty_Parsed_Async() { var parsed = new ParseJson { @@ -39,11 +39,11 @@ public async Task ExtractProperty_Parsed() } }; - Assert.That(await block.Evaluate(new Context(Site.Object)), Is.EqualTo(12.3d)); + Assert.That(await block.EvaluateAsync(new Context(Site.Object)), Is.EqualTo(12.3d)); } [Test] - public async Task ExtractProperty_ParsedNested() + public async Task ExtractProperty_ParsedNeste_Async() { var parsed = new ParseJson { @@ -74,11 +74,11 @@ public async Task ExtractProperty_ParsedNested() } }; - Assert.That(await block.Evaluate(new Context(Site.Object)), Is.True); + Assert.That(await block.EvaluateAsync(new Context(Site.Object)), Is.True); } [Test] - public async Task ExtractProperty_DotNetType() + public async Task ExtractProperty_DotNetType_Async() { var block = new ExtractProperty { @@ -88,11 +88,11 @@ public async Task ExtractProperty_DotNetType() } }; - Assert.That(await block.Evaluate(new Context(Site.Object)), Is.EqualTo("0.1")); + Assert.That(await block.EvaluateAsync(new Context(Site.Object)), Is.EqualTo("0.1")); } [Test] - public async Task ExtractProperty_AnonymousType() + public async Task ExtractProperty_AnonymousType_Async() { var block = new ExtractProperty { @@ -102,6 +102,6 @@ public async Task ExtractProperty_AnonymousType() } }; - Assert.That(await block.Evaluate(new Context(Site.Object)), Is.EqualTo("Jochen")); + Assert.That(await block.EvaluateAsync(new Context(Site.Object)), Is.EqualTo("Jochen")); } } \ No newline at end of file diff --git a/Tests/CoreEx/ModelUpdateTests.cs b/Tests/CoreEx/ModelUpdateTests.cs index 2d6fae6..9dcd74e 100644 --- a/Tests/CoreEx/ModelUpdateTests.cs +++ b/Tests/CoreEx/ModelUpdateTests.cs @@ -31,7 +31,7 @@ public class OuterClass } [Test] - public async Task Can_Update_Class_Instance() + public async Task Can_Update_Class_Instance_Async() { var instance = new OuterClass { @@ -50,7 +50,7 @@ public async Task Can_Update_Class_Instance() } }; - await block.Evaluate(Context); + await block.EvaluateAsync(Context); Assert.That(instance.Name, Is.EqualTo("Replace-Outer")); @@ -66,7 +66,7 @@ public async Task Can_Update_Class_Instance() } }; - await test.Evaluate(Context); + await test.EvaluateAsync(Context); Assert.That(instance.Inner[i].Id, Is.EqualTo(42 + i)); } @@ -82,11 +82,11 @@ public async Task Can_Update_Class_Instance() }"; [Test] - public async Task Can_Update_Parsed_Json() + public async Task Can_Update_Parsed_Json_Async() { var parser = new ParseJson { Values = { new() { Name = "JSON", Block = CreateStringBlock(jsonModel) } } }; - dynamic instance = (await parser.Evaluate(Context))!; + dynamic instance = (await parser.EvaluateAsync(Context))!; Context.Variables["instance"] = instance; @@ -99,7 +99,7 @@ public async Task Can_Update_Parsed_Json() } }; - await block.Evaluate(Context); + await block.EvaluateAsync(Context); Assert.That(instance.name, Is.EqualTo("Replace-Outer")); @@ -115,14 +115,14 @@ public async Task Can_Update_Parsed_Json() } }; - await test.Evaluate(Context); + await test.EvaluateAsync(Context); Assert.That(instance.inner[i].id, Is.EqualTo(42 + i)); } } [Test] - public async Task Can_Update_Untyped_Dictionary() + public async Task Can_Update_Untyped_Dictionary_Async() { var instance = new Dictionary { { "a", -1 }, { "b", -2 } }; @@ -137,13 +137,13 @@ public async Task Can_Update_Untyped_Dictionary() } }; - await block.Evaluate(Context); + await block.EvaluateAsync(Context); Assert.That(instance["b"], Is.EqualTo(42)); } [Test] - public async Task Can_Update_Typed_Dictionary() + public async Task Can_Update_Typed_Dictionary_Async() { var instance = new Dictionary { { Modes.One, -1 }, { Modes.Two, -2 } }; @@ -158,13 +158,13 @@ public async Task Can_Update_Typed_Dictionary() } }; - await block.Evaluate(Context); + await block.EvaluateAsync(Context); Assert.That(instance[Modes.One], Is.EqualTo(42)); } [Test] - public async Task Can_Read_Class_Instance() + public async Task Can_Read_Class_Instance_Async() { Context.Variables["instance"] = new OuterClass @@ -179,7 +179,7 @@ public async Task Can_Read_Class_Instance() Values = { new() { Name = "PATH", Block = CreateStringBlock("Name") }, } }; - Assert.That(await block.Evaluate(Context), Is.EqualTo("Outer")); + Assert.That(await block.EvaluateAsync(Context), Is.EqualTo("Outer")); for (var i = 0; i < 3; i++) { @@ -192,16 +192,16 @@ public async Task Can_Read_Class_Instance() } }; - Assert.That(await test.Evaluate(Context), Is.EqualTo(-(i + 1))); + Assert.That(await test.EvaluateAsync(Context), Is.EqualTo(-(i + 1))); } } [Test] - public async Task Can_Read_Parsed_Json() + public async Task Can_Read_Parsed_Json_Async() { var parser = new ParseJson { Values = { new() { Name = "JSON", Block = CreateStringBlock(jsonModel) } } }; - Context.Variables["instance"] = await parser.Evaluate(Context); + Context.Variables["instance"] = await parser.EvaluateAsync(Context); var block = new ReadFromModel { @@ -209,7 +209,7 @@ public async Task Can_Read_Parsed_Json() Values = { new() { Name = "PATH", Block = CreateStringBlock("name") }, } }; - Assert.That(await block.Evaluate(Context), Is.EqualTo("Outer")); + Assert.That(await block.EvaluateAsync(Context), Is.EqualTo("Outer")); for (var i = 0; i < 3; i++) { @@ -222,12 +222,12 @@ public async Task Can_Read_Parsed_Json() } }; - Assert.That(await test.Evaluate(Context), Is.EqualTo(-(i + 1))); + Assert.That(await test.EvaluateAsync(Context), Is.EqualTo(-(i + 1))); } } [Test] - public async Task Can_Read_Untyped_Dictionary() + public async Task Can_Read_Untyped_Dictionary_Async() { Context.Variables["instance"] = new Dictionary { { "a", -1 }, { "b", -2 } }; @@ -237,11 +237,11 @@ public async Task Can_Read_Untyped_Dictionary() Values = { new() { Name = "PATH", Block = CreateStringBlock("b") }, } }; - Assert.That(await block.Evaluate(Context), Is.EqualTo(-2)); + Assert.That(await block.EvaluateAsync(Context), Is.EqualTo(-2)); } [Test] - public async Task Can_Read_Typed_Dictionary() + public async Task Can_Read_Typed_Dictionary_Async() { Context.Variables["instance"] = new Dictionary { { Modes.One, -1 }, { Modes.Two, -2 } }; @@ -251,6 +251,6 @@ public async Task Can_Read_Typed_Dictionary() Values = { new() { Name = "PATH", Block = CreateStringBlock(Modes.One.ToString()) }, } }; - Assert.That(await block.Evaluate(Context), Is.EqualTo(-1)); + Assert.That(await block.EvaluateAsync(Context), Is.EqualTo(-1)); } } \ No newline at end of file diff --git a/Tests/CoreEx/NowTests.cs b/Tests/CoreEx/NowTests.cs index af4f42c..88d4060 100644 --- a/Tests/CoreEx/NowTests.cs +++ b/Tests/CoreEx/NowTests.cs @@ -11,7 +11,7 @@ public class NowTests : TestEnvironment /// Check the readout and formatting of the current time. /// [Test] - public async Task Can_Get_Current_Date_And_Time() + public async Task Can_Get_Current_Date_And_Time_Async() { /* Build the block tree manually and run it. */ var block = new Now @@ -19,7 +19,7 @@ public async Task Can_Get_Current_Date_And_Time() Values = { new() { Name = "FORMAT", Block = CreateStringBlock("dd.MM.yyyy") } } }; - var value = await block.Evaluate(new Context(Site.Object)); + var value = await block.EvaluateAsync(new Context(Site.Object)); /* May fail when tested around midnight. */ var now = DateTime.Now; diff --git a/Tests/CoreEx/ParseJsonTests.cs b/Tests/CoreEx/ParseJsonTests.cs index 5adea20..84d387a 100644 --- a/Tests/CoreEx/ParseJsonTests.cs +++ b/Tests/CoreEx/ParseJsonTests.cs @@ -10,7 +10,7 @@ namespace BlocklyNetTests.CoreEx; public class ParseJsonTests : TestEnvironment { [Test] - public async Task ParseJson() + public async Task ParseJson_Async() { var json = JsonSerializer.Serialize(new { @@ -22,7 +22,7 @@ public async Task ParseJson() var block = new ParseJson { Values = { new() { Name = "JSON", Block = CreateStringBlock(json) } } }; - var result = await block.Evaluate(new Context(Site.Object)); + var result = await block.EvaluateAsync(new Context(Site.Object)); Assert.That(result, Is.TypeOf()); diff --git a/Tests/CoreEx/ScriptParserTests.cs b/Tests/CoreEx/ScriptParserTests.cs index 4f88607..036cf61 100644 --- a/Tests/CoreEx/ScriptParserTests.cs +++ b/Tests/CoreEx/ScriptParserTests.cs @@ -34,7 +34,7 @@ public void Teardown() } [Test] - public async Task Can_Parse_And_Compile_Xml_Script() + public async Task Can_Parse_And_Compile_Xml_Script_Async() { const string xml = @" @@ -157,12 +157,12 @@ public async Task Can_Parse_And_Compile_Xml_Script() var engine = new ScriptEngine(Services, Services.GetRequiredService(), new NullLogger(), null); - await engine.Evaluate(xml, []); + await engine.EvaluateAsync(xml, []); } [TestCase(null)] [TestCase(30d)] - public async Task Can_Evaluate_With_Variables(double? a) + public async Task Can_Evaluate_With_Variables_Async(double? a) { const string xml = @" @@ -256,7 +256,7 @@ public async Task Can_Evaluate_With_Variables(double? a) if (a.HasValue) presets["a"] = a.Value; - var vars = (IList)(await engine.Evaluate(xml, presets))!; + var vars = (IList)(await engine.EvaluateAsync(xml, presets))!; Assert.Multiple(() => { @@ -268,7 +268,7 @@ public async Task Can_Evaluate_With_Variables(double? a) } [Test] - public async Task Can_Execute_Generic_Http_Request() + public async Task Can_Execute_Generic_Http_Request_Async() { const string xml = @" @@ -301,13 +301,13 @@ public async Task Can_Execute_Generic_Http_Request() var engine = new ScriptEngine(Services, Services.GetRequiredService(), new NullLogger(), null); - var body = await engine.Evaluate(xml, []); + var body = await engine.EvaluateAsync(xml, []); Assert.That(body, Has.Length.GreaterThan(1000)); } [Test] - public async Task Can_Execute_Try_Catch_Finally() + public async Task Can_Execute_Try_Catch_Finally_Async() { var xml = @" @@ -422,7 +422,7 @@ public async Task Can_Execute_Try_Catch_Finally() var engine = new ScriptEngine(Services, Services.GetRequiredService(), new NullLogger(), null); - var vars = (IList)(await engine.Evaluate(xml, []))!; + var vars = (IList)(await engine.EvaluateAsync(xml, []))!; Assert.Multiple(() => { diff --git a/Tests/CoreEx/SetProgressTests.cs b/Tests/CoreEx/SetProgressTests.cs index f5c82b8..7c5aa03 100644 --- a/Tests/CoreEx/SetProgressTests.cs +++ b/Tests/CoreEx/SetProgressTests.cs @@ -10,7 +10,7 @@ namespace BlocklyNetTests.CoreEx; public class SetProgressTests : TestEnvironment { [Test] - public async Task SetProgress() + public async Task SetProgress_Async() { var block = new SetProgress { @@ -26,7 +26,7 @@ public async Task SetProgress() Site.Setup(e => e.ReportProgress(It.IsAny(), 0.299d, "ZERA")).Callback((object? p, double? rel, string? name) => progress = (GenericProgress)p!); - await block.Evaluate(new Context(Site.Object)); + await block.EvaluateAsync(new Context(Site.Object)); Assert.That(progress, Is.Not.Null); diff --git a/Tests/CoreEx/ThrowTests.cs b/Tests/CoreEx/ThrowTests.cs index 9802721..8998b98 100644 --- a/Tests/CoreEx/ThrowTests.cs +++ b/Tests/CoreEx/ThrowTests.cs @@ -9,13 +9,13 @@ namespace BlocklyNetTests.CoreEx; public class ThrowTests : TestEnvironment { [Test] - public async Task CanThrow() + public async Task CanThrow_Async() { var block = new Throw { Values = { new() { Name = "MESSAGE", Block = CreateStringBlock("broken") } } }; try { - await block.Evaluate(new Context(Site.Object)); + await block.EvaluateAsync(new Context(Site.Object)); } catch (Exception e) { @@ -28,7 +28,7 @@ public async Task CanThrow() } [Test] - public async Task TryCatchFinally_Try() + public async Task TryCatchFinally_Try_Async() { var block = new TryCatchFinally { @@ -46,13 +46,13 @@ public async Task TryCatchFinally_Try() var context = new Context(Site.Object); - await block.Evaluate(context); + await block.EvaluateAsync(context); Assert.That(context.Variables["result"], Is.EqualTo(10)); } [Test] - public async Task TryCatchFinally_Finally() + public async Task TryCatchFinally_Finally_Async() { var block = new TryCatchFinally { @@ -70,13 +70,13 @@ public async Task TryCatchFinally_Finally() var context = new Context(Site.Object); - await block.Evaluate(context); + await block.EvaluateAsync(context); Assert.That(context.Variables["result"], Is.EqualTo(80)); } [Test] - public async Task TryCatchFinally_Try_Finally() + public async Task TryCatchFinally_Try_Finally_Async() { var block = new TryCatchFinally { @@ -102,13 +102,13 @@ public async Task TryCatchFinally_Try_Finally() var context = new Context(Site.Object); - await block.Evaluate(context); + await block.EvaluateAsync(context); Assert.That(context.Variables["result"], Is.EqualTo(40)); } [Test] - public async Task TryCatchFinally_Try_Catch() + public async Task TryCatchFinally_Try_Catch_Async() { var block = new TryCatchFinally { @@ -135,13 +135,13 @@ public async Task TryCatchFinally_Try_Catch() var context = new Context(Site.Object); - await block.Evaluate(context); + await block.EvaluateAsync(context); Assert.That(context.Variables["result"], Is.EqualTo(20)); } [Test] - public async Task TryCatchFinally_Try_Catch_Finally() + public async Task TryCatchFinally_Try_Catch_Finally_Async() { var block = new TryCatchFinally { @@ -176,7 +176,7 @@ public async Task TryCatchFinally_Try_Catch_Finally() var context = new Context(Site.Object); - await block.Evaluate(context); + await block.EvaluateAsync(context); Assert.That(context.Variables["result"], Is.EqualTo(30)); } diff --git a/Tests/CoreEx/UserInputTests.cs b/Tests/CoreEx/UserInputTests.cs index 15c9028..a3a10a4 100644 --- a/Tests/CoreEx/UserInputTests.cs +++ b/Tests/CoreEx/UserInputTests.cs @@ -13,7 +13,7 @@ private void SetupGetUserInput(Mock site, object value, double? { if (delay == null) { - site.Setup(s => s.GetUserInput("the.key", "string", It.IsAny())).ReturnsAsync((T?)value); + site.Setup(s => s.GetUserInputAsync("the.key", "string", It.IsAny())).ReturnsAsync((T?)value); return; } @@ -25,12 +25,14 @@ private void SetupGetUserInput(Mock site, object value, double? site.SetupGet(s => s.Engine).Returns(engine.Object); - site.Setup(s => s.GetUserInput("the.key", "string", It.IsAny())).Returns(() => task.Task); +#pragma warning disable VSTHRD003 // Avoid awaiting foreign Tasks + site.Setup(s => s.GetUserInputAsync("the.key", "string", It.IsAny())).Returns(() => task.Task); +#pragma warning restore VSTHRD003 // Avoid awaiting foreign Tasks } [TestCase(null)] [TestCase(10.0)] - public async Task UserInput(double? delay) + public async Task UserInput_Async(double? delay) { var block = new RequestUserInput { @@ -44,15 +46,15 @@ public async Task UserInput(double? delay) SetupGetUserInput(Site, 42); - var input = await block.Evaluate(new Context(Site.Object)); + var input = await block.EvaluateAsync(new Context(Site.Object)); Assert.That(input, Is.EqualTo(42)); - Site.Verify(e => e.GetUserInput(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + Site.Verify(e => e.GetUserInputAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } [Test] - public async Task UserInputWithAutoClose() + public async Task UserInputWithAutoClose_Async() { var block = new RequestUserInput { @@ -67,7 +69,7 @@ public async Task UserInputWithAutoClose() SetupGetUserInput(Site, 43, 1.0); - var input = await block.Evaluate(new Context(Site.Object)); + var input = await block.EvaluateAsync(new Context(Site.Object)); Assert.Multiple(() => { @@ -75,7 +77,7 @@ public async Task UserInputWithAutoClose() Assert.That((DateTime.Now - start).TotalMilliseconds, Is.GreaterThanOrEqualTo(750)); }); - Site.Verify(e => e.GetUserInput(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + Site.Verify(e => e.GetUserInputAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } [Test] @@ -95,7 +97,7 @@ public void UserInputWithAutoCloseAndException() SetupGetUserInput(Site, 43, 1.0); - var except = Assert.ThrowsAsync(() => block.Evaluate(new Context(Site.Object))); + var except = Assert.ThrowsAsync(() => block.EvaluateAsync(new Context(Site.Object))); Assert.That(except.Message, Is.EqualTo("busted")); } diff --git a/Tests/Customization/ModelAndEnumTests.cs b/Tests/Customization/ModelAndEnumTests.cs index 4fd8b45..d11f29e 100644 --- a/Tests/Customization/ModelAndEnumTests.cs +++ b/Tests/Customization/ModelAndEnumTests.cs @@ -273,7 +273,7 @@ public void Can_Create_A_Dictionary_Listed_In_An_Array() } [Test] - public async Task Set_Value_In_Dictionary() + public async Task Set_Value_In_Dictionary_Async() { var script = Engine.Parser.Parse(@" @@ -295,7 +295,7 @@ public async Task Set_Value_In_Dictionary() "); - var result = (ListDictClass)(await script.Run(Site.Object))!; + var result = (ListDictClass)(await script.RunAsync(Site.Object))!; Assert.That(result.TheList, Has.Count.EqualTo(1)); diff --git a/Tests/Customization/ModelGeneratorTests.cs b/Tests/Customization/ModelGeneratorTests.cs index 935fd74..88f6c34 100644 --- a/Tests/Customization/ModelGeneratorTests.cs +++ b/Tests/Customization/ModelGeneratorTests.cs @@ -70,7 +70,7 @@ private class ConstantBlock(object? value) : Block { private readonly object? _value = value; - public override Task Evaluate(Context context) => Task.FromResult(_value); + public override Task EvaluateAsync(Context context) => Task.FromResult(_value); } [Test] @@ -132,7 +132,7 @@ public void Can_Use_Arrays() } [Test] - public async Task Can_Create_Blockly_Model_Dynamically() + public async Task Can_Create_Blockly_Model_Dynamically_Async() { var definitions = ModelBlock.Initialize("K-2", "N-3", new ModelCache(), (type, key, name) => false); var blockJson = JsonSerializer.Serialize(definitions.Item1, JsonUtils.JsonSettings); @@ -156,7 +156,7 @@ public async Task Can_Create_Blockly_Model_Dynamically() model.Values.Add(new() { Name = nameof(TestModel.StringProp), Block = new ConstantBlock("testString") }); var siteMock = new Mock(); - var result = await model.Evaluate(new(siteMock.Object)); + var result = await model.EvaluateAsync(new(siteMock.Object)); Assert.That(result, Is.InstanceOf()); diff --git a/Tests/Engine/CancellationTests.cs b/Tests/Engine/CancellationTests.cs index 9abbed9..6c42827 100644 --- a/Tests/Engine/CancellationTests.cs +++ b/Tests/Engine/CancellationTests.cs @@ -67,7 +67,7 @@ public void Can_Cancel_A_Running_Script() var script = Engine.Parser.Parse(EndLessLoop); - Assert.ThrowsAsync(async () => await script.Run(Site.Object)); + Assert.ThrowsAsync(async () => await script.RunAsync(Site.Object)); } /// @@ -76,7 +76,7 @@ public void Can_Cancel_A_Running_Script() /// result calculated so far can still be kept. /// [Test] - public async Task Can_Silently_Cancel_A_Running_Script() + public async Task Can_Silently_Cancel_A_Running_Script_Async() { /* Prepare to cancel after 0.5 seconds. */ var cancel = new CancellationTokenSource(); @@ -84,7 +84,7 @@ public async Task Can_Silently_Cancel_A_Running_Script() cancel.CancelAfter(500); /* Execute the no longer so end-less loop. */ - var result = await ((IScriptSite)Engine).Run( + var result = await ((IScriptSite)Engine).RunAsync( new StartGenericScript { Name = "Will be stopped", ScriptId = AddScript("SCRIPT", EndLessLoop) }, new() { ShouldStopNow = () => cancel.IsCancellationRequested } ); diff --git a/Tests/Engine/ParallelTests.cs b/Tests/Engine/ParallelTests.cs index 90d62be..c5fd36a 100644 --- a/Tests/Engine/ParallelTests.cs +++ b/Tests/Engine/ParallelTests.cs @@ -187,7 +187,7 @@ protected override void OnSetup(IServiceCollection services) /// Run two scripts in parallel to each other. /// [Test] - public async Task Can_Run_In_Parallel() + public async Task Can_Run_In_Parallel_Async() { /* Termination helper. */ var done = new TaskCompletionSource(); diff --git a/Tests/Engine/ProgressTests.cs b/Tests/Engine/ProgressTests.cs index 2bf0db8..8e11418 100644 --- a/Tests/Engine/ProgressTests.cs +++ b/Tests/Engine/ProgressTests.cs @@ -194,7 +194,7 @@ protected override void OnSetup(IServiceCollection services) /// Check if the engine will provide progress information. /// [Test] - public async Task Can_Provide_Progress() + public async Task Can_Provide_Progress_Async() { /* Termination helper. */ var done = new TaskCompletionSource(); diff --git a/Tests/Engine/UserInputTests.cs b/Tests/Engine/UserInputTests.cs index b98b875..93924e2 100644 --- a/Tests/Engine/UserInputTests.cs +++ b/Tests/Engine/UserInputTests.cs @@ -74,7 +74,7 @@ protected override void OnSetup(IServiceCollection services) } [Test] - public async Task Can_Provide_A_User_Input_Model() + public async Task Can_Provide_A_User_Input_Model_Async() { /* Termination helper. */ var done = new TaskCompletionSource(); diff --git a/Tests/TestEnvironment.cs b/Tests/TestEnvironment.cs index cfe68f5..eca05f6 100644 --- a/Tests/TestEnvironment.cs +++ b/Tests/TestEnvironment.cs @@ -47,10 +47,10 @@ private class Definition : IScriptDefinition private readonly Dictionary _definitions = []; /* Find a script definition by its unique identifier. */ - public Task Get(string id) => Task.FromResult(_definitions.TryGetValue(id, out var definition) ? definition : null); + public Task GetAsync(string id) => Task.FromResult(_definitions.TryGetValue(id, out var definition) ? definition : null); /* Query on script definitions. */ - public Task Find(string byName) => Task.FromResult( + public Task FindAsync(string byName) => Task.FromResult( (IScriptDefinitionInfo)_definitions .Values .AsQueryable() @@ -83,7 +83,7 @@ protected class Sink : IScriptEngineNotifySink public Action? OnEvent; /// - public Task Send(ScriptEngineNotifyMethods method, object? arg1) + public Task SendAsync(ScriptEngineNotifyMethods method, object? arg1) { OnEvent?.Invoke(method, arg1); @@ -106,7 +106,7 @@ protected class AnyValueBlock(object? value) : Block /// /// Execution context - will be ignored. /// Our value. - public override Task Evaluate(Context context) => Task.FromResult(_value); + public override Task EvaluateAsync(Context context) => Task.FromResult(_value); } ///