Custom Activity

Custom Activity - the activity with custom edit form and custom visual display on canvas.

–°ontent

  1. Creating custom activity
  2. Custom form
  3. Custom canvas element
  4. Registration

Creating custom activity

For creating a custom Activity, a class inherited from ActivityBase should be created. In the Parameters field of ActivityBase, 2 parameters, Name and Stateare stored; those are the name of Activity and its state.

You can add variables of your own in the constructor. The variables are similar to the parameters in IDesignerParameterFormatProvider.

Parameters.Add(new CodeActionParameterDefinition() { Name = "Comment", Type = ParameterType.TextArea });

On entering this Activity, WFE calls the ExecutionAsync method (PreExecutionAsync for PreExecution mode).

Example of a class:

public class MyCustomActivity: ActivityBase
{
    public MyCustomActivity() : base()
    {
        Type = "MyCustomActivity";
        Title = "My Custom Activity";
        Description = "The action is mine";

        Template = "MyFormTemplate"; //the file name with your form template, without extension
        SVGTemplate = "MySVGTemplate"; //the file name with your svg template, without extension

        Parameters.Add(new CodeActionParameterDefinition() { Name = "MyField", Type = ParameterType.TextArea });
    }

    public override async Task ExecutionAsync(WorkflowRuntime runtime, ProcessInstance processInstance, Dictionary<string, string> parameters, CancellationToken token)
    {
        Console.WriteLine("MyCustomActivity:");
        foreach(var item in parameters)
            Console.WriteLine($"{item.Key} - {item.Value}");
        Console.WriteLine("--------------");
    }

    public override async Task PreExecutionAsync(WorkflowRuntime runtime, ProcessInstance processInstance, Dictionary<string, string> parameters, CancellationToken token)
    {

    }
}

Custom form

To change the Activity form, you should create a new file with .html extension in the templates folder, and specify its name in the Template field.

As an example, you can copy activity.html from the Designer

Custom canvas element

To change the Activity image in the canvas, you should create a new file with .svg exension in the templates\elements folder, and specify its name in the SVGTemplate field.

As an example, you can copy activity.svg from the Designer

Registration

For registration, the WithCustomActivities method of WorkflowRuntime should be executed:

_runtime.WithCustomActivities(new ActivityBase[] { new MyCustomActivity() })

All of the custom Activities will be displayed in the Elements panel:

1

To add your custom activity to the scheme, proceed as follows:

  1. Open the Elements panel
  2. Find the activity in the list of elements or use Search
  3. Drag the element to the canvas
Top