Skip to main content

Introducing Formengine - The New Formbuilder, try for FREE formengine.io.

Plugins

General information

A plugin is a class that extends the functionality of the Workflow Engine, and specifically:

The Workflow Engine package includes a set of predefined plugins; the features they add are described further in this section.

How to connect a plugin to Workflow Runtime

In case of using the Workflow Engine as an embedded solution, you should connect plugins when initializing the Workflow Runtime. It can be done with the following simple code.

var basicPlugin = new OptimaJet.Workflow.Core.Plugins.BasicPlugin();
// Settings for SendEmail actions in the Basic Plugin
plugin.Setting_Mailserver = "smtp.yourserver.com";
plugin.Setting_MailserverPort = 25;
plugin.Setting_MailserverFrom = "from@yourserver.com";
plugin.Setting_MailserverLogin = "login@yourserver.com";
plugin.Setting_MailserverPassword = "password";
plugin.Setting_MailserverSsl = true;
// simple delegate to access your security system roles
plugin.UsersInRoleAsync = UsersInRoleAsync;

var filePlugin = new OptimaJet.Workflow.Core.Plugins.FilePlugin();

var runtime = new WorkflowRuntime()
// The basic Workflow Runtime is skipped here
...
.WithPlugin(basicPlugin)
.WithPlugin(filePlugin)
.Start()

Here, the following procedures are performed:

  • Create instances of the two plugins: BasicPlugin and FilePlugin.
  • Set up the plugins.
  • Register them in the WorkflowRuntime calling the WithPlugin method.
  • Start the runtime.

After that, the Actions, Conditions and Authorization rules, which plugins add to the schemes designer, become available. For example, if you connect BasicPlugin to WorkflowRuntime and set the default parameters for the mail server, you can select the SendEmail Action in the Implementation section (or PreExecution Implementation) in the Activity editor. You can specify the body, title and recipient of the message in the Action parameter editor.

Fig1

The WithPlugin() method has a second optional parameter of type List<string> to specify a list of the codes of the schemes able to use the functionality added by a plugin. If the list is not specified, as in the samples above, then the functionality is added for all the schemes.

How to write a plugin of your own

A plugin is a class that must implement the IWorkflowPlugin interface. This interface is very simple:

public interface IWorkflowPlugin
{
string Name { get; }
Dictionary<string, string> PluginSettings { get; }
void OnPluginAdd(WorkflowRuntime runtime, List<string> schemes = null);
}

The interface members are assigned as follows:

  • Name - the plugin name.
  • PluginSettings - the dictionary of the plugin settings.
  • OnPluginAdd - called when the plugin is added to the runtime. This method is convenient for subscribing to the WorkflowRuntime events.

Also, the plugin class can optionally implement the following interfaces in any combination.

Thus, you get a class that connects to WorkflowRuntime by calling the WithPlugin() method only, and adds a certain class of functions to your system.