protected virtual bool ShouldIntercept( IRocketMethodInvocation invocation, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; if (RocketCrossCuttingConcerns.IsApplied(invocation.TargetObject, RocketCrossCuttingConcerns.Auditing)) { return(false); } var auditLogScope = _auditingManager.Current; if (auditLogScope == null) { return(false); } if (!_auditingHelper.ShouldSaveAudit(invocation.Method)) { return(false); } auditLog = auditLogScope.Log; auditLogAction = _auditingHelper.CreateAuditLogAction( auditLog, invocation.TargetObject.GetType(), invocation.Method, invocation.Arguments ); return(true); }
protected virtual void MergeEntityChanges(AuditLogInfo auditLog) { var changeGroups = auditLog.EntityChanges .Where(e => e.ChangeType == EntityChangeType.Updated) .GroupBy(e => new { e.EntityTypeFullName, e.EntityId }) .ToList(); foreach (var changeGroup in changeGroups) { if (changeGroup.Count() <= 1) { continue; } var firstEntityChange = changeGroup.First(); foreach (var entityChangeInfo in changeGroup) { if (entityChangeInfo == firstEntityChange) { continue; } firstEntityChange.Merge(entityChangeInfo); auditLog.EntityChanges.Remove(entityChangeInfo); } } }
public virtual AuditLogActionInfo CreateAuditLogAction( AuditLogInfo auditLog, Type type, MethodInfo method, object[] arguments) { return(CreateAuditLogAction(auditLog, type, method, CreateArgumentsDictionary(method, arguments))); }
public DisposableSaveHandle( AuditingManager auditingManager, IDisposable scope, AuditLogInfo auditLog, Stopwatch stopWatch) { _auditingManager = auditingManager; _scope = scope; AuditLog = auditLog; StopWatch = stopWatch; }
protected virtual void ExecutePreContributors(AuditLogInfo auditLogInfo) { using (var scope = ServiceProvider.CreateScope()) { var context = new AuditLogContributionContext(scope.ServiceProvider, auditLogInfo); foreach (var contributor in Options.Contributors) { try { contributor.PreContribute(context); } catch (Exception ex) { Logger.LogException(ex, LogLevel.Warning); } } } }
public virtual AuditLogActionInfo CreateAuditLogAction( AuditLogInfo auditLog, Type type, MethodInfo method, IDictionary <string, object> arguments) { var actionInfo = new AuditLogActionInfo { ServiceName = type != null ? type.FullName : "", MethodName = method.Name, Parameters = SerializeConvertArguments(arguments), ExecutionTime = Clock.Now }; //TODO Execute contributors return(actionInfo); }
public virtual AuditLogInfo CreateAuditLogInfo() { var auditInfo = new AuditLogInfo { ApplicationName = Options.ApplicationName, TenantId = CurrentTenant.Id, TenantName = CurrentTenant.Name, UserId = CurrentUser.Id, UserName = CurrentUser.Name, UserPhoneNumber = CurrentUser.PhoneNumber, ClientId = CurrentClient.Id, CorrelationId = CorrelationIdProvider.Get(), //ImpersonatorUserId = RocketSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet! //ImpersonatorTenantId = RocketSession.ImpersonatorTenantId, ExecutionTime = Clock.Now }; ExecutePreContributors(auditInfo); return(auditInfo); }
public AuditLogContributionContext(IServiceProvider serviceProvider, AuditLogInfo auditInfo) { ServiceProvider = serviceProvider; AuditInfo = auditInfo; }
public Task SaveAsync(AuditLogInfo auditInfo) { Logger.LogInformation(auditInfo.ToString()); return(Task.FromResult(0)); }