示例#1
0
        public AuditInfo CreateAuditInfo(Type type, MethodInfo method, IDictionary <Tuple <string, IEnumerable <Attribute> >, object> arguments)
        {
            var userAccount = _userContext.GetCurrentUser()?.UserAccount;

            var auditInfo = new AuditInfo
            {
                TenantId             = AbpSession.TenantId,
                UserId               = AbpSession.UserId,
                UserAccount          = userAccount,
                ImpersonatorUserId   = AbpSession.ImpersonatorUserId,
                ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
                ServiceName          = type != null
                    ? type.FullName
                    : "",
                MethodName            = method.Name,
                MethodDescription     = _localzaionHelper.CreateModuleLocalizableString(type.GetTypeInfo(), method)?.Name,
                Parameters            = ConvertArgumentsToJson(arguments.ToDictionary(k => k.Key.Item1, v => v.Value)),
                ParametersDescription = ConvertLocalizedArgumentsToJson(arguments),
                ExecutionTime         = Clock.Now
            };

            try
            {
                _auditInfoProvider.Fill(auditInfo);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
            }

            return(auditInfo);
        }
示例#2
0
        public AuditInfo CreateAuditInfo(Type type, MethodInfo method, IDictionary <string, object> arguments)
        {
            var auditInfo = new AuditInfo
            {
                TenantId             = CodeZeroSession.TenantId,
                UserId               = CodeZeroSession.UserId,
                ImpersonatorUserId   = CodeZeroSession.ImpersonatorUserId,
                ImpersonatorTenantId = CodeZeroSession.ImpersonatorTenantId,
                ServiceName          = type != null
                    ? type.FullName
                    : "",
                MethodName    = method.Name,
                Parameters    = ConvertArgumentsToJson(arguments),
                ExecutionTime = Clock.Now
            };

            try
            {
                _auditInfoProvider.Fill(auditInfo);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.ToString(), ex);
            }

            return(auditInfo);
        }
示例#3
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            using (AbpCrossCuttingConcerns.Applying(context.Controller, AbpCrossCuttingConcerns.Auditing))
            {
                if (!ShouldSaveAudit(context))
                {
                    await next();

                    return;
                }

                var auditInfo = CreateAuditInfo(context);
                var stopwatch = Stopwatch.StartNew();

                try
                {
                    await next();
                }
                catch (Exception ex)
                {
                    auditInfo.Exception = ex;
                    throw;
                }
                finally
                {
                    stopwatch.Stop();
                    auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
                    AuditInfoProvider?.Fill(auditInfo);
                    await AuditingStore.SaveAsync(auditInfo);
                }
            }
        }
示例#4
0
        public AuditInfo CreateAuditInfo(MethodInfo method, IDictionary <string, object> arguments)
        {
            var auditInfo = new AuditInfo
            {
                TenantId             = Session.TenantId,
                UserId               = Session.UserId,
                ImpersonatorUserId   = Session.ImpersonatorUserId,
                ImpersonatorTenantId = Session.ImpersonatorTenantId,
                ServiceName          = method.DeclaringType != null? method.DeclaringType.FullName : "",
                MethodName           = method.Name,
                Parameters           = ConvertArgumentsToJson(arguments),
                ExecutionTime        = Clock.Now
            };

            _auditInfoProvider.Fill(auditInfo);
            return(auditInfo);
        }
示例#5
0
        public void Intercept(IInvocation invocation)
        {
            if (!_configuration.IsEnabled)
            {
                invocation.Proceed();
                return;
            }

            if (!ShouldSaveAudit(invocation.MethodInvocationTarget))
            {
                invocation.Proceed();
                return;
            }

            var auditInfo = new AuditInfo
            {
                TenantId    = AbpSession.TenantId,
                UserId      = AbpSession.UserId,
                ServiceName = invocation.MethodInvocationTarget.DeclaringType != null
                              ? invocation.MethodInvocationTarget.DeclaringType.FullName
                              : "",
                MethodName    = invocation.MethodInvocationTarget.Name,
                Parameters    = ConvertArgumentsToJson(invocation),
                ExecutionTime = Clock.Now
            };

            _auditInfoProvider.Fill(auditInfo);

            var stopwatch = Stopwatch.StartNew();

            try
            {
                invocation.Proceed();
            }
            catch (Exception ex)
            {
                auditInfo.Exception = ex;
                throw;
            }
            finally
            {
                stopwatch.Stop();
                auditInfo.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
                _auditingStore.Save(auditInfo); //TODO: Call async when target method is async.
            }
        }
示例#6
0
        private AuditInfo CreateAuditInfo(IInvocation invocation)
        {
            var auditInfo = new AuditInfo
            {
                TenantId    = AbpSession.TenantId,
                UserId      = AbpSession.UserId,
                ServiceName = invocation.MethodInvocationTarget.DeclaringType != null
                    ? invocation.MethodInvocationTarget.DeclaringType.FullName
                    : "",
                MethodName    = invocation.MethodInvocationTarget.Name,
                Parameters    = ConvertArgumentsToJson(invocation),
                ExecutionTime = Clock.Now
            };

            _auditInfoProvider.Fill(auditInfo);

            return(auditInfo);
        }
示例#7
0
        private AuditInfo CreateAuditInfo(ActionExecutingContext context)
        {
            var auditInfo = new AuditInfo
            {
                TenantId             = AbpSession.TenantId,
                UserId               = AbpSession.UserId,
                ImpersonatorUserId   = AbpSession.ImpersonatorUserId,
                ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
                ServiceName          = context.Controller?.GetType().ToString() ?? "",
                MethodName           = context.ActionDescriptor.DisplayName,
                Parameters           = ConvertArgumentsToJson(context.ActionArguments),
                ExecutionTime        = Clock.Now
            };

            AuditInfoProvider.Fill(auditInfo);

            return(auditInfo);
        }