Scripts Module (Reference) provides automation and business logic capabilities through classes, tasks, expressions, and integrated development tools. It enables:
- Reusable code libraries via Script Classes
- Event-driven automation through Script Tasks
- Lightweight calculations using Script Expressions
- External integration with Script References
- Development productivity with integrated Code Editor
Scripts execute primarily server-side for web compatibility, with optional client-side execution for WPF-only deployments.
Overview
Links to Alarms Module tutorials, concepts, and how-to guides
On this page:
Table of Contents maxLevel 2 minLevel 2 indent 10px exclude
Module Configuration
Configuration UI
→ Solution / Alarms / Items - tags and conditions to generate alarm. Include AlarmGroup for Ack/Log settings and AlarmArea for hierarchy.
→ Solution / Alarms / Groups - Collection of AlarmItems sharing properties such as AckRequired and LogEvents.
→ Solution / Alarms / Areas - Hierarchical grouping of AlarmGroups for better organization.
→ Solution / Alarms / Audit Trail - Logs events on Operation actions, and on selected system events.
Configuration Workflow
Scripts Module configuration workflow
Action
Where
Comments
Manage ScriptClasses
Scripts / Classes
Create or Import you function Library. Learn more at Scripts Classes (Reference).
Manage ScriptTasks
Scripts / Tasks
Create or Import Tasks. Learn more at Scripts Tasks (Reference).
Manage ScriptExpressions
Scripts / Expressions
For simple event or time driven actions, use Expressions. Learn more at Scripts Expressions (Reference).
Manage Script References
Scripts / References.
If you code required their party libraries, include the references. Learn more at Scripts References (Reference).
Steps style none
Module Components
Configuration Sections
Section | Path | Purpose |
---|---|---|
Classes | Scripts → Classes | Reusable methods and functions |
Tasks | Scripts → Tasks | Event-driven automation logic |
Expressions | Scripts → Expressions | Simple calculations and method calls |
References | Scripts → References | External DLL integration |
Code Editor | Scripts → Code Editor | Integrated development environment |
Configuration Workflow
Action | Where | Purpose |
---|---|---|
Create Classes | Scripts → Classes | Build reusable function libraries |
Define Tasks | Scripts → Tasks | Implement automation logic |
Add Expressions | Scripts → Expressions | Configure simple calculations |
Import References | Scripts → References | Add external assemblies |
Edit Code | Scripts → Code Editor | Write and debug scripts |
Runtime Architecture
Execution Context
Default Configuration:
- Server-side: Tasks and expressions run on TServer.exe
- Client-side: Only Display Code Behind executes locally
- Script Classes: Available to both server and client
Web Compatibility:
- Client-side tasks disabled by default for HTML5 support
- Enable in Solution → Settings for WPF-only deployments
Script Namespace
Access script objects at runtime:
csharp
// Access Script Classes
var result = @Script.Class.ClassName.Method();
// Monitor Script Tasks
int count = @Script.Task.TaskName.ExecutionCount;
TimeSpan cpu = @Script.Task.TaskName.LastCPUTime;
Performance Considerations
For complex or large solutions requiring optimization: → See [Script Engine (Reference)] for deep technical details
Key Concepts
Script Classes
- Repository of reusable methods
- Automatic static instantiation
- Cross-language support (C#/VB.NET/Python)
- Three types: Methods, MCP Tools, Full Namespace
→ [Script Classes (Reference)]
Script Tasks
- Event or time-triggered execution
- Independent threading model
- Automatic exception protection
- Built-in startup/shutdown tasks
→ [Script Tasks (Reference)]
Script Expressions
- Single-line VB.NET statements
- Automatic change detection
- Ideal for simple calculations
- Reduces need for one-line tasks
→ [Script Expressions (Reference)]
Script References
- External DLL integration
- Framework compatibility management
- Namespace declaration system
- Path macro support
→ [Script References (Reference)]
Code Editor
- Multi-language support
- IntelliSense with solution objects
- Integrated debugging
- Language conversion
→ [Code Editor (Reference)]
Best Practices
Code Organization
- Use Classes for reusable logic
- Use Tasks for complex automation
- Use Expressions for simple calculations
- Name consistently with descriptive identifiers
Performance
- Server-side by default for web compatibility
- Monitor execution via diagnostic properties
- Build before deployment to ensure compilation
- Profile large solutions using Script Engine diagnostics
Development
- Format code for readability
- Handle exceptions even with automatic protection
- Test incrementally with build verification
- Document purpose in descriptions
Library Management
- Use References for external DLLs
- Manage namespaces via declaration dialog
- Version control external dependencies
- Test compatibility with target framework
Troubleshooting
Build Issues
Build Errors:
- Check BuildStatus property
- Review BuildErrors details
- Verify referenced objects exist
- Ensure correct language syntax
Circular Dependencies:
- Review build order
- Temporarily comment references
- Restructure class dependencies
Execution Problems
Tasks Not Running:
- Verify InitialState enabled
- Check trigger configuration
- Review domain settings
- Monitor execution count
Performance Issues:
- Check LastCPUTime metrics
- Review execution frequency
- Optimize synchronization
- Consider pre-loading strategy
Reference Issues
DLL Not Loading:
- Verify .NET framework compatibility
- Check path macros
- Restart after DLL updates
- Review resolved status
Namespace Conflicts:
- Use declaration dialog
- Check default namespaces
- Verify reference order
Debugging
Breakpoints Not Hit:
- Enable debug information
- Attach debugger to process
- Verify code has compiled
- Check execution path
Variable Inspection:
- Use @ prefix for solution objects
- PropertyWatch for real-time values
- Watch window during breaks
Common Issues
Language Conversion
- C# to VB.NET usually succeeds
- VB.NET to C# may need type casting fixes
- One-time migration recommended
Client-Side Limitations
- Disabled by default for web
- Only WPF clients support
- Server-side preferred approach
Incremental Compilation
- Automatic background process
- Cache invalidation on changes
- Full build before production
Advanced Topics
For deep technical understanding of the execution engine:
- Threading model details
- Synchronization mechanisms
- Pre-loading strategies
- Memory management
→ See [Script Engine (Reference)]
Related Information
- [Namespace API (Reference)] - Complete object model
- [Scripts Monitor (Reference)] - Runtime diagnostics
- [Python.NET Integration] - Cross-language details
- [Build and Publish] - Production deployment
In this section...
Page Tree | ||||
---|---|---|---|---|
|
Runtime Execution
The key concept to be aware of regarding the execution of the tasks and expressions defined in the Script Module is that they execute on the server computer.
Only the CodeBehind of the displays is executed on each client computer. The script classes can be consumed by both server and client stations.
Current solutions are prioritizing user interfaces that are portable, meaning the exact same drawing and display configuration can run as a WPF Windows Rich Client or as a web HTML5 page inside a browser. If you intend to run the graphical interface only on WPF Windows and not on web pages, it is possible to enable this in Solution / Settings to allow tasks and expressions to run on the client side.
For complex solutions or very large solutions, it's useful to get a deeper understanding of the Module execution process. Read more at Script Engine (Reference) if that is your case.
Script Namesace
The Namespace Script is the entry point for all objects related to the Scripts module.
The Script.Class
object lists all configured tables and its runtime properties. The Script.Task
object lists all configured database connections and their runtime properties.
Examples:
Script Task Properties
Property
Type
Description
Script.Task.Task1.ExecutionCount
Integer
Number of times the Script Task <Task1> was executed.
Script.Task.Task1.LastCPUTime
TimeSpan
The Amount of CPU used the last time the Script Task Task1 was executed.
→ Read more about Objects and Namespaces.
Best Practices and Recommendations
- Code Formatting: Use the 'Format' feature of the editor for more readability.
- Naming Convention: Use a coherent and descriptive naming convention for tasks.
- Task Domain: Select the appropriate domain for each task, considering whether the task is more suitable for client-side or server-side execution. Remember, Client-Side Tasks only applicable to RichClients
- Reusable Code: Use reusable code by creating classes that encapsulate functionalities for use in various parts of the project.
- Library Management: Manage libraries and external components effectively to avoid conflicts and compatibility issues.
- Code Consistency: Maintain code consistency by following best practices and coding conventions.
- Build Before Deployment: Always perform a build operation before deploying a project in a production environment to ensure all scripts are correct and up to date.
Troubleshooting and Common Issues
The Scripts module may encounter some issues in its operation. Here are some common issues and their troubleshooting:
- Build Errors and Warnings: Make sure to check the 'BuildStatus' and 'BuildErrors' tabs to identify and address errors and warnings that arise during the build.
- Code Language: If you change the code language in the code editor, confirm that the code has been correctly converted to the selected language.
- Build Order: Ensure that the build order of the classes is set up correctly to avoid circular dependencies or initialization issues.
- Domain Selection: Ensure that the domain is selected correctly (Client or Server) based on the needs of your project.
- Reference Issues: Make sure that all external references are configured correctly and that there are no compatibility issues or conflicts in the Code Editor.
- Code Formatting: Use the 'Format' feature of the editor for more readability.
- Incremental Compilation Issues: Monitor the incremental compilation process to identify and resolve potential issues that may arise.
- Debugger Setup: Ensure that the debugger setup is correct to allow effective code debugging.
- Breakpoints and Watch Variables: Use breakpoints and watch variables effectively to identify and resolve issues.
In this section:
Page Tree | ||||
---|---|---|---|---|
|