Browse Source

Enable nullable annotations for Volo.Abp.Auditing

pull/17108/head
liangshiwei 3 years ago
parent
commit
af1d8a84be
  1. 2
      framework/src/Volo.Abp.Auditing/Volo.Abp.Auditing.csproj
  2. 2
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs
  3. 6
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogActionInfo.cs
  4. 24
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs
  5. 22
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs
  6. 8
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptor.cs
  7. 4
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingManager.cs
  8. 8
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs
  9. 8
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityPropertyChangeInfo.cs
  10. 10
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditingHelper.cs
  11. 3
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditingManager.cs
  12. 6
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs

2
framework/src/Volo.Abp.Auditing/Volo.Abp.Auditing.csproj

@ -5,6 +5,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks> <TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.Auditing</AssemblyName> <AssemblyName>Volo.Abp.Auditing</AssemblyName>
<PackageId>Volo.Abp.Auditing</PackageId> <PackageId>Volo.Abp.Auditing</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

2
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs

@ -26,7 +26,7 @@ public class AbpAuditingOptions
/// The name of the application or service writing audit logs. /// The name of the application or service writing audit logs.
/// Default: null. /// Default: null.
/// </summary> /// </summary>
public string ApplicationName { get; set; } public string? ApplicationName { get; set; }
/// <summary> /// <summary>
/// Default: true. /// Default: true.

6
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogActionInfo.cs

