Browse Source

Merge pull request #7359 from abpframework/liangshiwei/cancell-token

Add CancellationToken optional parameter to all public repository methods
pull/7376/head
maliming 6 years ago
committed by GitHub
parent
commit
f5c3f30344
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs
  2. 26
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs
  3. 54
      modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs
  4. 5
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs
  5. 7
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs
  6. 11
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs
  7. 3
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs
  8. 11
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs
  9. 9
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs
  10. 8
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs
  11. 5
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs
  12. 17
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs
  13. 19
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs
  14. 16
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs
  15. 5
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs
  16. 25
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs
  17. 23
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs
  18. 18
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs
  19. 4
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs
  20. 2
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs
  21. 2
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs
  22. 9
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/IProjectRepository.cs
  23. 13
      modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs
  24. 15
      modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs
  25. 18
      modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/IFeatureValueRepository.cs
  26. 26
      modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs
  27. 30
      modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs
  28. 11
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs
  29. 9
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs
  30. 18
      modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/ISettingRepository.cs
  31. 29
      modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/EfCoreSettingRepository.cs
  32. 36
      modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs

9
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs

@ -44,9 +44,10 @@ namespace Volo.Abp.AuditLogging
Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync( Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(
DateTime startDate, DateTime startDate,
DateTime endDate); DateTime endDate,
CancellationToken cancellationToken = default);
Task<EntityChange> GetEntityChange(Guid entityChangeId); Task<EntityChange> GetEntityChange(Guid entityChangeId, CancellationToken cancellationToken = default);
Task<List<EntityChange>> GetEntityChangeListAsync( Task<List<EntityChange>> GetEntityChangeListAsync(
string sorting = null, string sorting = null,
@ -70,8 +71,8 @@ namespace Volo.Abp.AuditLogging
string entityTypeFullName = null, string entityTypeFullName = null,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
Task<EntityChangeWithUsername> GetEntityChangeWithUsernameAsync(Guid entityChangeId); Task<EntityChangeWithUsername> GetEntityChangeWithUsernameAsync(Guid entityChangeId, CancellationToken cancellationToken = default);
Task<List<EntityChangeWithUsername>> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName); Task<List<EntityChangeWithUsername>> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName, CancellationToken cancellationToken = default);
} }
} }

26
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs

