private static async Task ProceedByLoggingAsync( IAbpMethodInvocation invocation, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope) { var auditLog = auditLogScope.Log; var auditLogAction = auditingHelper.CreateAuditLogAction( auditLog, invocation.TargetObject.GetType(), invocation.Method, invocation.Arguments ); var stopwatch = Stopwatch.StartNew(); try { await invocation.ProceedAsync(); } catch (Exception ex) { auditLog.Exceptions.Add(ex); throw; } finally { stopwatch.Stop(); auditLogAction.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds); auditLog.Actions.Add(auditLogAction); } }
protected virtual bool ShouldIntercept( IAbpMethodInvocation invocation, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.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); }
/// <summary> /// Shoulds the intercept. /// </summary> /// <param name="invocation">The invocation.</param> /// <param name="auditLog">The audit log.</param> /// <param name="auditLogAction">The audit log action.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> protected virtual bool ShouldIntercept( IMethodInvocation invocation, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; if (CrossCuttingConcerns.IsApplied(invocation.TargetObject, CrossCuttingConcerns.Auditing)) { return(false); } // 如果没有获取到 Scop,则返回 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); }
private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; var method = context.HttpContext.Request.Method; if (method.Equals(HttpMethod.Options.Method, StringComparison.OrdinalIgnoreCase)) { return(false); } if (!Options.IsEnabled) { return(false); } if (!context.ActionDescriptor.IsControllerAction()) { return(false); } var auditLogScope = _auditingManager.Current; if (auditLogScope == null) { return(false); } if (!_auditingHelper.ShouldSaveAudit(context.ActionDescriptor.GetMethodInfo(), true)) { return(false); } auditLog = auditLogScope.Log; auditLog.UserId = _currentUser?.Id; auditLog.UserName = _currentUser?.UserName; auditLogAction = _auditingHelper.CreateAuditLogAction( auditLog, context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(), context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo, context.ActionArguments ); return(true); }
private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; if (!Options.IsEnabled) { return(false); } if (!context.ActionDescriptor.IsControllerAction()) { return(false); } var auditLogScope = _auditingManager.Current; if (auditLogScope == null) { return(false); } if (!_auditingHelper.ShouldSaveAudit(context.ActionDescriptor.GetMethodInfo(), true)) { return(false); } //TODO: This is partially duplication of AuditHelper.ShouldSaveAudit method. Check why it does not work for controllers if (!AuditingInterceptorRegistrar.ShouldAuditTypeByDefault(context.Controller.GetType())) { return(false); } auditLog = auditLogScope.Log; auditLogAction = _auditingHelper.CreateAuditLogAction( auditLog, context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(), context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo, context.ActionArguments ); return(true); }
private bool ShouldSaveAudit(ActionExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; if (!Options.IsEnabled) { return(false); } if (!context.ActionDescriptor.IsControllerAction()) { return(false); } var auditLogScope = _auditingManager.Current; if (auditLogScope == null) { return(false); } if (!_auditingHelper.ShouldSaveAudit(context.ActionDescriptor.GetMethodInfo(), true)) { return(false); } auditLog = auditLogScope.Log; auditLogAction = _auditingHelper.CreateAuditLogAction( auditLog, context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(), context.ActionDescriptor.AsControllerActionDescriptor().MethodInfo, context.ActionArguments ); return(true); }
private bool ShouldSaveAudit(PageHandlerExecutingContext context, out AuditLogInfo auditLog, out AuditLogActionInfo auditLogAction) { auditLog = null; auditLogAction = null; if (!Options.IsEnabled) { return(false); } if (!context.ActionDescriptor.IsPageAction()) { return(false); } var auditLogScope = _auditingManager.Current; if (auditLogScope == null) { return(false); } if (!_auditingHelper.ShouldSaveAudit(context.HandlerMethod.MethodInfo, true)) { return(false); } auditLog = auditLogScope.Log; auditLogAction = _auditingHelper.CreateAuditLogAction( auditLog, context.HandlerMethod.GetType(), context.HandlerMethod.MethodInfo, context.HandlerArguments ); return(true); }