Registering .NET Activities with Geocortex Workflow Designer

Geocortex 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 Geocortex Workflow Designer activity definition when the activity pack is registered. However, with .NET activities implemented for Geocortex Mobile or Geocortex Workflow Server, the implementation is defined on the host platform (.NET), while the Geocortex Workflow Designer activity definition must be defined in an activity pack (TypeScript).

note

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

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

Implement a TypeScript Activity Pack with Stub Activities

The idea behind creating activity definitions for Geocortex 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 Geocortex Mobile custom logarithm activity for example.

App1/App1/CustomActivity.cs
using Geocortex.Workflow.Runtime;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace App1.Workflow
{
public class CalculateLog : IActivityHandler
{
public const string Action = "your:unique:namespace::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.

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 Geocortex Mobile SDK or Geocortex Workflow for Server. In the case of the Logarithm activity, the stub might look like this.

important

The static action property of the original activity definition has been changed to your:unique:namespace::CalculateLog 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.

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 {
static action = "your:unique:namespace::CalculateLog";
static suite = "your:unique:namespace";
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 Geocortex Workflow Designer, that can be shared with other workflow authors.