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 2015, or higher
  • Microsoft .NET Framework 4.6.1
  • A deployed Dundas BI instance

2.1. Downloading sample solution

To download the server events sample solution, click here.

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

2.2. Extracting sample to SDK folder

This sample is designed to automatically publish the extension to your Dundas BI instance. First, you must extract the ZIP file to the SDK folder within the instance:

  1. Find the SDK folder for your instance. It is located at [instance root]\sdk.
  2. Extract the ServerEventsSample.zip to the SDK folder.
  3. You should see the following result:

    Samples added to SDK folder
    Samples added to SDK folder

    With the following structure:

    [instance root]
         •sdk
              •Samples
                   •ServerEventsSample

    Important
    If the sample is not in this specific folder, it will not work correctly.

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: [instance root]\sdk\Samples\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.
  • PublishExtension.targets - Used for auto publishing the extension after the build succeeds.

3.1. ExtensionPackageInfo class

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

/// <summary>
/// This class represents the extension package info for the Server Events. 
/// </summary>
public class ServerEventsExtensionPackageInfo : ExtensionPackageInfo
{
    /// <summary>
    /// Gets the name of the extension package author.
    /// </summary>
    public override string Author
    {
        get { return "Dundas Data Visualization Sample Author"; }
    }

    /// <summary>
    /// Gets the copyright text associated with the extension package.
    /// </summary>
    public override string Copyright
    {
        get { return "Dundas Data Visualization, Inc."; }
    }

    /// 
    /// Gets the localized display name of the extension package.
    /// 
    public override string DisplayName
    {
        get { return "Server Events Sample"; }
    }

    /// 
    /// Gets the unique identifier of the extension package.
    /// 
    public override Guid Id
    {
        get { return new Guid("c480e1de-2023-4de0-85a5-c303d4d4b994"); }
    }

    /// 
    /// Gets the name of the extension package.
    /// 
    public override string Name
    {
        get { return "Server Events Sample"; }
    }

    /// <summary>
    /// Gets the version of the extension package.
    /// </summary>
    public override Version Version
    {
        get { return new Version(0, 0, 1);  }
    }
}

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 targets

This sample has a mechanism to automatically publish the extension. This mechanism is the PublishExtension.targets file, which overrides the AfterBuild target. This will create the following file after successfully compiling the solution:

[instance root]\www\BIWebsite\App_Data\Extensions\ServerEventsSample\bin\ServerEventsSample.dll

It will then touch the web.config to force the web application to reset.

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: 7am-6pm, ET, Mon-Fri