Jump to: navigation, search

Reporting (Plugin)


The UBIK reporting module can be used to generate HTML and PDF reports from a template and a data object from within custom code.

Setup

Binaries

The plugin binaries can be downloaded from the release portal. In the plugins package, there is a folder "UBIK.Module.Reporting" containing required DLLs. Additionally, the "BlinkBinariesWindows" package must be downloaded also from the release portal, from the UBIK® Tools section in the Plugins page. All binaries must be placed in UBIK.Studio's, UBIK.EnterpriseService's or the UBIKContent web service's Injection folder to install the plugin.

Binding redirect for SyncFusion.Licensing

It appears to be necessary to define an assembly binding redirect for one of the DLLs to fix a version mismatch problem in the SyncFusion library. For this, the following XML code has to be added to the app config of the executing program (UBIK.Studio.exe.config, UBIK.EnterpriseService.exe.config, or a web service's web.config):

      <dependentAssembly>
        <assemblyIdentity name="Syncfusion.Licensing" publicKeyToken="632609b4d040f6b4" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-22.2460.7.0" newVersion="20.3460.0.47" />
      </dependentAssembly>

Usage

To use the plugin, you need the following parts in place:

  • Custom code to render the report
  • A Scriban template to define what the report should look like
  • An object containing the data that should be displayed in the report

Custom Code

The reporting plugin can be used with the following lines of code:

        UBIK.Module.Reporting.ReportEngine reportEngine = new UBIK.Module.Reporting.ReportEngine();
        string htmlContent = reportEngine.RenderReport(templateFolder, templateName, reportObject, fullPdfFileName);

Make an instance of the "ReportEngine" class and call its method "RenderReport" to create an HTML report and optionally also create a PDF file out of it. The method has the following parameters:

  • templateFolder: The path to the folder containing the report templates without trailing folder separator character
  • templateName: The name of the template file without extension
  • reportObject: The object to extract data for the report from
  • fullPdfFileName: The full path to where a PDF version of the report should be created at. This parameter is optional and can be null.

The resulting HTML code is returned by the method.

Template

Scriban is a scripting engine that can be used to parse text templates. In our case, this means we can create an HTML file and put placeholders into parts of the file where we want report data to show up. We also can use the scripting features to create many rows of a table in a loop, for example. In the Scriban code, the default object is called "report_object". If this report_object has properties, you can access them by writing report_object.property_name (fill in the actual name starting with a lower case and with underscores separating the words). For more detailed information about Scriban, please refer to the "see also" section.

Report object

It makes sense to create a new class (or multiple) just for the report content, as data container. This way, you can assemble your report data in a way that you can access it comfortably from within the template. In the template, it will always be called "report_object" and you can access its properties, as well as the properties of objects it provides in turn. A complex data hierarchy can be processed into a report like this.

Example

To test how it will look and whether it works, you can use the specified template and the specified code. To do this, simply create a folder called " C:\ReportingTest" and save the specified template.html document under it. Then start UBIK.Studio, connect to any UBIK® Environment, insert the code in Who-Bert and start. Afterwards, there should be a report PDF file showing the text "BASECLASS" in your ReportingTest folder.

Here's very primitive example for a template HTML file showing just a header containing the object's name:

<!DOCTYPE html>
<html>
        <head>
        </head>
        <body>
                <h1>{{ report_object.name }}</h1>
        </body>
</html>

Use the following Who-Bert code to render a report:

using System;
using System.Windows.Forms;
using UBIK.Kernel;
using UBIK.Compiler;
using System.Linq;

namespace Studio
{
        public class ObjectTest
        {
                public void TestObject (params BaseClass[] InVariables)
                {
                        //Example using static class debugger
                        Debugger.Output(this, "*** Started");
                        foreach (BaseClass obj in InVariables)
                        {
                                Debugger.Output(this, obj.Name + " " + obj.Description);
                               
                                ReportDTO dto = new ReportDTO(){Name = obj.Name};
                                UBIK.Module.Reporting.ReportEngine reportEngine = new UBIK.Module.Reporting.ReportEngine();
                                string htmlContent = reportEngine.RenderReport("C:/ReportingTest", "template", dto, "C:\\ReportingTest\\report.pdf");

                                Debugger.Output(this, htmlContent);
                               
                        }
                        Debugger.Output(this, "*** Finished");
                }
        }
       
        public class ReportDTO {
               
                public string Name { get; set; }
        }
}

See also