Browse Source

Added TruncateFromBeginning extension and used in audit loggng module

pull/395/head
Yunus Emre Kalkan 8 years ago
parent
commit
89f57cb738
  1. 19
      framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs
  2. 6
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityPropertyChangeConsts.cs
  3. 4
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs
  4. 7
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs
  5. 4
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs
  6. 8
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs

19
framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs

@ -364,6 +364,25 @@ namespace System
return str.Left(maxLength); return str.Left(maxLength);
} }
/// <summary>
/// Gets a substring of a string from Ending of the string if it exceeds maximum length.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
public static string TruncateFromBeginning(this string str, int maxLength)
{
if (str == null)
{
return null;
}
if (str.Length <= maxLength)
{
return str;
}
return str.Right(maxLength);
}
/// <summary> /// <summary>
/// Gets a substring of a string from beginning of the string if it exceeds maximum length. /// Gets a substring of a string from beginning of the string if it exceeds maximum length.
/// It adds a "..." postfix to end of the string if it's truncated. /// It adds a "..." postfix to end of the string if it's truncated.

6
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityPropertyChangeConsts.cs

@ -1,8 +1,4 @@
using System; namespace Volo.Abp.AuditLogging
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.AuditLogging
{ {
public class EntityPropertyChangeConsts public class EntityPropertyChangeConsts
{ {

4
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs

@ -59,8 +59,8 @@ namespace Volo.Abp.AuditLogging
ExecutionTime = auditInfo.ExecutionTime; ExecutionTime = auditInfo.ExecutionTime;
ExecutionDuration = auditInfo.ExecutionDuration; ExecutionDuration = auditInfo.ExecutionDuration;
ClientIpAddress = auditInfo.ClientIpAddress; ClientIpAddress = auditInfo.ClientIpAddress;
ClientName = auditInfo.ClientName; ClientName = auditInfo.ClientName.Truncate(AuditLogConsts.MaxClientNameLength);
BrowserInfo = auditInfo.BrowserInfo; BrowserInfo = auditInfo.BrowserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength);
HttpMethod = auditInfo.HttpMethod; HttpMethod = auditInfo.HttpMethod;
Url = auditInfo.Url; Url = auditInfo.Url;
HttpStatusCode = auditInfo.HttpStatusCode; HttpStatusCode = auditInfo.HttpStatusCode;

7
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs

@ -34,15 +34,16 @@ namespace Volo.Abp.AuditLogging
public AuditLogAction(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo) public AuditLogAction(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo)
{ {
Id = id; Id = id;
TenantId = actionInfo.TenantId; TenantId = actionInfo.TenantId;
AuditLogId = auditLogId; AuditLogId = auditLogId;
ServiceName = actionInfo.ServiceName;
MethodName = actionInfo.MethodName;
Parameters = actionInfo.Parameters;
ExecutionTime = actionInfo.ExecutionTime; ExecutionTime = actionInfo.ExecutionTime;
ExecutionDuration = actionInfo.ExecutionDuration; ExecutionDuration = actionInfo.ExecutionDuration;
ExtraProperties = actionInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value); ExtraProperties = actionInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value);
ServiceName = actionInfo.ServiceName.TruncateFromBeginning(AuditLogActionConsts.MaxServiceNameLength);
MethodName = actionInfo.MethodName.TruncateFromBeginning(AuditLogActionConsts.MaxMethodNameLength);
Parameters = actionInfo.Parameters.Length > AuditLogActionConsts.MaxParametersLength ? "" : actionInfo.Parameters;
} }
} }
} }

4
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs

@ -40,8 +40,8 @@ namespace Volo.Abp.AuditLogging
TenantId = entityChangeInfo.TenantId; TenantId = entityChangeInfo.TenantId;
ChangeTime = entityChangeInfo.ChangeTime; ChangeTime = entityChangeInfo.ChangeTime;
ChangeType = entityChangeInfo.ChangeType; ChangeType = entityChangeInfo.ChangeType;
EntityId = entityChangeInfo.EntityId; EntityId = entityChangeInfo.EntityId.Truncate(EntityChangeConsts.MaxEntityTypeFullNameLength);
EntityTypeFullName = entityChangeInfo.EntityTypeFullName; EntityTypeFullName = entityChangeInfo.EntityTypeFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength);
PropertyChanges = entityChangeInfo.PropertyChanges.Select(p => new EntityPropertyChange(guidGenerator, Id, p)).ToList(); PropertyChanges = entityChangeInfo.PropertyChanges.Select(p => new EntityPropertyChange(guidGenerator, Id, p)).ToList();
ExtraProperties = entityChangeInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value); ExtraProperties = entityChangeInfo.ExtraProperties.ToDictionary(pair => pair.Key, pair => pair.Value);
} }

8
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityPropertyChange.cs

@ -31,10 +31,10 @@ namespace Volo.Abp.AuditLogging
Id = guidGenerator.Create(); Id = guidGenerator.Create();
TenantId = entityChangeInfo.TenantId; TenantId = entityChangeInfo.TenantId;
EntityChangeId = entityChangeId; EntityChangeId = entityChangeId;
NewValue = entityChangeInfo.NewValue; NewValue = entityChangeInfo.NewValue.Truncate(EntityPropertyChangeConsts.MaxNewValueLength);
OriginalValue = entityChangeInfo.OriginalValue; OriginalValue = entityChangeInfo.OriginalValue.Truncate(EntityPropertyChangeConsts.MaxOriginalValueLength);
PropertyName = entityChangeInfo.PropertyName; PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength);
PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName; PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength);
} }
} }
} }
Loading…
Cancel
Save