Ejemplo n.º 1
0
        protected virtual bool ShouldIntercept(
            IPlusMethodInvocation invocation,
            out AuditLogInfo auditLog,
            out AuditLogActionInfo auditLogAction)
        {
            auditLog       = null;
            auditLogAction = null;

            if (PlusCrossCuttingConcerns.IsApplied(invocation.TargetObject, PlusCrossCuttingConcerns.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);
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
 public virtual AuditLogActionInfo CreateAuditLogAction(
     AuditLogInfo auditLog,
     Type type,
     MethodInfo method,
     object[] arguments)
 {
     return(CreateAuditLogAction(auditLog, type, method, CreateArgumentsDictionary(method, arguments)));
 }
Ejemplo n.º 4
0
 public DisposableSaveHandle(
     AuditingManager auditingManager,
     IDisposable scope,
     AuditLogInfo auditLog,
     Stopwatch stopWatch)
 {
     _auditingManager = auditingManager;
     _scope           = scope;
     AuditLog         = auditLog;
     StopWatch        = stopWatch;
 }
Ejemplo n.º 5
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public virtual AuditLogInfo CreateAuditLogInfo()
        {
            var auditInfo = new AuditLogInfo
            {
                ApplicationName = Options.ApplicationName,
                TenantId        = CurrentTenant.Id,
                TenantName      = CurrentTenant.Name,
                UserId          = CurrentUser.Id,
                UserName        = CurrentUser.UserName,
                ClientId        = CurrentClient.Id,
                CorrelationId   = CorrelationIdProvider.Get(),
                //ImpersonatorUserId = PlusSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet!
                //ImpersonatorTenantId = PlusSession.ImpersonatorTenantId,
                ExecutionTime = Clock.Now
            };

            ExecutePreContributors(auditInfo);

            return(auditInfo);
        }
Ejemplo n.º 8
0
 public AuditLogContributionContext(IServiceProvider serviceProvider, AuditLogInfo auditInfo)
 {
     ServiceProvider = serviceProvider;
     AuditInfo       = auditInfo;
 }
Ejemplo n.º 9
0
 public Task SaveAsync(AuditLogInfo auditInfo)
 {
     Logger.LogInformation(auditInfo.ToString());
     return(Task.FromResult(0));
 }