Creado apartir del commit b888de6c92056de294456f581a56e25e734d4ab7 de develop
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using adas_core.Domain.Enums;
|
||||
using adas_core.Domain.Models.MongoModels;
|
||||
using adas_core.Domain.Utils;
|
||||
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
public class DeviceMapContributor : IEntityMapContributor
|
||||
{
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceActionType)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceActionType>(cm => cm.AutoMap() );
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceAction)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceAction>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DeviceActionType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DeviceActionType>(BsonType.String));
|
||||
cm.MapMember(c => c.ConfigObservationId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlarmName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValueOnSingleClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
cm.MapMember(c => c.ValueOnDoubleClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
cm.MapMember(c => c.ValueOnHoldClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceSettings)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Action).SetDefaultValue(new DeviceAction());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Device)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<Device>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.DeviceType)
|
||||
.SetDefaultValue(DeviceType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DeviceType>(BsonType.String));
|
||||
cm.MapMember(c => c.Uuid).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MacAddr).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CreatedAt).SetDefaultValue(DateTime.UtcNow);
|
||||
cm.MapMember(c => c.UpdatedAt).SetDefaultValue(DateTime.UtcNow);
|
||||
cm.MapMember(c => c.Key).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Battery).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SerialNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PointOfCareIds).SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.Connected).SetDefaultValue(false).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Ready).SetDefaultValue(false).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DeviceType)
|
||||
.SetSerializer(new EnumSerializer<DeviceType>(BsonType.String));
|
||||
cm.MapMember(c => c.Settings).SetDefaultValue(new DeviceSettings());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user