Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Library/Extensions/SetProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,19 @@ public class SetProgress : Block
var script = context.Engine.MainScript as IGenericScript;
var progress = await Values.EvaluateAsync<double>("PROGRESS", context);
var name = await Values.EvaluateAsync<string?>("NAME", context, false);
var invisible = await Values.EvaluateAsync<bool?>("NOVISUALIZATION", context, false);

context.Engine.ReportProgress(
new GenericProgress
{
NoVisualisation = invisible,
Payload = await Values.EvaluateAsync("PAYLOAD", context, false),
PayloadType = await Values.EvaluateAsync<string>("PAYLOADTYPE", context, false),
Percentage = progress,
ScriptId = script?.Request.ScriptId,
},
progress / 100d,
name,
await Values.EvaluateAsync<bool?>("ADDESTIMATION", context, false) == true
await Values.EvaluateAsync<bool?>("ADDESTIMATION", context, false) == true,
await Values.EvaluateAsync<bool?>("NOVISUALIZATION", context, false) == true
);

return await base.EvaluateAsync(context);
Expand Down
3 changes: 2 additions & 1 deletion Library/Scripting/Engine/IScriptSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public interface IScriptSite
/// <param name="progress">Progress as a number between 0 and 1.</param>
/// <param name="name">Optional display name of the progress.</param>
/// <param name="addEstimation">If set add time to end estimtation if possible.</param>
void ReportProgress(object info, double? progress, string? name, bool? addEstimation);
/// <param name="noVisualisation">If set frontend should not display this progress.</param>
void ReportProgress(object info, double? progress, string? name, bool? addEstimation, bool? noVisualisation);

/// <summary>
/// Execute Blockly XML Script and report variables.
Expand Down
5 changes: 5 additions & 0 deletions Library/Scripting/Engine/ProgressDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public class ProgressDetails
/// get to a progress of 1 - in seconds.
/// </summary>
public double? EstimatedRemainingSeconds { get; set; }

/// <summary>
/// Set to hide this progress from the frontend.
/// </summary>
public bool? NoVisualisation { get; set; }
}
5 changes: 3 additions & 2 deletions Library/Scripting/Engine/ProgressManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public void Reset()
/// <param name="progress">Progress value between 0 and 1.</param>
/// <param name="name">Optional name of the progress.</param>
/// <param name="addEstimation">Set to add time to finish estimation - if possible.</param>
public void Update(object info, double? progress, string? name, bool? addEstimation)
/// <param name="noVisualisation">Set to hide progress from beeing shown.</param>
public void Update(object info, double? progress, string? name, bool? addEstimation, bool? noVisualisation)
{
// This is the very first.
if (Latest == null) _startProgress = null;

// Update as requested.
Latest = new() { Progress = progress ?? 0, Name = name, Info = info };
Latest = new() { Progress = progress ?? 0, Name = name, Info = info, NoVisualisation = noVisualisation };

// Can not estimate at all.
if (Latest.Progress < 0 || Latest.Progress > 1) return;
Expand Down
4 changes: 2 additions & 2 deletions Library/Scripting/Engine/ScriptEngine.Nested.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public Task<TResult> RunAsync<TResult>(StartScript request, StartScriptOptions?
=> _engine.GetUserInputAsync<T>(key, type, delay, required);

/// <inheritdoc/>
public void ReportProgress(object info, double? progress, string? name, bool? addEstimation)
public void ReportProgress(object info, double? progress, string? name, bool? addEstimation, bool? noVisualisation)
{
/* Remember and propagate. */
_progress.Update(info, progress, name, addEstimation);
_progress.Update(info, progress, name, addEstimation, noVisualisation);

_engine.ReportProgress(info, _depth);
}
Expand Down
4 changes: 2 additions & 2 deletions Library/Scripting/Engine/ScriptEngine.Progress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ partial class ScriptEngine<TLogType>
private readonly ProgressManager _progress = new();

/// <inheritdoc/>
public void ReportProgress(object info, double? progress, string? name, bool? addEstimation)
public void ReportProgress(object info, double? progress, string? name, bool? addEstimation, bool? noVisualisation)
{
_progress.Update(info, progress, name, addEstimation);
_progress.Update(info, progress, name, addEstimation, noVisualisation);

ReportProgress(info, 0);
}
Expand Down
5 changes: 0 additions & 5 deletions Library/Scripting/Generic/GenericProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@ public class GenericProgress
/// </summary>
[Required, NotNull]
public string? ScriptId { get; set; }

/// <summary>
/// Set to hide this progress from the frontend.
/// </summary>
public bool? NoVisualisation { get; set; }
}
4 changes: 2 additions & 2 deletions Tests/CoreEx/ProgressManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Calculate_Progress_Time_To_End(double initial, double next, double?

Assert.That(progress.Latest, Is.Null);

progress.Update(false, initial, null, true);
progress.Update(false, initial, null, true, null);

Assert.That(progress.Latest, Is.Not.Null);

Expand All @@ -29,7 +29,7 @@ public void Calculate_Progress_Time_To_End(double initial, double next, double?

now = now.AddSeconds(3);

progress.Update(false, next, null, true);
progress.Update(false, next, null, true, null);

Assert.That(progress.Latest, Is.Not.Null);

Expand Down
4 changes: 2 additions & 2 deletions Tests/CoreEx/SetProgressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public async Task SetProgress_Async()
GenericProgress? progress = null;

Site
.Setup(e => e.ReportProgress(It.IsAny<object>(), 0.299d, "ZERA", true))
.Callback((object? p, double? rel, string? name, bool? add) => progress = (GenericProgress)p!);
.Setup(e => e.ReportProgress(It.IsAny<object>(), 0.299d, "ZERA", true, false))
.Callback((object? p, double? rel, string? name, bool? add, bool? invisible) => progress = (GenericProgress)p!);

await block.EnterBlockAsync(new Context(Site.Object));

Expand Down