-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathCustomReportSourceResolver.cs
40 lines (33 loc) · 1.34 KB
/
CustomReportSourceResolver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using SqlDefinitionStorageExample.EFCore;
using SqlDefinitionStorageExample.EFCore.Models;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Telerik.Reporting;
using Telerik.Reporting.Services;
namespace SqlDefinitionStorageExample
{
public class CustomReportSourceResolver : IReportSourceResolver
{
private SqlDefinitionStorageContext _dbContext { get; }
public CustomReportSourceResolver(SqlDefinitionStorageContext context) {
_dbContext = context;
}
public ReportSource Resolve(string uri, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues)
{
var reportPackager = new ReportPackager();
if (!uri.Contains("Reports\\"))
{
uri = $"Reports\\{uri}";
}
var report = _dbContext.Resources.FirstOrDefault(r => r.Uri == uri.Replace("/", "\\")) ?? throw new FileNotFoundException();
MemoryStream stream = new(report.Bytes);
Telerik.Reporting.Report reportDocument = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(stream);
var instanceReportSource = new InstanceReportSource
{
ReportDocument = reportDocument
};
return instanceReportSource;
}
}
}