From b993b7540c6bde000a6ca9ec08f5fad5dd342b64 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Thu, 15 Feb 2024 18:03:13 +0330 Subject: [PATCH] add cancellation token --- .../EasyMicroservices.Cores.AspCoreApi.csproj | 2 +- ...oservices.Cores.AspEntityFrameworkCoreApi.csproj | 2 +- .../EasyMicroservices.Cores.Clients.csproj | 2 +- .../EasyMicroservices.Cores.Contracts.csproj | 2 +- .../Database/Interfaces/IDatabaseWidget.cs | 7 +++++-- .../Database/Interfaces/IDatabaseWidgetManager.cs | 7 +++++-- .../Database/Logics/DatabaseLogicInfrastructure.cs | 2 +- .../Database/Managers/DatabaseWidgetManager.cs | 7 +++++-- .../Database/Widgets/SimpleReportingEntityWidget.cs | 13 ++++++++----- .../EasyMicroservices.Cores.Database.csproj | 2 +- ...syMicroservices.Cores.EntityFrameworkCore.csproj | 2 +- .../EasyMicroservices.Cores.Infrastructure.csproj | 2 +- ...ices.Cores.Relational.EntityFrameworkCore.csproj | 2 +- 13 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 5b9abea..838496e 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -4,7 +4,7 @@ netstandard2.1;net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index c057c57..2022c8d 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj index 4528311..b662232 100644 --- a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 core of database. EasyMicroservices@gmail.com core,cores,base,client,clients diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index 44f21c8..4529935 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 core contracts. EasyMicroservices@gmail.com core,cores,base,contract,contracts,dto,dtos diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidget.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidget.cs index f656807..3df8f56 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidget.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidget.cs @@ -1,5 +1,6 @@ using EasyMicroservices.Cores.Interfaces; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace EasyMicroservices.Cores.Database.Interfaces; @@ -20,14 +21,16 @@ public interface IDatabaseWidget : IWidget /// /// /// + /// /// - Task AddProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract); + Task AddProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract, CancellationToken cancellationToken = default); /// /// /// /// /// /// + /// /// - Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary items); + Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary items, CancellationToken cancellationToken = default); } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidgetManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidgetManager.cs index 0804020..ef7a503 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidgetManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IDatabaseWidgetManager.cs @@ -1,5 +1,6 @@ using EasyMicroservices.Cores.Interfaces; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace EasyMicroservices.Cores.Database.Interfaces; @@ -16,8 +17,9 @@ public interface IDatabaseWidgetManager : IWidgetManager /// /// /// + /// /// - Task Add(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract) + Task Add(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract, CancellationToken cancellationToken = default) where TEntity : class; /// /// @@ -26,7 +28,8 @@ Task Add(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract) /// /// /// + /// /// - Task AddBulk(IBaseUnitOfWork baseUnitOfWork, Dictionary items) + Task AddBulk(IBaseUnitOfWork baseUnitOfWork, Dictionary items, CancellationToken cancellationToken = default) where TEntity : class; } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs index ed7ae16..2909150 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs @@ -1023,7 +1023,7 @@ internal async Task> AddBulk(IE { await InternalUpdateBulk(easyWritableQueryable, result.Select(x => x.Entity).ToList(), false, true, true, true, cancellationToken) .AsCheckedResult(); - await easyWritableQueryable.SaveChangesAsync(); + await easyWritableQueryable.SaveChangesAsync(cancellationToken); } var response = result.Select(x => x.Entity).ToList(); var widgetManager = _baseUnitOfWork.GetDatabaseWidgetManager(); diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DatabaseWidgetManager.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DatabaseWidgetManager.cs index ec7e9ae..0fd10f9 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DatabaseWidgetManager.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Managers/DatabaseWidgetManager.cs @@ -3,6 +3,7 @@ using EasyMicroservices.Cores.Widgets; using System.Collections.Generic; using System.Diagnostics.Contracts; +using System.Threading; using System.Threading.Tasks; namespace EasyMicroservices.Cores.Database.Managers; @@ -20,8 +21,9 @@ public class DatabaseWidgetManager : WidgetManager, IDatabaseWidgetManager /// /// /// + /// /// - public async Task Add(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract) + public async Task Add(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract, CancellationToken cancellationToken = default) where TEntity : class { var widgets = GetWidgetsByType(typeof(T)); @@ -41,8 +43,9 @@ public async Task Add(IBaseUnitOfWork baseUnitOfWork, TEntity entity /// /// /// + /// /// - public async Task AddBulk(IBaseUnitOfWork baseUnitOfWork, Dictionary items) where TEntity : class + public async Task AddBulk(IBaseUnitOfWork baseUnitOfWork, Dictionary items, CancellationToken cancellationToken = default) where TEntity : class { var widgets = GetWidgetsByType(typeof(T)); foreach (var widget in widgets) diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Widgets/SimpleReportingEntityWidget.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Widgets/SimpleReportingEntityWidget.cs index 1070525..9d8a0b7 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Widgets/SimpleReportingEntityWidget.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Widgets/SimpleReportingEntityWidget.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace EasyMicroservices.Cores.Widgets; @@ -64,9 +65,10 @@ public Task Initialize(params TObjectContract[] parameters) /// /// /// + /// /// /// - public async Task AddProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, TEntity entity, TObjectContract contract) + public async Task AddProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, TEntity entity, TObjectContract contract, CancellationToken cancellationToken = default) { var reportEntity = await baseUnitOfWork .GetMapper() @@ -77,7 +79,7 @@ public async Task AddProcess(IDatabaseWidgetManager databaseWidgetManager, IBase }); DatabaseExtensions.SetIdToRecordId(logic.GetReadableContext(), entity, reportEntity); await logic - .Add(reportEntity) + .Add(reportEntity, cancellationToken) .AsCheckedResult(); } @@ -87,8 +89,9 @@ await logic /// /// /// + /// /// - public async Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary items) + public async Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary items, CancellationToken cancellationToken = default) { var reportEntities = await baseUnitOfWork .GetMapper() @@ -99,7 +102,7 @@ public async Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, I }); DatabaseExtensions.SetIdToRecordId(logic.GetReadableContext(), reportEntities); await logic - .AddBulk(reportEntities.Values.ToList()) + .AddBulk(reportEntities.Values.ToList(), cancellationToken) .AsCheckedResult(); } -} +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 379cb96..1d905eb 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index 07f2446..3286fe6 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -4,7 +4,7 @@ netstandard2.1;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Infrastructure/EasyMicroservices.Cores.Infrastructure.csproj b/src/CSharp/EasyMicroservices.Cores.Infrastructure/EasyMicroservices.Cores.Infrastructure.csproj index f31d4e9..137db1c 100644 --- a/src/CSharp/EasyMicroservices.Cores.Infrastructure/EasyMicroservices.Cores.Infrastructure.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Infrastructure/EasyMicroservices.Cores.Infrastructure.csproj @@ -4,7 +4,7 @@ netstandard2.0;netstandard2.1;net45;net6.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 core of infrastructure. EasyMicroservices@gmail.com core,cores,base,infrastructure diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index d568237..21d24af 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -4,7 +4,7 @@ netstandard2.1;net6.0;net7.0;net8.0 AnyCPU;x64;x86 EasyMicroservices - 0.0.1.51 + 0.0.1.52 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational