-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add Microsoft.Extensions.DependencyInjection
- Loading branch information
1 parent
e4e300b
commit 1e92b23
Showing
57 changed files
with
2,906 additions
and
15 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
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
9 changes: 9 additions & 0 deletions
9
src/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList.Microsoft/AcceptType.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,9 @@ | ||
namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList.Microsoft | ||
{ | ||
public enum AcceptType | ||
{ | ||
Json, | ||
JsonLd, | ||
Xml | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...icrosoft/Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList.Microsoft.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\packages\Be.Vlaanderen.Basisregisters.Build.Pipeline\Content\Be.Vlaanderen.Basisregisters.Build.Pipeline.Settings.Library.props" /> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Be.Vlaanderen.Basisregisters.ProjectionHandling.Connector\Be.Vlaanderen.Basisregisters.ProjectionHandling.Connector.csproj" /> | ||
<ProjectReference Include="..\Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner\Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.csproj" /> | ||
<ProjectReference Include="..\Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore.Autofac\Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore.Autofac.csproj" /> | ||
<ProjectReference Include="..\Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore\Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore.csproj" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
101 changes: 101 additions & 0 deletions
101
...isters.ProjectionHandling.LastChangedList.Microsoft/LastChangedListConnectedProjection.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,101 @@ | ||
namespace Be.Vlaanderen.Basisregisters.ProjectionHandling.LastChangedList.Microsoft | ||
{ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Connector; | ||
using global::Microsoft.EntityFrameworkCore; | ||
using Model; | ||
|
||
public abstract class LastChangedListConnectedProjection : ConnectedProjection<LastChangedListContext> | ||
{ | ||
protected abstract string BuildCacheKey(AcceptType acceptType, string identifier); | ||
protected abstract string BuildUri(AcceptType acceptType, string identifier); | ||
|
||
private readonly AcceptType[] _supportedAcceptTypes; | ||
private readonly int _commandTimeoutInSeconds; | ||
|
||
protected LastChangedListConnectedProjection(AcceptType[] supportedAcceptTypes) : this(supportedAcceptTypes, 300) {} | ||
|
||
protected LastChangedListConnectedProjection(AcceptType[] supportedAcceptTypes, int commandTimeoutInSeconds) | ||
{ | ||
_supportedAcceptTypes = supportedAcceptTypes; | ||
_commandTimeoutInSeconds = commandTimeoutInSeconds; | ||
} | ||
|
||
protected async Task<IEnumerable<LastChangedRecord>> GetLastChangedRecords( | ||
string identifier, | ||
LastChangedListContext context, | ||
CancellationToken cancellationToken) | ||
{ | ||
context.Database.SetCommandTimeout(_commandTimeoutInSeconds); | ||
var attachedRecords = new List<LastChangedRecord>(); | ||
|
||
// Create a record for every type that our API accepts. | ||
foreach (var acceptType in _supportedAcceptTypes) | ||
{ | ||
var shortenedApplicationType = acceptType.ToString().ToLowerInvariant(); | ||
var id = $"{identifier}.{shortenedApplicationType}"; | ||
|
||
var record = await context | ||
.LastChangedList | ||
.FindAsync(id, cancellationToken: cancellationToken); | ||
|
||
if (record != null) | ||
attachedRecords.Add(record); | ||
} | ||
|
||
return attachedRecords; | ||
} | ||
|
||
protected async Task<IEnumerable<LastChangedRecord>> GetLastChangedRecordsAndUpdatePosition( | ||
string identifier, | ||
long position, | ||
LastChangedListContext context, | ||
CancellationToken cancellationToken) | ||
{ | ||
context.Database.SetCommandTimeout(_commandTimeoutInSeconds); | ||
var attachedRecords = new List<LastChangedRecord>(); | ||
|
||
// Create a record for every type that our API accepts. | ||
foreach (var acceptType in _supportedAcceptTypes) | ||
{ | ||
var shortenedApplicationType = acceptType.ToString().ToLowerInvariant(); | ||
var id = $"{identifier}.{shortenedApplicationType}"; | ||
|
||
var record = await context | ||
.LastChangedList | ||
.FindAsync(id, cancellationToken: cancellationToken); | ||
|
||
if (record == null) | ||
{ | ||
record = new LastChangedRecord | ||
{ | ||
Id = id, | ||
CacheKey = BuildCacheKey(acceptType, identifier), | ||
Uri = BuildUri(acceptType, identifier), | ||
AcceptType = GetApplicationType(acceptType) | ||
}; | ||
|
||
await context.LastChangedList.AddAsync(record, cancellationToken); | ||
} | ||
|
||
record.Position = position; | ||
attachedRecords.Add(record); | ||
} | ||
|
||
return attachedRecords; | ||
} | ||
|
||
private static string GetApplicationType(AcceptType acceptType) | ||
{ | ||
return acceptType switch | ||
{ | ||
AcceptType.Json => "application/json", | ||
AcceptType.JsonLd => "application/ld+json", | ||
AcceptType.Xml => "application/xml", | ||
_ => string.Empty | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.