private async Task ProcessWithNewAuditingScopeAsync( IAbpMethodInvocation invocation, AbpAuditingOptions options, ICurrentUser currentUser, IAuditingManager auditingManager, IAuditingHelper auditingHelper) { var hasError = false; using (var saveHandle = auditingManager.BeginScope()) { try { await ProceedByLoggingAsync(invocation, auditingHelper, auditingManager.Current); Debug.Assert(auditingManager.Current != null); if (auditingManager.Current.Log.Exceptions.Any()) { hasError = true; } } catch (Exception) { hasError = true; throw; } finally { if (ShouldWriteAuditLog(invocation, options, currentUser, hasError)) { await saveHandle.SaveAsync(); } } } }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { bool hasError = false; using (var scope = _auditingManager.BeginScope()) { try { await next(context); if (_auditingManager.Current.Log.Exceptions.Any()) { hasError = true; } } catch (Exception) { hasError = true; throw; } finally { if (ShouldWriteAuditLog(context, hasError)) { await scope.SaveAsync(); } } } }
public void AttributedAuditing() { using (_auditingManager.BeginScope()) { var service = ServiceProvider.GetService <IAttributedAuditingInterface>(); service.Test("test", 19); } var store = ServiceProvider.GetService <IAuditingStore>().ShouldBeOfType <FackAuditingStore>(); store.Info.ShouldNotBeNull(); store.Info.CurrentUser.ShouldBe("TestUser"); var action = store.Info.Actions.ShouldHaveSingleItem(); action.ServiceName.ShouldBe(typeof(AttributedAuditingInterface).FullName); action.MethodName.ShouldBe("Test"); }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { if (!AuditingOptions.IsEnabled || IsIgnoredUrl(context)) { await next(context); return; } var hasError = false; using (var saveHandle = _auditingManager.BeginScope()) { Debug.Assert(_auditingManager.Current != null); try { await next(context); if (_auditingManager.Current.Log.Exceptions.Any()) { hasError = true; } } catch (Exception ex) { hasError = true; if (!_auditingManager.Current.Log.Exceptions.Contains(ex)) { _auditingManager.Current.Log.Exceptions.Add(ex); } throw; } finally { if (ShouldWriteAuditLog(context, hasError)) { if (UnitOfWorkManager.Current != null) { try { await UnitOfWorkManager.Current.SaveChangesAsync(); } catch (Exception ex) { if (!_auditingManager.Current.Log.Exceptions.Contains(ex)) { _auditingManager.Current.Log.Exceptions.Add(ex); } } } await saveHandle.SaveAsync(); } } } }
public async Task Should_Write_AuditLog_For_Classes_That_Implement_IAuditingEnabled() { var myAuditedObject1 = GetRequiredService <MyAuditedObject1>(); using (var scope = _auditingManager.BeginScope()) { await myAuditedObject1.DoItAsync(new InputObject { Value1 = "forty-two", Value2 = 42 }); await scope.SaveAsync(); } #pragma warning disable 4014 _auditingStore.Received().SaveAsync(Arg.Any <AuditLogInfo>()); #pragma warning restore 4014 }
public async Task Should_Save_Audit_Logs_To_The_Tenant_Begins_The_Scope() { //Arrange var applicationName = Guid.NewGuid().ToString(); var tenantId = Guid.NewGuid(); var entityId1 = Guid.NewGuid(); var entityId2 = Guid.NewGuid(); //Act using (var scope = _auditingManager.BeginScope()) { _auditingManager.Current.Log.ApplicationName = applicationName; //Creating a host entity _auditingManager.Current.Log.EntityChanges.Add( new EntityChangeInfo { ChangeTime = DateTime.Now, ChangeType = EntityChangeType.Created, EntityEntry = new object(), EntityId = entityId1.ToString(), EntityTypeFullName = "TestEntity" } ); //Creating a tenant entity _auditingManager.Current.Log.EntityChanges.Add( new EntityChangeInfo { ChangeTime = DateTime.Now, ChangeType = EntityChangeType.Created, EntityEntry = new object(), EntityId = entityId2.ToString(), EntityTypeFullName = "TestEntity", EntityTenantId = tenantId } ); await scope.SaveAsync().ConfigureAwait(false); } //Assert var auditLogs = await _auditLogRepository.GetListAsync(applicationName : applicationName, includeDetails : true).ConfigureAwait(false); auditLogs.Count.ShouldBe(1); var auditLog = auditLogs.First(); auditLog.EntityChanges.ShouldNotBeNull(); auditLog.EntityChanges.Count.ShouldBe(2); auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId1.ToString()); auditLog.EntityChanges.ShouldContain(e => e.EntityId == entityId2.ToString()); }
public async Task Invoke(HttpContext httpContext) { if (!ShouldWriteAuditLog(httpContext)) { await _next(httpContext); return; } using (var scope = _auditingManager.BeginScope()) { try { await _next(httpContext); } finally { await scope.SaveAsync(); } } }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { if (!ShouldWriteAuditLog(context)) { await next(context).ConfigureAwait(false); return; } using (var scope = _auditingManager.BeginScope()) { try { await next(context).ConfigureAwait(false); } finally { await scope.SaveAsync().ConfigureAwait(false); } } }