Browse Source

Added startTime & endTime on IAuditLogRepository.

pull/1810/head
Halil İbrahim Kalkan 7 years ago
parent
commit
65c05a885d
  1. 4
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs
  2. 53
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs
  3. 56
      modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs
  4. 3
      modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs

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

@ -13,6 +13,8 @@ namespace Volo.Abp.AuditLogging
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = 50,
int skipCount = 0, int skipCount = 0,
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,
@ -26,6 +28,8 @@ namespace Volo.Abp.AuditLogging
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
Task<long> GetCountAsync( Task<long> GetCountAsync(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,

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

@ -23,6 +23,8 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = 50,
int skipCount = 0, int skipCount = 0,
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,
@ -35,7 +37,20 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxExecutionDuration, minExecutionDuration, hasException, httpStatusCode, includeDetails); var query = GetListQuery(
startTime,
endTime,
httpMethod,
url,
userName,
applicationName,
correlationId,
maxExecutionDuration,
minExecutionDuration,
hasException,
httpStatusCode,
includeDetails
);
var auditLogs = await query.OrderBy(sorting ?? "executionTime desc") var auditLogs = await query.OrderBy(sorting ?? "executionTime desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
@ -45,6 +60,8 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
} }
public async Task<long> GetCountAsync( public async Task<long> GetCountAsync(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,
@ -56,7 +73,19 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
HttpStatusCode? httpStatusCode = null, HttpStatusCode? httpStatusCode = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxExecutionDuration, minExecutionDuration, hasException, httpStatusCode); var query = GetListQuery(
startTime,
endTime,
httpMethod,
url,
userName,
applicationName,
correlationId,
maxExecutionDuration,
minExecutionDuration,
hasException,
httpStatusCode
);
var totalCount = await query.LongCountAsync(GetCancellationToken(cancellationToken)); var totalCount = await query.LongCountAsync(GetCancellationToken(cancellationToken));
@ -64,6 +93,8 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
} }
private IQueryable<AuditLog> GetListQuery( private IQueryable<AuditLog> GetListQuery(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,
@ -77,16 +108,18 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{ {
return DbSet.AsNoTracking() return DbSet.AsNoTracking()
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions.Length > 0) .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime)
.WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null || auditLog.Exceptions.Length == 0) .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime)
.WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod == httpMethod) .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null)
.WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null)
.WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod == httpMethod)
.WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.Contains(url)) .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.Contains(url))
.WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName) .WhereIf(userName != null, auditLog => auditLog.UserName == userName)
.WhereIf(applicationName != null, auditLog => auditLog.ApplicationName != null && auditLog.ApplicationName == applicationName) .WhereIf(applicationName != null, auditLog => auditLog.ApplicationName == applicationName)
.WhereIf(correlationId != null, auditLog => auditLog.CorrelationId != null && auditLog.CorrelationId == correlationId) .WhereIf(correlationId != null, auditLog => auditLog.CorrelationId == correlationId)
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode) .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode)
.WhereIf(maxExecutionDuration != null && maxExecutionDuration > 0, auditLog => auditLog.ExecutionDuration <= maxExecutionDuration) .WhereIf(maxExecutionDuration != null && maxExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration <= maxExecutionDuration)
.WhereIf(minExecutionDuration != null && minExecutionDuration > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration); .WhereIf(minExecutionDuration != null && minExecutionDuration.Value > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration);
} }
public override IQueryable<AuditLog> WithDetails() public override IQueryable<AuditLog> WithDetails()

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

