Skip to content

MIKE OPERATIONS Report Manager’s Content Provider

Introduction

This focuses on how to develop MIKE OPERATIONS Report Manager’s Content Provider.

It is assumed that the reader is familiar with MIKE OPERATIONS plugin architecture and configuration through runtime.config. If not, the reader should familiarize himself with reference /1/ and /2/.

Accompanying this document is a zip-file with the source code of the Visual Studio solutions and projects discussed in the text.

What is a Report Content Povider?

A Report Content Provider is a pluggable element of Report Manager that allows user to include desired data in a report. Each report consists of some static data (like text, images, etc.) defined in the report template and dynamic (also can be text, image, etc.) data provided by MIKE OPERATIONS. Content of each dynamic data item (or content item) is produced by a preconfigured Report Content Provider. A given Report Content Provider produces content of one of following types:

  • Text

  • Image

  • Table

  • Report

  • Typically Report Content Provider focuses on one type of data that the content is produced from. Examples of content providers included in Report Manager are:

  • Time series plot (creates an Image from Time series)

  • Spreadsheet table (creates a Table from a Spreadhseet)

  • Script text (creates Text based on a Scripe)

  • Content providers typically return content based on data stored in MIKE OPERATIONS system, but are by no means limited to that. They can easily return content based on data from external data sources (files, databases, web services, etc.)

    Configuration of each Content Provider consists of two elements:

  • Content configuration (defines where to get the data from, e.g. path to a time series)

  • Content formatting (defines how to render the data, e.g. type and size of an image)

  • Both content configuration and content formatting are part of a content provider implementation and can include any options that are necessary.

A walk-through - the CsvFileTableContentProvider

This section describes the steps for implementing a specific Content Provicer, the CsvFileTableContentProvider which exemplifies many of the aspects of creating a content provider in the Platform without requiring difficult data handling logic.

A Content Provider will normally comprise of:

  • Content configuration

  • Cotnent configuration UI

  • Content formatting

  • Content formatting UI

  • Content provider logic

Design of the content provider

The CsvFileTableContentProvider will provide a Table content based on a CSV file located on a disk.

User will be able to specify whether he wants the column headers to be included in the output data or not.

The Visual Studio project structure

Figure 1 shows a typical example of how to organize a Content Provider in a Visual Studio project.

Figure 1 The solution structure

It is enough to have content provider included in a single project in a Visual Studio solution. The project should reference (among standard .Net libraries) following MIKE OPERATIONS libraries:

  • DHI.Solutions.Generic

  • DHI.Solutions.ReportManager.Interfaces

  • DHI.Solutions.ReportManager.ContentProviders.General (this library is optional but simplifies a few things)

  • The example project consists of following files:

  • CsvFileContentConfiguration – represents the configuration of content for the provider

  • CsvFileContentConfigurationControl – allows user to edit the content configuration

  • CsvTableContentFormatting – represents the formatting of content for the provider

  • CsvTableContentFormattingControl – allows user to edit the content formatting

  • CsvFileTableContentProvider – contains the logic of content generation

Content configuration

The content configuration class should represent all information necessary to determine the source of content. It should implement the DHI.Solution.ReportManager.Interfaces.IReportContentConfiguration interface.

Listing - IReportContentConfiguration interface

The interface does not include any members itself, just states that each content configuration class should be able to serialize and deserialize itself to/from XML (this is needed to persist the configuration in database), notify about changes in it’s content and should be cloneable.

Serialization and cloning can be implemented from scratch but can also be reused by inheriting from DHI.Solutions.ReportManager.ContentProviders.General.BaseContentConfiguration class.

The code listing for CsvFileContentConfiguration is as follows:

Listing - CsvFileContentConfiguration

Serialization and cloning are taken care of in BaseContentConfiguration class. What is added in CsvFileContentConfiguration is the field and property representing CSV file name. Please note that:

  • CsvFileName property is marked as DssElement, so that dss serialization from BaseContentConfiguration takes the property into account.

  • Setter of CsvFileName sets _isModified and calls OnModified() so that IDssSerializable contract is met (notification about changes)

Content configuration control

The control should allow user to edit the content configuration. Control should implement the DHI.Solution.ReportManager.Interfaces.IReportContentConfigurationControl interface.

Listing - IReportContentConfigurationControl

The interface extends DHI.Solutions.Generic.IControl that represents a general MIKE OPERATIONS control and adds two methods to bind and unbind report content configuration.

Layout of the control will be very simple just a label and a textbox for entering the csv file path.

Figure - CsvFileContentConfigurationControl layout

The listing of control’s code is as follows:

Listing - CsvFileContentConfigurationControl code

Please note that:

  • Control binds CsvFileContentConfiguration properties to its children and unbinds them when requested

  • There’s no need to initialize the control with IShell, as no interaction with Shell or Application are performed in CsvFileContentConfigurationControl

  • Caption and IconHandle are not needed, as the control will be embedded in an already existing DataView

Content formatting

Content formatting class should contain all properties needed to format the content during rendering. It should implement the DHI.Solution.ReportManager.Interfaces.IReportContentFormatting interface.

Listing – IreportContentFormatting

The interface does not include any members itself, just states that each content formatting class should be able to serialize and deserialize itself to/from XML (this is needed to persist the formatting in database), notify about changes in its content and should be cloneable.

Serialization and cloning can be implemented from scratch but can also be reused by inheriting from DHI.Solutions.ReportManager.ContentProviders.General.ReportNoFormatting class.

