public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap) { var entityType = definition.EntityType; //Ignore extra elements when the "IgnoreExtraElementsAttribute" is on the Entity var ignoreExtraElements = entityType.GetCustomAttribute <IgnoreExtraElementsAttribute>(); if (ignoreExtraElements != null) { classMap.SetIgnoreExtraElements(true); classMap.SetIgnoreExtraElementsIsInherited(ignoreExtraElements.IgnoreInherited); } else { classMap.SetIgnoreExtraElements(false); //If any of the Entity's properties have the "ExtraElementsAttribute", assign that against the BsonClassMap foreach (var property in definition.Properties) { var extraElementsAttribute = property.PropertyInfo.GetCustomAttribute <ExtraElementsAttribute>(); if (extraElementsAttribute != null && typeof(IDictionary <string, object>).IsAssignableFrom(property.PropertyType)) { foreach (var memberMap in classMap.DeclaredMemberMaps) { if (memberMap.ElementName == property.ElementName) { classMap.SetExtraElementsMember(memberMap); return; } } } } } }
public static void Register(BsonClassMap <User> cm) { cm.AutoMap(); //cm.MapIdField(a ) //cm.MapIdMember(c => c.Username); // cm.MapIdProperty(c => c.Username); // cm.SetIdMember(cm.GetMemberMap(c => c.Username)); cm.SetIgnoreExtraElements(true); cm.SetIgnoreExtraElements(true); }
/*******************************************/ /**** Public Methods ****/ /*******************************************/ public static void RegisterClassMap(Type type) { if (!BsonClassMap.IsClassMapRegistered(type)) { try { if (type.IsEnum) { MethodInfo generic = m_CreateEnumSerializer.MakeGenericMethod(type); generic.Invoke(null, null); } else if (!type.IsGenericTypeDefinition) { BsonClassMap cm = new BsonClassMap(type); cm.AutoMap(); cm.SetDiscriminator(type.FullName); cm.SetDiscriminatorIsRequired(true); cm.SetIgnoreExtraElements(true); // It would have been nice to use cm.MapExtraElementsProperty("CustomData") but it doesn't work for inherited properties cm.SetIdMember(null); BsonClassMap.RegisterClassMap(cm); BsonSerializer.RegisterDiscriminatorConvention(type, new GenericDiscriminatorConvention()); } else { BsonSerializer.RegisterDiscriminatorConvention(type, new GenericDiscriminatorConvention()); } } catch (Exception e) { Debug.WriteLine(e.ToString()); } } }
public override void Map(BsonClassMap <ApiResource> cm) { cm.AutoMap(); cm.MapIdField(x => x.Id); //cm.GetMemberMap(x=>x.Description) cm.SetIgnoreExtraElements(true); }
internal static void InitializeSagaDataTypes(IMongoClient client, string databaseName, Func <Type, string> collectionNamingConvention, SagaMetadataCollection sagaMetadataCollection) { var databaseSettings = new MongoDatabaseSettings { ReadConcern = ReadConcern.Majority, ReadPreference = ReadPreference.Primary, WriteConcern = WriteConcern.WMajority }; var database = client.GetDatabase(databaseName, databaseSettings); foreach (var sagaMetadata in sagaMetadataCollection) { if (!BsonClassMap.IsClassMapRegistered(sagaMetadata.SagaEntityType)) { var classMap = new BsonClassMap(sagaMetadata.SagaEntityType); classMap.AutoMap(); classMap.SetIgnoreExtraElements(true); BsonClassMap.RegisterClassMap(classMap); } var collectionName = collectionNamingConvention(sagaMetadata.SagaEntityType); if (sagaMetadata.TryGetCorrelationProperty(out var property) && property.Name != "Id") { var propertyElementName = sagaMetadata.SagaEntityType.GetElementName(property.Name); var indexModel = new CreateIndexModel <BsonDocument>(new BsonDocumentIndexKeysDefinition <BsonDocument>(new BsonDocument(propertyElementName, 1)), new CreateIndexOptions { Unique = true }); database.GetCollection <BsonDocument>(collectionName).Indexes.CreateOne(indexModel); }
public static void Register(BsonClassMap <GlobalValue> sm) { sm.AutoMap(); // sm.MapIdMember(c => c.Id); sm.MapMember(m => m.Name).SetIsRequired(true); sm.SetIgnoreExtraElements(true); }
//Register type private void RegisterType(Type type) { if (!BsonClassMap.IsClassMapRegistered(type)) { string typeName = type.Name; if (typeName.Contains("Extension") || typeName.Contains("Util")) { return; } var bsonClassMap = new BsonClassMap(type); bsonClassMap.AutoMap(); bsonClassMap.SetIgnoreExtraElements(true); //Set date time with local var names = TypeUtil.GetNamesWithDateTime(type); if (names.Count > 0) { var dateTimeSerializer = new DateTimeSerializer(DateTimeKind.Local); foreach (var name in names) { if (bsonClassMap.GetMemberMap(name) != null) { bsonClassMap.GetMemberMap(name).SetSerializer(dateTimeSerializer); } } } BsonClassMap.RegisterClassMap(bsonClassMap); _logger.LogInformation(type.ToString()); } }
public static void Register(BsonClassMap <Update> cm) { cm.AutoMap(); // cm.GetMemberMap(c => c.Value).SetSerializer(new ObjectSerializer()); cm.SetIsRootClass(true); cm.SetIgnoreExtraElements(true); }
public static void Register(BsonClassMap <BaseCommand> cm) { cm.AutoMap(); AppDomain.CurrentDomain.GetAssemblies().SelectMany(assem => assem.GetTypes()).Where(type => type.IsSubclassOf(typeof(BaseCommand))).ToList() .ForEach(type => cm.AddKnownType(type)); cm.SetIgnoreExtraElements(true); }
public static void Register(BsonClassMap <JournalEntry> journal) { journal.AutoMap(); // journal.MapMember(c => c.Updates).SetSerializer(new EnumerableInterfaceImplementerSerializer<List<Update>>()); journal.SetIgnoreExtraElements(true); //cm.SetIdMember(cm.GetMemberMap(c => c.Id)).SetIdGenerator(CombGuidGenerator.Instance); }
public void ApplyMapping(Type entityType, BsonClassMap classMap) { //Ignore extra elements when the "IgnoreExtraElementsAttribute" is on the Entity var ignoreExtraElements = entityType.GetCustomAttribute <IgnoreExtraElementsAttribute>(); if (ignoreExtraElements != null) { classMap.SetIgnoreExtraElements(true); classMap.SetIgnoreExtraElementsIsInherited(ignoreExtraElements.IgnoreInherited); } else { //If any of the Entity's properties have the "ExtraElementsAttribute", assign that against the BsonClassMap var extraElementsProperty = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) .Select(p => new { PropertyInfo = p, ExtraElementsAttribute = p.GetCustomAttribute <ExtraElementsAttribute>() }).Where(p => p.ExtraElementsAttribute != null).FirstOrDefault(); if (extraElementsProperty != null && typeof(IDictionary <string, object>).IsAssignableFrom(extraElementsProperty.PropertyInfo.PropertyType)) { classMap.SetExtraElementsMember(new BsonMemberMap(classMap, extraElementsProperty.PropertyInfo)); } } }
public static bool RegisterTrackablePocoMap(Type trackablePocoType) { if (BsonClassMap.IsClassMapRegistered(trackablePocoType)) { return(false); } var classMap = new BsonClassMap(trackablePocoType); var pocoType = TrackableResolver.GetPocoType(trackablePocoType); // start with auto map classMap.AutoMap(); // ignore extra elements for smooth schema change classMap.SetIgnoreExtraElements(true); // unmap all members which T doesn't have var propertyNames = new HashSet <string>(pocoType.GetProperties().Select(p => p.Name)); var deletingMembers = classMap.DeclaredMemberMaps.Where(m => { var propertyInfo = m.MemberInfo as PropertyInfo; return(propertyInfo == null || propertyNames.Contains(propertyInfo.Name) == false); }).ToList(); foreach (var m in deletingMembers) { classMap.UnmapMember(m.MemberInfo); } // set default ignore for saving spaces foreach (var memberMap in classMap.DeclaredMemberMaps) { var mt = memberMap.MemberType; var defaultValue = mt.IsValueType ? Activator.CreateInstance(mt) : null; memberMap.SetDefaultValue(defaultValue); memberMap.SetIgnoreIfDefault(true); } // tell customized id to mongo-db var identityColumn = pocoType.GetProperties().FirstOrDefault( p => TrackablePropertyAttribute.GetParameter(p, "mongodb.identity") != null); if (identityColumn != null) { classMap.MapIdProperty(identityColumn.Name); } try { BsonClassMap.RegisterClassMap(classMap); } catch (ArgumentException) { // if duplicate key exists return(false); } return(true); }
public static void Register(BsonClassMap <Journal> journal) { journal.AutoMap(); journal.MapMember(c => c.JournalEntries).SetSerializer(new DictionaryInterfaceImplementerSerializer <SortedDictionary <int, JournalEntry> >(DictionaryRepresentation.ArrayOfDocuments)); journal.SetIgnoreExtraElements(true); //cm.SetIdMember(cm.GetMemberMap(c => c.Id)).SetIdGenerator(CombGuidGenerator.Instance); }
public override void Map(BsonClassMap <DiarySettingsPeriodDTO> cm) { cm.AutoMap(); cm.MapCreator(d => new DiarySettingsPeriodDTO(d.School, d.IsGuarianAllowedToSendMessage, d.MealSettingPeriods, d.NapSettingPeriods, d.MyDayPeriods, d.MyPopInfos)); cm.SetIgnoreExtraElements(true); MapNestedObjects(); }
/// <summary> /// Configure the default mapping for the model. /// </summary> protected virtual void ConfigureDetaultTableMappings <TType>( BsonClassMap <TType> c, string idColumn) { c.AutoMap(); c.MapIdProperty(idColumn); c.SetIgnoreExtraElements(true); }
private static void Initializer <TClass>(BsonClassMap <TClass> cm) where TClass : IModel { cm.AutoMap(); cm.MapIdMember(c => c.Id).SetIdGenerator(CombGuidGenerator.Instance); cm.SetDiscriminator(typeof(TClass).Name); cm.SetDiscriminatorIsRequired(true); cm.SetIgnoreExtraElements(true); }
protected override void ConfigureClassMap(BsonClassMap<DayStackStats> cm) { cm.AutoMap(); cm.SetIgnoreExtraElements(true); cm.SetIdMember(cm.GetMemberMap(c => c.Id)); cm.GetMemberMap(c => c.ProjectId).SetElementName(CommonFieldNames.ProjectId).SetRepresentation(BsonType.ObjectId).SetIdGenerator(new StringObjectIdGenerator()); cm.GetMemberMap(c => c.StackId).SetElementName(CommonFieldNames.StackId).SetRepresentation(BsonType.ObjectId).SetIdGenerator(new StringObjectIdGenerator()); cm.GetMemberMap(c => c.Total).SetElementName(FieldNames.Total); cm.GetMemberMap(c => c.MinuteStats).SetElementName(FieldNames.MinuteStats).SetSerializationOptions(DictionarySerializationOptions.Document); }
public void RegisterClassIgnoreExtraFields(Type type) { BsonClassMap cm = new BsonClassMap(type); cm.AutoMap(); cm.SetIgnoreExtraElements(true); BsonClassMap.RegisterClassMap(cm); //BsonSerializer.RegisterDiscriminatorConvention(type, new ScalarDiscriminatorConvention("type")); }
protected override void ConfigureClassMap(BsonClassMap <MonthProjectStats> cm) { cm.AutoMap(); cm.SetIgnoreExtraElements(true); cm.SetIdMember(cm.GetMemberMap(c => c.Id)); cm.GetMemberMap(c => c.ProjectId).SetElementName(CommonFieldNames.ProjectId).SetRepresentation(BsonType.ObjectId).SetIdGenerator(new StringObjectIdGenerator()); cm.GetMemberMap(c => c.DayStats).SetElementName(FieldNames.DayStats).SetSerializationOptions(DictionarySerializationOptions.Document); EventStatsHelper.MapStatsClasses(); }
public static void Register(BsonClassMap <BaseState> cm) { cm.AutoMap(); cm.SetIsRootClass(true); cm.SetIgnoreExtraElements(true); cm.MapMember(s => s.Nodes).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <Guid, NodeInformation> >(DictionaryRepresentation.ArrayOfArrays)); cm.MapMember(s => s.Indexes).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <string, Index> >(DictionaryRepresentation.ArrayOfArrays)); cm.MapMember(s => s.ClusterTasks).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <Guid, BaseTask> >(DictionaryRepresentation.ArrayOfArrays)); cm.MapMember(s => s.Locks).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <string, Lock> >(DictionaryRepresentation.ArrayOfArrays)); }
public override void Map(BsonClassMap <Campaign> config) { config.AutoMap(); config.SetIgnoreExtraElements(true); config.MapField("_name").SetElementName("Name"); config.MapField("_startsAt").SetElementName("StartsAt") .SetSerializer(new DateTimeSerializer(DateTimeKind.Local)); config.MapField("_completesAt").SetElementName("CompletesAt") .SetSerializer(new DateTimeSerializer(DateTimeKind.Local)); }
public override void Map(BsonClassMap <ReceiptItem> config) { config.AutoMap(); config.SetIgnoreExtraElements(true); config.MapProperty(t => t.Title).SetElementName("Title"); config.MapProperty(t => t.Description).SetElementName("Description"); config.MapProperty(t => t.Price).SetElementName("Price") .SetSerializer(new DecimalSerializer(BsonType.Decimal128)); config.MapProperty(t => t.Quantity).SetElementName("Quantity"); }
public static void Register(BsonClassMap <Condition> cm) { cm.AutoMap(); cm.SetIsRootClass(true); cm.SetIgnoreExtraElements(true); var featureType = typeof(Condition); featureType.Assembly.GetTypes() .Where(type => featureType.IsAssignableFrom(type)).ToList() .ForEach(type => cm.AddKnownType(type)); }
public override void Map(BsonClassMap <Article> cm) { cm.AutoMap(); cm.MapIdProperty(c => c.Id); cm.MapProperty(c => c.Title).SetElementName("title"); cm.MapProperty(c => c.Author).SetElementName("author"); cm.MapProperty(c => c.Summary).SetElementName("summary"); cm.MapProperty(c => c.Content).SetElementName("content"); cm.SetIgnoreExtraElements(true); }
public static void Register(BsonClassMap <NodeStorage <CindiClusterState> > cm) { cm.AutoMap(); cm.SetIsRootClass(true); cm.MapMember(s => s.Logs).SetSerializer(new DictionaryInterfaceImplementerSerializer <SortedList <int, LogEntry> >(DictionaryRepresentation.ArrayOfArrays)); /*AppDomain.CurrentDomain.GetAssemblies().SelectMany(assem => assem.GetTypes()).Where(type => type.IsSubclassOf(typeof(NodeStorage))).ToList() * .ForEach(type => cm.AddKnownType(type));*/ cm.UnmapMember(c => c.CommandsQueue); cm.SetIgnoreExtraElements(true); }
public override void Map(BsonClassMap <ReceiptItem> config) { config.AutoMap(); config.SetIgnoreExtraElements(true); config.MapField("_title").SetElementName("Title"); config.MapField("_description").SetElementName("Description"); config.MapField("_price").SetElementName("Price") .SetSerializer(new DecimalSerializer(BsonType.Decimal128)); config.MapField("_quantity").SetElementName("Quantity"); }
/// <summary> /// Configure the default mapping for the model. /// </summary> protected virtual void ConfigureDetaultTableMappings <TType, TKey>( BsonClassMap <TType> c, Expression <Func <TType, TKey> > idMap) { c.AutoMap(); if (idMap != null) { c.MapIdMember(idMap); } c.SetIgnoreExtraElements(true); }
public override void Map(BsonClassMap <Receipt> config) { config.AutoMap(); config.SetIgnoreExtraElements(true); config.MapProperty(t => t.Date).SetElementName("Date") .SetSerializer(new DateTimeSerializer(DateTimeKind.Local)); config.MapProperty(t => t.Description).SetElementName("Description"); config.MapProperty(t => t.CampaignId).SetElementName("CampaignId"); config.MapProperty(t => t.ReceiptItems).SetElementName("ReceiptItems"); config.MapProperty(t => t.Tags).SetElementName("Tags"); }
public override void Map(BsonClassMap <Receipt> config) { config.AutoMap(); config.SetIgnoreExtraElements(true); config.MapField("_date").SetElementName("Date") .SetSerializer(new DateTimeSerializer(DateTimeKind.Local)); config.MapField("_description").SetElementName("Description"); config.MapField("_campaignId").SetElementName("CampaignId"); config.MapField("_receiptItems").SetElementName("ReceiptItems"); config.MapField("_tags").SetElementName("Tags"); }
public static void Register(BsonClassMap <Step> cm) { cm.AutoMap(); cm.SetIgnoreExtraElements(true); // cm.MapIdMember(c => c.Id); //cm.SetIdMember(cm.GetMemberMap(c => c.Id)); //cm.SetIgnoreExtraElements(true); /*cm.UnmapMember(c => c.Status); * cm.UnmapMember(c => c.IsComplete); * cm.UnmapMember(c => c.Outputs); * cm.UnmapMember(c => c.TestResults); * cm.UnmapMember(c => c.Journal);*/ }
public static bool RegisterClassMap(Type classType) { if (BsonClassMap.IsClassMapRegistered(classType)) return false; var classMap = new BsonClassMap(classType); // start with auto map classMap.AutoMap(); // ignore extra elements for smooth schema change classMap.SetIgnoreExtraElements(true); // unmap all members which has mongodb.ignore attribute var deletingMembers = classMap.DeclaredMemberMaps.Where(m => { return TrackablePropertyAttribute.GetParameter(m.MemberInfo, "mongodb.ignore") != null; }).ToList(); foreach (var m in deletingMembers) classMap.UnmapMember(m.MemberInfo); // set default ignore for saving spaces foreach (var memberMap in classMap.DeclaredMemberMaps) { var mt = memberMap.MemberType; var defaultValue = mt.IsValueType ? Activator.CreateInstance(mt) : null; memberMap.SetDefaultValue(defaultValue); memberMap.SetIgnoreIfDefault(true); } try { BsonClassMap.RegisterClassMap(classMap); } catch (ArgumentException) { // if duplicate key exists return false; } return true; }
public void Apply(BsonClassMap classMap) { var value = _convention.IgnoreExtraElements(classMap.ClassType); classMap.SetIgnoreExtraElements(value); }
// public methods /// <summary> /// Applies a modification to the class map. /// </summary> /// <param name="classMap">The class map.</param> public void Apply(BsonClassMap classMap) { classMap.SetIgnoreExtraElements(_ignoreExtraElements); classMap.SetIgnoreExtraElementsIsInherited(_inherited); }
protected static void ConfigureErrorClassMap(BsonClassMap<OldModels.Error> cm) { cm.AutoMap(); cm.SetIgnoreExtraElements(true); cm.SetIdMember(cm.GetMemberMap(c => c.Id).SetRepresentation(BsonType.ObjectId).SetIdGenerator(new StringObjectIdGenerator())); cm.GetMemberMap(p => p.OrganizationId).SetElementName(ErrorFieldNames.OrganizationId).SetRepresentation(BsonType.ObjectId); cm.GetMemberMap(c => c.ErrorStackId).SetElementName(ErrorFieldNames.ErrorStackId).SetRepresentation(BsonType.ObjectId); cm.GetMemberMap(c => c.ProjectId).SetElementName(ErrorFieldNames.ProjectId).SetRepresentation(BsonType.ObjectId); cm.GetMemberMap(c => c.OccurrenceDate).SetElementName(ErrorFieldNames.OccurrenceDate).SetSerializer(new UtcDateTimeOffsetSerializer()); cm.GetMemberMap(c => c.Tags).SetElementName(ErrorFieldNames.Tags).SetIgnoreIfNull(true).SetShouldSerializeMethod(obj => ((OldModels.Error)obj).Tags.Any()); cm.GetMemberMap(c => c.UserEmail).SetElementName(ErrorFieldNames.UserEmail).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.UserName).SetElementName(ErrorFieldNames.UserName).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.UserDescription).SetElementName(ErrorFieldNames.UserDescription).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.RequestInfo).SetElementName(ErrorFieldNames.RequestInfo).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.ExceptionlessClientInfo).SetElementName(ErrorFieldNames.ExceptionlessClientInfo).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.Modules).SetElementName(ErrorFieldNames.Modules).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.EnvironmentInfo).SetElementName(ErrorFieldNames.EnvironmentInfo).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.IsFixed).SetElementName(ErrorFieldNames.IsFixed).SetIgnoreIfDefault(true); cm.GetMemberMap(c => c.IsHidden).SetElementName(ErrorFieldNames.IsHidden).SetIgnoreIfDefault(true); if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.ErrorInfo))) { BsonClassMap.RegisterClassMap<OldModels.ErrorInfo>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.Message).SetElementName(ErrorFieldNames.Message).SetIgnoreIfNull(true); cmm.GetMemberMap(c => c.Type).SetElementName(ErrorFieldNames.Type); cmm.GetMemberMap(c => c.Code).SetElementName(ErrorFieldNames.Code); cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.ErrorInfo)obj).ExtendedData.Any()); cmm.GetMemberMap(c => c.Inner).SetElementName(ErrorFieldNames.Inner); cmm.GetMemberMap(c => c.StackTrace).SetElementName(ErrorFieldNames.StackTrace).SetShouldSerializeMethod(obj => ((OldModels.ErrorInfo)obj).StackTrace.Any()); cmm.GetMemberMap(c => c.TargetMethod).SetElementName(ErrorFieldNames.TargetMethod).SetIgnoreIfNull(true); }); } if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.RequestInfo))) { BsonClassMap.RegisterClassMap<OldModels.RequestInfo>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.UserAgent).SetElementName(ErrorFieldNames.UserAgent); cmm.GetMemberMap(c => c.HttpMethod).SetElementName(ErrorFieldNames.HttpMethod); cmm.GetMemberMap(c => c.IsSecure).SetElementName(ErrorFieldNames.IsSecure); cmm.GetMemberMap(c => c.Host).SetElementName(ErrorFieldNames.Host); cmm.GetMemberMap(c => c.Port).SetElementName(ErrorFieldNames.Port); cmm.GetMemberMap(c => c.Path).SetElementName(ErrorFieldNames.Path); cmm.GetMemberMap(c => c.Referrer).SetElementName(ErrorFieldNames.Referrer).SetIgnoreIfNull(true); cmm.GetMemberMap(c => c.ClientIpAddress).SetElementName(ErrorFieldNames.ClientIpAddress); cmm.GetMemberMap(c => c.Cookies).SetElementName(ErrorFieldNames.Cookies).SetShouldSerializeMethod(obj => ((RequestInfo)obj).Cookies.Any()); cmm.GetMemberMap(c => c.PostData).SetElementName(ErrorFieldNames.PostData).SetShouldSerializeMethod(obj => ShouldSerializePostData(obj as RequestInfo)); cmm.GetMemberMap(c => c.QueryString).SetElementName(ErrorFieldNames.QueryString).SetShouldSerializeMethod(obj => ((OldModels.RequestInfo)obj).QueryString.Any()); cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.RequestInfo)obj).ExtendedData.Any()); }); } if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.ExceptionlessClientInfo))) { BsonClassMap.RegisterClassMap<OldModels.ExceptionlessClientInfo>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.Version).SetElementName(ErrorFieldNames.Version); cmm.GetMemberMap(c => c.InstallIdentifier).SetElementName(ErrorFieldNames.InstallIdentifier); cmm.GetMemberMap(c => c.InstallDate).SetElementName(ErrorFieldNames.InstallDate); cmm.GetMemberMap(c => c.StartCount).SetElementName(ErrorFieldNames.StartCount); cmm.GetMemberMap(c => c.SubmitCount).SetElementName(ErrorFieldNames.SubmitCount); cmm.GetMemberMap(c => c.Platform).SetElementName(ErrorFieldNames.Platform); cmm.GetMemberMap(c => c.SubmissionMethod).SetElementName(ErrorFieldNames.SubmissionMethod); }); } if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.EnvironmentInfo))) { BsonClassMap.RegisterClassMap<OldModels.EnvironmentInfo>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.ProcessorCount).SetElementName(ErrorFieldNames.ProcessorCount); cmm.GetMemberMap(c => c.TotalPhysicalMemory).SetElementName(ErrorFieldNames.TotalPhysicalMemory); cmm.GetMemberMap(c => c.AvailablePhysicalMemory).SetElementName(ErrorFieldNames.AvailablePhysicalMemory); cmm.GetMemberMap(c => c.CommandLine).SetElementName(ErrorFieldNames.CommandLine); cmm.GetMemberMap(c => c.ProcessName).SetElementName(ErrorFieldNames.ProcessName); cmm.GetMemberMap(c => c.ProcessId).SetElementName(ErrorFieldNames.ProcessId); cmm.GetMemberMap(c => c.ProcessMemorySize).SetElementName(ErrorFieldNames.ProcessMemorySize); cmm.GetMemberMap(c => c.ThreadName).SetElementName(ErrorFieldNames.ThreadName).SetIgnoreIfNull(true); cmm.GetMemberMap(c => c.ThreadId).SetElementName(ErrorFieldNames.ThreadId); cmm.GetMemberMap(c => c.Architecture).SetElementName(ErrorFieldNames.Architecture); cmm.GetMemberMap(c => c.OSName).SetElementName(ErrorFieldNames.OSName); cmm.GetMemberMap(c => c.OSVersion).SetElementName(ErrorFieldNames.OSVersion); cmm.GetMemberMap(c => c.MachineName).SetElementName(ErrorFieldNames.MachineName); cmm.GetMemberMap(c => c.RuntimeVersion).SetElementName(ErrorFieldNames.RuntimeVersion); cmm.GetMemberMap(c => c.IpAddress).SetElementName(ErrorFieldNames.IpAddress); cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.EnvironmentInfo)obj).ExtendedData.Any()); }); } if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.Method))) { BsonClassMap.RegisterClassMap<OldModels.Method>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.DeclaringNamespace).SetElementName(ErrorFieldNames.DeclaringNamespace); cmm.GetMemberMap(c => c.DeclaringType).SetElementName(ErrorFieldNames.DeclaringType); cmm.GetMemberMap(c => c.Name).SetElementName(ErrorFieldNames.Name); cmm.GetMemberMap(c => c.ModuleId).SetElementName(ErrorFieldNames.ModuleId); cmm.GetMemberMap(c => c.IsSignatureTarget).SetElementName(ErrorFieldNames.IsSignatureTarget); cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.Method)obj).ExtendedData.Any()); cmm.GetMemberMap(c => c.GenericArguments).SetElementName(ErrorFieldNames.GenericArguments).SetShouldSerializeMethod(obj => ((Method)obj).GenericArguments.Any()); cmm.GetMemberMap(c => c.Parameters).SetElementName(ErrorFieldNames.Parameters).SetShouldSerializeMethod(obj => ((OldModels.Method)obj).Parameters.Any()); }); } if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.Parameter))) { BsonClassMap.RegisterClassMap<OldModels.Parameter>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.Name).SetElementName(ErrorFieldNames.Name); cmm.GetMemberMap(c => c.Type).SetElementName(ErrorFieldNames.Type); cmm.GetMemberMap(c => c.TypeNamespace).SetElementName(ErrorFieldNames.TypeNamespace); cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.Parameter)obj).ExtendedData.Any()); cmm.GetMemberMap(c => c.GenericArguments).SetElementName(ErrorFieldNames.GenericArguments).SetShouldSerializeMethod(obj => ((OldModels.Parameter)obj).GenericArguments.Any()); }); } if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.StackFrame))) { BsonClassMap.RegisterClassMap<OldModels.StackFrame>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.FileName).SetElementName(ErrorFieldNames.FileName).SetIgnoreIfNull(true); cmm.GetMemberMap(c => c.LineNumber).SetElementName(ErrorFieldNames.LineNumber).SetIgnoreIfDefault(true); cmm.GetMemberMap(c => c.Column).SetElementName(ErrorFieldNames.Column).SetIgnoreIfDefault(true); }); } if (!BsonClassMap.IsClassMapRegistered(typeof(OldModels.Module))) { BsonClassMap.RegisterClassMap<OldModels.Module>(cmm => { cmm.AutoMap(); cmm.SetIgnoreExtraElements(true); cmm.GetMemberMap(c => c.ModuleId).SetElementName(ErrorFieldNames.ModuleId).SetIgnoreIfDefault(true); cmm.GetMemberMap(c => c.Name).SetElementName(ErrorFieldNames.Name); cmm.GetMemberMap(c => c.Version).SetElementName(ErrorFieldNames.Version).SetIgnoreIfNull(true); cmm.GetMemberMap(c => c.IsEntry).SetElementName(ErrorFieldNames.IsEntry).SetIgnoreIfDefault(true); cmm.GetMemberMap(c => c.CreatedDate).SetElementName(ErrorFieldNames.CreatedDate); cmm.GetMemberMap(c => c.ModifiedDate).SetElementName(ErrorFieldNames.ModifiedDate); cmm.GetMemberMap(c => c.ExtendedData).SetElementName(ErrorFieldNames.ExtendedData).SetShouldSerializeMethod(obj => ((OldModels.Module)obj).ExtendedData.Any()); }); } }
private BsonClassMap BuildClassMap(Type type, ProjectionMapping mapping) { if (type == null || type == typeof(object)) { return null; } var baseClassMap = BuildClassMap(type.BaseType, mapping); if (baseClassMap != null) { baseClassMap.Freeze(); } var classMap = new BsonClassMap(type, baseClassMap); // Ignore extra elements, as the projection expression will likely not be complete classMap.SetIgnoreExtraElements(true); foreach (var memberMapping in mapping.Members.Where(x => x.Member.DeclaringType == type)) { var serializationExpression = memberMapping.Expression as SerializationExpression; if (serializationExpression == null) { var serializer = Build(memberMapping.Expression); serializationExpression = new FieldExpression( memberMapping.Member.Name, serializer, memberMapping.Expression); } var memberMap = classMap.MapMember(memberMapping.Member) .SetSerializer(serializationExpression.Serializer) .SetElementName(memberMapping.Member.Name); if (classMap.IdMemberMap == null && serializationExpression is GroupingKeyExpression) { classMap.SetIdMember(memberMap); } } return classMap; }
protected static void ConfigureErrorStackClassMap(BsonClassMap<Stack> cm) { cm.AutoMap(); cm.SetIgnoreExtraElements(true); cm.SetIdMember(cm.GetMemberMap(c => c.Id).SetRepresentation(BsonType.ObjectId).SetIdGenerator(new StringObjectIdGenerator())); cm.GetMemberMap(p => p.OrganizationId).SetElementName(ErrorStackFieldNames.OrganizationId).SetRepresentation(BsonType.ObjectId); cm.GetMemberMap(c => c.ProjectId).SetRepresentation(BsonType.ObjectId).SetElementName(ErrorStackFieldNames.ProjectId); cm.GetMemberMap(c => c.SignatureHash).SetElementName(ErrorStackFieldNames.SignatureHash); cm.GetMemberMap(c => c.SignatureInfo).SetElementName(ErrorStackFieldNames.SignatureInfo); cm.GetMemberMap(c => c.FixedInVersion).SetElementName(ErrorStackFieldNames.FixedInVersion).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.DateFixed).SetElementName(ErrorStackFieldNames.DateFixed).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.Title).SetElementName(ErrorStackFieldNames.Title); cm.GetMemberMap(c => c.TotalOccurrences).SetElementName(ErrorStackFieldNames.TotalOccurrences); cm.GetMemberMap(c => c.FirstOccurrence).SetElementName(ErrorStackFieldNames.FirstOccurrence); cm.GetMemberMap(c => c.LastOccurrence).SetElementName(ErrorStackFieldNames.LastOccurrence); cm.GetMemberMap(c => c.Description).SetElementName(ErrorStackFieldNames.Description).SetIgnoreIfNull(true); cm.GetMemberMap(c => c.IsHidden).SetElementName(ErrorStackFieldNames.IsHidden).SetIgnoreIfDefault(true); cm.GetMemberMap(c => c.IsRegressed).SetElementName(ErrorStackFieldNames.IsRegressed).SetIgnoreIfDefault(true); cm.GetMemberMap(c => c.DisableNotifications).SetElementName(ErrorStackFieldNames.DisableNotifications).SetIgnoreIfDefault(true); cm.GetMemberMap(c => c.OccurrencesAreCritical).SetElementName(ErrorStackFieldNames.OccurrencesAreCritical).SetIgnoreIfDefault(true); cm.GetMemberMap(c => c.References).SetElementName(ErrorStackFieldNames.References).SetShouldSerializeMethod(obj => ((OldModels.ErrorStack)obj).References.Any()); cm.GetMemberMap(c => c.Tags).SetElementName(ErrorStackFieldNames.Tags).SetShouldSerializeMethod(obj => ((OldModels.ErrorStack)obj).Tags.Any()); }
/// <summary> /// Applies a modification to the class map. /// </summary> /// <param name="classMap">The class map.</param> public void Apply(BsonClassMap classMap) { classMap.SetIgnoreExtraElements(_ignoreExtraElements); }
public static bool RegisterTrackablePocoMap(Type trackablePocoType) { if (BsonClassMap.IsClassMapRegistered(trackablePocoType)) return false; var classMap = new BsonClassMap(trackablePocoType); var pocoType = TrackableResolver.GetPocoType(trackablePocoType); // start with auto map classMap.AutoMap(); // ignore extra elements for smooth schema change classMap.SetIgnoreExtraElements(true); // unmap all members which T doesn't have var propertyNames = new HashSet<string>(pocoType.GetProperties().Select(p => p.Name)); var deletingMembers = classMap.DeclaredMemberMaps.Where(m => { var propertyInfo = m.MemberInfo as PropertyInfo; return propertyInfo == null || propertyNames.Contains(propertyInfo.Name) == false; }).ToList(); foreach (var m in deletingMembers) classMap.UnmapMember(m.MemberInfo); // set default ignore for saving spaces foreach (var memberMap in classMap.DeclaredMemberMaps) { var mt = memberMap.MemberType; var defaultValue = mt.IsValueType ? Activator.CreateInstance(mt) : null; memberMap.SetDefaultValue(defaultValue); memberMap.SetIgnoreIfDefault(true); } // tell customized id to mongo-db var identityColumn = pocoType.GetProperties().FirstOrDefault( p => TrackablePropertyAttribute.GetParameter(p, "mongodb.identity") != null); if (identityColumn != null) { classMap.MapIdProperty(identityColumn.Name); } try { BsonClassMap.RegisterClassMap(classMap); } catch (ArgumentException) { // if duplicate key exists return false; } return true; }