-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support to .NET Standard and .NET Framework (#3507)
* Improve support to .NET Standard and .NET Framework * fixes build * fixes build * Improve async by using preprocessor --------- Co-authored-by: Ian Cooper <[email protected]>
- Loading branch information
Showing
53 changed files
with
345 additions
and
221 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
24 changes: 12 additions & 12 deletions
24
src/Paramore.Brighter.Archive.Azure/Paramore.Brighter.Archive.Azure.csproj
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,18 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>Paramore.Brighter.Storage.Azure</RootNamespace> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>Paramore.Brighter.Storage.Azure</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Blobs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Blobs"/> | ||
</ItemGroup> | ||
|
||
</Project> |
12 changes: 6 additions & 6 deletions
12
src/Paramore.Brighter.Dapper/Paramore.Brighter.Dapper.csproj
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,11 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/> | ||
</ItemGroup> | ||
|
||
</Project> |
22 changes: 11 additions & 11 deletions
22
src/Paramore.Brighter.DynamoDb/Paramore.Brighter.DynamoDb.csproj
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,16 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.DynamoDBv2" /> | ||
<PackageReference Include="NJsonSchema" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.DynamoDBv2"/> | ||
<PackageReference Include="NJsonSchema"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
14 changes: 7 additions & 7 deletions
14
...er.Extensions.DependencyInjection/Paramore.Brighter.Extensions.DependencyInjection.csproj
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,17 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks> | ||
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks> | ||
<Authors>Daniel Stockhammer, Toby Henderson</Authors> | ||
<Description>Brighter Microsoft.Extensions.DependencyInjection support</Description> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" /> | ||
<PackageReference Include="System.Text.Json" /> | ||
|
||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"/> | ||
<PackageReference Include="System.Text.Json"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter.DynamoDb\Paramore.Brighter.DynamoDb.csproj" /> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" /> | ||
<ProjectReference Include="..\Paramore.Brighter.DynamoDb\Paramore.Brighter.DynamoDb.csproj"/> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/> | ||
</ItemGroup> | ||
</Project> |
2 changes: 1 addition & 1 deletion
2
src/Paramore.Brighter.Extensions.Diagnostics/Paramore.Brighter.Extensions.Diagnostics.csproj
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
10 changes: 5 additions & 5 deletions
10
src/Paramore.Brighter.Inbox.DynamoDB/Paramore.Brighter.Inbox.DynamoDB.csproj
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,13 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks> | ||
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.DynamoDBv2" /> | ||
|
||
|
||
<ItemGroup> | ||
<PackageReference Include="AWSSDK.DynamoDBv2"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" /> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/> | ||
</ItemGroup> | ||
</Project> |
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
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
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,4 +1,5 @@ | ||
#region Licence | ||
|
||
/* The MIT License (MIT) | ||
Copyright © 2024 Ian Cooper <[email protected]> | ||
|
@@ -19,7 +20,9 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. */ | ||
#endregion | ||
|
||
#endregion | ||
|
||
using Azure; | ||
using Azure.Storage.Blobs; | ||
using Azure.Storage.Blobs.Specialized; | ||
|
@@ -34,7 +37,9 @@ namespace Paramore.Brighter.Locking.Azure; | |
/// <param name="options"></param> | ||
public class AzureBlobLockingProvider(AzureBlobLockingProviderOptions options) : IDistributedLock | ||
{ | ||
private readonly BlobContainerClient _containerClient = new BlobContainerClient(options.BlobContainerUri, options.TokenCredential); | ||
private readonly BlobContainerClient _containerClient = | ||
new BlobContainerClient(options.BlobContainerUri, options.TokenCredential); | ||
|
||
private readonly ILogger _logger = ApplicationLogging.CreateLogger<AzureBlobLockingProviderOptions>(); | ||
|
||
/// <summary> | ||
|
@@ -50,17 +55,27 @@ public class AzureBlobLockingProvider(AzureBlobLockingProviderOptions options) : | |
// Write if does not exist | ||
if (!await client.ExistsAsync(cancellationToken)) | ||
{ | ||
#if NETSTANDARD | ||
using var emptyStream = new MemoryStream(); | ||
using var writer = new StreamWriter(emptyStream); | ||
await writer.WriteAsync(string.Empty); | ||
await writer.FlushAsync(); | ||
emptyStream.Position = 0; | ||
await client.UploadAsync(emptyStream, cancellationToken: cancellationToken); | ||
#else | ||
await using var emptyStream = new MemoryStream(); | ||
await using var writer = new StreamWriter(emptyStream); | ||
await writer.WriteAsync(string.Empty); | ||
await writer.FlushAsync(cancellationToken); | ||
emptyStream.Position = 0; | ||
await client.UploadAsync(emptyStream, cancellationToken: cancellationToken); | ||
#endif | ||
} | ||
|
||
try | ||
{ | ||
var response = await client.GetBlobLeaseClient().AcquireAsync(options.LeaseValidity, cancellationToken: cancellationToken); | ||
var response = await client.GetBlobLeaseClient() | ||
.AcquireAsync(options.LeaseValidity, cancellationToken: cancellationToken); | ||
return response.Value.LeaseId; | ||
} | ||
catch (RequestFailedException) | ||
|
@@ -80,20 +95,21 @@ public class AzureBlobLockingProvider(AzureBlobLockingProviderOptions options) : | |
public async Task ReleaseLockAsync(string resource, string lockId, CancellationToken cancellationToken) | ||
{ | ||
var client = GetBlobLeaseClientForResource(resource, lockId); | ||
if(client == null) | ||
if (client == null) | ||
{ | ||
_logger.LogInformation("No lock found for {LockResourceName}", resource); | ||
return; | ||
} | ||
|
||
await client.ReleaseAsync(cancellationToken: cancellationToken); | ||
} | ||
|
||
private BlobLeaseClient? GetBlobLeaseClientForResource(string resource, string lockId) => | ||
GetBlobClient(resource).GetBlobLeaseClient(lockId); | ||
|
||
private BlobClient GetBlobClient(string resource) | ||
{ | ||
var storageLocation = options.StorageLocationFunc.Invoke(NormaliseResourceName(resource)); | ||
var storageLocation = options.StorageLocationFunc.Invoke(NormaliseResourceName(resource)); | ||
return _containerClient.GetBlobClient(storageLocation); | ||
} | ||
|
||
|
28 changes: 14 additions & 14 deletions
28
src/Paramore.Brighter.Locking.Azure/Paramore.Brighter.Locking.Azure.csproj
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,20 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Title>This is the Azure Distributed Locking Provider.</Title> | ||
<Authors>Paul Reardon</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Title>This is the Azure Distributed Locking Provider.</Title> | ||
<Authors>Paul Reardon</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Blobs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Blobs"/> | ||
</ItemGroup> | ||
|
||
</Project> |
2 changes: 1 addition & 1 deletion
2
src/Paramore.Brighter.Locking.DynamoDB/Paramore.Brighter.Locking.DynamoDB.csproj
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
Oops, something went wrong.