Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

The Scripts Module allows the automation of various tasks through scripting. You can configure these tasks to run Scripts Tasks (Reference) are automated program units that execute in response to specific events or on a scheduled basisintervals, enhancing the application's efficiency and functionality. ScriptTasks can also call ScriptClasses or use external DLLs.On providing the core automation logic for your FrameworX solution. ScriptTask is a self-contained code blocks that:

  • Execute when triggered by events or time intervals
  • Run in their own threads for optimal performance
  • Access all solution objects and namespaces
  • Support VB.NET, C#, and Python languages

Unlike Script Classes, Tasks don't require method declarations - you write directly the code to be executed, similar to the contents of a method body.

In this page:

Table of Contents
maxLevel

3

2
minLevel2
indent10px
excludeSteps
stylenone


Creating Script Tasks

  1. Navigate to Scripts → Tasks
  2. Click the plus icon
  3. Configure:
    • Name: Task identifier
    • Description: Purpose of the task
    • Language: VB.NET, C#, or Python
    • Code Source: New or Import from Library
  4. Click OK
  5. Double-click the row to open Code Editor

Configuration Properties

PropertyDescription
NameTask identifier used in runtime references
CodeProgramming language (VB.NET, C#, Python)
DomainExecution location: Server (default) or Client
TriggerEvent that initiates task execution
PeriodTime interval for periodic execution
InitialStateEnabled (ready to run) or Disabled
BuildStatus? Green = Success, ? Red = Errors
BuildErrorsCompilation error count
EditSecurityPermission level required to modify

Additional Properties

PropertyDescription
IDUnique task identifier
VersionIDModification version counter
LinesCode line count
BuildMessageCompilation messages
CategoryTask grouping category
LockStateEdit lock status
DateCreatedCreation timestamp
DateModifiedLast modification timestamp

Code Structure

<ac:structured-macro ac:name="warning"> ac:rich-text-body Important: Script Tasks contain only the method body code - no function declarations or wrappers. The platform automatically handles method creation, exception protection, and thread management. </ac:rich-text-body> </ac:structured-macro>

Correct Task Format

csharp

// Direct code - NO method declaration
double temperature = @Tag.Temperature;
if (temperature > 100)
{
    @Tag.AlarmActive = true;
    @Alarm.Notify("High Temperature");
}

Incorrect Format

csharp

// ? WRONG - Do not include method wrapper
public void ProcessTemperature()
{
    // Code here
}

Built-in Tasks

All solutions include predefined tasks:

Server Startup

  • Executes: When TServer.exe starts
  • Purpose: Initialize server-side components
  • Runs before: All other server tasks
  • Use for: Global initialization, connection setup

Server Shutdown

  • Executes: When solution stops
  • Purpose: Cleanup and finalization
  • Use for: Closing connections, saving state

Client Startup

  • Executes: When each client connects
  • Runs on: TRichClient.exe, TSmartClient.exe, or Web browser
  • Purpose: Initialize client-specific settings
  • Use for: UI setup, local preferences

Client Shutdown

  • Executes: When client closes
  • Purpose: Client cleanup
  • Use for: Saving user preferences, cleanup

Task Triggers

Event-Based Triggers

Tasks execute when specific events occur:

  • Tag Change: When tag value changes
  • Alarm State: When alarm activates/deactivates
  • Display Events: User interactions
  • Custom Events: Application-specific triggers

Time-Based Execution

Configure periodic execution:

  • Period: Interval in milliseconds
  • Options:
    • Fixed interval (e.g., every 1000ms)
    • Scheduled times (using expressions)
    • Calendar-based triggers

Execution Model

Threading

  • Each task runs in its own thread
  • Multiple tasks can execute simultaneously
  • No blocking between tasks
  • Automatic thread pool management

Exception Handling

  • Platform provides automatic exception protection
  • Errors logged but don't crash the application
  • Task continues next execution cycle
  • Access error details via BuildErrors

Domain Execution

<ac:structured-macro ac:name="info"> ac:rich-text-body Default Configuration: Client-side tasks are disabled by default in Solution Settings because web clients don't support them yet. Most solutions use only server-side tasks. </ac:rich-text-body> </ac:structured-macro>

Server Domain (Default):

  • Executes on server computer (TServer.exe)
  • Global scope across all clients
  • Access to all server resources
  • Typical use: Business logic, calculations, data processing

Client Domain (When Enabled):

  • Executes on each client independently
  • Local scope per client
  • Access to display context
  • Only for WPF clients (not web)

Runtime Namespace

Access task runtime information via @Script.Task namespace:

csharp

// Access task properties
int count = @Script.Task.MyTask.ExecutionCount;
TimeSpan cpu = @Script.Task.MyTask.LastCPUTime;
bool enabled = @Script.Task.MyTask.Enabled;

// Control task execution
@Script.Task.MyTask.Run();  // Force execution
@Script.Task.MyTask.Enabled = false;  // Disable task

Task Runtime Properties

PropertyTypeDescription
ExecutionCountIntegerNumber of executions
LastCPUTimeTimeSpanCPU time of last execution
EnabledBooleanTask enable state
IsRunningBooleanCurrently executing
LastErrorStringLast execution error

Using External Resources

Calling Script Classes

csharp

// Direct access to Script Classes
var result = @Script.Class.Calculations.Process(100);

Using External DLLs

  1. Add reference in Scripts → References
  2. Add namespace via Namespace Declarations button
  3. Use in task code

Accessing Solution Objects

csharp

// All namespaces available
@Tag.Temperature = 25;
@Alarm.Reset("Area1");
var data = @Dataset.Query("SELECT * FROM Production");
@Display.MainScreen.Open();

Best Practices

  1. Keep tasks focused - Single responsibility per task
  2. Handle exceptions - Even with automatic protection, validate inputs
  3. Use appropriate triggers - Event-based for reactive, time-based for polling
  4. Monitor performance - Check ExecutionCount and LastCPUTime
  5. Document purpose - Use Description field
  6. Test thoroughly - Verify BuildStatus before deployment
  7. Consider threading - Tasks run independently, avoid shared state issues

Language-Specific Features

VB.NET

vbnet

' Use Exit Function to stop execution
If temperature > 100 Then
    Exit Function
End If

C#

csharp

// Use return to stop execution
if (temperature > 100)
{
    return;
}

Python

python

# Standard Python syntax
if temperature > 100:
    return

Troubleshooting

Task not executing:

  • Check InitialState is Enabled
  • Verify trigger configuration
  • Review BuildStatus for errors
  • Check Domain setting matches deployment

Performance issues:

  • Monitor LastCPUTime for slow tasks
  • Check ExecutionCount for excessive runs
  • Consider longer Period for time-based tasks
  • Review threading conflicts

Compilation errors:

  • Double-click BuildStatus red X
  • Check namespace declarations
  • Verify referenced objects exist
  • Ensure no method wrappers included

In this section...

Page Tree
root@parent
spaces93DRAF

Configuring ScriptTasks

ScriptTasks are program units written in VB.NET, C#, or Python that execute when a trigger event occurs or periodically at specified intervals. To create and configure a ScriptTask, follow the steps below:

  1. Access Scripts → Tasks.
  2. Click on the plus icon.
  3. Input a task name and description, and select the desired language.
  4. Choose to either create a new code or import one from an existing library.
  5. Click Ok.

Now, you can double-click the newly created row to access the Code Editor, where you can insert the code for the ScriptTask.

Info

To edit a property of an existing ScriptTask, click the desired property to select it and click it again after a second to edit it. See a list of available properties in the next section.

The image below illustrates the process described above.

Built-in ScriptTasks

All solutions include the following built-in ScriptTasks:

  • Server Startup: Executed when the solution starts running. Runs on the server (computer running TServer.exe).
  • Server Shutdown: Executed when the solution shuts down. Runs on the server.
  • Client Startup: Executed on each client when the Displays module is activate on Windows (TRichClient.exe/TSmartClient.exe) or  on  a WebClient (HTML5).
  • Client Shutdown: Executed on each client when the Client closes.
Note

"Exit Function" can be used in VB.NET script tasks to stop the code of the currently running task.

ScriptTasks Configuration Tables

The following is a table describing each available property field for ScriptTasks Configuration Table.

Info

If a property column is not visible on the grid, enable it by right-clicking the grid header and selecting it from the list.

Property

Description

ID

Identifies the unique identifier of the ScriptTask object.

VersionID

Represents the modification version of the ScriptTask, which increments with each modification related to this object.

Name

Specifies the name assigned to the ScriptTask.

Code

Defines the programming language used for the ScriptTask.

Domain

Specifies where the script executes, either on the Client system locally or on the Server globally.

Trigger

Identifies the event that triggers the ScriptTask.

Period

Sets the interval for periodic execution of the task.

InitialState

Indicates if the task is initially Enabled (ready to run) or Disabled (not ready to run).

Lines

Displays the code lines for the ScriptTask.

EditSecurity

Controls the permissions for editing the ScriptTask.

BuildStatus

The task code's status results from the continuous compiling process.

Green check mark: The task runs without errors.

Red X:Thetask has warnings or errors, double-click to access the warning or error.

Warnings are information only.

Errors will prevent the code from running for that specific task. The rest of the solution will run.

BuildErrors

Lists the number of errors encountered during the build process.

BuildMessage

Provides messages related to the build process.

Category

Groups the ScriptTask into a specific category.

LockState

Indicates if the ScriptTask is locked for editing.

LockOwner

Displays the user who owns the lock on the ScriptTask.

DateCreated

Records the date and time when the ScriptTask was created.

DateModified

Shows the date and time of the last modification to the ScriptTask.

Description

Describes the purpose and functionality of the ScriptTask.

In this section:

Page Tree
rootV10:@parent
spacesV10