The code listing for CsvTableContentFormatting is as follows:

Listing - CsvTableContentFormatting

Serialization and cloning are taken care of in ReportNoFormatting class. What is added in CsvTableContentFormatting is the field and property representing include header names formatting option. Please note that:

  • IncludeHeaderNames property is marked as DssElement, so that dss serialization from ReportNoFormatting takes the property into account.

  • Setter of IncludeHeaderNames sets IsModified and calls OnModified() so that IDssSerializable contract is met (notification about changes)

Content formatting control

The control should allow user to edit the content formatting. Control should implement the DHI.Solution.ReportManager.Interfaces.IReportContentFormattingControl interface.

Listing - IReportContentFormattingControl

The interface extends DHI.Solutions.Generic.IControl that represents a general MIKE OPERATIONS control and adds two methods to bind and unbind report content formatting.

Layout of the control will be very simple just a checkbox for indicating whether a user wants to include header names in the output table.

Figure - CsvFileContentConfigurationControl layout

The listing of control’s code is as follows:

Listing - CsvTableContentFormattingControl code

Please note that:

  • Control binds CsvTableContentFormatting properties to its children and unbinds them when requested

  • There’s no need to initialize the control with IShell, as no interaction with Shell or Application are performed in CsvTableContentFormattingControl

  • Caption and IconHandle are not needed, as the control will be embedded in an already existing DataView

Content Provider

Content provider is the actual plugin in the MIKE OPERATIONS that provides the system with configuration and formatting classes and controls. Content provider also produces the actual content based on provided content configuration and formatting.

Each content provider has to implement DHI.Solutions.ReportManager.Interfaces.IReportContentProvider interface.

Listing - IContentProvider

The code of CsvFileTableContentProvider class is following:

Listing - CsvFileTableContentProvider part1

Please note following:

  • Content provider has its own GUID assigned that will identify the provider among other providers

  • Content provider specifies that it will return table content

  • Content provider returns a name and description that will be shown to the user (typically these come from a resource file, so they can be localized)

  • Application object is saved but just as an example, it’s not used anywhere in current provider

  • Content configuration, content configuration control, content formatting and content formatting control are returned from appropriate methods to allow user to configure the provider

Listing - CsvFileTableContentProvider part 2

This listing shows the implementation of IReportContentProvider.GenerateContent method. Please note following:

  • Method gets content configuration and content formatting objects which need to be casted to correct types

  • According to the csv file path and formatting option, content provider produces a table output. The output is of string[,] type, as is required by the method contract.

  • When content configuration, formatting or underlying data is incorrect method should throw ArgumentException with a user readable message explaining what the problem is (exception handling in the above code is simplified, there would be much more checks in production code)

Deploy file

Part of the solution is also a CsvFileTableContentProvider.deploy file. This is needed to ensure easy inclusion of CsvFileTableContentProvider in runtime.config.

Listing - CsvFileTableContentProvider.deploy

Deploy file for the content provider has only one plugin listed. The plugin is of type DHI.Solutions.ReportManager.Interfaces.IReportContentProvider. It is not a requirement though, that a single dll should contain a single content provider. Typically there are multiple content providers related to a given data source grouped in a single dll.

Use in application

After the content provider has been built, copied to Bin folder of MIKE OPERATIONS and included in runtime.config it should appear as one of Content sources in content configuration data view. It can be configured using provided content and formatting configuration controls and content should be generated according to the implemented code.

Examples with the content preview are presented below.

Figure – CsvFileTableContentProvider – include headers

Figure - CsvFileTableContentProvider - do not include headers

Following file was used as the content source

Listing - sample.csv

Content provider alternative – Scripting

In order to include a certain data in a report there’s an alternative to creating a new content provider. For each type of report content (Text, Table, Image, Report) there’s a corresponding Script content provider, which along with a specialized script can produce the same result as a new content provider.

Example of how to get the same results as in CsvFileTableContentProvider using scripting will be described.

Script

The first step is to create a script that will get data from a csv file and produce the output table according to “include header names” flag.

The script listing can be found below.

Listing - CsvFileTable script

Please note following:

  • “CSV file path” and “Include header names” are passed to the script as parameters

  • The script produces string[,] as an output

  • Exception handling should be done the same way as in CsvFileTableContentProvider, i.e. ArgumentException should be thrown when user provided data is wrong. Again exception handling in this particular script is limited to a minimum compared to production code.

Script table output configuration

Now when the script is ready one can configure Script table output content source to use it.

Below are screenshots showing configuration of Script table output content source using CsvFileTable script, along with results preview with “Include headers” flag turned on and off.

Listing - CsvFileTable script applied with headers

Listing - CsvFileTable script applied without headers

Comparison

As we have seen producing content using script is a good alternative to writing a new content provider. There are following advantages of using scripting as a way to provide report content:

  • It’s much quicker to write script code (a single function) than to implement full content provider which requires implementation of 5 interfaces

  • A script doesn’t need to be deployed to all clients, it’s automatically shared once it’s saved in the database

But there are also disadvantages of using scripts for providing content:

  • Content source definition and formatting are provided only as script parameters so it’s values are entered by user in the script definition grid, whereas stand-alone content provider can define it’s own controls which can handle arbitrarily complex content source definitions and formatting

  • If the content provider’s logic and possibly communication with other systems is very complex, it’s easier to manage and test such solution in Visual Studio rather than in Script Manager