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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
using Google.Protobuf;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.Core;
using Tango.FSE.Common.Connection;
using Tango.FSE.Common.Diagnostics;
using Tango.Integration.Operation;
using Tango.Scripting.Basic;
namespace Tango.FSE.Procedures
{
public interface IProcedureContext : IContext
{
/// <summary>
/// Occurs when the procedure is reporting about some progress.
/// </summary>
event EventHandler<TangoProgressChangedEventArgs<double>> Progress;
/// <summary>
/// Gets the list of current results.
/// </summary>
ReadOnlyCollection<Result> Results { get; }
/// <summary>
/// Adds a new procedure result.
/// </summary>
/// <param name="type">The result type.</param>
/// <param name="name">The result name.</param>
/// <param name="value">The result value.</param>
/// <returns></returns>
Result AddResult(ResultType type, String name, object value);
/// <summary>
/// Adds a new procedure graph result.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="name">The name.</param>
/// <param name="values">The values.</param>
/// <returns></returns>
Result AddGraphResult(ResultType type, String name, IEnumerable<double> values);
/// <summary>
/// Adds a new procedure bitmap result.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="name">The name.</param>
/// <param name="bitmap">The bitmap.</param>
/// <returns></returns>
Result AddBitmapResult(ResultType type, String name, Bitmap bitmap);
/// <summary>
/// Creates a new bitmap.
/// </summary>
/// <param name="width">The bitmap width.</param>
/// <param name="height">The bitmap height.</param>
/// <returns></returns>
Bitmap CreateBitmap(int width, int height);
/// <summary>
/// Creates a new drawing context for the specified bitmap.
/// </summary>
/// <param name="bitmap">The bitmap.</param>
/// <returns></returns>
Graphics GetDrawingContext(Bitmap bitmap);
/// <summary>
/// Adds a new procedure result.
/// </summary>
/// <param name="result">The result.</param>
/// <returns></returns>
Result AddResult(Result result);
/// <summary>
/// Removes the specified procedure result.
/// </summary>
/// <param name="result">The result.</param>
void RemoveResult(Result result);
/// <summary>
/// Clears all current procedure results.
/// </summary>
void ClearResults();
/// <summary>
/// Sends a request by name with optional comma separated arguments.
/// </summary>
/// <param name="messageName">Name of the message.</param>
/// <param name="timeout">The timeout in seconds.</param>
/// <param name="args">The arguments separated by commas.</param>
/// <returns></returns>
IMessage Send(String messageName, TimeSpan? timeout = null, params Object[] args);
/// <summary>
/// Sends a request by name with optional comma separated arguments.
/// </summary>
/// <param name="messageName">Name of the message.</param>
/// <param name="args">The arguments separated by commas.</param>
/// <returns></returns>
IMessage Send(String messageName, params Object[] args);
/// <summary>
/// Sends a request by name with optional comma separated arguments.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="messageName">Name of the message.</param>
/// <param name="timeout">The timeout in seconds.</param>
/// <param name="args">The arguments separated by commas.</param>
/// <returns></returns>
T Send<T>(String messageName, TimeSpan? timeout = null, params Object[] args) where T : class, IMessage;
/// <summary>
/// Sends a request by name with optional comma separated arguments.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="messageName">Name of the message.</param>
/// <param name="args">The arguments separated by commas.</param>
/// <returns></returns>
T Send<T>(String messageName, params Object[] args) where T : class, IMessage;
/// <summary>
/// Sends the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="timeout">The timeout in seconds.</param>
/// <returns></returns>
IMessage Send(IMessage message, int? timeout = null);
/// <summary>
/// Sends the specified message.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="message">The message.</param>
/// <param name="timeout">The timeout in seconds.</param>
/// <returns></returns>
T Send<T>(IMessage message, int? timeout = null) where T : class, IMessage;
/// <summary>
/// Sends the specified continuous message.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="message">The message.</param>
/// <param name="callback">Callback for continuous responses.</param>
/// <param name="timeout">The timeout in seconds.</param>
void SendContinuous<T>(IMessage message, Action<T> callback, int? timeout) where T : class, IMessage;
/// <summary>
/// Sends a continuous message with optional comma separated arguments.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="messageName">Name of the message.</param>
/// <param name="callback">Callback for continuous responses.</param>
/// <param name="timeout">The timeout in seconds.</param>
/// <param name="args">The arguments.</param>
void SendContinuous<T>(String messageName, Action<T> callback, int? timeout, params Object[] args) where T : class, IMessage;
/// <summary>
/// Sends a continuous message with optional comma separated arguments.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="messageName">Name of the message.</param>
/// <param name="callback">Callback for continuous responses.</param>
/// <param name="args">The arguments.</param>
void SendContinuous<T>(String messageName, Action<T> callback, params Object[] args) where T : class, IMessage;
/// <summary>
/// Writes the specified object string representation to the output window.
/// </summary>
/// <param name="obj">The object.</param>
void WriteLine(Object obj);
/// <summary>
/// Writes the specified object string representation to the output window.
/// </summary>
/// <param name="obj">The object.</param>
void Write(Object obj);
/// <summary>
/// Writes the hexadecimal representation of the specified object to the output window.
/// </summary>
/// <param name="number">The number.</param>
/// <param name="digits">The digits.</param>
void WriteLineHex(Object number, int digits);
/// <summary>
/// Writes the hexadecimal representation of the specified object to the output window.
/// </summary>
/// <param name="number">The number.</param>
/// <param name="digits">The digits.</param>
void WriteHex(Object number, int digits);
/// <summary>
/// Writes the specified array to the output window using the specified parsing style.
/// </summary>
/// <param name="array">The array.</param>
/// <param name="style">The style.</param>
void WriteLineArray(IEnumerable array, ArrayParsingStyle style);
/// <summary>
/// Reads the specified file as string.
/// </summary>
/// <param name="path">The file path.</param>
/// <returns></returns>
String GetFileText(String path);
/// <summary>
/// Read the specified file bytes
/// </summary>
/// <param name="path">The file path.</param>
/// <returns></returns>
byte[] GetFileBytes(String path);
/// <summary>
/// Clears the output window.
/// </summary>
void Clear();
/// <summary>
/// Writes a string content to the specified file.
/// If the file already exists it will be overwritten.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <param name="content">The content.</param>
void WriteToFile(String filePath, String content);
/// <summary>
/// Appends the string content to the specified file.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <param name="content">The content.</param>
void AppendToFile(String filePath, String content);
/// <summary>
/// Get the value of a user input by key.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key">The input key.</param>
/// <returns></returns>
T GetInput<T>(String key);
/// <summary>
/// Gets the value of a user input as an array.
/// User input must be a comma separated string.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key">The input key.</param>
/// <returns></returns>
List<T> GetInputArray<T>(String key);
/// <summary>
/// Get the value of a user input by key.
/// </summary>
/// <param name="key">The input key.</param>
/// <returns></returns>
Object GetInput(String key);
/// <summary>
/// Fails the current procedure with the specified error message.
/// </summary>
/// <param name="message">The error message.</param>
void Fail(String message);
/// <summary>
/// Displays an information message to the user.
/// </summary>
/// <param name="message">The message.</param>
void ShowInfo(String message);
/// <summary>
/// Displays a warning message to the user.
/// </summary>
/// <param name="message">The message.</param>
void ShowWarning(String message);
/// <summary>
/// Displays an error message to the user.
/// </summary>
/// <param name="message">The message.</param>
void ShowError(String message);
/// <summary>
/// Present the user with a question an returns a value indicating the confirmation.
/// </summary>
/// <param name="message">The message.</param>
/// <returns></returns>
bool ShowQuestion(String message);
/// <summary>
/// Presents the user with a warning and returns a value indicating the confirmation.
/// </summary>
/// <param name="message">The message.</param>
/// <returns></returns>
bool ShowWarningQuestion(String message);
/// <summary>
/// Request a user input for the specified primitive or complex type.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="title">The request title.</param>
/// <param name="message">The request message.</param>
/// <returns></returns>
T RequestUserInputFor<T>(String title, String message);
/// <summary>
/// Request a user input for the specified primitive or complex type (model).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="model">The existing model.</param>
/// <param name="title">The request title.</param>
/// <param name="message">The request message.</param>
/// <returns></returns>
T RequestUserInputFor<T>(T model, String title, String message);
/// <summary>
/// Requests a file selection from the user.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="extension">Extension filter (default "*.*").</param>
/// <returns></returns>
String RequestFileOpen(String message, String extension = "*.*");
/// <summary>
/// Requests a file save location from the user.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="extension">Extension filter (default "*.*").</param>
/// <param name="defaultFileName">Optional default file name.</param>
/// <returns></returns>
String RequestFileSave(String message, String extension = "*.*", String defaultFileName = null);
/// <summary>
/// Updates the procedure progress.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="isIndeterminate">Is the progress indeterminate (not need to set value and max).</param>
/// <param name="value">The progress value.</param>
/// <param name="maximum">The maximum progress .</param>
void UpdateProgress(String message, bool isIndeterminate = true, double value = 0, double maximum = 100);
/// <summary>
/// Gets the latest diagnostics package.
/// </summary>
/// <param name="waitForNext">Waits for a fresh package.</param>
/// <returns></returns>
DiagnosticsPackage GetDiagnosticsPackage(bool waitForNext = false);
/// <summary>
/// Pauses the script execution for the specified time in milliseconds.
/// </summary>
/// <param name="milliseconds">The milliseconds.</param>
void Sleep(int milliseconds);
/// <summary>
/// Runs the specified action asynchronously.
/// </summary>
/// <param name="action">The action.</param>
/// <returns></returns>
Thread RunAsync(Action action);
/// <summary>
/// Loads the specified procedure dialog on the main UI thread.
/// </summary>
/// <param name="name">The name of the dialog file.</param>
/// <returns></returns>
IDialogController LoadDialog(String name);
/// <summary>
/// Loads the specified procedure dialog as a window on the current thread.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="windowTitle">The window title</param>
/// <returns></returns>
IDialogController LoadDialogAsWindow(String name, String windowTitle);
/// <summary>
/// Gets the type of the current machine connection.
/// </summary>
MachineConnectionTypes ConnectionType { get; }
/// <summary>
/// Gets or sets a value indicating whether a machine is currently connected.
/// </summary>
bool IsConnected { get; }
/// <summary>
/// Gets the currently connected machine entity.
/// </summary>
Machine ConnectedMachine { get; }
/// <summary>
/// Gets a registered injected service from the Tango FSE application.
/// </summary>
/// <typeparam name="T">Type of service</typeparam>
/// <returns></returns>
T GetService<T>();
/// <summary>
/// Gets the specified resource as byte array.
/// </summary>
/// <param name="resourceName">Name of the resource.</param>
/// <returns></returns>
byte[] GetResourceBytes(String resourceName);
/// <summary>
/// Gets the specified resource as UTF-8 string.
/// </summary>
/// <param name="resourceName">Name of the resource.</param>
/// <returns></returns>
String GetResourceString(String resourceName);
/// <summary>
/// Copies the specified resource to a temporary path and opens it using the default application.
/// </summary>
/// <param name="resourceName">Name of the resource.</param>
void OpenResource(String resourceName);
/// <summary>
/// Gets the specified procedure variable.
/// </summary>
/// <param name="name">The name of the variable.</param>
/// <returns></returns>
Object GetVariable(String name);
/// <summary>
/// Gets the specified procedure variable.
/// </summary>
/// <param name="name">The name of the variable.</param>
/// <returns></returns>
T GetVariable<T>(String name);
/// <summary>
/// Gets the specified procedure variable value as an array.
/// User value must be a comma separated string.
/// </summary>
/// <param name="name">The name of the variable.</param>
/// <returns></returns>
List<T> GetVariableArray<T>(String name);
/// <summary>
/// Reads the specified csv file to a list of type T.
/// The given type T model must contain properties not fields.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="file">The file path.</param>
/// <returns></returns>
List<T> ReadCsv<T>(String file) where T : class, new();
/// <summary>
/// Reads the specified csv byte array to a list of type T.
/// The given type T model must contain properties not fields.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data">The data.</param>
/// <returns></returns>
List<T> ReadCsv<T>(byte[] data) where T : class, new();
/// <summary>
/// Writes a CSV file to the specified file.
/// The given type T model must contain properties not fields.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="file">The file path.</param>
/// <param name="items">The items to write.</param>
void WriteCsv<T>(String file, List<T> items);
}
}
|