Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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);
        }
 public virtual AuditLogActionInfo CreateAuditLogAction(
     AuditLogInfo auditLog,
     Type type,
     MethodInfo method,
     object[] arguments)
 {
     return(CreateAuditLogAction(auditLog, type, method, CreateArgumentsDictionary(method, arguments)));
 }
Beispiel #4
0
        protected bool ShouldSave(AuditLogInfo auditLog)
        {
            if (!auditLog.Actions.Any() && !auditLog.EntityChanges.Any())
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
 public DisposableSaveHandle(
     AuditingManager auditingManager,
     IDisposable scope,
     AuditLogInfo auditLog,
     Stopwatch stopWatch)
 {
     _auditingManager = auditingManager;
     _scope           = scope;
     AuditLog         = auditLog;
     StopWatch        = stopWatch;
 }
Beispiel #6
0
        public virtual AuditLogInfo CreateAuditLogInfo()
        {
            var auditInfo = new AuditLogInfo
            {
                TenantId = CurrentTenant.Id,
                UserId   = CurrentUser.Id,
                UserName = CurrentUser.UserName,
                //ImpersonatorUserId = AbpSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet!
                //ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
                ExecutionTime = Clock.Now
            };

            ExecutePreContributors(auditInfo);

            return(auditInfo);
        }
        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 = DateTime.Now
            };

            //TODO Execute contributors

            return(actionInfo);
        }
Beispiel #8
0
        protected virtual void ExecutePostContributors(AuditLogInfo auditLogInfo)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var context = new AuditLogContributionContext(scope.ServiceProvider, auditLogInfo);

                foreach (var contributor in Options.Contributors)
                {
                    try
                    {
                        contributor.PostContribute(context);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex, LogLevel.Warning);
                    }
                }
            }
        }
Beispiel #9
0
        public virtual AuditLogInfo CreateAuditLogInfo()
        {
            var auditInfo = new AuditLogInfo
            {
                ApplicationName = Options.ApplicationName,
                TenantId        = CurrentTenant.Id,
                UserId          = CurrentUser.Id,
                UserName        = CurrentUser.UserName,
                ClientId        = CurrentClient.Id,
                CorrelationId   = CorrelationIdProvider.Get(),
                //ImpersonatorUserId = AbpSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet!
                //ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
                ExecutionTime = Clock.Now
            };

            ExecutePreContributors(auditInfo);

            return(auditInfo);
        }
        public virtual AuditLogInfo CreateAuditLogInfo()
        {
            var auditInfo = new AuditLogInfo
            {
                ApplicationName = "PostSharpTest",
                TenantId        = null,
                TenantName      = "",
                UserId          = null,
                UserName        = "",
                ClientId        = "",
                CorrelationId   = "",
                //ImpersonatorUserId = AbpSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet!
                //ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
                ExecutionTime = DateTime.Now
            };

            //ExecutePreContributors(auditInfo);

            return(auditInfo);
        }
Beispiel #11
0
        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);
            }

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var auditingManager = scope.ServiceProvider.GetRequiredService <IAuditingManager>();
                var auditLogScope   = auditingManager.Current;
                if (auditLogScope == null)
                {
                    return(false);
                }

                var auditingHelper = scope.ServiceProvider.GetRequiredService <IAuditingHelper>();
                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 bool ShouldIntercept(MethodInterceptionArgs args, out AuditLogInfo auditLog,
                                               out AuditLogActionInfo auditLogAction)
        {
            auditLog       = new AuditLogInfo();
            auditLogAction = new AuditLogActionInfo();

            var auditLogScope = _auditingManager.Current;

            if (auditLogScope == null)
            {
                return(false);
            }

            auditLog       = auditLogScope.Log;
            auditLogAction = _auditingHelper.CreateAuditLogAction(
                auditLog,
                args.Method.DeclaringType?.GetType(),
                args.Method as MethodInfo,
                args.Arguments.ToArray()
                );

            return(true);
        }
 public AuditLogContributionContext(IServiceProvider serviceProvider, AuditLogInfo auditInfo)
 {
     ServiceProvider = serviceProvider;
     AuditInfo       = auditInfo;
 }
Beispiel #14
0
 public Task SaveAsync(AuditLogInfo auditInfo)
 {
     Save(auditInfo);
     return(Task.FromResult(0));
 }
Beispiel #15
0
 public void Save(AuditLogInfo auditInfo)
 {
     Logger.LogInformation(auditInfo.ToString());
 }
 public static void Save(this IAuditingStore auditingStore, AuditLogInfo auditInfo)
 {
     AsyncHelper.RunSync(() => auditingStore.SaveAsync(auditInfo));
 }
Beispiel #17
0
        public ValueTask SaveAsync(AuditLogInfo auditInfo)
        {
            Console.WriteLine(auditInfo.ToString());

            return(ValueTask.CompletedTask);
        }
        public Task SaveAsync(AuditLogInfo auditInfo)
        {
            Logger.LogInformation(auditInfo.ToString());

            return(Task.FromResult(0));
        }