@ -125,14 +125,17 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
.WhereIf(minExecutionDuration != null && minExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration); .WhereIf(minExecutionDuration != null && minExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration);
} }
public virtual async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate) public virtual async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(
DateTime startDate,
DateTime endDate,
CancellationToken cancellationToken = default)
{ {
var result = await (await GetDbSetAsync()).AsNoTracking() var result = await (await GetDbSetAsync()).AsNoTracking()
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
.OrderBy(t => t.ExecutionTime) .OrderBy(t => t.ExecutionTime)
.GroupBy(t => new { t.ExecutionTime.Date }) .GroupBy(t => new { t.ExecutionTime.Date })
.Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) }) .Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) })
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime); return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime);
} }
@ -148,14 +151,16 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
return (await GetQueryableAsync()).IncludeDetails(); return (await GetQueryableAsync()).IncludeDetails();
} }
public virtual async Task<EntityChange> GetEntityChange(Guid entityChangeId) public virtual async Task<EntityChange> GetEntityChange(
Guid entityChangeId,
CancellationToken cancellationToken = default)
{ {
var entityChange = await (await GetDbContextAsync()).Set<EntityChange>() var entityChange = await (await GetDbContextAsync()).Set<EntityChange>()
.AsNoTracking() .AsNoTracking()
.IncludeDetails() .IncludeDetails()
.Where(x => x.Id == entityChangeId) .Where(x => x.Id == entityChangeId)
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (entityChange == null) if (entityChange == null)
{ {
@ -201,10 +206,12 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
return totalCount; return totalCount;
} }
public virtual async Task<EntityChangeWithUsername> GetEntityChangeWithUsernameAsync(Guid entityChangeId) public virtual async Task<EntityChangeWithUsername> GetEntityChangeWithUsernameAsync(
Guid entityChangeId,
CancellationToken cancellationToken = default)
{ {
var auditLog = await (await GetDbSetAsync()).AsNoTracking().IncludeDetails() var auditLog = await (await GetDbSetAsync()).AsNoTracking().IncludeDetails()
.Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)).FirstAsync(); .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)).FirstAsync(GetCancellationToken(cancellationToken));
return new EntityChangeWithUsername() return new EntityChangeWithUsername()
{ {
@ -213,7 +220,10 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
}; };
} }
public virtual async Task<List<EntityChangeWithUsername>> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName) public virtual async Task<List<EntityChangeWithUsername>> GetEntityChangesWithUsernameAsync(
string entityId,
string entityTypeFullName,
CancellationToken cancellationToken = default)
{ {
var dbContext = await GetDbContextAsync(); var dbContext = await GetDbContextAsync();
@ -225,7 +235,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
return await (from e in query return await (from e in query
join auditLog in dbContext.AuditLogs on e.AuditLogId equals auditLog.Id join auditLog in dbContext.AuditLogs on e.AuditLogId equals auditLog.Id
select new EntityChangeWithUsername {EntityChange = e, UserName = auditLog.UserName}) select new EntityChangeWithUsername {EntityChange = e, UserName = auditLog.UserName})
.OrderByDescending(x => x.EntityChange.ChangeTime).ToListAsync(); .OrderByDescending(x => x.EntityChange.ChangeTime).ToListAsync(GetCancellationToken(cancellationToken));
} }
protected virtual async Task<IQueryable<EntityChange>> GetEntityChangeListQueryAsync( protected virtual async Task<IQueryable<EntityChange>> GetEntityChangeListQueryAsync(

54
modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs

@ -52,7 +52,8 @@ namespace Volo.Abp.AuditLogging.MongoDB
minDuration, minDuration,
hasException, hasException,
httpStatusCode, httpStatusCode,
includeDetails includeDetails,
cancellationToken
); );
return await query.OrderBy(sorting ?? "executionTime desc").As<IMongoQueryable<AuditLog>>() return await query.OrderBy(sorting ?? "executionTime desc").As<IMongoQueryable<AuditLog>>()
@ -85,7 +86,8 @@ namespace Volo.Abp.AuditLogging.MongoDB
maxDuration, maxDuration,
minDuration, minDuration,
hasException, hasException,
httpStatusCode httpStatusCode,
cancellationToken: cancellationToken
); );
var count = await query.As<IMongoQueryable<AuditLog>>() var count = await query.As<IMongoQueryable<AuditLog>>()
@ -106,9 +108,10 @@ namespace Volo.Abp.AuditLogging.MongoDB
int? minDuration = null, int? minDuration = null,
bool? hasException = null, bool? hasException = null,
HttpStatusCode? httpStatusCode = null, HttpStatusCode? httpStatusCode = null,
bool includeDetails = false) bool includeDetails = false,
CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync()) return (await GetMongoQueryableAsync(cancellationToken))
.WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime) .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime)
.WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime) .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime)
.WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "") .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions != "")
@ -124,9 +127,12 @@ namespace Volo.Abp.AuditLogging.MongoDB
} }
public virtual async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate) public virtual async Task<Dictionary<DateTime, double>> GetAverageExecutionDurationPerDayAsync(
DateTime startDate,
DateTime endDate,
CancellationToken cancellationToken = default)
{ {
var result = await (await GetMongoQueryableAsync()) var result = await (await GetMongoQueryableAsync(cancellationToken))
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
.OrderBy(t => t.ExecutionTime) .OrderBy(t => t.ExecutionTime)
.GroupBy(t => new .GroupBy(t => new
@ -136,17 +142,19 @@ namespace Volo.Abp.AuditLogging.MongoDB
t.ExecutionTime.Day t.ExecutionTime.Day
}) })
.Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) }) .Select(g => new { Day = g.Min(t => t.ExecutionTime), avgExecutionTime = g.Average(t => t.ExecutionDuration) })
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime); return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime);
} }
public virtual async Task<EntityChange> GetEntityChange(Guid entityChangeId) public virtual async Task<EntityChange> GetEntityChange(
Guid entityChangeId,
CancellationToken cancellationToken = default)
{ {
var entityChange = (await (await GetMongoQueryableAsync()) var entityChange = (await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstAsync()).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); .FirstAsync(GetCancellationToken(cancellationToken))).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId);
if (entityChange == null) if (entityChange == null)
{ {
@ -169,7 +177,7 @@ namespace Volo.Abp.AuditLogging.MongoDB
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName); var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken);
return await query return await query
.OrderBy(sorting ?? "changeTime desc") .OrderBy(sorting ?? "changeTime desc")
@ -187,18 +195,20 @@ namespace Volo.Abp.AuditLogging.MongoDB
string entityTypeFullName = null, string entityTypeFullName = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName); var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken);
var count = await query.As<IMongoQueryable<EntityChange>>().LongCountAsync(GetCancellationToken(cancellationToken)); var count = await query.As<IMongoQueryable<EntityChange>>().LongCountAsync(GetCancellationToken(cancellationToken));
return count; return count;
} }
public virtual async Task<EntityChangeWithUsername> GetEntityChangeWithUsernameAsync(Guid entityChangeId) public virtual async Task<EntityChangeWithUsername> GetEntityChangeWithUsernameAsync(
Guid entityChangeId,
CancellationToken cancellationToken = default)
{ {
var auditLog = (await (await GetMongoQueryableAsync()) var auditLog = await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId))
.FirstAsync()); .FirstAsync(GetCancellationToken(cancellationToken));
return new EntityChangeWithUsername() return new EntityChangeWithUsername()
{ {
@ -207,13 +217,16 @@ namespace Volo.Abp.AuditLogging.MongoDB
}; };
} }
public virtual async Task<List<EntityChangeWithUsername>> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName) public virtual async Task<List<EntityChangeWithUsername>> GetEntityChangesWithUsernameAsync(
string entityId,
string entityTypeFullName,
CancellationToken cancellationToken = default)
{ {
var auditLogs = await (await GetMongoQueryableAsync()) var auditLogs = await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)) .Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName))
.As<IMongoQueryable<AuditLog>>() .As<IMongoQueryable<AuditLog>>()
.OrderByDescending(x => x.ExecutionTime) .OrderByDescending(x => x.ExecutionTime)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
var entityChanges = auditLogs.SelectMany(x => x.EntityChanges).ToList(); var entityChanges = auditLogs.SelectMany(x => x.EntityChanges).ToList();
@ -229,9 +242,10 @@ namespace Volo.Abp.AuditLogging.MongoDB
DateTime? endTime = null, DateTime? endTime = null,
EntityChangeType? changeType = null, EntityChangeType? changeType = null,
string entityId = null, string entityId = null,
string entityTypeFullName = null) string entityTypeFullName = null,
CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync()) return (await GetMongoQueryableAsync(cancellationToken))
.SelectMany(x => x.EntityChanges) .SelectMany(x => x.EntityChanges)
.WhereIf(auditLogId.HasValue, e => e.Id == auditLogId) .WhereIf(auditLogId.HasValue, e => e.Id == auditLogId)
.WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime)

