Back to Devexpress

ICachedReportSourceWebResolver Interface

xtrareports-devexpress-dot-xtrareports-dot-web-dot-webdocumentviewer-da47927e.md

latest5.6 KB
Original Source

ICachedReportSourceWebResolver Interface

Retrieves a CachedReportSourceWeb object associated with the specified report name.

Namespace : DevExpress.XtraReports.Web.WebDocumentViewer

Assembly : DevExpress.XtraReports.v25.2.Web.dll

NuGet Package : DevExpress.Web.Reporting.Common

Declaration

csharp
public interface ICachedReportSourceWebResolver
vb
Public Interface ICachedReportSourceWebResolver

Remarks

When the Web Document Viewer displays a report specified by its name, it can use a ICachedReportSourceWebResolver service to get the CachedReportSourceWeb object that generates a document from a report and caches the document pages.

Implementation

The following code is a custom ICachedReportSourceWebResolver implementation:

csharp
public class CustomCachedReportSourceWebResolver : ICachedReportSourceWebResolver {
  public bool TryGetCachedReportSourceWeb(string reportName, out CachedReportSourceWeb CachedReportSourceWeb) {
      XtraReport report = null;
      if(reportName == "Report1") {
          report = new Report1();
      }
      if(reportName == "Report2") {
          report = new Report2();
      }
      if(reportName == "DocumentMerging") {
          var report1 = new Report1();
          var cachedReportSource1 = new CachedReportSourceWeb(report1);
          cachedReportSource1.CreateDocument();

          var report2 = new Report2();
          var cachedReportSource2 = new CachedReportSourceWeb(report2);
          cachedReportSource2.CreateDocument();

          cachedReportSource1.ModifyDocument(x => {
            x.AddPages(cachedReportSource2.PrintingSystem.Pages);
          }
          CachedReportSourceWeb = cachedReportSource1;
          return true;
      }
      if(report == null) {
          CachedReportSourceWeb = null;
          return false;
      }
      CachedReportSourceWeb = new CachedReportSourceWeb(report);
      return true;
  }
}
vb
Public Class CustomCachedReportSourceWebResolver
    Implements ICachedReportSourceWebResolver

  Public Function TryGetCachedReportSourceWeb(ByVal reportName As String,  ByRef CachedReportSourceWeb As CachedReportSourceWeb) As Boolean
      Dim report As XtraReport = Nothing
      If reportName = "Report1" Then
          report = New Report1()
      End If
      If reportName = "Report2" Then
          report = New Report2()
      End If
      If reportName = "DocumentMerging" Then
          Dim report1 = New Report1()
          Dim cachedReportSource1 = New CachedReportSourceWeb(report1)
          cachedReportSource1.CreateDocument()

          Dim report2 = New Report2()
          Dim cachedReportSource2 = New CachedReportSourceWeb(report2)
          cachedReportSource2.CreateDocument()

          cachedReportSource1.ModifyDocument(Function(x)
              x.AddPages(cachedReportSource2.PrintingSystem.Pages)
          End Function
          CachedReportSourceWeb = cachedReportSource1
          Return True
      End If
      If report Is Nothing Then
          CachedReportSourceWeb = Nothing
          Return False
      End If
      CachedReportSourceWeb = New CachedReportSourceWeb(report)
      Return True
  End Function
End Class

Registration

ASP.NET Web Forms and MVC applications

csharp
using DevExpress.XtraReports.Web.WebDocumentViewer;
//...
void Application_Start(object sender, EventArgs e) {
    DefaultWebDocumentViewerContainer.Register<ICachedReportSourceWebResolver, CustomCachedReportSourceWebResolver>();
}
vb
Imports DevExpress.XtraReports.Web.WebDocumentViewer
'...
Private Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    DefaultWebDocumentViewerContainer.Register(Of ICachedReportSourceWebResolver, CustomCachedReportSourceWebResolver)()
End Sub

ASP.NET Core applications

csharp
using DevExpress.XtraReports.Web.WebDocumentViewer;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSingleton<ICachedReportSourceWebResolver>(new CustomCachedReportSourceWebResolver());

var app = builder.Build();

If the TryGetCachedReportSourceWeb(String, out CachedReportSourceWeb) method returns false , the Document Viewer calls the IWebDocumentViewerReportResolver service.

Note

Review the Open a Report in ASP.NET Core Application help topic for more information.

See Also

ICachedReportSourceWebResolver Members

DevExpress.XtraReports.Web.WebDocumentViewer Namespace