Skip to content

Commit 605b2fd

Browse files
Use file scoped namespaces
1 parent 9e08aa6 commit 605b2fd

16 files changed

+936
-954
lines changed

src/Umbraco.StorageProviders.AzureBlob.ImageSharp/AzureBlobFileSystemImageCache.cs

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,72 @@
66
using SixLabors.ImageSharp.Web.Resolvers.Azure;
77
using Umbraco.StorageProviders.AzureBlob.IO;
88

9-
namespace Umbraco.StorageProviders.AzureBlob.ImageSharp
9+
namespace Umbraco.StorageProviders.AzureBlob.ImageSharp;
10+
11+
/// <summary>
12+
/// Implements an Azure Blob Storage based cache storing files in a <c>cache</c> subfolder.
13+
/// </summary>
14+
public sealed class AzureBlobFileSystemImageCache : IImageCache
1015
{
16+
private const string CachePath = "cache/";
17+
private BlobContainerClient _container;
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache" /> class.
21+
/// </summary>
22+
/// <param name="options">The options.</param>
23+
/// <exception cref="ArgumentNullException"><paramref name="options" /> is <c>null</c>.</exception>
24+
public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions> options)
25+
: this(AzureBlobFileSystemOptions.MediaFileSystemName, options)
26+
{ }
27+
1128
/// <summary>
12-
/// Implements an Azure Blob Storage based cache storing files in a <c>cache</c> subfolder.
29+
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache"/> class.
1330
/// </summary>
14-
public sealed class AzureBlobFileSystemImageCache : IImageCache
31+
/// <param name="name">The name.</param>
32+
/// <param name="options">The options.</param>
33+
/// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
34+
/// <exception cref="ArgumentNullException"><paramref name="options" /> is <c>null</c>.</exception>
35+
public AzureBlobFileSystemImageCache(string name, IOptionsMonitor<AzureBlobFileSystemOptions> options)
1536
{
16-
private const string CachePath = "cache/";
17-
private BlobContainerClient _container;
37+
ArgumentNullException.ThrowIfNull(name);
38+
ArgumentNullException.ThrowIfNull(options);
1839

19-
/// <summary>
20-
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache" /> class.
21-
/// </summary>
22-
/// <param name="options">The options.</param>
23-
/// <exception cref="ArgumentNullException"><paramref name="options" /> is <c>null</c>.</exception>
24-
public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions> options)
25-
: this(AzureBlobFileSystemOptions.MediaFileSystemName, options)
26-
{ }
40+
var fileSystemOptions = options.Get(name);
41+
_container = new BlobContainerClient(fileSystemOptions.ConnectionString, fileSystemOptions.ContainerName);
2742

28-
/// <summary>
29-
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache"/> class.
30-
/// </summary>
31-
/// <param name="name">The name.</param>
32-
/// <param name="options">The options.</param>
33-
/// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
34-
/// <exception cref="ArgumentNullException"><paramref name="options" /> is <c>null</c>.</exception>
35-
public AzureBlobFileSystemImageCache(string name, IOptionsMonitor<AzureBlobFileSystemOptions> options)
43+
options.OnChange((options, changedName) =>
3644
{
37-
ArgumentNullException.ThrowIfNull(name);
38-
ArgumentNullException.ThrowIfNull(options);
39-
40-
var fileSystemOptions = options.Get(name);
41-
_container = new BlobContainerClient(fileSystemOptions.ConnectionString, fileSystemOptions.ContainerName);
42-
43-
options.OnChange((options, changedName) =>
45+
if (changedName == name)
4446
{
45-
if (changedName == name)
46-
{
47-
_container = new BlobContainerClient(options.ConnectionString, options.ContainerName);
48-
}
49-
});
50-
}
47+
_container = new BlobContainerClient(options.ConnectionString, options.ContainerName);
48+
}
49+
});
50+
}
5151

52-
/// <summary>
53-
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache" /> class.
54-
/// </summary>
55-
/// <param name="blobContainerClient">The blob container client.</param>
56-
/// <exception cref="ArgumentNullException"><paramref name="blobContainerClient" /> is <c>null</c>.</exception>
57-
public AzureBlobFileSystemImageCache(BlobContainerClient blobContainerClient)
58-
=> _container = blobContainerClient ?? throw new ArgumentNullException(nameof(blobContainerClient));
52+
/// <summary>
53+
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache" /> class.
54+
/// </summary>
55+
/// <param name="blobContainerClient">The blob container client.</param>
56+
/// <exception cref="ArgumentNullException"><paramref name="blobContainerClient" /> is <c>null</c>.</exception>
57+
public AzureBlobFileSystemImageCache(BlobContainerClient blobContainerClient)
58+
=> _container = blobContainerClient ?? throw new ArgumentNullException(nameof(blobContainerClient));
5959