5
modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/IBackgroundJobRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -7,6 +8,6 @@ namespace Volo.Abp.BackgroundJobs
{ {
public interface IBackgroundJobRepository : IBasicRepository<BackgroundJobRecord, Guid> public interface IBackgroundJobRepository : IBasicRepository<BackgroundJobRecord, Guid>
{ {
Task<List<BackgroundJobRecord>> GetWaitingListAsync(int maxResultCount); Task<List<BackgroundJobRecord>> GetWaitingListAsync(int maxResultCount, CancellationToken cancellationToken = default);
} }
} }

7
modules/background-jobs/src/Volo.Abp.BackgroundJobs.EntityFrameworkCore/Volo/Abp/BackgroundJobs/EntityFrameworkCore/EfCoreBackgroundJobRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -21,9 +22,11 @@ namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore
Clock = clock; Clock = clock;
} }
public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(int maxResultCount) public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(
int maxResultCount,
CancellationToken cancellationToken = default)
{ {
return await (await GetWaitingListQueryAsync(maxResultCount)).ToListAsync(); return await (await GetWaitingListQueryAsync(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken));
} }
protected virtual async Task<IQueryable<BackgroundJobRecord>> GetWaitingListQueryAsync(int maxResultCount) protected virtual async Task<IQueryable<BackgroundJobRecord>> GetWaitingListQueryAsync(int maxResultCount)

11
modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/MongoBackgroundJobRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
@ -21,15 +22,17 @@ namespace Volo.Abp.BackgroundJobs.MongoDB
Clock = clock; Clock = clock;
} }
public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(int maxResultCount) public virtual async Task<List<BackgroundJobRecord>> GetWaitingListAsync(
int maxResultCount,
CancellationToken cancellationToken = default)
{ {
return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(); return await (await GetWaitingListQuery(maxResultCount)).ToListAsync(GetCancellationToken(cancellationToken));
} }
protected virtual async Task<IMongoQueryable<BackgroundJobRecord>> GetWaitingListQuery(int maxResultCount) protected virtual async Task<IMongoQueryable<BackgroundJobRecord>> GetWaitingListQuery(int maxResultCount, CancellationToken cancellationToken = default)
{ {
var now = Clock.Now; var now = Clock.Now;
return (await GetMongoQueryableAsync()) return (await GetMongoQueryableAsync(cancellationToken))
.Where(t => !t.IsAbandoned && t.NextTryTime <= now) .Where(t => !t.IsAbandoned && t.NextTryTime <= now)
.OrderByDescending(t => t.Priority) .OrderByDescending(t => t.Priority)
.ThenBy(t => t.TryCount) .ThenBy(t => t.TryCount)

3
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -6,6 +7,6 @@ namespace Volo.Blogging.Blogs
{ {
public interface IBlogRepository : IBasicRepository<Blog, Guid> public interface IBlogRepository : IBasicRepository<Blog, Guid>
{ {
Task<Blog> FindByShortNameAsync(string shortName); Task<Blog> FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default);
} }
} }

11
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -7,14 +8,12 @@ namespace Volo.Blogging.Comments
{ {
public interface ICommentRepository : IBasicRepository<Comment, Guid> public interface ICommentRepository : IBasicRepository<Comment, Guid>
{ {
Task<List<Comment>> GetListOfPostAsync( Task<List<Comment>> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default);
Guid postId
);
Task<int> GetCommentCountOfPostAsync(Guid postId); Task<int> GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default);
Task<List<Comment>> GetRepliesOfComment(Guid id); Task<List<Comment>> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default);
Task DeleteOfPost(Guid id); Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default);
} }
} }

