using Google.Protobuf; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; 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.DataStore; using Tango.FSE.Common.Diagnostics; using Tango.Integration.Operation; using Tango.Scripting.Basic; using Tango.Scripting.Editors.Intellisense; namespace Tango.FSE.Procedures { /// /// Represents the main procedures API. /// /// public interface IProcedureContext : IContext { /// /// Occurs when the procedure is reporting about some progress. /// [HideIntellisense] event EventHandler> Progress; /// /// Occurs when a procedure object break point request occurs through the IDE break points. /// [HideIntellisense] event EventHandler BreakPointRequest; /// /// Gets the list of current results. /// [HideIntellisense] ReadOnlyCollection Results { get; } /// /// Adds a new procedure result. /// The value object can be a primitive, a collection of primitives or a collection of complex types. /// /// Result type. /// Result title. /// Result value. /// The result instance. /// /// /// /// The following example demonstrates how to add various procedure results. /// /// /// /// Result AddResult(ResultType type, String name, object value); /// /// Adds a new procedure result that will be displayed as a graph with X/Y axis. /// The specified values will be plotted as Y axis values while the X axis will be auto generated by each value index. /// /// Result type. /// Result title. /// Graph Y axis values. /// The result instance. /// /// /// /// The following example demonstrates how to add various procedure results. /// /// /// /// Result AddGraphResult(ResultType type, String name, IEnumerable values); /// /// Adds a new procedure result with custom appearance by providing a bitmap to draw as the result. /// Use the to create a new bitmap. /// Then, to get the bitmap drawing context in order to start drawing. /// /// Result type. /// Result title. /// Result bitmap. /// The result instance. /// /// /// /// The following example demonstrates how to add various procedure results. /// /// /// /// Result AddBitmapResult(ResultType type, String name, Bitmap bitmap); /// /// Creates a new bitmap to be provided as a bitmap result via . /// /// The bitmap width. /// The bitmap height. /// The bitmap instance. Bitmap CreateBitmap(int width, int height); /// /// Creates a new drawing context for the specified bitmap. /// /// /// Please use when finish drawing. /// /// The bitmap. /// The drawing context. Graphics GetDrawingContext(Bitmap bitmap); /// /// Adds a new procedure result. /// /// The result. /// [HideIntellisense] Result AddResult(Result result); /// /// Removes the specified procedure result. /// /// The result. void RemoveResult(Result result); /// /// Clears all current procedure results. /// void ClearResults(); /// /// Sends a stub request by name, with optional timeout and comma separated arguments. /// /// /// This method accepts only stub messages. /// /// Full or shortened name of the message (e.g "CalculateRequest" or "calculate"). /// Request timeout. /// Request arguments separated by commas. /// The corresponding response message. /// /// /// /// The following example demonstrates how to send a request to the machine and get a response using the various different Send method overrides. /// /// /// /// IMessage Send(String messageName, TimeSpan? timeout = null, params Object[] args); /// /// Sends a request by name with optional comma separated arguments. /// /// /// This method accepts only stub messages. /// /// Full or shortened name of the message (e.g "CalculateRequest" or "calculate"). /// Request arguments separated by commas. /// The corresponding response message. /// /// /// /// The following example demonstrates how to send a request to the machine and get a response using the various different Send method overrides. /// /// /// /// IMessage Send(String messageName, params Object[] args); /// /// Sends a request by name with optional timeout and comma separated arguments. /// /// /// This method accepts only stub messages. /// /// Type of expected response message. /// Full or shortened name of the message (e.g "CalculateRequest" or "calculate"). /// The request timeout. /// Request arguments separated by commas. /// The corresponding response message of type T. /// /// /// /// The following example demonstrates how to send a request to the machine and get a response using the various different Send method overrides. /// /// /// /// T Send(String messageName, TimeSpan? timeout = null, params Object[] args) where T : class, IMessage; /// /// Sends a request by name with optional comma separated arguments. /// /// /// This method accepts only stub messages. /// /// Type of expected response message. /// Full or shortened name of the message (e.g "CalculateRequest" or "calculate"). /// Request arguments separated by commas. /// The corresponding response message of type T. /// /// /// /// The following example demonstrates how to send a request to the machine and get a response using the various different Send method overrides. /// /// /// /// T Send(String messageName, params Object[] args) where T : class, IMessage; /// /// Sends the specified request message. /// /// Request message instance. /// Request timeout in seconds. (leave empty to get the default timeout) /// The corresponding response message. /// /// /// /// The following example demonstrates how to send a request to the machine and get a response using the various different Send method overrides. /// /// /// /// IMessage Send(IMessage message, int? timeout = null); /// /// Sends the specified request message. /// /// Type of expected response message. /// Request message instance. /// Request timeout in seconds. (leave empty to get the default timeout) /// The corresponding response message of type T. /// /// /// /// The following example demonstrates how to send a request to the machine and get a response using the various different Send method overrides. /// /// /// /// T Send(IMessage message, int? timeout = null) where T : class, IMessage; /// /// Sends the specified continuous request message. /// /// Type of expected continuous response message. /// Request message instance. /// Specify a callback method to handle the incoming response messages. /// First and continuous request timeout in seconds. (leave empty to get the default timeout) /// /// /// /// The following example demonstrates how to send a continuous request to the machine and get a continuous response using the various different SendContinuous method overrides. /// /// /// /// void SendContinuous(IMessage message, Action callback, int? timeout) where T : class, IMessage; /// /// Sends a continuous request message with optional timeout and comma separated arguments. /// /// /// This method accepts only stub messages. /// /// Type of expected continuous response message. /// Full or shortened name of the message (e.g "CalculateRequest" or "calculate"). /// Specify a callback method to handle the incoming response messages. /// First and continuous request timeout in seconds. (leave empty to get the default timeout) /// Request arguments separated by commas. /// /// /// /// The following example demonstrates how to send a continuous request to the machine and get a continuous response using the various different SendContinuous method overrides. /// /// /// /// void SendContinuous(String messageName, Action callback, TimeSpan? timeout, params Object[] args) where T : class, IMessage; /// /// Sends a continuous request message with optional timeout and comma separated arguments. /// /// /// This method accepts only stub messages. /// /// Type of expected continuous response message. /// Full or shortened name of the message (e.g "CalculateRequest" or "calculate"). /// Specify a callback method to handle the incoming response messages. /// Request arguments separated by commas. /// /// /// /// The following example demonstrates how to send a continuous request to the machine and get a continuous response using the various different SendContinuous method overrides. /// /// /// /// void SendContinuous(String messageName, Action callback, params Object[] args) where T : class, IMessage; /// /// Writes the specified object string representation to the output window. /// /// The object. void WriteLine(Object obj); /// /// Writes a carriage return to the output window. /// void WriteLine(); /// /// Writes the specified object string representation to the output window. /// /// The object. void Write(Object obj); /// /// Writes the hexadecimal representation of the specified object to the output window. /// /// The number. /// The digits. void WriteLineHex(Object number, int digits); /// /// Writes the hexadecimal representation of the specified object to the output window. /// /// The number. /// The digits. void WriteHex(Object number, int digits); /// /// Writes the specified array to the output window using the specified parsing style. /// /// The array. /// Array parsing style. void WriteLineArray(IEnumerable array, ArrayParsingStyle style); /// /// Reads the specified file as string. /// /// The file path. /// The file text content. String GetFileText(String path); /// /// Read the specified file bytes. /// /// The file path. /// The file byte array. byte[] GetFileBytes(String path); /// /// Clears the output window. /// void Clear(); /// /// Writes a string to the specified file. /// If the file already exists it will be overwritten. /// /// The file path. /// The content. void WriteToFile(String filePath, String content); /// /// Appends the string content to the specified file. /// /// The file path. /// The content. void AppendToFile(String filePath, String content); /// /// Get the value of a user input by key. /// /// Type of expected value. /// The input key. /// The input value. T GetInput(String key); /// /// Gets the value of a user input as an array. /// User input must be a comma separated string. /// /// Type of expected values. /// The input key. /// List containing the input array. List GetInputArray(String key); /// /// Get the value of a user input by key. /// /// The input key. /// The input value. Object GetInput(String key); /// /// Fails the procedure with the specified error message. /// /// The error message. void Fail(String message); /// /// Displays an information message to the user. /// /// The message. void ShowInfo(String message); /// /// Displays a warning message to the user. /// /// The message. void ShowWarning(String message); /// /// Displays an error message to the user. /// /// The message. void ShowError(String message); /// /// Present the user with a question an returns a value indicating the confirmation. /// /// The message. /// bool ShowQuestion(String message); /// /// Presents the user with a warning and returns a value indicating the confirmation. /// /// The message. /// bool ShowWarningQuestion(String message); /// /// Displays an information message to the remote user. /// /// The message. /// Timeout in seconds. void ShowInfoRemote(String message, int timeout); /// /// Displays a warning message to the remote user. /// /// The message. /// Timeout in seconds. void ShowWarningRemote(String message, int timeout); /// /// Displays an error message to the remote user. /// /// The message. /// Timeout in seconds. void ShowErrorRemote(String message, int timeout); /// /// Present the remote user with a question an returns a value indicating the confirmation. /// /// The message. /// Timeout in seconds. /// bool ShowQuestionRemote(String message, int timeout); /// /// Request user input for the specified primitive or complex type (model). /// /// Type of input (primitive or complex) /// The request title. /// The request message. /// Request result of type T. /// /// /// /// The following example demonstrates how to create a model and request the user to fill or modify that model. /// The model can contain primitives, arrays (comma separated), enums and booleans. /// /// /// /// T RequestUserInputFor(String title, String message); /// /// Request a user input for the specified primitive or complex type (model). /// /// Type of input (primitive or complex) /// Existing model (default values). /// The request title. /// The request message. /// Request result of type T. /// /// /// /// The following example demonstrates how to create a model and request the user to fill or modify that model. /// The model can contain primitives, arrays (comma separated), enums and booleans. /// /// /// /// T RequestUserInputFor(T model, String title, String message); /// /// Requests a file selection from the user. /// /// The message. /// Extension filter (default "*.*"). /// The full path to the selected file or null if user canceled. String RequestFileOpen(String message, String extension = "*.*"); /// /// Requests a file save location from the user. /// /// The message. /// Extension filter (default "*.*"). /// Optional default file name. /// The full path to the selected file or null if user canceled. String RequestFileSave(String message, String extension = "*.*", String defaultFileName = null); /// /// Requests a folder path from the user. /// /// The message. /// String RequestFolderSelect(String message); /// /// Updates the procedure user progress. /// /// The progress message. /// Is the progress indeterminate (no need to set value and max). /// The progress value. /// The maximum progress. void UpdateProgress(String message, bool isIndeterminate = true, double value = 0, double maximum = 100); /// /// Gets the current diagnostics package. /// /// Blocks the execution until a fresh diagnostics frame is available. /// This will guarantee that you will get a distinct package each time. /// /// The diagnostics package. /// /// /// /// The following example demonstrates how to collect 100 middle dancer samples and plot them as a graph result. /// /// /// /// /// DiagnosticsPackage GetDiagnosticsPackage(bool waitForNext = false); /// /// Pauses the procedure execution for the specified time in milliseconds. /// /// Milliseconds. void Sleep(int milliseconds); /// /// Runs the specified action asynchronously. /// /// The action. /// The thread instance that has been created for the task. Thread RunAsync(Action action); /// /// Loads the specified procedure dialog on the main UI thread as a standard FSE dialog. /// /// The name of the dialog file. /// The dialog controller. IDialogController LoadDialog(String name); /// /// Loads the specified procedure dialog as a window on the current thread. /// /// The name of the dialog. /// The window title. /// The dialog controller. IDialogWindowController LoadDialogAsWindow(String name, String windowTitle); /// /// Gets the type of the current machine connection. /// It is recommended to use before, to ensure active machine connection. /// /// /// /// /// The following example demonstrates how to check for valid machine connection, check the connection type and get the connected machine's serial number. /// /// /// /// MachineConnectionTypes ConnectionType { get; } /// /// Gets or sets a value indicating whether a machine is currently connected. /// /// /// /// /// The following example demonstrates how to check for valid machine connection, check the connection type and get the connected machine's serial number. /// /// /// /// bool IsConnected { get; } /// /// Gets the currently connected machine entity. /// /// /// /// /// The following example demonstrates how to check for valid machine connection, check the connection type and get the connected machine's serial number. /// /// /// /// Machine ConnectedMachine { get; } /// /// Gets the specified service of type T from the global Tango FSE IOC container.. /// /// Type of service /// The service instance. T GetService(); /// /// Gets the specified resource as byte array. /// /// Name of the resource. /// Resource bytes. byte[] GetResourceBytes(String resourceName); /// /// Gets the specified resource as UTF-8 string. /// /// Name of the resource. /// Resource text. String GetResourceString(String resourceName); /// /// Copies the specified resource to a temporary path and opens it using the default windows application. /// /// Name of the resource. void OpenResource(String resourceName); /// /// Gets the specified procedure variable value. /// /// The name of the variable. /// The variable value. Object GetVariable(String name); /// /// Gets the specified procedure variable value. /// /// Type of expected variable value. /// The name of the variable. /// The variable value of type T. T GetVariable(String name); /// /// Gets the specified procedure variable value as an array. /// Value must be a comma separated string. /// /// The name of the variable. /// List containing the variable values. List GetVariableArray(String name); /// /// Reads the specified csv file to a list of type T. /// The given type T model must contain properties not fields. /// /// CSV model type. /// The file path. /// A list containing all the CSV rows as models of type T. /// /// /// /// The following example demonstrates CSV file writing and reading. /// The csv reading method also accepts a byte array so you can also read a CSV file from a procedure resource. /// /// /// /// List ReadCsv(String file) where T : class, new(); /// /// Reads the specified csv byte array to a list of type T. /// The given type T model must contain properties not fields. /// /// CSV model type. /// The byte array. /// A list containing all the CSV rows as models of type T. /// /// /// /// The following example demonstrates CSV file writing and reading. /// The csv reading method also accepts a byte array so you can also read a CSV file from a procedure resource. /// /// /// /// List ReadCsv(byte[] data) where T : class, new(); /// /// Writes a CSV file to the specified file. /// The given type T model must contain properties not fields. /// /// CSV model type. /// The output file path. /// The items to write. /// /// /// /// The following example demonstrates CSV file writing and reading. /// The csv reading method also accepts a byte array so you can also read a CSV file from a procedure resource. /// /// /// /// void WriteCsv(String file, List items); /// /// Gets the remote data store manager. /// /// IRemoteDataStoreManager GetRemoteDataStoreManager(); /// /// Request a breakpoint operation from the host IDE (internal use only). /// /// The file. /// The line number. /// The symbols map. [HideIntellisense] void BreakPoint(String file, int lineNumber, params Object[] symbolsMap); /// /// Gets or sets the optional exit action for this script. /// [HideIntellisense] Action OnExitAction { get; set; } } }