Skip to content

Commit

Permalink
IASyncDataImporter added
Browse files Browse the repository at this point in the history
  • Loading branch information
bdongus committed May 10, 2024
1 parent fb87d05 commit dbcb398
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
20 changes: 6 additions & 14 deletions idee5.Common.Data/AsyncDataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
using System.Threading;

namespace idee5.Common.Data;
/// <summary>
/// The asynchronous data importer
/// </summary>
/// <typeparam name="TQuery">The query parameter type</typeparam>
/// <typeparam name="TCommand">The command data type</typeparam>
public class AsyncDataImporter<TQuery, TCommand, TCleanupCmd> where TQuery : IQuery<TCommand> where TCleanupCmd : ICleanupCommand {
/// <inheritdoc/>
public class AsyncDataImporter<TQuery, TCommand, TCleanupCmd> : IAsyncDataImporter<TQuery, TCommand, TCleanupCmd> where TQuery : IQuery<TCommand> where TCleanupCmd : ICleanupCommand {
protected readonly IAsyncInputHandler<TQuery, TCommand> inputHandler;
protected readonly ICommandHandlerAsync<TCommand> outputHandler;
private readonly ITimeProvider _timeProvider;
Expand All @@ -33,19 +29,15 @@ public AsyncDataImporter(IAsyncInputHandler<TQuery, TCommand> inputHandler, ICom
this.cleanupHandler = cleanupHandler ?? throw new ArgumentNullException(nameof(cleanupHandler));
_logger = logger ?? NullLogger<AsyncDataImporter<TQuery, TCommand, TCleanupCmd>>.Instance;
}
/// <summary>
/// <summary>
/// Executes the <see cref="Task"/>
/// </summary>
/// <param name="query">The query parameters</param>
/// <param name="cleanupCmd">The cleanup parameters</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <exception cref="ArgumentNullException"></exception>
/// <inheritdoc />
/// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> or <paramref name="cleanupCmd"/> is <c>NULL</c></exception>
public virtual async Task ExecuteAsync(TQuery query, TCleanupCmd cleanupCmd, CancellationToken cancellationToken = default) {
#if NETSTANDARD2_0_OR_GREATER
if (query == null) throw new ArgumentNullException(nameof(query));
if (cleanupCmd == null) throw new ArgumentNullException(nameof(cleanupCmd));
#else
ArgumentNullException.ThrowIfNull(query);
ArgumentNullException.ThrowIfNull(cleanupCmd);
#endif
DateTime importStartedAt = _timeProvider.UtcNow;
int importCount = 0;
Expand Down
19 changes: 19 additions & 0 deletions idee5.Common.Data/IAsyncDataImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Threading;
using System.Threading.Tasks;

namespace idee5.Common.Data;
/// <summary>
/// The asynchronous data importer
/// </summary>
/// <typeparam name="TQuery">The query parameter type</typeparam>
/// <typeparam name="TCommand">The command parameter type</typeparam>
/// <typeparam name="TCleanupCmd">The cleanup command parameter type</typeparam>
public interface IAsyncDataImporter<TQuery, TCommand, TCleanupCmd> where TQuery : IQuery<TCommand> where TCleanupCmd : ICleanupCommand {
/// <summary>
/// Executes the import
/// </summary>
/// <param name="query">The query parameters</param>
/// <param name="cleanupCmd">The cleanup parameters</param>
/// <param name="cancellationToken">The cancellation token</param>
Task ExecuteAsync(TQuery query, TCleanupCmd cleanupCmd, CancellationToken cancellationToken = default);
}
2 changes: 1 addition & 1 deletion idee5.Common.Data/idee5.Common.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Description>Data access abstractions used by idee5</Description>
<Copyright>Copyright © 2017 - 2024</Copyright>
<PackageTags>idee5</PackageTags>
<Version>2.3</Version>
<Version>2.3.1</Version>
<PackageReleaseNotes>Check the readme</PackageReleaseNotes>
<RepositoryUrl>https://github.com/bdongus/idee5.Common</RepositoryUrl>
<Nullable>enable</Nullable>
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,5 @@ Nullable support in IAuditedEntity
### 2.3
* KeyNamePair added
* Generic data paging support for queries
## 2.3.1
* Interface IASyncDataImporter added to enable the decorator pattern

0 comments on commit dbcb398

Please sign in to comment.