Skip to content

Commit be0b923

Browse files
Multiple now works properly.
1 parent 27d2858 commit be0b923

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/UmbracoFileSystemProviders.Azure/AzureBlobFileSystem.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,7 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
6363
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
6464
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
6565
{
66-
bool useDefaultRouteParsed;
67-
int maxDaysParsed;
68-
69-
if (int.TryParse(maxDays, out maxDaysParsed) == false)
70-
{
71-
throw new ArgumentException(string.Format("Argument maxDays with value {0} could be converted from string to int", maxDays));
72-
}
73-
74-
if (bool.TryParse(useDefaultRoute, out useDefaultRouteParsed) == false)
75-
{
76-
throw new ArgumentException(string.Format("Argument useDefaultRoute with value {0} could be converted from string to bool", useDefaultRoute));
77-
}
78-
79-
this.FileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, maxDaysParsed, useDefaultRouteParsed);
66+
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute);
8067
}
8168

8269
/// <summary>
@@ -85,7 +72,6 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
8572
/// </summary>
8673
public AzureBlobFileSystem()
8774
{
88-
8975
string connectionString = ConfigurationManager.AppSettings[ConnectionStringKey];
9076
if (!string.IsNullOrWhiteSpace(connectionString))
9177
{

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ internal class AzureFileSystem : IFileSystem
4545
private static readonly List<AzureFileSystem> FileSystems = new List<AzureFileSystem>();
4646

4747
/// <summary>
48-
/// The root url.
48+
/// The root host url.
4949
/// </summary>
50-
private readonly string rootBlobUrl;
50+
private readonly string rootHostUrl;
51+
52+
/// <summary>
53+
/// The combined root and container url.
54+
/// </summary>
55+
private readonly string rootContainerUrl;
5156

5257
/// <summary>
5358
/// The cloud media blob container.
@@ -94,12 +99,16 @@ internal AzureFileSystem(string containerName, string rootUrl, string connection
9499
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
95100
this.cloudBlobContainer = CreateContainer(cloudBlobClient, containerName, BlobContainerPublicAccessType.Blob);
96101

102+
// First assign a local copy before editing. We use that to track the type.
103+
// TODO: Do we need this? The container should be an identifer.
104+
this.rootHostUrl = rootUrl;
105+
97106
if (!rootUrl.Trim().EndsWith("/"))
98107
{
99108
rootUrl = rootUrl.Trim() + "/";
100109
}
101110

102-
this.rootBlobUrl = rootUrl + containerName + "/";
111+
this.rootContainerUrl = rootUrl + containerName + "/";
103112
this.ContainerName = containerName;
104113
this.MaxDays = maxDays;
105114
this.UseDefaultRoute = useDefaultRoute;
@@ -148,11 +157,13 @@ internal AzureFileSystem(string containerName, string rootUrl, string connection
148157
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
149158
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
150159
/// <returns>The <see cref="AzureFileSystem"/></returns>
151-
public AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
160+
public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
152161
{
153162
lock (Locker)
154163
{
155-
if (FileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootBlobUrl == rootUrl) == null)
164+
AzureFileSystem fileSystem = FileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootHostUrl == rootUrl);
165+
166+
if (fileSystem == null)
156167
{
157168
int max;
158169
if (!int.TryParse(maxDays, out max))
@@ -166,11 +177,11 @@ public AzureFileSystem GetInstance(string containerName, string rootUrl, string
166177
defaultRoute = true;
167178
}
168179

169-
AzureFileSystem fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute);
180+
fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute);
170181
FileSystems.Add(fileSystem);
171182
}
172183

173-
return FileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootBlobUrl == rootUrl);
184+
return fileSystem;
174185
}
175186
}
176187

@@ -418,14 +429,14 @@ public IEnumerable<string> GetFiles(string path, string filter)
418429

419430
if (filter.Equals("*.*", StringComparison.InvariantCultureIgnoreCase))
420431
{
421-
return url.Substring(this.rootBlobUrl.Length);
432+
return url.Substring(this.rootContainerUrl.Length);
422433
}
423434

424435
// Filter by name.
425436
filter = filter.TrimStart('*');
426437
if (url.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) > -1)
427438
{
428-
return url.Substring(this.rootBlobUrl.Length);
439+
return url.Substring(this.rootContainerUrl.Length);
429440
}
430441

431442
return null;
@@ -583,7 +594,7 @@ private string ResolveUrl(string path, bool relative)
583594
// First create the full url
584595
string fixedPath = this.FixPath(path);
585596

586-
Uri url = new Uri(new Uri(this.rootBlobUrl, UriKind.Absolute), fixedPath);
597+
Uri url = new Uri(new Uri(this.rootContainerUrl, UriKind.Absolute), fixedPath);
587598

588599
if (!relative)
589600
{
@@ -619,9 +630,9 @@ private string FixPath(string path)
619630
}
620631

621632
// Strip root url
622-
if (path.StartsWith(this.rootBlobUrl, StringComparison.InvariantCultureIgnoreCase))
633+
if (path.StartsWith(this.rootContainerUrl, StringComparison.InvariantCultureIgnoreCase))
623634
{
624-
path = path.Substring(this.rootBlobUrl.Length);
635+
path = path.Substring(this.rootContainerUrl.Length);
625636
}
626637

627638
// Strip default route

0 commit comments

Comments
 (0)