Exemplo n.º 1
0
        public EntityChange(
            IGuidGenerator guidGenerator,
            Guid auditLogId,
            EntityChangeInfo entityChangeInfo,
            Guid?tenantId = null)
        {
            Id                 = guidGenerator.Create();
            AuditLogId         = auditLogId;
            TenantId           = tenantId;
            ChangeTime         = entityChangeInfo.ChangeTime;
            ChangeType         = entityChangeInfo.ChangeType;
            EntityId           = entityChangeInfo.EntityId.Truncate(EntityChangeConsts.MaxEntityTypeFullNameLength);
            EntityTypeFullName = entityChangeInfo.EntityTypeFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength);

            PropertyChanges = entityChangeInfo
                              .PropertyChanges?
                              .Select(p => new EntityPropertyChange(guidGenerator, Id, p, tenantId))
                              .ToList()
                              ?? new List <EntityPropertyChange>();

            ExtraProperties = new ExtraPropertyDictionary();
            if (entityChangeInfo.ExtraProperties != null)
            {
                foreach (var pair in entityChangeInfo.ExtraProperties)
                {
                    ExtraProperties.Add(pair.Key, pair.Value);
                }
            }
        }
Exemplo n.º 2
0
        public AuditLog(IGuidGenerator guidGenerator, AuditLogInfo auditInfo)
            : base(guidGenerator.Create())
        {
            ApplicationName   = auditInfo.ApplicationName.Truncate(AuditLogConsts.MaxApplicationNameLength);
            TenantId          = auditInfo.TenantId;
            TenantName        = auditInfo.TenantName.Truncate(AuditLogConsts.MaxTenantNameLength);
            UserId            = auditInfo.UserId;
            UserName          = auditInfo.UserName.Truncate(AuditLogConsts.MaxUserNameLength);
            ExecutionTime     = auditInfo.ExecutionTime;
            ExecutionDuration = auditInfo.ExecutionDuration;
            ClientIpAddress   = auditInfo.ClientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength);
            ClientName        = auditInfo.ClientName.Truncate(AuditLogConsts.MaxClientNameLength);
            ClientId          = auditInfo.ClientId.Truncate(AuditLogConsts.MaxClientIdLength);
            CorrelationId     = auditInfo.CorrelationId.Truncate(AuditLogConsts.MaxCorrelationIdLength);
            BrowserInfo       = auditInfo.BrowserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength);
            HttpMethod        = auditInfo.HttpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength);
            Url                  = auditInfo.Url.Truncate(AuditLogConsts.MaxUrlLength);
            HttpStatusCode       = auditInfo.HttpStatusCode;
            ImpersonatorUserId   = auditInfo.ImpersonatorUserId;
            ImpersonatorTenantId = auditInfo.ImpersonatorTenantId;

            ExtraProperties = new ExtraPropertyDictionary();
            if (auditInfo.ExtraProperties != null)
            {
                foreach (var pair in auditInfo.ExtraProperties)
                {
                    ExtraProperties.Add(pair.Key, pair.Value);
                }
            }

            EntityChanges = auditInfo
                            .EntityChanges?
                            .Select(entityChangeInfo => new EntityChange(guidGenerator, Id, entityChangeInfo, tenantId: auditInfo.TenantId))
                            .ToList()
                            ?? new List <EntityChange>();

            Actions = auditInfo
                      .Actions?
                      .Select(auditLogActionInfo => new AuditLogAction(guidGenerator.Create(), Id, auditLogActionInfo, tenantId: auditInfo.TenantId))
                      .ToList()
                      ?? new List <AuditLogAction>();

            Exceptions = auditInfo
                         .Exceptions?
                         .JoinAsString(Environment.NewLine)
                         .Truncate(AuditLogConsts.MaxExceptionsLengthValue);

            Comments = auditInfo
                       .Comments?
                       .JoinAsString(Environment.NewLine)
                       .Truncate(AuditLogConsts.MaxCommentsLength);
        }
Exemplo n.º 3
0
    public virtual Task <AuditLog> ConvertAsync(AuditLogInfo auditLogInfo)
    {
        var auditLogId = GuidGenerator.Create();

        var extraProperties = new ExtraPropertyDictionary();

        if (auditLogInfo.ExtraProperties != null)
        {
            foreach (var pair in auditLogInfo.ExtraProperties)
            {
                extraProperties.Add(pair.Key, pair.Value);
            }
        }

        var entityChanges = auditLogInfo
                            .EntityChanges?
                            .Select(entityChangeInfo => new EntityChange(GuidGenerator, auditLogId, entityChangeInfo, tenantId: auditLogInfo.TenantId))
                            .ToList()
                            ?? new List <EntityChange>();

        var actions = auditLogInfo
                      .Actions?
                      .Select(auditLogActionInfo => new AuditLogAction(GuidGenerator.Create(), auditLogId, auditLogActionInfo, tenantId: auditLogInfo.TenantId))
                      .ToList()
                      ?? new List <AuditLogAction>();

        var remoteServiceErrorInfos = auditLogInfo.Exceptions?.Select(exception => ExceptionToErrorInfoConverter.Convert(exception, true))
                                      ?? new List <RemoteServiceErrorInfo>();

        var exceptions = remoteServiceErrorInfos.Any()
            ? JsonSerializer.Serialize(remoteServiceErrorInfos, indented: true)
            : null;

        var comments = auditLogInfo
                       .Comments?
                       .JoinAsString(Environment.NewLine);

        var auditLog = new AuditLog(
            auditLogId,
            auditLogInfo.ApplicationName,
            auditLogInfo.TenantId,
            auditLogInfo.TenantName,
            auditLogInfo.UserId,
            auditLogInfo.UserName,
            auditLogInfo.ExecutionTime,
            auditLogInfo.ExecutionDuration,
            auditLogInfo.ClientIpAddress,
            auditLogInfo.ClientName,
            auditLogInfo.ClientId,
            auditLogInfo.CorrelationId,
            auditLogInfo.BrowserInfo,
            auditLogInfo.HttpMethod,
            auditLogInfo.Url,
            auditLogInfo.HttpStatusCode,
            auditLogInfo.ImpersonatorUserId,
            auditLogInfo.ImpersonatorTenantId,
            extraProperties,
            entityChanges,
            actions,
            exceptions,
            comments
            );

        return(Task.FromResult(auditLog));
    }