WorkflowRuntime: Process Management

This Section describes basic workflow management functionality. In fact, there are far more ways of managing workflows through Workflow Engine, however, in most cases you are likely to apply only these methods.

Process Creation

A minimum version of the CreateInstance method accepts two parameters: scheme code (name) and process ID:

WorkflowInit.Runtime.CreateInstance("SchemeCode", processId);

The most extensive version of the CreateInstance method accepts CreateInstanceParams. This object contains supplementary input parameters for process creation:

var createInstanceParams = new CreateInstanceParams("SchemeCode", processId)
    InitialProcessParameters = new Dictionary<string, object>()
    SchemeCreationParameters = new Dictionary<string, object>()
    IdentityId = identityId,
    ImpersonatedIdentityId = impersonatedIdentityId

  • InitialProcessParameters is a process parameters dictionary that is passed during the process creation;

  • SchemeCreationParameters are parameters passed to the scheme generator. They are not used in case the generator is delivered to persistence providers;

  • IdentityIdand ImpersonatedIdentityId are identifiers of the user performing an operation and the one on whose behalf it is performed. These attributes should be transferred during the creation stage only if the process demands so right after the start;
  • ImpersonatedIdentityId should be transferred only if you use impersonation (user performs operations on behalf of another user), otherwise it doesn't have to be transferred.

During workflow instance creation the only required parameters you have to fill are the scheme code (name) and process ID.

Commands Retrieval and Execution

In order to get a list of commands available to a user call the GetAvailableCommands method which accepts process ID and user ID:

The IEnumerable<WorkflowCommand> retrieves a list of commands available for a particular user, enquiring process ID and user identity ID:

var commandsList = WorkflowInit.Runtime.GetAvailableCommands(processId, identityId);

WorkflowCommand contains information on original and localized command names, along with parameters that should be transferred along with the command. This object supports serialization both in JSON and XML formats, thus, enabling you to easily retrieve it from your services.

To execute a command, you should request the following method:


identityId and impersonatedIdentityId parameters define the user performing the operation and the one on whose behalf it is performed. If you don't use impersonation, simply submit identityId as impersonatedIdentityId.

command is a command retrieved by calling the GetAvailableCommands method.

A use case for web application that already contains client data validation looks like this:

var processId = ...;//Get it from a request
var commandName = ...;//Get it from a request

var currentUser = HttpContext.User.Identity.Name;
var commands = WorkflowInit.Runtime.GetAvailableCommands(processId, currentUser);

var command = commands.FirstOrDefault(c => c.CommandName == commandName);

if (command == null)
    return; //Or throw an error      


Running ahead, in order to identify the user's identityId you may enquire for user login, database GUID or anything else.

Workflow State Retrieval and Change

In order to get a list of available states call the GetAvailableStateToSet method which accepts process ID:

var statesList = WorkflowInit.Runtime.GetAvailableCommands(processId, identityId);

WorkflowState contains information on original and localized state names. This object supports serialization both in JSON and XML formats, enabling you to easily retrieve it from your services.

The SetState method is applied for setting up the process state:

IDictionary<string, object> parameters = null;
bool preventExecution = false;

processId, identityId, impersonatedIdentityId attributes are equivalent to those submitted to the command execution method. stateName is the state name parameter on the scheme. parameters dictionary are attributes assigned to the process. preventExecution determines the way a process state is being configured. If this parameter is set to false, then WorkflowEngine will execute the Implementation section of the initial Activity of the current state, and start the transient process if possible. In case preventExecution is set to true, the current state and activity will be changed, while no execution will be performed.

The minimum parameter set of the SetState function includes:


Process Deletion

The DeleteInstance method removes the entire process with the associated artifacts from persistence storage:


Async API

All the methods described have asynchronous versions. Simply add Async at the end of the method's name, as in ExecuteCommand and ExecuteCommandAsync.

Base Events

In day-to-day work you may need 2 events:

runtime.ProcessActivityChanged  += (sender, args) => { };
runtime.ProcessStatusChanged += (sender, args) => { };

ProcessActivityChanged event is raised every time the current process activity is changed. Two objects are passed in event arguments: ProcessInstance with all process parameters and CurrentActivity defining the updated current activity. TransitionalProcessWasCompleted attribute signifies whether or not the transient process is completed. If it is, then the process stops, awaiting for a command or timer. It is appropriate to fill in the WorkflowInbox table in this event-handler.

ProcessStatusChanged event happens, when the process status is changed, for example if running-to-idled transition (and vice versa) has taken place. Event arguments contain the former and new status data, giving access to the ProcessInstance object. This event-handler enables you to delete the process once it reached the finalized status.