60-
/// <inheritdoc />
61-
public async Task<IImageCacheResolver?> GetAsync(string key)
62-
{
63-
var blob = _container.GetBlobClient(CachePath + key);
60+
/// <inheritdoc />
61+
public async Task<IImageCacheResolver?> GetAsync(string key)
62+
{
63+
var blob = _container.GetBlobClient(CachePath + key);
6464

65-
return !await blob.ExistsAsync().ConfigureAwait(false)
66-
? null
67-
: new AzureBlobStorageCacheResolver(blob);
68-
}
65+
return !await blob.ExistsAsync().ConfigureAwait(false)
66+
? null
67+
: new AzureBlobStorageCacheResolver(blob);
68+
}
6969

70-
/// <inheritdoc />
71-
public async Task SetAsync(string key, Stream stream, ImageCacheMetadata metadata)
72-
{
73-
var blob = _container.GetBlobClient(CachePath + key);
70+
/// <inheritdoc />
71+
public async Task SetAsync(string key, Stream stream, ImageCacheMetadata metadata)
72+
{
73+
var blob = _container.GetBlobClient(CachePath + key);
7474

75-
await blob.UploadAsync(stream, metadata: metadata.ToDictionary()).ConfigureAwait(false);
76-
}
75+
await blob.UploadAsync(stream, metadata: metadata.ToDictionary()).ConfigureAwait(false);
7776
}
7877
}

src/Umbraco.StorageProviders.AzureBlob.ImageSharp/DependencyInjection/AddAzureBlobImageSharpCacheExtensions.cs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,40 @@
55
using Umbraco.StorageProviders.AzureBlob.ImageSharp;
66
using Umbraco.StorageProviders.AzureBlob.IO;
77

