How to add a 3rd-party event recorder to the K2 blackpearl Server

The Event Bus is an extendible piece of the K2 platform that allows third-party events to be raised on a K2 server.

If you want to consume events raised in the K2 environment so that you can perform an action based on an event (for example, write to a text file if a SmartObject is executed), you will need to create a custom Notification Provider as described in the Custom Notification Providers topic.
The difference is that a Notification Provider responds to events and performs an action, while an Event Bus Server raises custom events which a notification provider can then respond to.

The Event Bus Architecture

The following diagram illustrates the architecture of the Event Bus and shows how 3rd-Party event recorders function in the context of built-in K2 event recorders. All events are funneled into the Generic Client Recorder and queued (using MSMQ or another queuing system) to be processed by the Event Bus.

Components and Interfaces

There are three main components that need to be developed in order to surface events from a 3rd-party server to the Event Bus and to use those events in custom notifications.

Custom Event Recorder

Implements: IEventRecorder

Sample code

ClientRecorderEvent newEvent = new ClientRecorderEvent();
newEvent.RaiseEvent((object) context, ProviderID, eventName, eventData);

The Custom Event Recorder provides an interface between the server and the custom recorder. The recorder and interface components are developed separately as custom components. The recorder needs to implement the 3rd-party system interfaces to ensure that the events from that system can be consumed. The recorder also needs to reference the SourceCode.Eventbus.ClientRecorder assembly in order to raise the event via the RaiseEvent method.

Resolver

Inherits: RuntimeDataResolverBase

The Resolver allows data fields, along with their types and values, to be passed from the custom recorder through to the K2 server. These values can then be used in the custom notification designer as illustrated in the sample below.

Object Browser

Implements: IObjectBrowser

To display the server’s data structure in the K2 Notification Event object browser as shown below, another component needs to be developed. This component will display the objects, events and properties of the 3rd-party server, and needs to implement the IObjectBrowser interface, which is in the SourceCode.Eventbus.Interfaces assembly.

Example

In the solution provided here, a custom recorder is used to capture events from a watched folder on the local server. By default, only new files that have a particular filename cause the recorder to process the event.

The solution is made up of three projects:

The resulting assemblies created when the project is compiled do not ship with K2 blackpearl. These are assemblies that are to be used as samples when creating your own event recorder.

