-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExternalFileSystemStorageProvider.cs
63 lines (48 loc) · 2.41 KB
/
ExternalFileSystemStorageProvider.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
using System;
using System.IO;
using Telerik.Sitefinity.BlobStorage;
using Telerik.Sitefinity.Modules.Libraries.BlobStorage;
namespace SitefinityWebApp.Helpers {
public class ExternalFileSystemStorageProvider : FileSystemStorageProvider, IExternalBlobStorageProvider {
protected override void InitializeStorage(System.Collections.Specialized.NameValueCollection config) {
base.InitializeStorage(config);
var url = string.Concat(Telerik.Sitefinity.Services.SystemManager.RootUrl, config["rootUrl"]);
this.rootUrl = url;
if (this.rootUrl.IsNullOrEmpty()) {
this.rootUrl = Telerik.Sitefinity.Services.SystemManager.RootUrl;
if (this.StorageFolder.StartsWith(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, StringComparison.OrdinalIgnoreCase)) {
var pathFromRoot = this.StorageFolder.Substring(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath.Length);
pathFromRoot.Replace('\\', '/');
this.rootUrl += pathFromRoot;
}
}
}
public void Copy(IBlobContentLocation source, IBlobContentLocation destination) {
File.Copy(this.GetFilePath(source), this.GetFilePath(destination));
}
public string GetItemUrl(IBlobContentLocation content) {
return string.Concat(this.rootUrl, "/", content.FilePath);
}
public IBlobProperties GetProperties(IBlobContentLocation location) {
return null;
}
public void Move(IBlobContentLocation source, IBlobContentLocation destination) {
File.Move(this.GetFilePath(source), this.GetFilePath(destination));
}
public void SetProperties(IBlobContentLocation location, IBlobProperties properties) {
}
public override Stream GetUploadStream(IBlobContent content) {
EnsureFilePath(content);
return base.GetUploadStream(content);
}
protected override string GetFilePath(IBlobContentLocation location) {
return Path.Combine(this.StorageFolder, location.FilePath);
}
private void EnsureFilePath(IBlobContentLocation location) {
FileInfo file = new FileInfo(this.GetFilePath(location));
if (!file.Directory.Exists)
file.Directory.Create();
}
private string rootUrl;
}
}