General .NET Script Notes
Editing Scripts
Attention: Only assemblies compiled for .NET Core are supported within a Docker container.
The script plug-in allows you to freely define transfer and trigger objects with your own C# code. In this respect, the plug-in configuration differs from the other plug-ins: After assigning 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 will find the basic methods already created, which you can program
- you have tools for OPC access and writing log messages at your disposal
The script plug-in allows you to describe complex issues in transfer objects and triggers, e.g., to perform conversions or trigger complex database queries.
At the top of the menu bar, you will find the "Rename script" button (blank sheet with pen) to change the previous name of your script.
Note: In larger application scenarios, the router will be part of an overall strategy, e.g., with regard to where code that carries business logic is stored. Even for 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 include the IDisposable interface in the script. This allows you to free up memory, e.g. when you open ports or start threads in the script. Open ports or 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 making changes
- You publish a connection after deleting it
- The plug-in is stopped (this always happens when publishing)
Creating scripts
- Open the plug-in by double-clicking on "Scripts" in the "Plug-ins" menu. You will see a list of the transfer object scripts and trigger scripts that have been created on two tabs.
- Select "Add new connection" to create a new script and enter a name and type. When you create a new script, it opens automatically in the script editor. Double-clicking on an existing entry also opens the script in the script editor.
- Program your script (see below). Remember to compile and save it.
Transfer objects and triggers are then available for connection project planning.