42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
using adas_core.Domain.Models.MongoModels;
|
|
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
|
|
using adas_core.module.LightBeacons.Devices;
|
|
using MongoDB.Bson.Serialization;
|
|
using LightBeacon = adas_core.Domain.Models.MongoModels.LightBeacon;
|
|
|
|
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
|
|
|
public class BeaconMapContributor : IEntityMapContributor
|
|
{
|
|
public void RegisterMaps()
|
|
{
|
|
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeacon)))
|
|
BsonClassMap.RegisterClassMap<LightBeacon>(cm =>
|
|
{
|
|
cm.AutoMap();
|
|
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
|
cm.MapMember(c => c.Type).SetDefaultValue(string.Empty);
|
|
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
|
cm.MapMember(c => c.Options).SetDefaultValue(new Options());
|
|
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
|
|
});
|
|
|
|
if (!BsonClassMap.IsClassMapRegistered(typeof(Options)))
|
|
BsonClassMap.RegisterClassMap<Options>(cm =>
|
|
{
|
|
cm.AutoMap();
|
|
cm.MapMember(c => c.Url).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.Port).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.Emulate).SetDefaultValue(false);
|
|
});
|
|
|
|
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeaconAbstract)))
|
|
BsonClassMap.RegisterClassMap<LightBeaconAbstract>(cm =>
|
|
{
|
|
cm.AutoMap();
|
|
cm.MapMember(c => c.Host);
|
|
cm.MapMember(c => c.Password);
|
|
});
|
|
}
|
|
} |