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 2012, or higher.
  • Microsoft .NET Framework 4.5
  • Dundas BI Server

2.1. Downloading file

To download the Server Events Sample solution click here.

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 ServerEventsSample.zip to the SDK folder within the instance. To extract the ServerEventsSample.zip do the following:

  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 the exact folder, it will not work correctly.

    2.3. Opening Solution

    To open the Visual Studio solution simply do the following:

    1. Right click on the Microsoft Visual Studio shortcut, and click run as administrator.
    2. Click the File Menu, then Open Solution.
    3. Double click 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

    In order to hook into the server events in Dundas BI the extension needs to first contain a class that extends the ExtensionPackageInfo class. This class contains the package information about the extension package.

    /// <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."; }
        }
    
        public override string DisplayName
        {
            get { return "Server Events Sample"; }
        }
    
        public override Guid Id
        {
            get { return new Guid("c480e1de-2023-4de0-85a5-c303d4d4b994"); }
        }
    
        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. For more information about Clearing the result cache, click here.

    /// <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