Infragistics (R) NetAdvantage(R) Reporting
How to Customize Report Uri Resolution
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic shows you how to customize how a defined Uri resolves itself.

In this topic

This topic contains the following sections:


Changing How a Report is Loaded at Run-Time

Introduction

Occasionally, you may need to customize how reports are loaded at run-time. The Report Uri Resolver allows you to anticipate the Report Viewer default resolution and implement your own loading method.

When rendering a report, the engine executes all registered Uri Resolvers allowing you to customize how the report loads. A Report Uri Resolver class implements the IReportUriResolver interface, which implements the Resolve method invoked by the engine when trying to load a report.

Overview

This topic takes you step-by-step through the process of implementing a Report Uri Resolver. The following is a conceptual overview of the process:

1. Add a Report Uri Resolver. 
2. Code the Resolve method to load a report.
3. (Conditional) Add Resolver to Report Service Engine.

Steps

The following steps demonstrate how to add a Report Uri Resolver.

Step

Description

1. Add a Report Uri Resolver

For .NET projects, you can create a Report Uri Resolver using the Infragistics Report Uri Resolver template.

To create a new Report Uri Resolver:

a. Solution Explorer: right-click your project and select Add > New Item.

b. Visual C#: in the Installed Templates frame, click and select Infragistics > Reporting > Infragistics Report Uri Resolver.

c. If necessary, you can modify the Report Uri Resolver’s Name in the text box.

d. Click Add.

The Infragistics Report Uri Resolver template creates a new class file and adds all required references for implementing a Report Uri Resolver.

In C#:

using System;
using Infragistics.Reports;
namespace MyAssemblyWithUriResolvers1
{
    [ReportUriResolverExport]
    public class ReportUriResolver1 : IReportUriResolver
    {
        public void Resolve(Uri reportUri, Action<UriResolverData> result)
        {
            // TODO: Add report load logic based on the reportUri parameter.
            // if (reportUri.Equals(<<Some Report URI>>))
            // {
            //     Stream reportStream = <<Get Report stream>>
            //     Assembly reportAssembly = <<Get Report associated assembly (if any) >>
            //     result.Invoke(new UriResolverData(reportStream, reportAssembly));      
            // }
            // else
            // {      
            //     // Ignore this resolver.      
            //     result.Invoke(null);
            // }            
            throw new NotImplementedException();
        }
    }
}
Note: The class implementing the IReportUriResolver interface defines only one method by default. The engine invokes this method (Resolve) when requesting a report rendering.

Note: The class implementing the IReportUriResolver interface has a ReportUriResolverExport attribute. NetAdvantage Reporting uses the Managed Extensibility Framework (MEF) as a way to compose all the pieces required to create a report.
Note: The user is responsible for disposing the report Stream or any other resources used in this method.
2. Code the Resolve method to load a report

The following are the parameters used in the Resolve method:

  • The first parameter in the Resolve method (i.e., Uri reportUri) retrieves the specified definition Uri.
  • The second parameter in the Resolve method (i.e., Action<UriResolverData> result) specifies the callback method the engine executes to load the report.

Report Uri Resolver Example

Description

Below you can see how to use the IReportUriResolver interface and its Resolve method to map a specified definition Uri to a local path at run-time. If the resolver is unable to load the report (e.g., provider returns null), the engine will continue executing other resolvers if any, or fallback to its default resolution method.

Code

The Infragistics Report Uri Resolver template creates a new class file and adds all required references.

In C#:


using System; using System.IO; using Infragistics.Reports; namespace Infragistics.Reports.Samples.Resolvers { [ReportUriResolverExport] public class ReportUriResolver1 : IReportUriResolver { const string ResolverPrefix = "file://localfolder/CustomerList.igr"; public void Resolve(Uri reportUri, Action<UriResolverData> result) { UriResolverData resultUri = null; // Recognize LocalPathUri if (reportUri.ToString().StartsWith(ResolverPrefix)) { // Map uri to local path according to thread's culture string localReportFolderPath = @"C:\MyReportLibrary\CustomersList.igr"; using (var reportStream = new FileStream(localReportFolderPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { resultUri = new UriResolverData(reportStream, null);
result.Invoke(resultUri);
} } } } }

The second parameter of the UriResolverData object is an alternate way of specify additional runtime assemblies.

3. (Conditional) Add Resolver to Report Service Engine

Every time the engine receives a rendering request it starts executing registered Uri Resolvers to check if any of them are able to load the specified Uri. This allows you to specify the conditions and patterns in which each Uri Resolver applies, or does not apply and reverts to its default resolution method. There is not a specific order in which Uri resolvers execute since the mechanism relies on how these are loaded by MEF.

You can also add assemblies (containing Uri Resolvers) to look in, by adding them in your configuration file as shown in the following code (e.g., a web project’s Web.config).

<configuration>
  <configSections>
    <section name="infragistics.reports" type="Infragistics.Reports.ReportsConfigurationSection, InfragisticsWPF4.Reports.Client.v12.1"/>
  </configSections>

 <infragistics.reports>
    <reportServercleanupIntervalInMinutes="10" timeoutInMinutes="10" includeExceptionDetail="true"/>
      <!-- Add more assemblies to look up for Report Uri Resolvers -->
    <runtimeAssemblies>
        <add assembly="MyAssemblyWithUriResolvers1"/>
        <add assembly="MyAssemblyWithUriResolvers2"/>
    </runtimeAssemblies>
  </infragistics.reports>
</configuration> 

Given that this procedure only runs once over the life of the application, its overall impact on performance is negligible.

Note: Setting a valid Action<UriResolverData> in the result parameter of the resolve method will stop the search. If none of the registered Uri Resolvers are able to load the report, it will fallback to its default resolution mechanism.


Related Content

Topics

The following topics provide additional information related to this topic.

Topic

Purpose

This topic provides an overview of how to change your report’s data source at run-time.

This topic provides an overview of how the IReportDataSourceProvider interface allows you to change your report’s data source at run-time.

How to Change the Connection String at Run-Time This topic explains how to change the connection string of a report's data source ar run-time using the IReportDbConnectionProvider interface.

Samples

The following samples provide additional information related to this topic.

Sample

Purpose

Change How a Report is Loaded at Run-Time

This sample shows a report definition being loaded from a file located in the file system.



©2012. All Rights Reserved.