Files
adas-core/adas-core.Infrastructure/Utils/MongoMaps/ComunicationFlowMapContributor.cs
T
2026-06-26 10:29:23 +02:00

46 lines
2.3 KiB
C#

using adas_core.Domain.Models;
using adas_core.Domain.Models.Recording;
using adas_core.Domain.Models.SignalR;
using adas_core.Domain.Models.SystemAlerts;
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
using MongoDB.Bson.Serialization;
namespace adas_core.Infrastructure.Utils.MongoMaps;
/// <summary>
/// Represents a map contributor that provides mapping configuration for communication flow entities by implementing the <see cref="IEntityMapContributor"/> interface.
/// </summary>
public class ComunicationFlowMapContributor : IEntityMapContributor
{
/// <summary>
/// Registers BSON class maps for the application's MongoDB-serialized types, including <see cref="Message"/>, <see cref="Queue"/>, <see cref="ApiRequest"/>, <see cref="AdmPanelRequest"/>, <see cref="ApiClients"/>, and <see cref="VideoDto"/>, applying custom mapping rules such as unmapping the <c>Operation</c> member on <see cref="Message"/> and ignoring null values for <c>ObsertationData</c> on <see cref="AdmPanelRequest"/>. Each type is only registered if a class map has not already been registered, preventing duplicate registration.
/// </summary>
public void RegisterMaps()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(Message)))
BsonClassMap.RegisterClassMap<Message>(cm =>
{
cm.AutoMap();
cm.UnmapMember(c => c.Operation);
});
if (!BsonClassMap.IsClassMapRegistered(typeof(Queue)))
BsonClassMap.RegisterClassMap<Queue>(cm => { cm.AutoMap(); });
if (!BsonClassMap.IsClassMapRegistered(typeof(ApiRequest)))
BsonClassMap.RegisterClassMap<ApiRequest>(cm => { cm.AutoMap(); });
if (!BsonClassMap.IsClassMapRegistered(typeof(AdmPanelRequest)))
BsonClassMap.RegisterClassMap<AdmPanelRequest>(cm =>
{
cm.AutoMap();
cm.GetMemberMap(c => c.ObsertationData).SetIgnoreIfNull(true);
});
if (!BsonClassMap.IsClassMapRegistered(typeof(ApiClients)))
BsonClassMap.RegisterClassMap<ApiClients>(cm => { cm.AutoMap(); });
if (!BsonClassMap.IsClassMapRegistered(typeof(VideoDto)))
BsonClassMap.RegisterClassMap<VideoDto>(cm => { cm.AutoMap(); });
}
}