Skip to content

Commit e1dbd2e

Browse files
Allow for multiple UmbracoFileSystemProviders.Azure instances #52
1 parent db4b093 commit e1dbd2e

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/UmbracoFileSystemProviders.Azure/AzureBlobFileSystem.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,20 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
3939
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
4040
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
4141
{
42-
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute);
42+
bool useDefaultRouteParsed;
43+
int maxDaysParsed;
44+
45+
if (int.TryParse(maxDays, out maxDaysParsed) == false)
46+
{
47+
throw new ArgumentException(string.Format("Argument maxDays with value {0} could be converted from string to int", maxDays));
48+
}
49+
50+
if (bool.TryParse(useDefaultRoute, out useDefaultRouteParsed) == false)
51+
{
52+
throw new ArgumentException(string.Format("Argument useDefaultRoute with value {0} could be converted from string to bool", useDefaultRoute));
53+
}
54+
55+
this.FileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, maxDaysParsed, useDefaultRouteParsed);
4356
}
4457

4558
/// <summary>

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ internal class AzureFileSystem : IFileSystem
4848
private static readonly object Locker = new object();
4949

5050
/// <summary>
51-
/// The singleton instance of <see cref="AzureFileSystem"/>.
51+
/// A list of <see cref="AzureFileSystem"/>.
5252
/// </summary>
53-
private static AzureFileSystem fileSystem;
53+
private static List<AzureFileSystem> fileSystems;
5454

5555
/// <summary>
5656
/// The root url.
@@ -73,7 +73,7 @@ internal class AzureFileSystem : IFileSystem
7373
/// <exception cref="ArgumentNullException">
7474
/// Thrown if <paramref name="containerName"/> is null or whitespace.
7575
/// </exception>
76-
private AzureFileSystem(string containerName, string rootUrl, string connectionString, int maxDays, bool useDefaultRoute)
76+
internal AzureFileSystem(string containerName, string rootUrl, string connectionString, int maxDays, bool useDefaultRoute)
7777
{
7878
if (string.IsNullOrWhiteSpace(containerName))
7979
{
@@ -156,11 +156,11 @@ private AzureFileSystem(string containerName, string rootUrl, string connectionS
156156
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
157157
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
158158
/// <returns>The <see cref="AzureFileSystem"/></returns>
159-
public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
159+
public AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
160160
{
161161
lock (Locker)
162162
{
163-
if (fileSystem == null)
163+
if (fileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootUrl == rootUrl) == null)
164164
{
165165
int max;
166166
if (!int.TryParse(maxDays, out max))
@@ -174,10 +174,19 @@ public static AzureFileSystem GetInstance(string containerName, string rootUrl,
174174
defaultRoute = true;
175175
}
176176

177-
fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute);
177+
var fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute);
178+
179+
if (fileSystems == null)
180+
{
181+
fileSystems = new List<AzureFileSystem> { fileSystem };
182+
}
183+
else
184+
{
185+
fileSystems.Add(fileSystem);
186+
}
178187
}
179188

180-
return fileSystem;
189+
return fileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootUrl == rootUrl);
181190
}
182191
}
183192

0 commit comments

Comments
 (0)