-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19dcad7
commit b9b9f9a
Showing
14 changed files
with
630 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
GuildWarsPartySearch/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using GuildWarsPartySearch.Server.Options; | ||
using GuildWarsPartySearch.Server.Services.Azure; | ||
using Microsoft.Extensions.Options; | ||
using System.Core.Extensions; | ||
|
||
namespace GuildWarsPartySearch.Server.Extensions; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddSingletonTableClient<TOptions>(this IServiceCollection services) | ||
where TOptions : class, IAzureTableStorageOptions, new() | ||
{ | ||
services.ThrowIfNull() | ||
.AddSingleton(sp => | ||
{ | ||
var storageOptions = sp.GetRequiredService<IOptions<StorageAccountOptions>>(); | ||
var clientOptions = sp.GetRequiredService<IOptions<TOptions>>(); | ||
var logger = sp.GetRequiredService<ILogger<NamedTableClient<TOptions>>>(); | ||
return new NamedTableClient<TOptions>(logger, storageOptions.Value.ConnectionString!, clientOptions.Value.TableName); | ||
}); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddScopedTableClient<TOptions>(this IServiceCollection services) | ||
where TOptions : class, IAzureTableStorageOptions, new() | ||
{ | ||
services.ThrowIfNull() | ||
.AddScoped(sp => | ||
{ | ||
var storageOptions = sp.GetRequiredService<IOptions<StorageAccountOptions>>(); | ||
var clientOptions = sp.GetRequiredService<IOptions<TOptions>>(); | ||
var logger = sp.GetRequiredService<ILogger<NamedTableClient<TOptions>>>(); | ||
return new NamedTableClient<TOptions>(logger, storageOptions.Value.ConnectionString!, clientOptions.Value.TableName); | ||
}); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddSingletonBlobContainerClient<TOptions>(this IServiceCollection services) | ||
where TOptions : class, IAzureBlobStorageOptions, new() | ||
{ | ||
services.ThrowIfNull() | ||
.AddSingleton(sp => | ||
{ | ||
var storageOptions = sp.GetRequiredService<IOptions<StorageAccountOptions>>(); | ||
var clientOptions = sp.GetRequiredService<IOptions<TOptions>>(); | ||
return new NamedBlobContainerClient<TOptions>(storageOptions.Value.ConnectionString!, clientOptions.Value.ContainerName); | ||
}); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddScopedBlobContainerClient<TOptions>(this IServiceCollection services) | ||
where TOptions : class, IAzureBlobStorageOptions, new() | ||
{ | ||
services.ThrowIfNull() | ||
.AddScoped(sp => | ||
{ | ||
var storageOptions = sp.GetRequiredService<IOptions<StorageAccountOptions>>(); | ||
var clientOptions = sp.GetRequiredService<IOptions<TOptions>>(); | ||
return new NamedBlobContainerClient<TOptions>(storageOptions.Value.ConnectionString!, clientOptions.Value.ContainerName); | ||
}); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public sealed class ContentOptions | ||
public sealed class ContentOptions : IAzureBlobStorageOptions | ||
{ | ||
public TimeSpan UpdateFrequency { get; set; } = TimeSpan.FromMinutes(5); | ||
public string StagingFolder { get; set; } = "Content"; | ||
public string ContainerName { get; set; } = default!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public interface IAzureBlobStorageOptions | ||
{ | ||
string ContainerName { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public interface IAzureTableStorageOptions | ||
{ | ||
string TableName { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace GuildWarsPartySearch.Server.Options; | ||
|
||
public class PartySearchTableOptions : IAzureTableStorageOptions | ||
{ | ||
public string TableName { get; set; } = default!; | ||
} |
35 changes: 35 additions & 0 deletions
35
GuildWarsPartySearch/Services/Azure/InterceptingAsyncPageable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Azure; | ||
|
||
namespace GuildWarsPartySearch.Server.Services.Azure; | ||
|
||
public class InterceptingAsyncPageable<T> : AsyncPageable<T> where T : notnull | ||
{ | ||
private readonly Action<Page<T>> interceptPage; | ||
private readonly Action interceptSuccess; | ||
private readonly AsyncPageable<T> originalPageable; | ||
|
||
public InterceptingAsyncPageable(AsyncPageable<T> originalPageable, Action<Page<T>> interceptPage, Action interceptSuccess) | ||
{ | ||
this.originalPageable = originalPageable; | ||
this.interceptPage = interceptPage; | ||
this.interceptSuccess = interceptSuccess; | ||
} | ||
|
||
public override async IAsyncEnumerable<Page<T>> AsPages(string? continuationToken = null, int? pageSizeHint = null) | ||
{ | ||
await foreach (var page in this.originalPageable.AsPages(continuationToken, pageSizeHint)) | ||
{ | ||
this.interceptPage(page); | ||
yield return page; | ||
} | ||
} | ||
|
||
public async override IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default) | ||
{ | ||
await foreach(var item in this.originalPageable) | ||
{ | ||
this.interceptSuccess(); | ||
yield return item; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
GuildWarsPartySearch/Services/Azure/InterceptingPageable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Azure; | ||
|
||
namespace GuildWarsPartySearch.Server.Services.Azure; | ||
|
||
public sealed class InterceptingPageable<T> : Pageable<T> where T: notnull | ||
{ | ||
private readonly Action<Page<T>> interceptPage; | ||
private readonly Action interceptSuccess; | ||
private readonly Pageable<T> originalPageable; | ||
|
||
public InterceptingPageable(Pageable<T> originalPageable, Action<Page<T>> interceptPage, Action interceptSuccess) | ||
{ | ||
this.originalPageable = originalPageable; | ||
this.interceptPage = interceptPage; | ||
this.interceptSuccess = interceptSuccess; | ||
} | ||
|
||
public override IEnumerable<Page<T>> AsPages(string? continuationToken = null, int? pageSizeHint = null) | ||
{ | ||
foreach (var page in this.originalPageable.AsPages(continuationToken, pageSizeHint)) | ||
{ | ||
this.interceptPage(page); | ||
yield return page; | ||
} | ||
} | ||
|
||
public override IEnumerator<T> GetEnumerator() | ||
{ | ||
foreach (var item in this.originalPageable) | ||
{ | ||
this.interceptSuccess(); | ||
yield return item; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
GuildWarsPartySearch/Services/Azure/NamedBlobContainerClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Azure; | ||
using Azure.Core; | ||
using Azure.Storage; | ||
using Azure.Storage.Blobs; | ||
using Azure.Storage.Blobs.Models; | ||
using GuildWarsPartySearch.Server.Options; | ||
|
||
namespace GuildWarsPartySearch.Server.Services.Azure; | ||
|
||
public class NamedBlobContainerClient<TOptions> : BlobContainerClient | ||
where TOptions : IAzureBlobStorageOptions | ||
{ | ||
public NamedBlobContainerClient(string connectionString, string blobContainerName) : base(connectionString, blobContainerName) | ||
{ | ||
} | ||
|
||
public NamedBlobContainerClient(Uri blobContainerUri, BlobClientOptions? options = null) : base(blobContainerUri, options) | ||
{ | ||
} | ||
|
||
public NamedBlobContainerClient(string connectionString, string blobContainerName, BlobClientOptions options) : base(connectionString, blobContainerName, options) | ||
{ | ||
} | ||
|
||
public NamedBlobContainerClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions? options = null) : base(blobContainerUri, credential, options) | ||
{ | ||
} | ||
|
||
public NamedBlobContainerClient(Uri blobContainerUri, AzureSasCredential credential, BlobClientOptions? options = null) : base(blobContainerUri, credential, options) | ||
{ | ||
} | ||
|
||
public NamedBlobContainerClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions? options = null) : base(blobContainerUri, credential, options) | ||
{ | ||
} | ||
|
||
protected NamedBlobContainerClient() | ||
{ | ||
} | ||
} |
Oops, something went wrong.