9
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -7,12 +8,12 @@ namespace Volo.Blogging.Posts
{ {
public interface IPostRepository : IBasicRepository<Post, Guid> public interface IPostRepository : IBasicRepository<Post, Guid>
{ {
Task<List<Post>> GetPostsByBlogId(Guid id); Task<List<Post>> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default);
Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null); Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default);
Task<Post> GetPostByUrl(Guid blogId, string url); Task<Post> GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default);
Task<List<Post>> GetOrderedList(Guid blogId,bool descending = false); Task<List<Post>> GetOrderedList(Guid blogId,bool descending = false, CancellationToken cancellationToken = default);
} }
} }

8
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs

@ -8,13 +8,13 @@ namespace Volo.Blogging.Tagging
{ {
public interface ITagRepository : IBasicRepository<Tag, Guid> public interface ITagRepository : IBasicRepository<Tag, Guid>
{ {
Task<List<Tag>> GetListAsync(Guid blogId); Task<List<Tag>> GetListAsync(Guid blogId, CancellationToken cancellationToken = default);
Task<Tag> GetByNameAsync(Guid blogId, string name); Task<Tag> GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default);
Task<Tag> FindByNameAsync(Guid blogId, string name); Task<Tag> FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default);
Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids); Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default);
Task DecreaseUsageCountOfTagsAsync(List<Guid> id, CancellationToken cancellationToken = default); Task DecreaseUsageCountOfTagsAsync(List<Guid> id, CancellationToken cancellationToken = default);
} }

5
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -15,9 +16,9 @@ namespace Volo.Blogging.Blogs
} }
public async Task<Blog> FindByShortNameAsync(string shortName) public async Task<Blog> FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName); return await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName, GetCancellationToken(cancellationToken));
} }
} }
} }

17
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -16,29 +17,29 @@ namespace Volo.Blogging.Comments
{ {
} }
public async Task<List<Comment>> GetListOfPostAsync(Guid postId) public async Task<List<Comment>> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where(a => a.PostId == postId) .Where(a => a.PostId == postId)
.OrderBy(a => a.CreationTime) .OrderBy(a => a.CreationTime)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<int> GetCommentCountOfPostAsync(Guid postId) public async Task<int> GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.CountAsync(a => a.PostId == postId); .CountAsync(a => a.PostId == postId, GetCancellationToken(cancellationToken));
} }
public async Task<List<Comment>> GetRepliesOfComment(Guid id) public async Task<List<Comment>> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where(a => a.RepliedCommentId == id).ToListAsync(); .Where(a => a.RepliedCommentId == id).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task DeleteOfPost(Guid id) public async Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default)
{ {
var recordsToDelete = (await GetDbSetAsync()).Where(pt => pt.PostId == id); var recordsToDelete = await (await GetDbSetAsync()).Where(pt => pt.PostId == id).ToListAsync(GetCancellationToken(cancellationToken));
(await GetDbSetAsync()).RemoveRange(recordsToDelete); (await GetDbSetAsync()).RemoveRange(recordsToDelete);
} }
} }

19
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@ -18,12 +19,12 @@ namespace Volo.Blogging.Posts
} }
public async Task<List<Post>> GetPostsByBlogId(Guid id) public async Task<List<Post>> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync(); return await (await GetDbSetAsync()).Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default)
{ {
var query = (await GetDbSetAsync()).Where(p => blogId == p.BlogId && p.Url == url); var query = (await GetDbSetAsync()).Where(p => blogId == p.BlogId && p.Url == url);
@ -32,12 +33,12 @@ namespace Volo.Blogging.Posts
query = query.Where(p => excludingPostId != p.Id); query = query.Where(p => excludingPostId != p.Id);
} }
return await query.AnyAsync(); return await query.AnyAsync(GetCancellationToken(cancellationToken));
} }
public async Task<Post> GetPostByUrl(Guid blogId, string url) public async Task<Post> GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default)
{ {
var post = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); var post = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url, GetCancellationToken(cancellationToken));
if (post == null) if (post == null)
{ {
@ -47,15 +48,15 @@ namespace Volo.Blogging.Posts
return post; return post;
} }
public async Task<List<Post>> GetOrderedList(Guid blogId,bool descending = false) public async Task<List<Post>> GetOrderedList(Guid blogId,bool descending = false, CancellationToken cancellationToken = default)
{ {
if (!descending) if (!descending)
{ {
return await (await GetDbSetAsync()).Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync(); return await (await GetDbSetAsync()).Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken));
} }
else else
{ {
return await (await GetDbSetAsync()).Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync(); return await (await GetDbSetAsync()).Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken));
} }
} }

