using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Bson.Serialization.Serializers;
using Core.DomainObjects;
using Core.DomainObjects.Pages;
using Core.DomainObjects.PageSections;
using Core.DomainObjects.Documents;
namespace DataProviders {
public class Mappings {
public static void RegisterClassMap() {
ConventionRegistry.Register("MyConventions",
new ConventionPack {
new CamelCaseElementNameConvention(),
new IgnoreIfNullConvention(true)
}, type => true);
// https://kevsoft.net/2020/06/25/storing-guids-as-strings-in-mongodb-with-csharp.html
BsonSerializer.RegisterSerializer(new GuidSerializer(BsonType.String));
#region Primitives
if (!BsonClassMap.IsClassMapRegistered(typeof(Address))) {
BsonClassMap.RegisterClassMap
(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Author))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Category))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Comment))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Contact))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Feature))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(FormItem))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Header))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Image))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Link))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(Localization))) {
BsonClassMap.RegisterClassMap(cm => {
cm.AutoMap();
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(MenuItem))) {
BsonClassMap.RegisterClassMap