Release Resources (IDisposable)
Editing Scripts
Within a Docker container, only assemblies compiled for .NET Core are supported.
The Script plug-in allows you to freely define transfer and trigger objects using your own C# code. As such, the plug-in configuration differs from that of other plug-ins: After specifying the name and type, open a code editor to edit the script.
In the code editor
- you create assembly references
- you define input and output parameters
- you’ll find the basic methods already created, which you can implement
- tools for OPC access and writing log messages are available to you
The Script plug-in allows you to describe complex scenarios using transfer objects and triggers, such as performing conversions or triggering complex database queries.
At the top of the menu bar, you’ll find the “Rename script” button (blank sheet with a pencil) to change the current name of your script.
In larger application scenarios, the router will be part of an overall strategy, such as where code containing business logic is stored. Even in smaller projects, it makes sense to consider whether, for example, conversions should be performed in the router or via stored procedures in the database.
IDisposable
We recommend that you implement the IDisposable interface in the script. This allows you to free up memory, for example, when you open ports or start threads in the script. Open ports and running threads are thus closed or terminated at the end of the script. Write the necessary code for this in the corresponding method.
public void Dispose()
{
// Your code
}
The Dispose method is called when:
- You publish the script after making changes
- You publish the script without changes
- You publish a flow after deleting it
- The plug-in is stopped (this always happens upon publication)
Creating Scripts
- Open the plug-in by double-clicking on “Scripts” under the “Plug-ins” menu. You’ll see a list of existing transfer object scripts and trigger scripts displayed on two tabs: “ ” and “2. .” Select “Add New Connection” to create a new script, and specify the name and type. When you create a new script, the script opens automatically in the script editor. You can also open the script in the script editor by double-clicking an existing entry.
- Write your script (see below). Remember to compile and save it.
Transfer objects and triggers are then available for use in flow configuration.