16
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs

@ -17,24 +17,24 @@ namespace Volo.Blogging.Tagging
{ {
} }
public async Task<List<Tag>> GetListAsync(Guid blogId) public async Task<List<Tag>> GetListAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).Where(t=>t.BlogId == blogId).ToListAsync(); return await (await GetDbSetAsync()).Where(t=>t.BlogId == blogId).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<Tag> GetByNameAsync(Guid blogId, string name) public async Task<Tag> GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).FirstAsync(t=> t.BlogId == blogId && t.Name == name); return await (await GetDbSetAsync()).FirstAsync(t=> t.BlogId == blogId && t.Name == name, GetCancellationToken(cancellationToken));
} }
public async Task<Tag> FindByNameAsync(Guid blogId, string name) public async Task<Tag> FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name); return await (await GetDbSetAsync()).FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name, GetCancellationToken(cancellationToken));
} }
public async Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids) public async Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(); return await (await GetDbSetAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default) public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default)

5
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
@ -13,9 +14,9 @@ namespace Volo.Blogging.Blogs
{ {
} }
public async Task<Blog> FindByShortNameAsync(string shortName) public async Task<Blog> FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName); return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.ShortName == shortName, GetCancellationToken(cancellationToken));
} }
} }
} }

25
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
@ -15,33 +16,33 @@ namespace Volo.Blogging.Comments
{ {
} }
public async Task<List<Comment>> GetListOfPostAsync(Guid postId) public async Task<List<Comment>> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.Where(a => a.PostId == postId) .Where(a => a.PostId == postId)
.OrderBy(a => a.CreationTime) .OrderBy(a => a.CreationTime)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<int> GetCommentCountOfPostAsync(Guid postId) public async Task<int> GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.CountAsync(a => a.PostId == postId); .CountAsync(a => a.PostId == postId, GetCancellationToken(cancellationToken));
} }
public async Task<List<Comment>> GetRepliesOfComment(Guid id) public async Task<List<Comment>> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.Where(a => a.RepliedCommentId == id).ToListAsync(); .Where(a => a.RepliedCommentId == id).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task DeleteOfPost(Guid id) public async Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default)
{ {
var recordsToDelete = (await GetMongoQueryableAsync()).Where(pt => pt.PostId == id); var recordsToDelete = (await GetMongoQueryableAsync(cancellationToken)).Where(pt => pt.PostId == id);
foreach (var record in recordsToDelete) foreach (var record in recordsToDelete)
{ {
await DeleteAsync(record); await DeleteAsync(record, cancellationToken: GetCancellationToken(cancellationToken));
} }
} }
} }

23
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
@ -16,27 +17,27 @@ namespace Volo.Blogging.Posts
{ {
} }
public async Task<List<Post>> GetPostsByBlogId(Guid id) public async Task<List<Post>> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(); return await (await GetMongoQueryableAsync(cancellationToken)).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default)
{ {
var query = (await GetMongoQueryableAsync()).Where(p => blogId == p.BlogId && p.Url == url); var query = (await GetMongoQueryableAsync(cancellationToken)).Where(p => blogId == p.BlogId && p.Url == url);
if (excludingPostId != null) if (excludingPostId != null)
{ {
query = query.Where(p => excludingPostId != p.Id); query = query.Where(p => excludingPostId != p.Id);
} }
return await query.AnyAsync(); return await query.AnyAsync(GetCancellationToken(cancellationToken));
} }
public async Task<Post> GetPostByUrl(Guid blogId, string url) public async Task<Post> GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default)
{ {
var post = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); var post = await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url, GetCancellationToken(cancellationToken));
if (post == null) if (post == null)
{ {
@ -46,16 +47,16 @@ namespace Volo.Blogging.Posts
return post; return post;
} }
public async Task<List<Post>> GetOrderedList(Guid blogId, bool @descending = false) public async Task<List<Post>> GetOrderedList(Guid blogId, bool @descending = false, CancellationToken cancellationToken = default)
{ {
var query = (await GetMongoQueryableAsync()).Where(x => x.BlogId == blogId); var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.BlogId == blogId);
if (!descending) if (!descending)
{ {
return await query.OrderBy(x => x.CreationTime).ToListAsync(); return await query.OrderBy(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken));
} }
return await query.OrderByDescending(x => x.CreationTime).ToListAsync(); return await query.OrderByDescending(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

18
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs

@ -18,29 +18,29 @@ namespace Volo.Blogging.Tagging
{ {
} }
public async Task<List<Tag>> GetListAsync(Guid blogId) public async Task<List<Tag>> GetListAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId).ToListAsync(); return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<Tag> GetByNameAsync(Guid blogId, string name) public async Task<Tag> GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(); return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(GetCancellationToken(cancellationToken));
} }
public async Task<Tag> FindByNameAsync(Guid blogId, string name) public async Task<Tag> FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(); return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids) public async Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(); return await (await GetMongoQueryableAsync(cancellationToken)).Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default) public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default)
{ {
var tags = await (await GetMongoQueryableAsync()) var tags = await (await GetMongoQueryableAsync(cancellationToken))
.Where(t => ids.Contains(t.Id)) .Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));

