Plugins
General information​
A plugin is a class that extends the functionality of the Workflow Engine, and specifically:
- Adds predefined Actions, Conditions and Authorization rules to the schemes designer.
- Performs additional processing of the Workflow Runtime standard events.
- Connects a provider of external parameters to your processes.
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 we perform the following procedures:
- Create instances of the two plugins: BasicPlugin and FilePlugin.
- Set up the plugins.
- Register them in the
WorkflowRuntime
calling theWithPlugin
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.
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 of the schemes.
How to connect a plugin to Workflow Server​
To connect a plugin to Workflow Server, go to the Dashboard page and the Plugins tab. You should simply enable the plugin with the toggle and establish its settings, if any. After that, the functionality added by the plugin will become available for all of 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);
void OnPluginRemove(WorkflowRuntime runtime);
}
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 theWorkflowRuntime
events.OnPluginRemove
- called when the plugin is removed from the runtime.
Also, the plugin class can optionally implement the following interfaces in any combination.
- IWorkflowActionProvider - adds Actions and Conditions.
- IWorkflowRuleProvider - adds Authorization rules for arranging access to the commands.
- IDesignerAutocompleteProvider - arranges a simple autocomplete for the parameters of Actions, Conditions or Authorization Rules.
- IDesignerParameterFormatProvider - creates complex forms for editing the parameters of Actions, Conditions or Authorization Rules.
- IWorkflowExternalParametersProvider - adds external parameters to the process.
ICustomActivityProvider
. This interface contains only one methodList<ActivityBase> GetCustomActivities()
. You can return the list of Custom Activities that will be added to the Designer.
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.