2
2
// Copyright (c) James Jackson-South, Jeavon Leopold, and contributors. All rights reserved.
3
3
// Licensed under the Apache License, Version 2.0.
4
4
// </copyright>
5
-
6
5
namespace Our . Umbraco . FileSystemProviders . Azure
7
6
{
8
7
using System ;
9
8
using System . Collections . Generic ;
9
+ using System . Configuration ;
10
10
using System . IO ;
11
11
12
12
using global ::Umbraco . Core . IO ;
13
- using System . Configuration ;
13
+
14
14
/// <summary>
15
15
/// The azure file system.
16
16
/// </summary>
17
17
public class AzureBlobFileSystem : IFileSystem
18
18
{
19
19
/// <summary>
20
- /// The configuration key for disabling the virtual path provider .
20
+ /// The configuration key for determining the connection string .
21
21
/// </summary>
22
22
private const string ConnectionStringKey = Constants . Configuration . ConnectionStringKey ;
23
23
24
24
/// <summary>
25
- /// The configuration key for disabling the virtual path provider .
25
+ /// The configuration key for determining the container name .
26
26
/// </summary>
27
27
private const string ContainerNameKey = Constants . Configuration . ContainerNameKey ;
28
28
29
29
/// <summary>
30
- /// The configuration key for disabling the virtual path provider .
30
+ /// The configuration key for determining the root url .
31
31
/// </summary>
32
32
private const string RootUrlKey = Constants . Configuration . RootUrlKey ;
33
33
34
34
/// <summary>
35
- /// The configuration key for disabling the virtual path provider .
35
+ /// The configuration key for determining the maximum days to cache values .
36
36
/// </summary>
37
37
private const string MaxDaysKey = Constants . Configuration . MaxDaysKey ;
38
38
39
+ /// <summary>
40
+ /// The configuration key for determining whether the path provider should use the default root.
41
+ /// </summary>
42
+ private const string UseDefaultRootKey = Constants . Configuration . UseDefaultRouteKey ;
43
+
39
44
/// <summary>
40
45
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
41
46
/// </summary>
@@ -61,42 +66,45 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
61
66
}
62
67
63
68
/// <summary>
64
- /// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class from values in web.config through ConfigurationManager.
69
+ /// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class
70
+ /// from values in application settings.
65
71
/// </summary>
66
72
public AzureBlobFileSystem ( )
67
73
{
68
74
69
- string connectionString = ConfigurationManager . AppSettings [ ConnectionStringKey ] as string ;
75
+ string connectionString = ConfigurationManager . AppSettings [ ConnectionStringKey ] ;
70
76
if ( ! string . IsNullOrWhiteSpace ( connectionString ) )
71
77
{
72
- string rootUrl = ConfigurationManager . AppSettings [ RootUrlKey ] as string ;
78
+ string rootUrl = ConfigurationManager . AppSettings [ RootUrlKey ] ;
73
79
if ( string . IsNullOrWhiteSpace ( rootUrl ) )
74
80
{
75
- throw new InvalidOperationException ( "Azure Storage Root URL is not defined in web.config . The " + RootUrlKey + " property was not defined or is empty." ) ;
81
+ throw new InvalidOperationException ( "Azure Storage Root URL is not defined in application settings . The " + RootUrlKey + " property was not defined or is empty." ) ;
76
82
}
77
83
78
- string containerName = ConfigurationManager . AppSettings [ ContainerNameKey ] as string ;
79
-
84
+ string containerName = ConfigurationManager . AppSettings [ ContainerNameKey ] ;
80
85
if ( string . IsNullOrWhiteSpace ( containerName ) )
81
86
{
82
87
containerName = "media" ;
83
88
}
84
89
85
- string maxDays = ConfigurationManager . AppSettings [ MaxDaysKey ] as string ;
86
-
90
+ string maxDays = ConfigurationManager . AppSettings [ MaxDaysKey ] ;
87
91
if ( string . IsNullOrWhiteSpace ( maxDays ) )
88
92
{
89
93
maxDays = "365" ;
90
94
}
91
95
92
- this . FileSystem = AzureFileSystem . GetInstance ( containerName , rootUrl , connectionString , maxDays ) ;
96
+ string useDefaultRoute = ConfigurationManager . AppSettings [ UseDefaultRootKey ] ;
97
+ if ( string . IsNullOrWhiteSpace ( useDefaultRoute ) )
98
+ {
99
+ useDefaultRoute = "true" ;
100
+ }
101
+
102
+ this . FileSystem = AzureFileSystem . GetInstance ( containerName , rootUrl , connectionString , maxDays , useDefaultRoute ) ;
93
103
}
94
104
else
95
105
{
96
- throw new InvalidOperationException ( "Unable to retreive the Azure Storage configuration from web.config . " + ConnectionStringKey + " was not defined or is empty." ) ;
106
+ throw new InvalidOperationException ( "Unable to retrieve the Azure Storage configuration from the application settings . " + ConnectionStringKey + " was not defined or is empty." ) ;
97
107
}
98
-
99
-
100
108
}
101
109
102
110
/// <summary>
0 commit comments