Skip to main content

Registering .NET Activities with VertiGIS Studio Workflow Designer

VertiGIS Studio Workflow activities can be implemented in either TypeScript or C#, depending on the target platform. For custom activities implemented in TypeScript, the registration of the workflow activity implementation is done alongside the VertiGIS Studio Workflow Designer activity definition when the activity pack is registered. However, with .NET activities implemented for VertiGIS Studio Mobile or VertiGIS Studio Workflow Server, the implementation is defined on the host platform (.NET), while the VertiGIS Studio Workflow Designer activity definition must be defined in an activity pack (TypeScript).

note

If no VertiGIS Studio Workflow Designer activity definition is provided for a custom activity implemented for VertiGIS Studio Mobile or VertiGIS Studio Workflow Server, the activity will not show up in VertiGIS Studio Workflow Designer and must be run using RunActivity.

This article covers how to create an activity pack to register VertiGIS Studio Workflow Designer activity definitions for custom activities implemented in VertiGIS Studio Mobile or VertiGIS Studio Workflow Server.

Implement a TypeScript Activity Pack with Stub Activities

The idea behind creating activity definitions for VertiGIS Studio Workflow Designer is that every activity implemented in .NET has a corresponding stub activity with the metadata, but no execution body, in a TypeScript activity pack.

Let's take the VertiGIS Studio Mobile custom logarithm activity for example.

App1/App1/CustomActivity.cs
using VertiGIS.Workflow.Runtime;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace App1.Workflow
{
public class CalculateLog : IActivityHandler
{
public const string Action = "uuid:<uuid>::CalculateLog";

public Task<IDictionary<string, object>> Execute(IDictionary<string, object> inputs, IActivityContext context)
{
double? logBase = null;
if (inputs.ContainsKey("base")) {
var logBase = inputs["base"];
}
var value = (double)inputs["value"];

double logResult;
if(logBase != null)
{
logResult = Math.Log(value, (double)logBase);
} else
{
logResult = Math.Log(value);
}

return Task.FromResult((IDictionary<string, object>)new Dictionary<string, object>()
{
["result"] = logResult
});
}
}
}

This activity will need a TypeScript stub that defines its input and output types and descriptions, specifies the runtime environments it supports, and an activity description.

Create a new Activity Pack

Follow the instructions in Implement a Custom Activity for Web Applications up to Implement the Activity. You will need to update the uuid value in uuid.js of your activity pack to match the uuid of your .NET project.

Stub out the Activity Metadata

Stub out the appropriate metadata and type information for the .NET activity you are stubbing out. The execute body is left empty, as the implementation is defined in .NET using the VertiGIS Studio Mobile SDK or VertiGIS Studio Workflow for Server. In the case of the Logarithm activity, the stub might look like this.

Important

By default the static action property will be generated for you when you build the TypeScript activity pack. In the example below we've explicitly declared the static action property to match the action name in the .NET implementation. If these two action names are not the same, the .NET workflow runtime will not be able to find the correct activity.

import type { IActivityHandler } from "@vertigis/workflow/IActivityHandler";

export interface CalculateLogInputs {
/**
* @description The base of the logarithm. Defaults to the natural log.
*/
base?: number;

/**
* @description The number to calculate the logarithm for.
* @required
*/
value: number;
}

export interface CalculateLogOutputs {
/**
* @description The logarithm output.
*/
result: number;
}

/**
* @supportedApps GMV
* @category Custom Activities
* @description An activity that calculates the log of a number with the given base.
*/
export class CalculateLog implements IActivityHandler {
static action = "uuid:<uuid>::CalculateLog";

async execute(
inputs: CalculateLogInputs
): Promise<CalculateLogOutputs> {
// The host application must implement this activity
throw new Error(
"Activity not implemented for this platform."
);
}
}

The activity now has a friendly user interface in VertiGIS Studio Workflow Designer, that can be shared with other workflow authors.