forked from ZeraGmbH/Blockly.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptEngine.Logging.cs
More file actions
52 lines (43 loc) · 1.84 KB
/
ScriptEngine.Logging.cs
File metadata and controls
52 lines (43 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Microsoft.Extensions.Logging;
namespace BlocklyNet.Scripting.Engine;
partial class ScriptEngine<TLogType>
{
/// <inheritdoc/>
public Task UpdateLogAsync() => CurrentScript == null ? Task.CompletedTask : UpdateResultLogEntryAsync(CurrentScript, null, false);
/// <summary>
/// Update the log entry for a script.
/// </summary>
/// <param name="script">Script to update.</param>
/// <param name="parent">Optional the parent script - null for the root.</param>
/// <param name="final">Set if the script is now finished - unset for updates during the execution.</param>
private async Task UpdateResultLogEntryAsync(IScript<TLogType> script, IScript<TLogType>? parent, bool final)
{
using (Lock.Wait())
try
{
/* For the outer script always add the current status of the exeuction groups. */
if (parent == null) script.SetGroups(SerializeGroupStatus(true));
/* Mark as finished. */
if (final) script.ResultForLogging.Finished = DateTime.UtcNow;
var id = await script.WriteToLogAsync();
/* Register in parent script. */
if (parent == null || parent.ResultForLogging.Children.Contains(id)) return;
/* Forward update to parent. */
await parent.RegisterChildAsync(id);
}
catch (Exception e)
{
Logger.LogError("Unable to create log entry: {Exception}", e.Message);
return;
}
try
{
/* Must forward to parent if child list has been updated - make sure we left the lock. */
await UpdateLogAsync();
}
catch (Exception e)
{
Logger.LogError("Unable to create log entry: {Exception}", e.Message);
}
}
}