Table of Contents

Class ExecuteCode

Namespace
Acuit.Pinpoint.Workflows.Activities
Assembly
Acuit.Pinpoint.Workflows.dll

An activity that executes a C# script.

[TypeConverter(typeof(ExecuteCodeTypeConverter))]
public class ExecuteCode : Activity<object?>, IActivity
Inheritance
ExecuteCode
Implements
Inherited Members

Examples

A CDATA section can be used to specify the C# script to execute without needing to escape special characters within the XAML:

<Sequence>
    <Sequence.Variables>
        <Variable Name="DateTimeNow" Type="string" />
    </Sequence.Variables>
    <ExecuteCode>
        <![CDATA[
            var.DateTimeNow = DateTime.Now.ToString();
        ]]>
    </ExecuteCode>
</Sequence>

This example behaves the same as the previous example but demonstrates how the C# script can return a value that becomes the activity's result:

<Sequence>
    <Sequence.Variables>
        <Variable Name="DateTimeNow" Type="string" />
    </Sequence.Variables>
    <SetVariable Name="DateTimeNow">
        <ExecuteCode>
            <![CDATA[
                return DateTime.Now.ToString();
            ]]>
        </ExecuteCode>
    </SetVariable>
</Sequence>

await can be used to await asynchronous operations, referencing CancellationToken for cancellation support, like this:

<ExecuteCode>
    <![CDATA[
        await Task.Delay(1000, CancellationToken);
    ]]>
</ExecuteCode>

Remarks

The C# script will be compiled and executed using the same C# scripting environment as is used for C# workflow expressions.

The C# script can optionally return a value, which will be the result value produced by this activity. If the C# script does not return a value, the activity's result will be null.

The await keyword can be used within the C# script to await asynchronous operations. The CancellationToken global property should be used to cancel pending asynchronous operations.

Constructors

ExecuteCode()

public ExecuteCode()

Properties

Code

Gets or sets the C# code block to execute.

public CodeScript? Code { get; set; }

Property Value

CodeScript

Methods

OnExecuteAsync(ActivityContext, CancellationToken)

Derived classes must implement this to perform the activity.

protected override Task<object?> OnExecuteAsync(ActivityContext context, CancellationToken cancellationToken)

Parameters

context ActivityContext

The activity context.

cancellationToken CancellationToken

The cancellation token used to request canceling the activity.

Returns

Task<object>

A task that represents the asynchronous operation. The value of its Result property contains the result.

Exceptions

ArgumentNullException

context is null.

InvalidOperationException

A service required by the activity is not available, or a required activity property value is not set.

Exception

An error occurred while performing the activity.