@ -7,11 +7,11 @@ namespace Volo.Abp.Auditing;
[Serializable] [Serializable]
public class AuditLogActionInfo : IHasExtraProperties public class AuditLogActionInfo : IHasExtraProperties
{ {
public string ServiceName { get; set; } public string ServiceName { get; set; } = default!;
public string MethodName { get; set; } public string MethodName { get; set; } = default!;
public string Parameters { get; set; } public string Parameters { get; set; } = default!;
public DateTime ExecutionTime { get; set; } public DateTime ExecutionTime { get; set; }

24
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs

@ -9,43 +9,43 @@ namespace Volo.Abp.Auditing;
[Serializable] [Serializable]
public class AuditLogInfo : IHasExtraProperties public class AuditLogInfo : IHasExtraProperties
{ {
public string ApplicationName { get; set; } public string? ApplicationName { get; set; }
public Guid? UserId { get; set; } public Guid? UserId { get; set; }
public string UserName { get; set; } public string? UserName { get; set; }
public Guid? TenantId { get; set; } public Guid? TenantId { get; set; }
public string TenantName { get; set; } public string? TenantName { get; set; }
public Guid? ImpersonatorUserId { get; set; } public Guid? ImpersonatorUserId { get; set; }
public Guid? ImpersonatorTenantId { get; set; } public Guid? ImpersonatorTenantId { get; set; }
public string ImpersonatorUserName { get; set; } public string? ImpersonatorUserName { get; set; }
public string ImpersonatorTenantName { get; set; } public string? ImpersonatorTenantName { get; set; }
public DateTime ExecutionTime { get; set; } public DateTime ExecutionTime { get; set; }
public int ExecutionDuration { get; set; } public int ExecutionDuration { get; set; }
public string ClientId { get; set; } public string? ClientId { get; set; }
public string CorrelationId { get; set; } public string? CorrelationId { get; set; }
public string ClientIpAddress { get; set; } public string? ClientIpAddress { get; set; }
public string ClientName { get; set; } public string? ClientName { get; set; }
public string BrowserInfo { get; set; } public string? BrowserInfo { get; set; }
public string HttpMethod { get; set; } public string? HttpMethod { get; set; }
public int? HttpStatusCode { get; set; } public int? HttpStatusCode { get; set; }
public string Url { get; set; } public string? Url { get; set; }
public List<AuditLogActionInfo> Actions { get; set; } public List<AuditLogActionInfo> Actions { get; set; }

22
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs

@ -52,7 +52,7 @@ public class AuditingHelper : IAuditingHelper, ITransientDependency
CorrelationIdProvider = correlationIdProvider; CorrelationIdProvider = correlationIdProvider;
} }
public virtual bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false, bool ignoreIntegrationServiceAttribute = false) public virtual bool ShouldSaveAudit(MethodInfo? methodInfo, bool defaultValue = false, bool ignoreIntegrationServiceAttribute = false)
{ {
if (methodInfo == null) if (methodInfo == null)
{ {
@ -150,23 +150,23 @@ public class AuditingHelper : IAuditingHelper, ITransientDependency
public virtual AuditLogActionInfo CreateAuditLogAction( public virtual AuditLogActionInfo CreateAuditLogAction(
AuditLogInfo auditLog, AuditLogInfo auditLog,
Type type, Type? type,
MethodInfo method, MethodInfo method,
object[] arguments) object?[] arguments)
{ {
return CreateAuditLogAction(auditLog, type, method, CreateArgumentsDictionary(method, arguments)); return CreateAuditLogAction(auditLog, type, method, CreateArgumentsDictionary(method, arguments));
} }
public virtual AuditLogActionInfo CreateAuditLogAction( public virtual AuditLogActionInfo CreateAuditLogAction(
AuditLogInfo auditLog, AuditLogInfo auditLog,
Type type, Type? type,
MethodInfo method, MethodInfo method,
IDictionary<string, object> arguments) IDictionary<string, object?> arguments)
{ {
var actionInfo = new AuditLogActionInfo var actionInfo = new AuditLogActionInfo
{ {
ServiceName = type != null ServiceName = type != null
? type.FullName ? type.FullName!
: "", : "",
MethodName = method.Name, MethodName = method.Name,
Parameters = SerializeConvertArguments(arguments), Parameters = SerializeConvertArguments(arguments),
@ -198,7 +198,7 @@ public class AuditingHelper : IAuditingHelper, ITransientDependency
} }
} }
protected virtual string SerializeConvertArguments(IDictionary<string, object> arguments) protected virtual string SerializeConvertArguments(IDictionary<string, object?> arguments)
{ {
try try
{ {
@ -207,7 +207,7 @@ public class AuditingHelper : IAuditingHelper, ITransientDependency
return "{}"; return "{}";
} }
var dictionary = new Dictionary<string, object>(); var dictionary = new Dictionary<string, object?>();
foreach (var argument in arguments) foreach (var argument in arguments)
{ {
@ -230,14 +230,14 @@ public class AuditingHelper : IAuditingHelper, ITransientDependency
} }
} }
protected virtual Dictionary<string, object> CreateArgumentsDictionary(MethodInfo method, object[] arguments) protected virtual Dictionary<string, object?> CreateArgumentsDictionary(MethodInfo method, object?[] arguments)
{ {
var parameters = method.GetParameters(); var parameters = method.GetParameters();
var dictionary = new Dictionary<string, object>(); var dictionary = new Dictionary<string, object?>();
for (var i = 0; i < parameters.Length; i++) for (var i = 0; i < parameters.Length; i++)
{ {
dictionary[parameters[i].Name] = arguments[i]; dictionary[parameters[i].Name!] = arguments[i];
} }
return dictionary; return dictionary;

8
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptor.cs

@ -80,7 +80,7 @@ public class AuditingInterceptor : AbpInterceptor, ITransientDependency
{ {
var auditLog = auditLogScope.Log; var auditLog = auditLogScope.Log;
AuditLogActionInfo auditLogAction = null; AuditLogActionInfo? auditLogAction = null;
if (!options.DisableLogActionInfo) if (!options.DisableLogActionInfo)
{ {
auditLogAction = auditingHelper.CreateAuditLogAction( auditLogAction = auditingHelper.CreateAuditLogAction(
@ -127,10 +127,10 @@ public class AuditingInterceptor : AbpInterceptor, ITransientDependency
{ {
try try
{ {
await ProceedByLoggingAsync(invocation, options, auditingHelper, auditingManager.Current); await ProceedByLoggingAsync(invocation, options, auditingHelper, auditingManager.Current!);
Debug.Assert(auditingManager.Current != null); Debug.Assert(auditingManager.Current != null);
if (auditingManager.Current.Log.Exceptions.Any()) if (auditingManager.Current!.Log.Exceptions.Any())
{ {
hasError = true; hasError = true;
} }
@ -142,7 +142,7 @@ public class AuditingInterceptor : AbpInterceptor, ITransientDependency
} }
finally finally
{ {
if (await ShouldWriteAuditLogAsync(invocation, auditingManager.Current.Log, options, currentUser, hasError)) if (await ShouldWriteAuditLogAsync(invocation, auditingManager.Current!.Log, options, currentUser, hasError))
{ {
if (unitOfWorkManager.Current != null) if (unitOfWorkManager.Current != null)
{ {

4
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingManager.cs

@ -38,7 +38,7 @@ public class AuditingManager : IAuditingManager, ITransientDependency
_auditingStore = auditingStore; _auditingStore = auditingStore;
} }
public IAuditLogScope Current => _ambientScopeProvider.GetValue(AmbientContextKey); public IAuditLogScope? Current => _ambientScopeProvider.GetValue(AmbientContextKey);
public IAuditLogSaveHandle BeginScope() public IAuditLogSaveHandle BeginScope()
{ {
@ -49,7 +49,7 @@ public class AuditingManager : IAuditingManager, ITransientDependency
Debug.Assert(Current != null, "Current != null"); Debug.Assert(Current != null, "Current != null");
return new DisposableSaveHandle(this, ambientScope, Current.Log, Stopwatch.StartNew()); return new DisposableSaveHandle(this, ambientScope, Current!.Log, Stopwatch.StartNew());
} }
protected virtual void ExecutePostContributors(AuditLogInfo auditLogInfo) protected virtual void ExecutePostContributors(AuditLogInfo auditLogInfo)

8
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs

@ -19,15 +19,15 @@ public class EntityChangeInfo : IHasExtraProperties
/// </summary> /// </summary>
public Guid? EntityTenantId { get; set; } public Guid? EntityTenantId { get; set; }
public string EntityId { get; set; } public string? EntityId { get; set; }
public string EntityTypeFullName { get; set; } public string? EntityTypeFullName { get; set; }
public List<EntityPropertyChangeInfo> PropertyChanges { get; set; } public List<EntityPropertyChangeInfo> PropertyChanges { get; set; } = default!;
public ExtraPropertyDictionary ExtraProperties { get; } public ExtraPropertyDictionary ExtraProperties { get; }
public virtual object EntityEntry { get; set; } //TODO: Try to remove since it breaks serializability public virtual object EntityEntry { get; set; } = default!; //TODO: Try to remove since it breaks serializability
public EntityChangeInfo() public EntityChangeInfo()
{ {

8
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityPropertyChangeInfo.cs

@ -23,11 +23,11 @@ public class EntityPropertyChangeInfo
/// </summary> /// </summary>
public static int MaxPropertyTypeFullNameLength = 192; public static int MaxPropertyTypeFullNameLength = 192;
public virtual string NewValue { get; set; } public virtual string? NewValue { get; set; }
public virtual string OriginalValue { get; set; } public virtual string? OriginalValue { get; set; }
public virtual string PropertyName { get; set; } public virtual string PropertyName { get; set; } = default!;
public virtual string PropertyTypeFullName { get; set; } public virtual string PropertyTypeFullName { get; set; } = default!;
} }

10
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditingHelper.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.Auditing;
//TODO: Move ShouldSaveAudit & IsEntityHistoryEnabled and rename to IAuditingFactory //TODO: Move ShouldSaveAudit & IsEntityHistoryEnabled and rename to IAuditingFactory
public interface IAuditingHelper public interface IAuditingHelper
{ {
bool ShouldSaveAudit(MethodInfo methodInfo, bool defaultValue = false, bool ignoreIntegrationServiceAttribute = false); bool ShouldSaveAudit(MethodInfo? methodInfo, bool defaultValue = false, bool ignoreIntegrationServiceAttribute = false);
bool IsEntityHistoryEnabled(Type entityType, bool defaultValue = false); bool IsEntityHistoryEnabled(Type entityType, bool defaultValue = false);
@ -15,15 +15,15 @@ public interface IAuditingHelper
AuditLogActionInfo CreateAuditLogAction( AuditLogActionInfo CreateAuditLogAction(
AuditLogInfo auditLog, AuditLogInfo auditLog,
Type type, Type? type,
MethodInfo method, MethodInfo method,
object[] arguments object?[] arguments
); );
AuditLogActionInfo CreateAuditLogAction( AuditLogActionInfo CreateAuditLogAction(
AuditLogInfo auditLog, AuditLogInfo auditLog,
Type type, Type? type,
MethodInfo method, MethodInfo method,
IDictionary<string, object> arguments IDictionary<string, object?> arguments
); );
} }

3
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditingManager.cs

@ -4,8 +4,7 @@ namespace Volo.Abp.Auditing;
public interface IAuditingManager public interface IAuditingManager
{ {
[CanBeNull] IAuditLogScope? Current { get; }
IAuditLogScope Current { get; }
IAuditLogSaveHandle BeginScope(); IAuditLogSaveHandle BeginScope();
} }

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

@ -177,10 +177,10 @@ public class EntityHistoryHelper : IEntityHistoryHelper, ITransientDependency
{ {
propertyChanges.Add(new EntityPropertyChangeInfo propertyChanges.Add(new EntityPropertyChangeInfo
{ {
NewValue = isDeleted ? null : JsonSerializer.Serialize(propertyEntry.CurrentValue).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength), NewValue = isDeleted ? null : JsonSerializer.Serialize(propertyEntry.CurrentValue!).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength),
OriginalValue = isCreated ? null : JsonSerializer.Serialize(propertyEntry.OriginalValue).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength), OriginalValue = isCreated ? null : JsonSerializer.Serialize(propertyEntry.OriginalValue!).TruncateWithPostfix(EntityPropertyChangeInfo.MaxValueLength),
PropertyName = property.Name, PropertyName = property.Name,
PropertyTypeFullName = property.ClrType.GetFirstGenericArgumentIfNullable().FullName PropertyTypeFullName = property.ClrType.GetFirstGenericArgumentIfNullable().FullName!
}); });
} }
} }

Loading…
Cancel
Save