How to use CustomReportResolver for multiple reports

2 Answers 85 Views
DataSources Report Designer (standalone)
Amr
Top achievements
Rank 1
Iron
Amr asked on 17 Aug 2023, 09:19 AM | edited on 19 Aug 2023, 02:08 AM

Hi support team,

Currently I have 3 reports called A, B, C with format *.trdp

I used CustomReportResolver to bind datasource for these reports. The problem is I have to use if else condition to know which report is A or B or C to get and bind correct data to the report. Imagine I have 100 reports it will be nightmare for me.

Do we have any way to resolve this or any way to get data source at run time for Standalone Report except the way I described above ?

NOTE: Before I used Visual Studio Report Designer and use NeedDataSource event in each report to get data for them now I have this issue when migrate to Standalone Report Designer.

Example Code:

public ReportSource Resolve(string reportId, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues)
{
    var reportPath = Path.Combine(this.ReportsPath, reportId);
    var reportPackager = new ReportPackager();

    Report report = null;
    using (var sourceStream = File.OpenRead(reportPath))
    {
        report = (Report)reportPackager.Unpackage(sourceStream);
    }

    if (reportId == "A")
    {
        if (operationOrigin == OperationOrigin.GenerateReportDocument)
        {
            report.DataSource = GetDataForReportA();
        }        
    }
  else if (reportId == "B")
    {
        if (operationOrigin == OperationOrigin.GenerateReportDocument)
        {
            report.DataSource = GetDataForReportB();
        }        
    }
else if (reportId == "C")
    {
        if (operationOrigin == OperationOrigin.GenerateReportDocument)
        {
            report.DataSource = GetDataForReportC();
        }        
    }

    return new InstanceReportSource
    {
        ReportDocument = report
    };
}


Thanks

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 22 Aug 2023, 08:43 AM

Hi Amr,

Thank you for the provided information!

You may use the corresponding method for each report in an ObjectDataSource component, then you won't need to make any "if" checks, every report will have the data method it uses defined in the report definition. You likely won't even need a custom resolver after this change.

Please visit the following articles for more information on how to use this component:

Hope this helps, let me know if you have any additional questions.

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
0
Amr
Top achievements
Rank 1
Iron
answered on 23 Aug 2023, 08:13 AM | edited on 23 Aug 2023, 08:38 AM

Hi Dimitar,

I tried to load bind ObjectDataSource and the step Choose a Business Object is empty.

I tried to archive in many ways but still no luck

- Updated report designer configuration (file name is Telerik.ReportDesigner.Net.dll.config):


- also configured in appsettings.json file

- I did try to copy all files to the same folder

-> The result is still empty list at the step Choose a business object

Could you tell me how to load a business object for ObjectDataSource?

 

Thanks.

Dimitar
Telerik team
commented on 25 Aug 2023, 02:37 PM

Hi Amr,

Thank you for the images!

It appears that you have correctly followed the instructions which suggests that the problem might be with the assembly. What target framework did you build the assembly for? Could you attach it so that I can test it locally?

You may use the Fuslogvw.exe (Assembly Binding Log Viewer) - .NET Framework | Microsoft Learn tool to see if the designer is trying to load the assembly and if so, why it is unsuccessful.

For further assistance, please send me the assembly.

Amr
Top achievements
Rank 1
Iron
commented on 28 Aug 2023, 01:51 AM

hi Dimitar,

I worked on .Net 6.

Now I understand that "Choose a Business Object" only works if we open Telerik.ReportDesigner.Net.exe (1) then open the report (2) from this app. It will not work if I open the report (2) directly.

 To make it work. Currently, I have to do the steps: copy assembly, appsettings.json and Telerik.ReportDesigner.Net.exe files at the same place and have to load report by using Telerik.ReportDesigner.Net.exe. This approach is not good because you can imagine that I work on many projects it will be very take time.

I see the easiest way that open report directly from Visual Studio and Business Object will be loaded based on appsettings.json. (as picture below)

Do we have any way to open the report directly from the project (inside Visual Studio) and it can load all assemblies based on appsettings.json?

 

Thanks

 

Dimitar
Telerik team
commented on 30 Aug 2023, 12:16 PM

Hi Amir,

That is because when you open the report by double-clicking it or from the Visual Studio application, it will open it with the default Standalone Report Designer exe, located at the following path:

C:\Program Files (x86)\Progress\Telerik Reporting <Release>\Report Designer

In order to have the reports opened with the .NET Standalone Report Designer instead, you need to file your system's file associations so that TRDP/TRDX are opened with the Telerik.ReportDesigner.Net.exe by default.

Tags
DataSources Report Designer (standalone)
Asked by
Amr
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Amr
Top achievements
Rank 1
Iron
Share this question
or