Hook into Dundas BI server events

Contents[Hide]

1. Overview

This sample shows how to hook into Dundas BI Server events from your extension. The extension created in the sample subscribes to the CreatedFileSystemEntry event, and then resets the data result cache.

2. Getting started

The following prerequisites must be installed on your computer:

  • Visual Studio 2017, or higher
  • Microsoft .NET Framework 4.7.2 or higher, and Microsoft .NET Core 3.1 or highe/li>
  • A deployed instance of Dundas BI version 7 or higher/li>

2.1. Downloading sample solution

To download the server events sample solution, click here.

(A sample solution is also available for Dundas BI version 6.0, versions 5.0 and older.)

2.2. Extract the sample to a folder

This sample is designed to automatically publish the extension to the instance. First, you must extract ServerEventsSample.zip to a folder.

2.3. Opening solution

To open the Visual Studio solution:

  1. Right-click on the Microsoft Visual Studio shortcut, and click Run as administrator.
  2. Click the File menu, then Open Solution.
  3. Choose the solution located at: [Extracted folder]\ServerEventsSample\ServerEventsSample.sln

3. The project

The project is a class library.

  • ServerEventsExtensionPackageInfo.cs - This class contains the package information about the extension package. The server events are hooked up by overloading the OnLoaded method.
  • PublishExtensionTemplate.props - Used for auto publishing the extension after the build succeeds, and defines extension properties, and files.

3.1. ExtensionPackageInfo class

To register as an extension, extend the ExtensionPackageInfo2 class. This class contains the extension package information.

/// <summary>
/// This class represents the extension package info for the Server Events. 
/// </summary>
public class ServerEventsExtensionPackageInfo : ExtensionPackageInfo2
{
    ...
}

To hook into events in Dundas BI, override the OnLoaded method. Next, get the IEventHookService and subscribe to one of the events.

In the example below, the event hook service is used to hook up to the CreateFileEntry event. This event is then used to clear the result cache.

/// <summary>
/// Called after the extension package is loaded during engine startup.
/// </summary>
public override void OnLoaded()
{
    IEventHookService eventHookService = Engine.Current.GetService<IEventHookService>();

    // Hooks up event handler when a file system entry is created.
    eventHookService.CreatedFileSystemEntry += eventHookService_CreatedFileSystemEntry;
}

/// <summary>
/// Handles the CreatedFileSystemEntry event of the eventHookService control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemChangedEventArgs{Dundas.BI.FileSystem.FileSystemEntry}"/> 
/// instance containing the event data.</param>
void eventHookService_CreatedFileSystemEntry(
    object sender, ItemChangedEventArgs<Dundas.BI.FileSystem.FileSystemEntry> e
)
{
    IDataRetrievalService dataRetrievalService = Engine.Current.GetService<IDataRetrievalService>();

    dataRetrievalService.ClearResultCache();
}

3.2. Publish Extension Template Props

This sample has a mechanism to automatically publish the extension when building. This mechanism is the Dundas.BI.PublishExtension NuGet package. When the Dundas.BI.PublishExtension package is added to the project it creates a PublishExtensionTemplate.props file in the project. This file contains Msbuild property and item groups, these are defined to create the extension.

When the DtFilePath property is set to the file path of the dt utility inside an instance. It will then publish the extension to that instance. It will also then touch the web.config to force the web application to reset.

If the DtFilePath property is not set it will create a zip file in the based on the ExtensionOutputFolder folder. This can then be added through the Dundas BI user interface to add the extension to the instance.

4. See also

Dundas Data Visualization, Inc.
500-250 Ferrand Drive
Toronto, ON, Canada
M3C 3G8

North America: 1.800.463.1492
International: 1.416.467.5100

Dundas Support Hours:
Phone: 9am-6pm, ET, Mon-Fri
Email: 7am-6pm, ET, Mon-Fri