4
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs

@ -15,7 +15,7 @@ namespace Volo.Blogging.Users
{ {
} }
public async Task<List<BlogUser>> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken) public async Task<List<BlogUser>> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken = default)
{ {
var query = await GetMongoQueryableAsync(cancellationToken); var query = await GetMongoQueryableAsync(cancellationToken);
@ -24,7 +24,7 @@ namespace Volo.Blogging.Users
query = query.Where(x => x.UserName.Contains(filter)); query = query.Where(x => x.UserName.Contains(filter));
} }
return await query.Take(maxCount).ToListAsync(cancellationToken); return await query.Take(maxCount).ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

2
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs

@ -54,7 +54,7 @@ namespace Volo.CmsKit.MongoDB.Contents
public async Task<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) public async Task<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()).AnyAsync(x => return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&
x.TenantId == tenantId, x.TenantId == tenantId,

2
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs

@ -63,7 +63,7 @@ namespace Volo.CmsKit.MongoDB.Pages
public virtual async Task<bool> ExistsAsync(string url, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(string url, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).AnyAsync(x => x.Url == url, GetCancellationToken(cancellationToken)); return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Url == url, GetCancellationToken(cancellationToken));
} }
} }
} }

9
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/IProjectRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -7,10 +8,10 @@ namespace Volo.Docs.Projects
{ {
public interface IProjectRepository : IBasicRepository<Project, Guid> public interface IProjectRepository : IBasicRepository<Project, Guid>
{ {
Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount); Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount, CancellationToken cancellationToken = default);
Task<Project> GetByShortNameAsync(string shortName); Task<Project> GetByShortNameAsync(string shortName, CancellationToken cancellationToken = default);
Task<bool> ShortNameExistsAsync(string shortName); Task<bool> ShortNameExistsAsync(string shortName, CancellationToken cancellationToken = default);
} }
} }

