54 lines
3.0 KiB
C#
54 lines
3.0 KiB
C#
using adas_core.Domain.Models.MongoModels;
|
|
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
|
|
using MongoDB.Bson.Serialization;
|
|
|
|
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
|
|
|
/// <summary>
|
|
/// Provides a standard implementation of the <see cref="IEntityMapContributor"/> interface.
|
|
/// </summary>
|
|
public class StandardMapContributor : IEntityMapContributor
|
|
{
|
|
/// <summary>
|
|
/// Registers BSON class maps for <see cref="HistoricalConfigChanges"/> and <see cref="UiFontData"/> types
|
|
/// used during MongoDB serialization, skipping any types that are already registered. For
|
|
/// <see cref="UiFontData"/>, several nullable UI configuration members are configured to be ignored
|
|
/// when null to avoid persisting default values.
|
|
/// </summary>
|
|
public void RegisterMaps()
|
|
{
|
|
if (!BsonClassMap.IsClassMapRegistered(typeof(HistoricalConfigChanges)))
|
|
BsonClassMap.RegisterClassMap<HistoricalConfigChanges>(cm =>
|
|
{
|
|
cm.AutoMap();
|
|
//cm.MapMember(c => c.Id)
|
|
// .SetSerializer(new ObjectIdSerializer(BsonType.String));
|
|
//cm.GetMemberMap(c => c.ConfigType)
|
|
// .SetSerializer(new NullableSerializer<ConfigTypes>(new EnumSerializer<ConfigTypes>(BsonType.String)));
|
|
});
|
|
|
|
if (!BsonClassMap.IsClassMapRegistered(typeof(UiFontData)))
|
|
BsonClassMap.RegisterClassMap<UiFontData>(cm =>
|
|
{
|
|
cm.AutoMap();
|
|
cm.MapMember(c => c.WidthStepBed).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.HeightStepBed).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeValue).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeMediumValue).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeHeaderValue).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeLittleValue).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeMicroValue).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeNanoValue).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeLittleTextValue).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeName).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeLittleName).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.FontSizeUnit).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.BorderColor).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.BackGroundColor).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.BoxMarginTop).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.BoxMarginBot).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.BoxMarginLeft).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.BoxMarginRight).SetIgnoreIfNull(true);
|
|
});
|
|
}
|
|
} |