Steps

  1. Download, extract and open the sample project: K2Documentation.Samples.Extensions.Eventbus.FileSystem.zip

    This example assumes Visual Studio is installed on the same machine as the K2 Server.

  2. Update the references in the SourceCode.EventBus.Samples.FileSystemEventRecorder and the SourceCode.EventBus.Samples.FileSystemObjectBrowser projects by browsing to C:\Program Files\K2 blackpearl\Host Server\Bin to locate these assemblies.
  3. Build the solution
  4. Copy assemblies from their to the correct places as noted below. Remember to also copy the SourceCode.EventBus.Samples.FileSystemEventRecorder.dll.config file to the same location as its associated assembly.
    • For SourceCode.EventBus.Samples.FileSystemEventRecorder
      Copy To: C:\Program Files\K2 blackpearl\Bin
    • For SourceCode.EventBus.Samples.FileSystemObjectBrowser
      Copy To: C:\Program Files\K2 blackpearl\Bin
    • For SourceCode.EventBus.Samples.FileSystemXmlResolver
      Copy To: C:\Program Files\K2 blackpearl\Bin
  5. Make the necessary changes to the SourceCode.Eventbus.Mapping.dll.config file, the SourceCode.Eventbus.Server.config and the Workspace Web.config as noted below. These steps are similar to the steps included in the KB article KB000185 - How to add a 3rd party server to the Event Bus (requires portal login).

    In K2 blackpearl version 4.6.9, a number of configuration files have been consolidated into a single configuration file to simplify the management of configuration settings. The SourceCode.EventBus.Assemblies.config file has been consolidated into the K2HostServer.exe.Config file, which is located in the \K2 blackpearl\Host Server\Bin folder on the K2 Server. The connection strings previously stored in this file are now retrieved from the K2HostServer.exe.Config file.


    <!--
    Add the following to the K2HostServer.exe.Config file located at C:\Program Files\K2 blackpearl\HostServer\Bin
    This allows the resolver to be instantiated and the runtime data to be resolved to actual values.
    -->
    <resolver id="502B68FF-1C66-45F8-9E45-5537A9521FF2" assembly ="SourceCode.EventBus.Samples.FileSystemXmlResolver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=16a2c5aaaa1b130d" assemblytype="SourceCode.EventBus.Samples.FileSystemXmlResolver.ExpenseClaimResolver" />
    <resolver id="F07C0651-5ADE-4364-B54A-9FB0AB59ED2D" assembly ="SourceCode.EventBus.Samples.FileSystemXmlResolver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=16a2c5aaaa1b130d" assemblytype ="SourceCode.EventBus.Samples.FileSystemXmlResolver.OrderResolver" />


    <!--
    Add the following mappings to the K2HostServer.exe.config located at C:\Program Files\K2 blackpearl\HostServer\Bin
    This registers the specific resolvers with the Event Bus, allowing runtime data to be created. This information is used when an event definition is saved.
    -->
    <mappingguid="502B68FF-1C66-45F8-9E45-5537A9521FF2"assemblyfullname="SourceCode.EventBus.Samples.FileSystemXmlResolver, Version=1.0.0.0, Culture=neutral,PublicKeyToken=16a2c5aaaa1b130d" asssemblytyperesolver ="SourceCode.EventBus.Samples.FileSystemXmlResolver.ExpenseClaimResolver" assemblytypeprovider="SourceCode.EventBus.Samples.FileSystemXmlResolver.ExpenseClaimProvider"/>
    <mappingguid="F07C0651-5ADE-4364-B54A-9FB0AB59ED2D"assemblyfullname="SourceCode.EventBus.Samples.FileSystemXmlResolver, Version=1.0.0.0, Culture=neutral,PublicKeyToken=16a2c5aaaa1b130d" assemblytyperesolver ="SourceCode.EventBus.Samples.FileSystemXmlResolver.OrderResolver" assemblytypeprovider ="SourceCode.EventBus.Samples.FileSystemXmlResolver.OrderProvider"/>


    <!--
    Add the following section in the <appsettings> section of the SourceCode.Eventbus.Server.config file, e.g. after the </mappings> node.
    This registers the event recorder with the Event Bus.
    -->
    <eventrecorders>
      <recordername="FileSystemEventRecorder"assembly="SourceCode.EventBus.Samples.FileSystemEventRecorder" type ="SourceCode.EventBus.Samples.FileSystemEventRecorder.Recorder"/>
    </eventrecorders>


    <!--
    Add the following to the Workspace Web.config file located at C:\Program Files\K2 blackpearl\WorkSpace\Site, in the<eventbusobjectbrowsers>
    section. This registers the Object Browser for the custom event recorder to appear in Workspace, as you can see in the image below this code box.
    -->
    <objectbrowserid="09C19823-5A81-4AC0-BD1A-BFE1243BB6B5"displayname="File System Object Browser"assemblyfullname="C:\Program Files\K2 blackpearl\Bin\SourceCode.EventBus.Samples.FileSystemObjectBrowser.dll" assemblytypeprovider="SourceCode.EventBus.Samples.FileSystemObjectBrowser.ObjectBrowser" imageclosed="images/OB/folder_closed.gif" imageopen ="images/OB/folder_open.gif" connectionstring ="C:\Program Files\K2 blackpearl\Host Server\Bin\SourceCode.EventBus.Samples.FileSystemEventRecorder.dll.config"/>



    When copying code from these examples please make sure that the full XML node is located on the same line. Carriage returns may be inserted by html rendering and will need to be removed.


    After the changes have been made to the .config files, either restart the K2 blackpearl Server service or console application. Note: The target folder (in the case of the example, C:\FSW\) must exist before the K2 blackpearl Server is started. If not, create the target folder and then restart the K2 blackpearl Server.

Verifying the New Recorder

When the new event recorder is deployed to the server and the necessary .config file changes are made, run the K2 blackpearl Server in console mode from the Start menu to verify it is working. When the example project is built and deployed, the server window will display the following entries when it is finished loading:

If you do not see this message, it could mean that the information messages are not displayed in the console window. To check, browse to C:\Program Files\K2 blackpearl\Host Server\Bin and open the HostServerLogging.config file. In the <ApplicationLevelLogSetting> section of the <ApplicationLevelSettings> section, modify the FileExension LogLocation Active Setting to be True, and the LogLevel Setting to All, as in the following line:

<LogLocationName="FileExtension"Active="True" LogLevel ="All"/>

Save the changes to this file and restart the K2 blackpearl Server from the Start menu.

Then, once you see the message in the server console that the event recorder is loaded, copy the ORD123.txt example file to the C:\FSW\ folder. This will fire an event that will register in the server console.

To further test the example event recorder, browse to K2 Workspace and create a new notification using the data fields from the File System Object Browser. You can test multiple events by creating copies of the example file and changing some of the fields inside the file. The fields can be dragged over to the notification event designer in order to send customized e-mail notifications based on the XML content of the file dropped into the C:\FSW\ folder.

See also: Adding a 3rd Party Server to the Notification Event subsystem

K2 blackpearl Developers Reference4.7
Video Links Learn Support
No videos found for this article
K2 on YouTube
No Additional links found for this article
No self-learning content for this article
Try some scenarios...
No relevant support links available for this article