Skip to content

Commit 27d2858

Browse files
Initialize and remove redundant check
1 parent 1470979 commit 27d2858

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) James Jackson-South, Jeavon Leopold, and contributors. All rights reserved.
33
// Licensed under the Apache License, Version 2.0.
44
// </copyright>
5-
65
namespace Our.Umbraco.FileSystemProviders.Azure
76
{
87
using System;
@@ -43,7 +42,7 @@ internal class AzureFileSystem : IFileSystem
4342
/// <summary>
4443
/// A list of <see cref="AzureFileSystem"/>.
4544
/// </summary>
46-
private static List<AzureFileSystem> fileSystems = new List<AzureFileSystem>();
45+
private static readonly List<AzureFileSystem> FileSystems = new List<AzureFileSystem>();
4746

4847
/// <summary>
4948
/// The root url.
@@ -153,7 +152,7 @@ public AzureFileSystem GetInstance(string containerName, string rootUrl, string
153152
{
154153
lock (Locker)
155154
{
156-
if (fileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootBlobUrl == rootUrl) == null)
155+
if (FileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootBlobUrl == rootUrl) == null)
157156
{
158157
int max;
159158
if (!int.TryParse(maxDays, out max))
@@ -167,19 +166,11 @@ public AzureFileSystem GetInstance(string containerName, string rootUrl, string
167166
defaultRoute = true;
168167
}
169168

170-
var fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute);
171-
172-
if (fileSystems == null)
173-
{
174-
fileSystems = new List<AzureFileSystem> { fileSystem };
175-
}
176-
else
177-
{
178-
fileSystems.Add(fileSystem);
179-
}
169+
AzureFileSystem fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute);
170+
FileSystems.Add(fileSystem);
180171
}
181172

182-
return fileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootBlobUrl == rootUrl);
173+
return FileSystems.SingleOrDefault(fs => fs.ContainerName == containerName && fs.rootBlobUrl == rootUrl);
183174
}
184175
}
185176

@@ -197,8 +188,8 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
197188

198189
if (!overrideIfExists && exists)
199190
{
200-
InvalidOperationException error = new InvalidOperationException(string.Format("File already exists at {0}", blockBlob.Uri));
201-
this.LogHelper.Error<AzureBlobFileSystem>(string.Format("File already exists at {0}", path), error);
191+
InvalidOperationException error = new InvalidOperationException($"File already exists at {blockBlob.Uri}");
192+
this.LogHelper.Error<AzureBlobFileSystem>($"File already exists at {path}", error);
202193
return;
203194
}
204195

@@ -224,7 +215,7 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
224215
blockBlob.Properties.ContentType = contentType;
225216
}
226217

227-
blockBlob.Properties.CacheControl = string.Format("public, max-age={0}", this.MaxDays * 86400);
218+
blockBlob.Properties.CacheControl = $"public, max-age={this.MaxDays * 86400}";
228219
blockBlob.SetProperties();
229220

230221
if (created == DateTimeOffset.MinValue)
@@ -246,7 +237,7 @@ public void AddFile(string path, Stream stream, bool overrideIfExists)
246237
}
247238
catch (Exception ex)
248239
{
249-
this.LogHelper.Error<AzureBlobFileSystem>(string.Format("Unable to upload file at {0}", path), ex);
240+
this.LogHelper.Error<AzureBlobFileSystem>($"Unable to upload file at {path}", ex);
250241
}
251242
}
252243

@@ -305,7 +296,7 @@ public void DeleteDirectory(string path, bool recursive)
305296
}
306297
catch (Exception ex)
307298
{
308-
this.LogHelper.Error<AzureBlobFileSystem>(string.Format("Unable to delete directory at {0}", path), ex);
299+
this.LogHelper.Error<AzureBlobFileSystem>($"Unable to delete directory at {path}", ex);
309300
}
310301
}
311302

@@ -340,7 +331,7 @@ public void DeleteFile(string path)
340331
}
341332
catch (Exception ex)
342333
{
343-
this.LogHelper.Error<AzureBlobFileSystem>(string.Format("Unable to delete file at {0}", path), ex);
334+
this.LogHelper.Error<AzureBlobFileSystem>($"Unable to delete file at {path}", ex);
344335
}
345336
}
346337

@@ -601,10 +592,10 @@ private string ResolveUrl(string path, bool relative)
601592

602593
if (this.UseDefaultRoute)
603594
{
604-
return string.Format("/{0}/{1}", Constants.DefaultMediaRoute, fixedPath);
595+
return $"/{Constants.DefaultMediaRoute}/{fixedPath}";
605596
}
606597

607-
return string.Format("/{0}/{1}", this.ContainerName, fixedPath);
598+
return $"/{this.ContainerName}/{fixedPath}";
608599
}
609600

610601
/// <summary>

0 commit comments

Comments
 (0)