diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs index ad0e0d20c2..cd7e22b9a2 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs @@ -44,9 +44,10 @@ namespace Volo.Abp.AuditLogging Task> GetAverageExecutionDurationPerDayAsync( DateTime startDate, - DateTime endDate); + DateTime endDate, + CancellationToken cancellationToken = default); - Task GetEntityChange(Guid entityChangeId); + Task GetEntityChange(Guid entityChangeId, CancellationToken cancellationToken = default); Task> GetEntityChangeListAsync( string sorting = null, @@ -70,8 +71,8 @@ namespace Volo.Abp.AuditLogging string entityTypeFullName = null, CancellationToken cancellationToken = default); - Task GetEntityChangeWithUsernameAsync(Guid entityChangeId); + Task GetEntityChangeWithUsernameAsync(Guid entityChangeId, CancellationToken cancellationToken = default); - Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName); + Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName, CancellationToken cancellationToken = default); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs index edb1f3f599..acd1912925 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs +++ b/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); } - public virtual async Task> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate) + public virtual async Task> GetAverageExecutionDurationPerDayAsync( + DateTime startDate, + DateTime endDate, + CancellationToken cancellationToken = default) { var result = await (await GetDbSetAsync()).AsNoTracking() .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .OrderBy(t => t.ExecutionTime) .GroupBy(t => new { t.ExecutionTime.Date }) .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); } @@ -148,14 +151,16 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore return (await GetQueryableAsync()).IncludeDetails(); } - public virtual async Task GetEntityChange(Guid entityChangeId) + public virtual async Task GetEntityChange( + Guid entityChangeId, + CancellationToken cancellationToken = default) { var entityChange = await (await GetDbContextAsync()).Set() .AsNoTracking() .IncludeDetails() .Where(x => x.Id == entityChangeId) .OrderBy(x => x.Id) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); if (entityChange == null) { @@ -201,10 +206,12 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore return totalCount; } - public virtual async Task GetEntityChangeWithUsernameAsync(Guid entityChangeId) + public virtual async Task GetEntityChangeWithUsernameAsync( + Guid entityChangeId, + CancellationToken cancellationToken = default) { 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() { @@ -213,7 +220,10 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore }; } - public virtual async Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName) + public virtual async Task> GetEntityChangesWithUsernameAsync( + string entityId, + string entityTypeFullName, + CancellationToken cancellationToken = default) { var dbContext = await GetDbContextAsync(); @@ -225,7 +235,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore return await (from e in query join auditLog in dbContext.AuditLogs on e.AuditLogId equals auditLog.Id 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> GetEntityChangeListQueryAsync( diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index 788b6995bb..ce3c0e18c8 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -124,9 +124,12 @@ namespace Volo.Abp.AuditLogging.MongoDB } - public virtual async Task> GetAverageExecutionDurationPerDayAsync(DateTime startDate, DateTime endDate) + public virtual async Task> GetAverageExecutionDurationPerDayAsync( + DateTime startDate, + DateTime endDate, + CancellationToken cancellationToken = default) { - var result = await (await GetMongoQueryableAsync()) + var result = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .OrderBy(t => t.ExecutionTime) .GroupBy(t => new @@ -136,17 +139,19 @@ namespace Volo.Abp.AuditLogging.MongoDB t.ExecutionTime.Day }) .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); } - public virtual async Task GetEntityChange(Guid entityChangeId) + public virtual async Task GetEntityChange( + Guid entityChangeId, + CancellationToken cancellationToken = default) { - var entityChange = (await (await GetMongoQueryableAsync()) + var entityChange = (await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) .OrderBy(x => x.Id) - .FirstAsync()).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); + .FirstAsync(GetCancellationToken(cancellationToken))).EntityChanges.FirstOrDefault(x => x.Id == entityChangeId); if (entityChange == null) { @@ -194,11 +199,13 @@ namespace Volo.Abp.AuditLogging.MongoDB return count; } - public virtual async Task GetEntityChangeWithUsernameAsync(Guid entityChangeId) + public virtual async Task GetEntityChangeWithUsernameAsync( + Guid entityChangeId, + CancellationToken cancellationToken = default) { - var auditLog = (await (await GetMongoQueryableAsync()) + var auditLog = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.EntityChanges.Any(y => y.Id == entityChangeId)) - .FirstAsync()); + .FirstAsync(GetCancellationToken(cancellationToken)); return new EntityChangeWithUsername() { @@ -207,13 +214,16 @@ namespace Volo.Abp.AuditLogging.MongoDB }; } - public virtual async Task> GetEntityChangesWithUsernameAsync(string entityId, string entityTypeFullName) + public virtual async Task> GetEntityChangesWithUsernameAsync( + string entityId, + string entityTypeFullName, + CancellationToken cancellationToken = default) { - var auditLogs = await (await GetMongoQueryableAsync()) + var auditLogs = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) .Where(x => x.EntityChanges.Any(y => y.EntityId == entityId && y.EntityTypeFullName == entityTypeFullName)) .As>() .OrderByDescending(x => x.ExecutionTime) - .ToListAsync(); + .ToListAsync(GetCancellationToken(cancellationToken)); var entityChanges = auditLogs.SelectMany(x => x.EntityChanges).ToList();