-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathCustomDefinitionStorage.cs
66 lines (50 loc) · 2.41 KB
/
CustomDefinitionStorage.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using SqlDefinitionStorageExample.EFCore;
using System.Collections.Generic;
using System.Threading.Tasks;
using Telerik.WebReportDesigner.Services;
using Telerik.WebReportDesigner.Services.Models;
using System;
namespace SqlDefinitionStorageExample
{
public class CustomDefinitionStorage : ResourceStorageBase, IDefinitionStorage, IAssetsStorage
{
public CustomDefinitionStorage(SqlDefinitionStorageContext dbContext, string rootFolder = "Reports" ) : base(dbContext, rootFolder)
{
}
public new Task<ResourceFolderModel> CreateFolderAsync(CreateFolderModel model)
{
if(model.Name == Root)
{
throw new Exception($"Cannot name folder as base folder - '{Root}'");
}
if (string.IsNullOrEmpty(model.ParentUri))
{
model.ParentUri = Root;
}
return base.CreateFolderAsync(model);
}
public new Task<ResourceFileModel> SaveAsync(SaveResourceModel model, byte[] resource)
{
model.ParentUri = PrepareResourceUri(model.ParentUri);
return base.SaveAsync(model, resource);
}
public new Task<ResourceFolderModel> GetFolderAsync(string uri) => base.GetFolderAsync(PrepareResourceUri(uri));
public new Task DeleteAsync(string uri) => base.DeleteAsync(PrepareResourceUri(uri));
public new Task<IEnumerable<ResourceModelBase>> GetFolderContentsAsync(string uri) => base.GetFolderContentsAsync(PrepareResourceUri(uri));
Task IAssetsStorage.DeleteFolderAsync(string uri) => DeleteFolderAsync(PrepareResourceUri(uri));
Task<byte[]> IAssetsStorage.GetAsync(string resourceName) => GetAsync(PrepareResourceUri(resourceName));
Task<ResourceFileModel> IAssetsStorage.GetModelAsync(string uri) => GetModelAsync(PrepareResourceUri(uri));
Task<ResourceFileModel> IAssetsStorage.RenameAsync(RenameResourceModel model) => RenameAsync(model);
Task<ResourceFolderModel> IAssetsStorage.RenameFolderAsync(RenameFolderModel model) => RenameFolderAsync(model);
protected string PrepareResourceUri(string uri)
{
if (string.IsNullOrEmpty(uri))
{
return Root;
}
uri = uri.Replace("/", "\\");
uri = uri.Contains($"{Root}\\") ? uri : $"{Root}\\{uri}";
return uri;
}
}
}