-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathCustomSharedDataSourceResolver.cs
35 lines (28 loc) · 1.38 KB
/
CustomSharedDataSourceResolver.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
namespace SqlDefinitionStorageExample
{
using Microsoft.EntityFrameworkCore;
using SqlDefinitionStorageExample.EFCore;
using System.IO;
using System.Linq;
using Telerik.WebReportDesigner.Services;
using Data = Telerik.Reporting.Processing.Data;
class CustomSharedDataSourceResolver : Data.ISharedDataSourceResolver
{
readonly string _root = "Shared Data Sources";
Telerik.Reporting.DataSource Data.ISharedDataSourceResolver.Resolve(string sharedDataSourcePath)
{
if (!sharedDataSourcePath.Contains($"{_root}\\"))
{
sharedDataSourcePath = $"{_root}\\{sharedDataSourcePath}";
}
sharedDataSourcePath = sharedDataSourcePath.Replace("/", "\\");
var optionsBuilder = new DbContextOptionsBuilder<SqlDefinitionStorageContext>();
// It is necessary to initialize a new dbContent because this code will be executed in a new thread
using SqlDefinitionStorageContext dbContext = new(optionsBuilder.Options);
var sds = dbContext.Resources.FirstOrDefault(m => m.Uri == sharedDataSourcePath) ?? throw new ResourceNotFoundException();
using var ms = new MemoryStream(sds.Bytes);
return (Telerik.Reporting.DataSource)new Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
.Deserialize(ms);
}
}
}