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 higher
  • A deployed instance of Dundas BI - this article details extensions for version 7 and higher

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. Opening solution

Extract ServerEventsSample.zip to a folder and open the solution in Microsoft Visual Studio to build the extension.

To use the option to publish directly to your Dundas BI instance, run Visual Studio as an administrator before opening the solution. For example, you can right-click Visual Studio in the start menu and find the Run as administrator option.

The solution file is 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

This sample has a mechanism to automatically publish the extension when building, which is the Dundas.BI.PublishExtension NuGet package. When this package is added to the project, it creates a PublishExtensionTemplate.props file containing MSBuild property and item groups, which define how to create and publish the extension.

When the DtFilePath property is set to the file path of the dt tool of a Dundas BI instance, it will then publish the extension directly to that instance when you build the solution. It will also touch the web.config file to force the web application to reset.

If the DtFilePath property is not set, it will create a .zip file you can add to your Dundas BI instance using the Extensions screen in the administration UI. After building the solution with the solution configuration set to Release, this .zip file can be found in the bin\Release\netcoreapp[x] subfolder of your solution. It targets both .NET Framework and .NET Core.

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