forked from ZeraGmbH/Blockly.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptEngine.Progress.cs
More file actions
65 lines (52 loc) · 2.12 KB
/
ScriptEngine.Progress.cs
File metadata and controls
65 lines (52 loc) · 2.12 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
53
54
55
56
57
58
59
60
61
62
63
64
65
using Microsoft.Extensions.Logging;
namespace BlocklyNet.Scripting.Engine;
partial class ScriptEngine<TLogType>
{
/// <summary>
/// Child progress information - nested by depth.
/// </summary>
private readonly List<List<ScriptSite>> _allProgress = [];
/// <summary>
/// Last progress reported.
/// </summary>
private readonly ProgressManager _progress = new();
/// <inheritdoc/>
public void ReportProgress(object info, double? progress, string? name, bool? addEstimation, bool? noVisualisation)
{
_progress.Update(info, progress, name, addEstimation, noVisualisation);
ReportProgress(info, 0);
}
private void ReportProgress(object info, int depth)
{
using (Lock.Wait())
{
if (_active == null) return;
/* Check for nested progress. */
var nextProgress = new ScriptProgress { Info = info, JobId = _active.JobId };
if (depth > 0)
{
/* Outer script must have sent any progress. */
if (_lastProgress == null) return;
/* Use last progress from outer. */
nextProgress.Info = _lastProgress.Info;
}
/* Fill in all nested progress in order. */
if (_progress.Latest != null) nextProgress.AllProgress.Add(_progress.Latest);
foreach (var list in _allProgress)
foreach (var site in list)
if (site.LastProgress != null)
nextProgress.AllProgress.Add(site.LastProgress);
/* Remember for reconnect. */
_lastProgress = nextProgress;
_lastProgress.GroupStatus = SerializeGroupStatus();
_context?
.SendAsync(ScriptEngineNotifyMethods.Progress, _lastProgress)
.ContinueWith(
t => Logger.LogError("Failed to forward progress: {Exception}", t.Exception?.Message),
CancellationToken.None,
TaskContinuationOptions.NotOnRanToCompletion,
TaskScheduler.Current)
.Touch();
}
}
}