@@ -10,12 +10,32 @@ namespace Our.Umbraco.FileSystemProviders.Azure
10
10
using System . IO ;
11
11
12
12
using global ::Umbraco . Core . IO ;
13
-
13
+ using System . Configuration ;
14
14
/// <summary>
15
15
/// The azure file system.
16
16
/// </summary>
17
17
public class AzureBlobFileSystem : IFileSystem
18
18
{
19
+ /// <summary>
20
+ /// The configuration key for disabling the virtual path provider.
21
+ /// </summary>
22
+ private const string ConnectionStringKey = Constants . Configuration . ConnectionStringKey ;
23
+
24
+ /// <summary>
25
+ /// The configuration key for disabling the virtual path provider.
26
+ /// </summary>
27
+ private const string ContainerNameKey = Constants . Configuration . ContainerNameKey ;
28
+
29
+ /// <summary>
30
+ /// The configuration key for disabling the virtual path provider.
31
+ /// </summary>
32
+ private const string RootUrlKey = Constants . Configuration . RootUrlKey ;
33
+
34
+ /// <summary>
35
+ /// The configuration key for disabling the virtual path provider.
36
+ /// </summary>
37
+ private const string MaxDaysKey = Constants . Configuration . MaxDaysKey ;
38
+
19
39
/// <summary>
20
40
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
21
41
/// </summary>
@@ -40,6 +60,45 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
40
60
this . FileSystem = AzureFileSystem . GetInstance ( containerName , rootUrl , connectionString , maxDays , useDefaultRoute ) ;
41
61
}
42
62
63
+ /// <summary>
64
+ /// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class from values in web.config through ConfigurationManager.
65
+ /// </summary>
66
+ public AzureBlobFileSystem ( )
67
+ {
68
+
69
+ string connectionString = ConfigurationManager . AppSettings [ ConnectionStringKey ] as string ;
70
+ if ( ! string . IsNullOrWhiteSpace ( connectionString ) )
71
+ {
72
+ string rootUrl = ConfigurationManager . AppSettings [ RootUrlKey ] as string ;
73
+ if ( string . IsNullOrWhiteSpace ( rootUrl ) )
74
+ {
75
+ throw new InvalidOperationException ( "Azure Storage Root URL is not defined in web.config. The " + RootUrlKey + " property was not defined or is empty." ) ;
76
+ }
77
+
78
+ string containerName = ConfigurationManager . AppSettings [ ContainerNameKey ] as string ;
79
+
80
+ if ( string . IsNullOrWhiteSpace ( containerName ) )
81
+ {
82
+ containerName = "media" ;
83
+ }
84
+
85
+ string maxDays = ConfigurationManager . AppSettings [ MaxDaysKey ] as string ;
86
+
87
+ if ( string . IsNullOrWhiteSpace ( maxDays ) )
88
+ {
89
+ maxDays = "365" ;
90
+ }
91
+
92
+ this . FileSystem = AzureFileSystem . GetInstance ( containerName , rootUrl , connectionString , maxDays ) ;
93
+ }
94
+ else
95
+ {
96
+ throw new InvalidOperationException ( "Unable to retreive the Azure Storage configuration from web.config. " + ConnectionStringKey + " was not defined or is empty." ) ;
97
+ }
98
+
99
+
100
+ }
101
+
43
102
/// <summary>
44
103
/// Gets a singleton instance of the <see cref="AzureFileSystem"/> class.
45
104
/// </summary>
0 commit comments