13
modules/docs/src/Volo.Docs.EntityFrameworkCore/Volo/Docs/Projects/EfCoreProjectRepository.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@ -18,20 +19,20 @@ namespace Volo.Docs.Projects
{ {
} }
public async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount) public async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount, CancellationToken cancellationToken = default)
{ {
var projects = await (await GetDbSetAsync()).OrderBy(sorting ?? "Id desc") var projects = await (await GetDbSetAsync()).OrderBy(sorting ?? "Id desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
return projects; return projects;
} }
public async Task<Project> GetByShortNameAsync(string shortName) public async Task<Project> GetByShortNameAsync(string shortName, CancellationToken cancellationToken = default)
{ {
var normalizeShortName = NormalizeShortName(shortName); var normalizeShortName = NormalizeShortName(shortName);
var project = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName); var project = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName, GetCancellationToken(cancellationToken));
if (project == null) if (project == null)
{ {
@ -41,11 +42,11 @@ namespace Volo.Docs.Projects
return project; return project;
} }
public async Task<bool> ShortNameExistsAsync(string shortName) public async Task<bool> ShortNameExistsAsync(string shortName, CancellationToken cancellationToken = default)
{ {
var normalizeShortName = NormalizeShortName(shortName); var normalizeShortName = NormalizeShortName(shortName);
return await (await GetDbSetAsync()).AnyAsync(x => x.ShortName == normalizeShortName); return await (await GetDbSetAsync()).AnyAsync(x => x.ShortName == normalizeShortName, GetCancellationToken(cancellationToken));
} }
private string NormalizeShortName(string shortName) private string NormalizeShortName(string shortName)

15
modules/docs/src/Volo.Docs.MongoDB/Volo/Docs/Projects/MongoProjectRepository.cs

@ -9,6 +9,7 @@ using Volo.Abp.MongoDB;
using Volo.Docs.MongoDB; using Volo.Docs.MongoDB;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading;
namespace Volo.Docs.Projects namespace Volo.Docs.Projects
{ {
@ -19,20 +20,20 @@ namespace Volo.Docs.Projects
{ {
} }
public async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount) public async Task<List<Project>> GetListAsync(string sorting, int maxResultCount, int skipCount, CancellationToken cancellationToken = default)
{ {
var projects = await (await GetMongoQueryableAsync()).OrderBy(sorting ?? "Id desc").As<IMongoQueryable<Project>>() var projects = await (await GetMongoQueryableAsync(cancellationToken)).OrderBy(sorting ?? "Id desc").As<IMongoQueryable<Project>>()
.PageBy<Project, IMongoQueryable<Project>>(skipCount, maxResultCount) .PageBy<Project, IMongoQueryable<Project>>(skipCount, maxResultCount)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
return projects; return projects;
} }
public async Task<Project> GetByShortNameAsync(string shortName) public async Task<Project> GetByShortNameAsync(string shortName, CancellationToken cancellationToken = default)
{ {
var normalizeShortName = NormalizeShortName(shortName); var normalizeShortName = NormalizeShortName(shortName);
var project = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName); var project = await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(p => p.ShortName == normalizeShortName, GetCancellationToken(cancellationToken));
if (project == null) if (project == null)
{ {
@ -42,11 +43,11 @@ namespace Volo.Docs.Projects
return project; return project;
} }
public async Task<bool> ShortNameExistsAsync(string shortName) public async Task<bool> ShortNameExistsAsync(string shortName, CancellationToken cancellationToken = default)
{ {
var normalizeShortName = NormalizeShortName(shortName); var normalizeShortName = NormalizeShortName(shortName);
return await (await GetMongoQueryableAsync()).AnyAsync(x => x.ShortName == normalizeShortName); return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.ShortName == normalizeShortName, GetCancellationToken(cancellationToken));
} }
private string NormalizeShortName(string shortName) private string NormalizeShortName(string shortName)

18
modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/IFeatureValueRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -7,10 +8,21 @@ namespace Volo.Abp.FeatureManagement
{ {
public interface IFeatureValueRepository : IBasicRepository<FeatureValue, Guid> public interface IFeatureValueRepository : IBasicRepository<FeatureValue, Guid>
{ {
Task<FeatureValue> FindAsync(string name, string providerName, string providerKey); Task<FeatureValue> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default);
Task<List<FeatureValue>> FindAllAsync(string name, string providerName, string providerKey); Task<List<FeatureValue>> FindAllAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default);
Task<List<FeatureValue>> GetListAsync(string providerName, string providerKey); Task<List<FeatureValue>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default);
} }
} }

26
modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -15,29 +16,38 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore
{ {
} }
public virtual async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey) public virtual async Task<FeatureValue> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, GetCancellationToken(cancellationToken));
s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey
);
} }
public async Task<List<FeatureValue>> FindAllAsync(string name, string providerName, string providerKey) public async Task<List<FeatureValue>> FindAllAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where( .Where(
s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey
).ToListAsync(); ).ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<FeatureValue>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<FeatureValue>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where( .Where(
s => s.ProviderName == providerName && s.ProviderKey == providerKey s => s.ProviderName == providerName && s.ProviderKey == providerKey
).ToListAsync(); ).ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

30
modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
@ -16,24 +17,35 @@ namespace Volo.Abp.FeatureManagement.MongoDB
} }
public virtual async Task<FeatureValue> FindAsync(string name, string providerName, string providerKey) public virtual async Task<FeatureValue> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey, GetCancellationToken(cancellationToken));
} }
public async Task<List<FeatureValue>> FindAllAsync(string name, string providerName, string providerKey) public async Task<List<FeatureValue>> FindAllAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.Where(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(); .Where(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<FeatureValue>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<FeatureValue>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

11
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs

@ -44,7 +44,8 @@ namespace Volo.Abp.Identity.MongoDB
userId, userId,
userName, userName,
clientId, clientId,
correlationId correlationId,
cancellationToken
); );
return await query.OrderBy(sorting ?? nameof(IdentitySecurityLog.CreationTime) + " desc") return await query.OrderBy(sorting ?? nameof(IdentitySecurityLog.CreationTime) + " desc")
@ -74,7 +75,8 @@ namespace Volo.Abp.Identity.MongoDB
userId, userId,
userName, userName,
clientId, clientId,
correlationId correlationId,
cancellationToken
); );
return await query.As<IMongoQueryable<IdentitySecurityLog>>() return await query.As<IMongoQueryable<IdentitySecurityLog>>()
@ -98,9 +100,10 @@ namespace Volo.Abp.Identity.MongoDB
Guid? userId = null, Guid? userId = null,
string userName = null, string userName = null,
string clientId = null, string clientId = null,
string correlationId = null) string correlationId = null,
CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync()) return (await GetMongoQueryableAsync(cancellationToken))
.WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value) .WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value)
.WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date) .WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date)
.WhereIf(!applicationName.IsNullOrWhiteSpace(), .WhereIf(!applicationName.IsNullOrWhiteSpace(),

9
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs

@ -21,7 +21,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
public async Task<List<PersistedGrant>> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false, public async Task<List<PersistedGrant>> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await FilterAsync(subjectId, sessionId, clientId, type)) return await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
@ -57,7 +57,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
string type = null, string type = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type)) var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken))
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
foreach (var persistedGrant in persistedGrants) foreach (var persistedGrant in persistedGrants)
@ -86,9 +86,10 @@ namespace Volo.Abp.IdentityServer.MongoDB
string subjectId, string subjectId,
string sessionId, string sessionId,
string clientId, string clientId,
string type) string type,
CancellationToken cancellationToken = default)
{ {
return (await GetMongoQueryableAsync()) return (await GetMongoQueryableAsync(cancellationToken))
.WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) .WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId)
.WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) .WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId)
.WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) .WhereIf<PersistedGrant, IMongoQueryable<PersistedGrant>>(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)

