| | | 1 | | namespace ProjectTemplate.Infrastructure.Data.Auditing; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Carries host-owned identity and correlation data into application mutation audit records. |
| | | 5 | | /// </summary> |
| | | 6 | | public sealed record ApplicationAuditContext |
| | | 7 | | { |
| | 6 | 8 | | public static ApplicationAuditContext System { get; } = new( |
| | 2 | 9 | | SystemCurrentActorAccessor.ActorName, |
| | 2 | 10 | | ApplicationAuditActorTypes.System, |
| | 2 | 11 | | SystemCurrentActorAccessor.ActorName); |
| | | 12 | | |
| | 52 | 13 | | public ApplicationAuditContext( |
| | 52 | 14 | | string actorId, |
| | 52 | 15 | | string actorType, |
| | 52 | 16 | | string actorDisplayName, |
| | 52 | 17 | | string? operationExecutionId = null, |
| | 52 | 18 | | string? executionAttemptId = null, |
| | 52 | 19 | | string? correlationId = null, |
| | 52 | 20 | | string? traceId = null, |
| | 52 | 21 | | string? spanId = null, |
| | 52 | 22 | | string? decisionAuditRecordId = null, |
| | 52 | 23 | | string? tenantHash = null, |
| | 52 | 24 | | string? organizationHash = null) |
| | | 25 | | { |
| | 52 | 26 | | ActorId = NormalizeRequired(actorId, nameof(actorId)); |
| | 52 | 27 | | ActorType = NormalizeRequired(actorType, nameof(actorType)); |
| | 52 | 28 | | ActorDisplayName = NormalizeRequired(actorDisplayName, nameof(actorDisplayName)); |
| | 52 | 29 | | OperationExecutionId = NormalizeOptional(operationExecutionId); |
| | 52 | 30 | | ExecutionAttemptId = NormalizeOptional(executionAttemptId); |
| | 52 | 31 | | CorrelationId = NormalizeOptional(correlationId); |
| | 52 | 32 | | TraceId = NormalizeOptional(traceId); |
| | 52 | 33 | | SpanId = NormalizeOptional(spanId); |
| | 52 | 34 | | DecisionAuditRecordId = NormalizeOptional(decisionAuditRecordId); |
| | 52 | 35 | | TenantHash = NormalizeOptional(tenantHash); |
| | 52 | 36 | | OrganizationHash = NormalizeOptional(organizationHash); |
| | 52 | 37 | | } |
| | | 38 | | |
| | 56 | 39 | | public string ActorId { get; } |
| | | 40 | | |
| | 56 | 41 | | public string ActorType { get; } |
| | | 42 | | |
| | 56 | 43 | | public string ActorDisplayName { get; } |
| | | 44 | | |
| | 100 | 45 | | public string? OperationExecutionId { get; } |
| | | 46 | | |
| | 100 | 47 | | public string? ExecutionAttemptId { get; } |
| | | 48 | | |
| | 100 | 49 | | public string? CorrelationId { get; } |
| | | 50 | | |
| | 100 | 51 | | public string? TraceId { get; } |
| | | 52 | | |
| | 56 | 53 | | public string? SpanId { get; } |
| | | 54 | | |
| | 100 | 55 | | public string? DecisionAuditRecordId { get; } |
| | | 56 | | |
| | 56 | 57 | | public string? TenantHash { get; } |
| | | 58 | | |
| | 56 | 59 | | public string? OrganizationHash { get; } |
| | | 60 | | |
| | | 61 | | private static string NormalizeRequired(string value, string parameterName) |
| | | 62 | | { |
| | 156 | 63 | | return string.IsNullOrWhiteSpace(value) |
| | 156 | 64 | | ? throw new ArgumentException("Value must not be empty.", parameterName) |
| | 156 | 65 | | : value.Trim(); |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | private static string? NormalizeOptional(string? value) |
| | | 69 | | { |
| | 416 | 70 | | return string.IsNullOrWhiteSpace(value) ? null : value.Trim(); |
| | | 71 | | } |
| | | 72 | | } |