-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSetProgress.cs
More file actions
125 lines (121 loc) · 3.74 KB
/
Copy pathSetProgress.cs
File metadata and controls
125 lines (121 loc) · 3.74 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using BlocklyNet.Core.Model;
using BlocklyNet.Extensions.Builder;
using BlocklyNet.Scripting.Generic;
namespace BlocklyNet.Extensions;
/// <summary>
/// Set a progress for the current script execution.
/// </summary>
[CustomBlock(
"set_progress",
"",
@"{
""message0"": ""SetProgress %1 Name of the progress %2 Progress (%%) %3 Extra data %4 Type of extra data %5 Add Time Estimation %6 Do not visualize %7"",
""args0"": [
{
""type"": ""input_dummy""
},
{
""type"": ""input_value"",
""name"": ""NAME"",
""check"": ""String""
},
{
""type"": ""input_value"",
""name"": ""PROGRESS"",
""check"": ""Number""
},
{
""type"": ""input_value"",
""name"": ""PAYLOAD""
},
{
""type"": ""input_value"",
""name"": ""PAYLOADTYPE"",
""check"": ""String""
},
{
""type"": ""input_value"",
""name"": ""ADDESTIMATION"",
""check"": ""Boolean""
},
{
""type"": ""input_value"",
""name"": ""NOVISUALIZATION"",
""check"": ""Boolean""
}
],
""previousStatement"": null,
""nextStatement"": null,
""colour"": ""#107159"",
""tooltip"": ""Set script execution progress in percentage"",
""helpUrl"": """"
}",
@"{
""inputs"": {
""NAME"": {
""shadow"": {
""type"": ""text"",
""fields"": {
""TEXT"": """"
}
}
},
""PROGRESS"": {
""shadow"": {
""type"": ""math_number"",
""fields"": {
""NUM"": ""0""
}
}
},
""PAYLOADTYPE"": {
""shadow"": {
""type"": ""text"",
""fields"": {
""TEXT"": """"
}
}
},
""ADDESTIMATION"": {
""shadow"": {
""type"": ""logic_boolean"",
""fields"": {
""BOOL"": ""FALSE""
}
}
},
""NOVISUALIZATION"": {
""shadow"": {
""type"": ""logic_boolean"",
""fields"": {
""BOOL"": ""FALSE""
}
}
}
}
}"
)]
public class SetProgress : Block
{
/// <inheritdoc/>
protected override async Task<object?> EvaluateAsync(Context context)
{
var script = context.Engine.MainScript as IGenericScript;
var progress = await Values.EvaluateDoubleAsync("PROGRESS", context);
var name = await Values.EvaluateAsync<string?>("NAME", context, false);
context.Engine.ReportProgress(
new GenericProgress
{
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?>("NOVISUALIZATION", context, false) == true
);
return await base.EvaluateAsync(context);
}
}