adding
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using LCU.Library.Internal.DocumentModels.Requests;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.Containers;
|
||||
|
||||
[BsonKnownTypes(typeof(DocumentFieldAudit), typeof(DocumentActionAudit))]
|
||||
public abstract class DocumentAudit
|
||||
{
|
||||
protected DocumentAudit(Guid documentId, string source, DateTime date, string userId)
|
||||
{
|
||||
DocumentId = documentId;
|
||||
Source = source;
|
||||
Date = date;
|
||||
UserId = userId;
|
||||
}
|
||||
|
||||
public Guid DocumentId { get; set; }
|
||||
public string Source { get; set; }
|
||||
|
||||
[BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public string UserId { get; set; }
|
||||
}
|
||||
|
||||
[BsonIgnoreExtraElements]
|
||||
public class DocumentFieldAudit : DocumentAudit
|
||||
{
|
||||
public DocumentFieldAudit(Guid documentId, string source, DateTime date, string userId, string field, object previousValue, object currentValue)
|
||||
: base(documentId, source, date, userId)
|
||||
{
|
||||
Field = field;
|
||||
PreviousValue = previousValue;
|
||||
CurrentValue = currentValue;
|
||||
}
|
||||
|
||||
public string Field { get; set; }
|
||||
public object PreviousValue { get; set; }
|
||||
public object CurrentValue { get; set; }
|
||||
}
|
||||
|
||||
[BsonIgnoreExtraElements]
|
||||
public class DocumentActionAudit : DocumentAudit
|
||||
{
|
||||
public DocumentActionAudit(Guid documentId, string source, DateTime date, string userId, DocumentAction action, string description)
|
||||
: base(documentId, source, date, userId)
|
||||
{
|
||||
Action = action;
|
||||
ActionDescription = description;
|
||||
}
|
||||
|
||||
public DocumentAction Action { get; set; }
|
||||
public string ActionDescription { get; set; }
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.IO;
|
||||
using MongoDB.Bson.Serialization.Conventions;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.Containers;
|
||||
|
||||
public class DocumentAuditDiscriminatorConvention : IDiscriminatorConvention
|
||||
{
|
||||
public static string Discriminator = StandardDiscriminatorConvention.Scalar.ElementName;
|
||||
public string ElementName => Discriminator;
|
||||
|
||||
public Type GetActualType(IBsonReader bsonReader, Type nominalType)
|
||||
{
|
||||
var bookmark = bsonReader.GetBookmark();
|
||||
|
||||
try
|
||||
{
|
||||
bsonReader.ReadStartDocument();
|
||||
|
||||
if (!bsonReader.FindElement(ElementName)) return typeof(DocumentFieldAudit);
|
||||
|
||||
return bsonReader.ReadString() switch
|
||||
{
|
||||
nameof(DocumentFieldAudit) => typeof(DocumentFieldAudit),
|
||||
nameof(DocumentActionAudit) => typeof(DocumentActionAudit),
|
||||
_ => throw new NotSupportedException()
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
bsonReader.ReturnToBookmark(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
public BsonValue GetDiscriminator(Type nominalType, Type actualType)
|
||||
{
|
||||
return actualType.Name;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace LCU.API.Internal.DocumentLib.Containers;
|
||||
|
||||
[BsonIgnoreExtraElements]
|
||||
public class DocumentInformation
|
||||
{
|
||||
public Guid DocumentId { get; set; }
|
||||
public Guid? DocumentBlobId { get; set; }
|
||||
public Guid? TraceId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Source { get; set; }
|
||||
|
||||
public string DataSource { get; set; }
|
||||
|
||||
[BsonSerializer(typeof(BigIntSerializer))]
|
||||
public BigInteger FileSize { get; set; }
|
||||
|
||||
public bool? ScanStatus { get; set; }
|
||||
|
||||
[BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
|
||||
public DateTime UploadDate { get; set; }
|
||||
|
||||
[BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
|
||||
public DateTime? LastModifiedDate { get; set; }
|
||||
|
||||
[BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
|
||||
public DateTime CreatedDate { get; set; }
|
||||
public string[] PersonNumbers { get; set; }
|
||||
public string[] OrganizationNumbers { get; set; }
|
||||
public string AccountNumber { get; set; }
|
||||
public Dictionary<string, string> Attributes { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class BigIntSerializer : SerializerBase<BigInteger>
|
||||
{
|
||||
public override BigInteger Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
|
||||
{
|
||||
var val = context.Reader.ReadString();
|
||||
return BigInteger.Parse(val);
|
||||
}
|
||||
|
||||
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, BigInteger value)
|
||||
{
|
||||
context.Writer.WriteString(value.ToString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user