18
modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/ISettingRepository.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -7,10 +8,21 @@ namespace Volo.Abp.SettingManagement
{ {
public interface ISettingRepository : IBasicRepository<Setting, Guid> public interface ISettingRepository : IBasicRepository<Setting, Guid>
{ {
Task<Setting> FindAsync(string name, string providerName, string providerKey); Task<Setting> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default);
Task<List<Setting>> GetListAsync(string providerName, string providerKey); Task<List<Setting>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default);
Task<List<Setting>> GetListAsync(string[] names, string providerName, string providerKey); Task<List<Setting>> GetListAsync(
string[] names,
string providerName,
string providerKey,
CancellationToken cancellationToken = default);
} }
} }

29
modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/EfCoreSettingRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -8,36 +9,48 @@ using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.SettingManagement.EntityFrameworkCore namespace Volo.Abp.SettingManagement.EntityFrameworkCore
{ {
public class EfCoreSettingRepository : EfCoreRepository<ISettingManagementDbContext, Setting, Guid>, ISettingRepository public class EfCoreSettingRepository : EfCoreRepository<ISettingManagementDbContext, Setting, Guid>,
ISettingRepository
{ {
public EfCoreSettingRepository(IDbContextProvider<ISettingManagementDbContext> dbContextProvider) public EfCoreSettingRepository(IDbContextProvider<ISettingManagementDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
} }
public virtual async Task<Setting> FindAsync(string name, string providerName, string providerKey) public virtual async Task<Setting> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync( .FirstOrDefaultAsync(
s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey,
); GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<Setting>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<Setting>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where( .Where(
s => s.ProviderName == providerName && s.ProviderKey == providerKey s => s.ProviderName == providerName && s.ProviderKey == providerKey
).ToListAsync(); ).ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<Setting>> GetListAsync(string[] names, string providerName, string providerKey) public virtual async Task<List<Setting>> GetListAsync(
string[] names,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.Where( .Where(
s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey
).ToListAsync(); ).ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

36
modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/MongoSettingRepository.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
@ -9,33 +10,46 @@ using Volo.Abp.MongoDB;
namespace Volo.Abp.SettingManagement.MongoDB namespace Volo.Abp.SettingManagement.MongoDB
{ {
public class MongoSettingRepository : MongoDbRepository<ISettingManagementMongoDbContext, Setting, Guid>, ISettingRepository public class MongoSettingRepository : MongoDbRepository<ISettingManagementMongoDbContext, Setting, Guid>,
ISettingRepository
{ {
public MongoSettingRepository(IMongoDbContextProvider<ISettingManagementMongoDbContext> dbContextProvider) public MongoSettingRepository(IMongoDbContextProvider<ISettingManagementMongoDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
} }
public virtual async Task<Setting> FindAsync(string name, string providerName, string providerKey) public virtual async Task<Setting> FindAsync(
string name,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.OrderBy(x => x.Id) .OrderBy(x => x.Id)
.FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); .FirstOrDefaultAsync(
s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey,
GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<Setting>> GetListAsync(string providerName, string providerKey) public virtual async Task<List<Setting>> GetListAsync(
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<Setting>> GetListAsync(string[] names, string providerName, string providerKey) public virtual async Task<List<Setting>> GetListAsync(
string[] names,
string providerName,
string providerKey,
CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync()) return await (await GetMongoQueryableAsync(cancellationToken))
.Where(s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey) .Where(s => names.Contains(s.Name) && s.ProviderName == providerName && s.ProviderKey == providerKey)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
} }
} }
} }

Loading…
Cancel
Save