8-
namespace Umbraco.Cms.Core.DependencyInjection
8+
namespace Umbraco.Cms.Core.DependencyInjection;
9+
10+
/// <summary>
11+
/// Extension methods to help registering Azure Blob Storage image caches for ImageSharp.
12+
/// </summary>
13+
public static class AddAzureBlobImageSharpCacheExtensions
914
{
1015
/// <summary>
11-
/// Extension methods to help registering Azure Blob Storage image caches for ImageSharp.
16+
/// Registers an <see cref="IImageCache" /> configured using the specified <see cref="IAzureBlobFileSystem" />.
1217
/// </summary>
13-
public static class AddAzureBlobImageSharpCacheExtensions
14-
{
15-
/// <summary>
16-
/// Registers an <see cref="IImageCache" /> configured using the specified <see cref="IAzureBlobFileSystem" />.
17-
/// </summary>
18-
/// <param name="builder">The <see cref="IUmbracoBuilder" />.</param>
19-
/// <param name="name">The name of the file system.</param>
20-
/// <returns>
21-
/// The <see cref="IUmbracoBuilder" />.
22-
/// </returns>
23-
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
24-
public static IUmbracoBuilder AddAzureBlobImageSharpCache(this IUmbracoBuilder builder, string name = AzureBlobFileSystemOptions.MediaFileSystemName)
25-
=> builder.AddInternal(name);
18+
/// <param name="builder">The <see cref="IUmbracoBuilder" />.</param>
19+
/// <param name="name">The name of the file system.</param>
20+
/// <returns>
21+
/// The <see cref="IUmbracoBuilder" />.
22+
/// </returns>
23+
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
24+
public static IUmbracoBuilder AddAzureBlobImageSharpCache(this IUmbracoBuilder builder, string name = AzureBlobFileSystemOptions.MediaFileSystemName)
25+
=> builder.AddInternal(name);
2626

27-
/// <summary>
28-
/// Registers an <see cref="IImageCache" /> configured using the specified <see cref="IAzureBlobFileSystem" />.
29-
/// </summary>
30-
/// <param name="builder">The <see cref="IUmbracoBuilder" />.</param>
31-
/// <param name="name">The name of the file system.</param>
32-
/// <returns>
33-
/// The <see cref="IUmbracoBuilder" />.
34-
/// </returns>
35-
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
36-
internal static IUmbracoBuilder AddInternal(this IUmbracoBuilder builder, string name = AzureBlobFileSystemOptions.MediaFileSystemName)
37-
{
38-
ArgumentNullException.ThrowIfNull(builder);
27+
/// <summary>
28+
/// Registers an <see cref="IImageCache" /> configured using the specified <see cref="IAzureBlobFileSystem" />.
29+
/// </summary>
30+
/// <param name="builder">The <see cref="IUmbracoBuilder" />.</param>
31+
/// <param name="name">The name of the file system.</param>
32+
/// <returns>
33+
/// The <see cref="IUmbracoBuilder" />.
34+
/// </returns>
35+
/// <exception cref="System.ArgumentNullException"><paramref name="builder" /> is <c>null</c>.</exception>
36+
internal static IUmbracoBuilder AddInternal(this IUmbracoBuilder builder, string name = AzureBlobFileSystemOptions.MediaFileSystemName)
37+
{
38+
ArgumentNullException.ThrowIfNull(builder);
3939

40-
builder.Services.AddUnique<IImageCache>(provider => new AzureBlobFileSystemImageCache(name, provider.GetRequiredService<IOptionsMonitor<AzureBlobFileSystemOptions>>()));
40+
builder.Services.AddUnique<IImageCache>(provider => new AzureBlobFileSystemImageCache(name, provider.GetRequiredService<IOptionsMonitor<AzureBlobFileSystemOptions>>()));
4141

42-
return builder;
43-
}
42+
return builder;
4443
}
4544
}

src/Umbraco.StorageProviders.AzureBlob/AzureBlobDirectoryContents.cs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,41 @@
33
using Azure.Storage.Blobs.Models;
44
using Microsoft.Extensions.FileProviders;
55

6-
namespace Umbraco.StorageProviders.AzureBlob
6+
namespace Umbraco.StorageProviders.AzureBlob;
7+
8+
/// <summary>
9+
/// Represents a virtual hierarchy of Azure Blob Storage blobs.
10+
/// </summary>
11+
/// <seealso cref="Microsoft.Extensions.FileProviders.IDirectoryContents" />
12+
public sealed class AzureBlobDirectoryContents : IDirectoryContents
713
{
14+
private readonly BlobContainerClient _containerClient;
15+
private readonly IReadOnlyCollection<BlobHierarchyItem> _items;
16+
817
/// <summary>
9-
/// Represents a virtual hierarchy of Azure Blob Storage blobs.
18+
/// Initializes a new instance of the <see cref="AzureBlobDirectoryContents" /> class.
1019
/// </summary>
11-
/// <seealso cref="Microsoft.Extensions.FileProviders.IDirectoryContents" />
12-
public sealed class AzureBlobDirectoryContents : IDirectoryContents
20+
/// <param name="containerClient">The container client.</param>
21+
/// <param name="items">The items.</param>
22+
/// <exception cref="ArgumentNullException"><paramref name="containerClient"/> is <c>null</c>.</exception>
23+
/// <exception cref="ArgumentNullException"><paramref name="items"/> is <c>null</c>.</exception>
24+
public AzureBlobDirectoryContents(BlobContainerClient containerClient, IReadOnlyCollection<BlobHierarchyItem> items)
1325
{
14-
private readonly BlobContainerClient _containerClient;
15-
private readonly IReadOnlyCollection<BlobHierarchyItem> _items;
16-
17-
/// <summary>
18-
/// Initializes a new instance of the <see cref="AzureBlobDirectoryContents" /> class.
19-
/// </summary>
20-
/// <param name="containerClient">The container client.</param>
21-
/// <param name="items">The items.</param>
22-
/// <exception cref="ArgumentNullException"><paramref name="containerClient"/> is <c>null</c>.</exception>
23-
/// <exception cref="ArgumentNullException"><paramref name="items"/> is <c>null</c>.</exception>
24-
public AzureBlobDirectoryContents(BlobContainerClient containerClient, IReadOnlyCollection<BlobHierarchyItem> items)
25-
{
26-
_containerClient = containerClient ?? throw new ArgumentNullException(nameof(containerClient));
27-
_items = items ?? throw new ArgumentNullException(nameof(items));
26+
_containerClient = containerClient ?? throw new ArgumentNullException(nameof(containerClient));
27+
_items = items ?? throw new ArgumentNullException(nameof(items));
2828

29-
Exists = items.Count > 0;
30-
}
29+
Exists = items.Count > 0;
30+
}
3131

32-
/// <inheritdoc />
33-
public bool Exists { get; }
32+
/// <inheritdoc />
33+
public bool Exists { get; }
3434

35-
/// <inheritdoc />
36-
public IEnumerator<IFileInfo> GetEnumerator()
37-
=> _items.Select<BlobHierarchyItem, IFileInfo>(x => x.IsPrefix
38-
? new AzureBlobPrefixInfo(x.Prefix)
39-
: new AzureBlobItemInfo(_containerClient.GetBlobClient(x.Blob.Name), x.Blob.Properties)).GetEnumerator();
35+
/// <inheritdoc />
36+
public IEnumerator<IFileInfo> GetEnumerator()
37+
=> _items.Select<BlobHierarchyItem, IFileInfo>(x => x.IsPrefix
38+
? new AzureBlobPrefixInfo(x.Prefix)
39+
: new AzureBlobItemInfo(_containerClient.GetBlobClient(x.Blob.Name), x.Blob.Properties)).GetEnumerator();
4040

41-
/// <inheritdoc/>
42-
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
43-
}
41+
/// <inheritdoc/>
42+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
4443
}

0 commit comments

Comments
 (0)