Browse Source

Merge branch 'master' of https://github.com/volosoft/abp

pull/395/head
Halil ibrahim Kalkan 8 years ago
parent
commit
006ebdbb0e
  1. 19
      framework/src/Volo.Abp.Core/System/AbpStringExtensions.cs
  2. 15
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs
  3. 5
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs
  4. 20
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/Reflection/TypeHelper_Tests.cs
  5. 6
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/EntityPropertyChangeConsts.cs
  6. 4
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs
  7. 7
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLogAction.cs
  8. 4
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/EntityChange.cs
  9. 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);
}
/// <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>
/// 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.

15
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Reflection;
namespace Volo.Abp.Reflection
@ -33,8 +34,8 @@ namespace Volo.Abp.Reflection
return true;
}
if (includeNullables &&
type.IsGenericType &&
if (includeNullables &&
type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0], includeEnums);
@ -43,6 +44,16 @@ namespace Volo.Abp.Reflection
return false;
}
public static Type GetFirstGenericArgumentIfNullable(this Type t)
{
if (t.GetGenericArguments().Length > 0 && t.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return t.GetGenericArguments().FirstOrDefault();
}
return t;
}
private static bool IsPrimitiveExtendedInternal(Type type, bool includeEnums)
{
if (type.IsPrimitive)

5
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs

@ -13,6 +13,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Json;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Reflection;
using Volo.Abp.Timing;
using Volo.Abp.Uow;
@ -170,7 +171,7 @@ namespace Volo.Abp.EntityFrameworkCore.EntityHistory
NewValue = isDeleted ? null : JsonSerializer.Serialize(propertyEntry.CurrentValue).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength),
OriginalValue = isCreated ? null : JsonSerializer.Serialize(propertyEntry.OriginalValue).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength),
PropertyName = property.Name,
PropertyTypeFullName = property.ClrType.FullName,
PropertyTypeFullName = property.ClrType.GetFirstGenericArgumentIfNullable().FullName,
TenantId = GetTenantId(entityEntry.Entity)
});
}
@ -311,7 +312,7 @@ namespace Volo.Abp.EntityFrameworkCore.EntityHistory
NewValue = JsonSerializer.Serialize(propertyEntry.CurrentValue),
OriginalValue = JsonSerializer.Serialize(propertyEntry.OriginalValue),
PropertyName = property.Name,
PropertyTypeFullName = property.ClrType.FullName
PropertyTypeFullName = property.ClrType.GetFirstGenericArgumentIfNullable().FullName
});
}

20
framework/test/Volo.Abp.Core.Tests/Volo/Abp/Reflection/TypeHelper_Tests.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using Shouldly;
using Xunit;
namespace Volo.Abp.Reflection
{
public class TypeHelper_Tests
{
[Fact]
public void Should_Generic_Type_From_Nullable()
{
var nullableType = typeof(Guid?);
var guidType = nullableType.GetFirstGenericArgumentIfNullable();
guidType.ShouldBe(typeof(Guid));
}
}
}

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

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.AuditLogging
namespace Volo.Abp.AuditLogging
{
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;
ExecutionDuration = auditInfo.ExecutionDuration;
ClientIpAddress = auditInfo.ClientIpAddress;
ClientName = auditInfo.ClientName;
BrowserInfo = auditInfo.BrowserInfo;
ClientName = auditInfo.ClientName.Truncate(AuditLogConsts.MaxClientNameLength);
BrowserInfo = auditInfo.BrowserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength);
HttpMethod = auditInfo.HttpMethod;
Url = auditInfo.Url;
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)
{
Id = id;
TenantId = actionInfo.TenantId;
AuditLogId = auditLogId;
ServiceName = actionInfo.ServiceName;
MethodName = actionInfo.MethodName;
Parameters = actionInfo.Parameters;
ExecutionTime = actionInfo.ExecutionTime;
ExecutionDuration = actionInfo.ExecutionDuration;
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;
ChangeTime = entityChangeInfo.ChangeTime;
ChangeType = entityChangeInfo.ChangeType;
EntityId = entityChangeInfo.EntityId;
EntityTypeFullName = entityChangeInfo.EntityTypeFullName;
EntityId = entityChangeInfo.EntityId.Truncate(EntityChangeConsts.MaxEntityTypeFullNameLength);
EntityTypeFullName = entityChangeInfo.EntityTypeFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength);
PropertyChanges = entityChangeInfo.PropertyChanges.Select(p => new EntityPropertyChange(guidGenerator, Id, p)).ToList();
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();
TenantId = entityChangeInfo.TenantId;
EntityChangeId = entityChangeId;
NewValue = entityChangeInfo.NewValue;
OriginalValue = entityChangeInfo.OriginalValue;
PropertyName = entityChangeInfo.PropertyName;
PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName;
NewValue = entityChangeInfo.NewValue.Truncate(EntityPropertyChangeConsts.MaxNewValueLength);
OriginalValue = entityChangeInfo.OriginalValue.Truncate(EntityPropertyChangeConsts.MaxOriginalValueLength);
PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength);
PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength);
}
}
}
Loading…
Cancel
Save