Steps to Create Custom Event Provider
- Last UpdatedJun 10, 2024
- 5 minute read
AVEVA Work Tasks allows creation of custom event providers using its Event Framework. Using this framework any custom event raised can be used to trigger a workflow or an activity.
Step 1: Creating the Class Library Project
Open a new Class Library type project and name it as you want to name the custom event provider. For this example we will be using "SkeltaSampleEventProvider" as the project name, and this should create a namespace of the same name. Please refer to Code Sample to see code implementation.
-
Add reference to Workflow.NET.NET2.dll
-
Add the following to the project:
using Skelta.Events.Interfaces;
using Skelta.Core;
using Workflow.NET;
using Skelta.Events;
using Workflow.NET.Engine;
using System.Collections;
-
Create a new class for EventPort which implements the interface IEventPort. The IEventPort interface has the following properties.
Properties
Description
string EventName
Get Event Provider name specific to provider.
Guid PortGuid
Id used Internally to identify the port
string PortName
Name used to represent the port internally
string PortXmlString
Port level custom logic can be persisted inside this XML string.
-
Create another class in the same file for EventProvider which implements the interfaces
-
IEventClientServiceProvider
-
The IEventClientServiceProvider interface has the following properties and methods.
|
Properties |
Description |
|---|---|
|
string EventName |
The name of the event can be hard coded in class implementation. |
|
string ListBigIcon |
Path of the image file to be displayed in event association page for the custom activity. |
|
string ListSmallIcon |
Path of the image file to be displayed in event association page for the custom activity. |
|
Methods |
Description |
|
bool EventBindingAdding(EventBinding eventBinding) |
This method will get called while adding an eventbinding of the particular provider type. The code to be executed while adding an event binding should be written here. |
|
bool EventBindingDeleting(EventBinding eventBinding) |
This method will get called while deleting an eventbinding of this provider type. The code to be executed while deleting an event binding should be written here. |
|
EventBindingUpdating(EventBinding eventBinding) |
This method will get called while Updating an eventbinding of this provider type. The code to be executed while Updating an event binding should be written here. |
|
EventParameter[] GetAllEventParameters(IEventPort port) |
This method gives all correlation parameters used for filtering event bindings when an event occurs. |
|
string GetEventBindingNameForDisplay(EventBinding eventBinding) |
This method will give name for the Event Binding for displaying purpose. |
|
IEventPort GetNewEventPort() |
Will return new port specific to the provider. |
|
List<EventProvisionFormDetails> GetProvisionForms(EventProvisionFormType provisionType) |
Used to render forms for association. Returns list of EventProvisionFormDetails which can be used for rendering Event association page. (This is the page which should appear when we are trying to associate a workflow with the Custom Created Event Provider. On the page we should specify the details of the event on which workflow has to be triggered). See the code Samples for more details. |
|
bool IsEventValidForTheTarget(EventItem eventItem, EventBinding eventBinding, VariablesCollection varCollection) |
This method will be called from Engine after filtering the eventbindings for specific events. If it returns true then this eventbinding should be considered for executing/alerting workflow. Users business logic can be implemented here. For Activity type eventbindings, variables can be updated here. |
|
IEventPort LoadEventPort(Guid id, string portName, string portXml) |
Used internally to get a specific event port. |
-
IEventServiceProvider
Note: This interface should be implemented only if EventProvider is going to be hosted inside the Engine. If the EventProvider is going to be hosted outside, the region "OnEventReceived" in the sample code file should be shifted to the custom implemented Event receiving class.
The IEventServiceProvider interface has the following methods:
|
Methods |
Description |
|---|---|
|
Dictionary<string, IEventPort> GetListeningEventPorts() |
Returns all the listening Event Ports. |
|
void Initialize() |
This method is called to initialize the provider before starting it. |
|
bool IsGlobal() |
returns true if the provider is global else returns false. This method is used internally. |
|
object OnClientMessage(string methodName, object message) |
- |
|
void OnStop() |
- |
|
void RefreshListeningPort(IEventPort eventPort) |
This method is from Engine for re-starting an eventport. |
|
void StartListeningPort(IEventPort eventPort) |
Method is called for starting an EventPort |
|
void StopListeningPort(IEventPort eventPort) |
Method is called for Stopping an EventPort |
-
ISkeltaAddInProvider
|
Properties |
Description |
|---|---|
|
Guid Id |
Unique is for the Add in provider |
|
string Settings |
Contains the settings for the add in provider |
|
Methods |
Description |
|
void InitializeProvider(string settings, Guid id) |
Initializes the ad |
Note: To implement load Balancing, the interface IEventSupportsLoadBalancing also has to be implemented. Implementing this interface is completely optional and depends on the requirement. The interface has the following definition.
|
IEventSupportsLoadBalancing |
|
|---|---|
|
Methods |
Description |
|
void OnMachineAdded(string machineName) |
Implement this method to specify what has to done when a new machine is added. it takes the new machine name added as its parameter. |
|
void OnMachineDown(string machineName) |
Implement this method to specify how load should be distributed when any of the machine is down. |
-
Strong name the dll and build the project.
-
Register the dll in the GAC and one copy in the AVEVA Work Tasks bin folder.
Step 2: Add the new Event provider to the Repository
-
Go to Repository Settings from the top right menu bar.
-
Go to the Advanced Settings tab and click Manage Event Providers.
-
Click New in the Event Provider page and enter the details for the new Event Provider.
The Title should besSame as that of the Event Provider being created.
Provider Type should be given as EventHost if the event provider is going to hosted inside the Engine, or as Event if the Provider is going to be hosted externally.Display priority is the order in which the icon is going to be displayed on the top menu.

-
Click Save & Continue which will successfully add a new event provider. A new entry will be made in the SKEEventProviders table for the Custom event provider.
-
Execute the following Query for the Repository database.
INSERT INTO SKAddInProviders (Type,[Name],ClassName,[Assembly],Settings,IsGacAssembly) VALUES ('EventHost','SkeltaSampleEventProvider','SkeltaSampleEventProvider.EngineHostedProvider','bin\SkeltaSampleEventProvider.dll','',1)
Here,
-
Type- The field which decides the provider is hosted inside the Engine or externally.
-
Name- Name of the provider being created
-
ClassName- Namespace.Classname of the class in the class library file
-
Assembly- Location of the dll created
-
Settings- Settings for the provider, if any
-
IsGacAssembly- Represents whether dll is registered in the GAC or not
A row will be added to the AddInProviders table. A new Event Provider has been added in the repository with name SkeltaSampleEventProvider.
Step 3: Verification
We can verify whether it has been correctly added by following the below procedure.
-
Go to the list of workflows.
-
Right-click any workflow.
-
Click Create Associations which would lead to a new page from where we can associate to different event providers.
-
With the list of default Event providers, the newly added event provider icon is also displayed.