Skip to content

Commit

Permalink
Merge pull request #160 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
add cancellation token
  • Loading branch information
Ali-YousefiTelori authored Feb 15, 2024
2 parents 78d7a81 + e760bea commit 1c848bc
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>asp core servces.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,services,asp,aspnet</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>asp core servces.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,services,asp,aspnet,aspcore,efcore</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,client,clients</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>core contracts.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,contract,contracts,dto,dtos</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using EasyMicroservices.Cores.Interfaces;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace EasyMicroservices.Cores.Database.Interfaces;
Expand All @@ -20,14 +21,16 @@ public interface IDatabaseWidget<TEntity, T> : IWidget<T>
/// <param name="baseUnitOfWork"></param>
/// <param name="entity"></param>
/// <param name="contract"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task AddProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract);
Task AddProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract, CancellationToken cancellationToken = default);
/// <summary>
///
/// </summary>
/// <param name="databaseWidgetManager"></param>
/// <param name="baseUnitOfWork"></param>
/// <param name="items"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary<T, TEntity> items);
Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary<T, TEntity> items, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using EasyMicroservices.Cores.Interfaces;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace EasyMicroservices.Cores.Database.Interfaces;
Expand All @@ -16,8 +17,9 @@ public interface IDatabaseWidgetManager : IWidgetManager
/// <param name="baseUnitOfWork"></param>
/// <param name="entity"></param>
/// <param name="contract"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Add<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract)
Task Add<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract, CancellationToken cancellationToken = default)
where TEntity : class;
/// <summary>
///
Expand All @@ -26,7 +28,8 @@ Task Add<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract)
/// <typeparam name="TEntity"></typeparam>
/// <param name="baseUnitOfWork"></param>
/// <param name="items"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task AddBulk<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, Dictionary<T, TEntity> items)
Task AddBulk<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, Dictionary<T, TEntity> items, CancellationToken cancellationToken = default)
where TEntity : class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ internal async Task<ListMessageContract<TEntity>> AddBulk<TEntity, TContract>(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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,8 +21,9 @@ public class DatabaseWidgetManager : WidgetManager, IDatabaseWidgetManager
/// <param name="baseUnitOfWork"></param>
/// <param name="entity"></param>
/// <param name="contract"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task Add<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract)
public async Task Add<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, TEntity entity, T contract, CancellationToken cancellationToken = default)
where TEntity : class
{
var widgets = GetWidgetsByType(typeof(T));
Expand All @@ -41,8 +43,9 @@ public async Task Add<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, TEntity entity
/// <typeparam name="T"></typeparam>
/// <param name="baseUnitOfWork"></param>
/// <param name="items"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task AddBulk<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, Dictionary<T, TEntity> items) where TEntity : class
public async Task AddBulk<TEntity, T>(IBaseUnitOfWork baseUnitOfWork, Dictionary<T, TEntity> items, CancellationToken cancellationToken = default) where TEntity : class
{
var widgets = GetWidgetsByType(typeof(T));
foreach (var widget in widgets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace EasyMicroservices.Cores.Widgets;
Expand Down Expand Up @@ -64,9 +65,10 @@ public Task Initialize(params TObjectContract[] parameters)
/// <param name="baseUnitOfWork"></param>
/// <param name="entity"></param>
/// <param name="contract"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
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()
Expand All @@ -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();
}

Expand All @@ -87,8 +89,9 @@ await logic
/// <param name="databaseWidgetManager"></param>
/// <param name="baseUnitOfWork"></param>
/// <param name="items"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary<TObjectContract, TEntity> items)
public async Task AddBulkProcess(IDatabaseWidgetManager databaseWidgetManager, IBaseUnitOfWork baseUnitOfWork, Dictionary<TObjectContract, TEntity> items, CancellationToken cancellationToken = default)
{
var reportEntities = await baseUnitOfWork
.GetMapper()
Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>ef core of database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,ef,efcore</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>core of infrastructure.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,infrastructure</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<Version>0.0.1.51</Version>
<Version>0.0.1.52</Version>
<Description>ef core of Relational database.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,ef,efcore,Relational</PackageTags>
Expand Down

0 comments on commit 1c848bc

Please sign in to comment.