@ -24,6 +24,8 @@ namespace Volo.Abp.AuditLogging.MongoDB
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = 50,
int skipCount = 0, int skipCount = 0,
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,
@ -36,14 +38,29 @@ namespace Volo.Abp.AuditLogging.MongoDB
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxDuration, minDuration, hasException, httpStatusCode, includeDetails); var query = GetListQuery(
startTime,
endTime,
httpMethod,
url,
userName,
applicationName,
correlationId,
maxDuration,
minDuration,
hasException,
httpStatusCode,
includeDetails
);
return await query.OrderBy(sorting ?? "executionTime desc").As<IMongoQueryable<AuditLog>>() return await query.OrderBy(sorting ?? "executionTime desc").As<IMongoQueryable<AuditLog>>()
.PageBy<AuditLog, IMongoQueryable<AuditLog>>(skipCount, maxResultCount) .PageBy<AuditLog, IMongoQueryable<AuditLog>>(skipCount, maxResultCount)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<long> GetCountAsync( public async Task<long> GetCountAsync(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,
@ -55,14 +72,29 @@ namespace Volo.Abp.AuditLogging.MongoDB
HttpStatusCode? httpStatusCode = null, HttpStatusCode? httpStatusCode = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxDuration, minDuration, hasException, httpStatusCode); var query = GetListQuery(
startTime,
endTime,
httpMethod,
url,
userName,
applicationName,
correlationId,
maxDuration,
minDuration,
hasException,
httpStatusCode
);
var count = await query.As<IMongoQueryable<AuditLog>>().LongCountAsync(); var count = await query.As<IMongoQueryable<AuditLog>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
return count; return count;
} }
private IQueryable<AuditLog> GetListQuery( private IQueryable<AuditLog> GetListQuery(
DateTime? startTime = null,
DateTime? endTime = null,
string httpMethod = null, string httpMethod = null,
string url = null, string url = null,
string userName = null, string userName = null,
@ -75,13 +107,15 @@ namespace Volo.Abp.AuditLogging.MongoDB
bool includeDetails = false) bool includeDetails = false)
{ {
return GetMongoQueryable() return GetMongoQueryable()
.WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null && auditLog.Exceptions.Length > 0) .WhereIf(startTime.HasValue, auditLog => auditLog.ExecutionTime >= startTime)
.WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null || auditLog.Exceptions.Length == 0) .WhereIf(endTime.HasValue, auditLog => auditLog.ExecutionTime <= endTime)
.WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant()) .WhereIf(hasException.HasValue && hasException.Value, auditLog => auditLog.Exceptions != null)
.WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant())) .WhereIf(hasException.HasValue && !hasException.Value, auditLog => auditLog.Exceptions == null)
.WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName.ToLowerInvariant() == userName.ToLowerInvariant()) .WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod == httpMethod)
.WhereIf(applicationName != null, auditLog => auditLog.ApplicationName != null && auditLog.ApplicationName.ToLowerInvariant() == applicationName.ToLowerInvariant()) .WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.Contains(url))
.WhereIf(correlationId != null, auditLog => auditLog.CorrelationId != null && auditLog.CorrelationId.ToLowerInvariant() == correlationId.ToLowerInvariant()) .WhereIf(userName != null, auditLog => auditLog.UserName == userName)
.WhereIf(applicationName != null, auditLog => auditLog.ApplicationName == applicationName)
.WhereIf(correlationId != null, auditLog => auditLog.CorrelationId == correlationId)
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode) .WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode)
.WhereIf(maxDuration != null && maxDuration > 0, auditLog => auditLog.ExecutionDuration <= maxDuration) .WhereIf(maxDuration != null && maxDuration > 0, auditLog => auditLog.ExecutionDuration <= maxDuration)
.WhereIf(minDuration != null && minDuration > 0, auditLog => auditLog.ExecutionDuration >= minDuration); .WhereIf(minDuration != null && minDuration > 0, auditLog => auditLog.ExecutionDuration >= minDuration);

3
modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs

@ -103,8 +103,7 @@ namespace VoloDocs.Web
options.DocInclusionPredicate((docName, description) => true); options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName); options.CustomSchemaIds(type => type.FullName);
}); });
Configure<VirtualFileSystemOptions>(options => Configure<VirtualFileSystemOptions>(options =>
{ {
options.FileSets.AddEmbedded<VoloDocsWebModule>("VoloDocs.Web"); options.FileSets.AddEmbedded<VoloDocsWebModule>("VoloDocs.Web");

Loading…
Cancel
Save