Skip to content

Commit ec61094

Browse files
Merge branch 'refs/heads/pr/28' into develop
2 parents b825f55 + 5116958 commit ec61094

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

src/UmbracoFileSystemProviders.Azure/AzureBlobFileSystem.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,32 @@ namespace Our.Umbraco.FileSystemProviders.Azure
1010
using System.IO;
1111

1212
using global::Umbraco.Core.IO;
13-
13+
using System.Configuration;
1414
/// <summary>
1515
/// The azure file system.
1616
/// </summary>
1717
public class AzureBlobFileSystem : IFileSystem
1818
{
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+
1939
/// <summary>
2040
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
2141
/// </summary>
@@ -40,6 +60,45 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
4060
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute);
4161
}
4262

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+
43102
/// <summary>
44103
/// Gets a singleton instance of the <see cref="AzureFileSystem"/> class.
45104
/// </summary>

src/UmbracoFileSystemProviders.Azure/Constants.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ public static class Configuration
2929
/// The configuration key for enabling the storage emulator.
3030
/// </summary>
3131
public const string UseStorageEmulatorKey = "AzureBlobFileSystem.UseStorageEmulator";
32+
33+
/// <summary>
34+
/// The configuration key for providing the connection string via the web.config
35+
/// </summary>
36+
public const string ConnectionStringKey = "AzureBlobFileSystem.ConnectionString";
37+
38+
/// <summary>
39+
/// The configuration key for providing the Azure Blob Container Name via the web.config
40+
/// </summary>
41+
public const string ContainerNameKey = "AzureBlobFileSystem.ContainerName";
42+
43+
/// <summary>
44+
/// The configuration key for providing the Storage Root URL via the web.config
45+
/// </summary>
46+
public const string RootUrlKey = "AzureBlobFileSystem.RootUrl";
47+
48+
/// <summary>
49+
/// The configuration key for providing the Maximum Days Cache value via the web.config
50+
/// </summary>
51+
public const string MaxDaysKey = "AzureBlobFileSystem.MaxDays";
3252
}
3353
}
3454
}

0 commit comments

Comments
 (0)