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