public BuildingInfoValuesCollectionDefinition(IMongoConnectionHandler connectionHandler)
     : base(connectionHandler)
 {
     if (!BsonClassMap.IsClassMapRegistered(typeof(BuildingInfoValues)))
     {
         try
         {
             BsonClassMap.RegisterClassMap <BuildingInfoValues>(
                 cm =>
             {
                 cm.AutoMap();
             });
         }
         catch (ArgumentException)
         {
             // this fails with an argument exception at startup, but otherwise works fine.  Probably should try to figure out why, but ignoring it is easier :(
         }
     }
 }
Пример #2
0
        public void Initialize()
        {
            var mappings = new HashSet <Type>();

            CreateMapping(typeof(Envelope), mappings);
            CreateMapping(typeof(Subscriber), mappings);

            foreach (var type in mappings)
            {
                if (BsonClassMap.IsClassMapRegistered(type))
                {
                    continue;
                }
                var map = new DocumentClassMap(type);
                map.AutoMap();
                map.SetIgnoreExtraElements(true);
                BsonClassMap.RegisterClassMap(map);
            }
        }
Пример #3
0
        public void ShouldInvokeConfigureForAllRegisteredProfiles()
        {
            //Arrange
            var containerExtension = A.Fake <IBootstrapperContainerExtension>();
            var profiles           = new List <BsonClassMap> {
                new TestMongoClassMap()
            };

            A.CallTo(() => containerExtension.ResolveAll <BsonClassMap>()).Returns(profiles);
            Bootstrapper.With.Extension(containerExtension);
            var mapperExtension = new MongoExtension(registrationHelper);

            //Act
            mapperExtension.Run();

            //Assert
            A.CallTo(() => containerExtension.ResolveAll <BsonClassMap>()).MustHaveHappened();
            Assert.IsTrue(BsonClassMap.IsClassMapRegistered(typeof(TestMongo)));
        }
        public static void RegisterClass <T>()
        {
            if (BsonClassMap.IsClassMapRegistered(typeof(T)))
            {
                return;
            }

            BsonClassMap.RegisterClassMap <T>(x =>
            {
                x.AutoMap();
                x.SetDiscriminatorIsRequired(true);

                var typeName = typeof(T).Name;
                if (typeName.EndsWith("Document"))
                {
                    x.SetDiscriminator(typeName.Substring(0, typeName.Length - "Document".Length));
                }
            });
        }
Пример #5
0
        internal static void ConfigureClassMaps()
        {
            if (BsonClassMap.IsClassMapRegistered(typeof(TimeoutEntity)))
            {
                return;
            }

            BsonClassMap.RegisterClassMap <TimeoutEntity>(
                cm =>
            {
                cm.AutoMap();
                cm.MapMember(mm => mm.Time)
                .SetSerializer(new DateTimeSerializer(DateTimeKind.Utc, BsonType.Document));
                cm.MapMember(mm => mm.Headers)
                .SetSerializer(
                    new DictionaryInterfaceImplementerSerializer <Dictionary <string, string> >(
                        DictionaryRepresentation.ArrayOfDocuments));
            });
        }
        protected override void ConfigureClassMap(BsonClassMap <Organization> cm)
        {
            base.ConfigureClassMap(cm);
            cm.GetMemberMap(c => c.Name).SetElementName(FieldNames.Name);
            cm.GetMemberMap(c => c.StripeCustomerId).SetElementName(FieldNames.StripeCustomerId).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.PlanId).SetElementName(FieldNames.PlanId).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.CardLast4).SetElementName(FieldNames.CardLast4).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.SubscribeDate).SetElementName(FieldNames.SubscribeDate).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.BillingChangeDate).SetElementName(FieldNames.BillingChangeDate).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.BillingChangedByUserId).SetElementName(FieldNames.BillingChangedByUserId).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.BillingStatus).SetElementName(FieldNames.BillingStatus);
            cm.GetMemberMap(c => c.BillingPrice).SetElementName(FieldNames.BillingPrice);
            cm.GetMemberMap(c => c.RetentionDays).SetElementName(FieldNames.RetentionDays);
            cm.GetMemberMap(c => c.HasPremiumFeatures).SetElementName(FieldNames.HasPremiumFeatures);
            cm.GetMemberMap(c => c.MaxUsers).SetElementName(FieldNames.MaxUsers);
            cm.GetMemberMap(c => c.MaxProjects).SetElementName(FieldNames.MaxProjects);
            cm.GetMemberMap(c => c.MaxEventsPerMonth).SetElementName(FieldNames.MaxEventsPerMonth);
            cm.GetMemberMap(c => c.TotalEventCount).SetElementName(FieldNames.TotalEventCount);
            cm.GetMemberMap(c => c.LastEventDate).SetElementName(FieldNames.LastEventDate).SetIgnoreIfDefault(true);

            cm.GetMemberMap(c => c.IsSuspended).SetElementName(FieldNames.IsSuspended);
            cm.GetMemberMap(c => c.SuspensionCode).SetElementName(FieldNames.SuspensionCode).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.SuspensionNotes).SetElementName(FieldNames.SuspensionNotes).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.SuspensionDate).SetElementName(FieldNames.SuspensionDate).SetIgnoreIfNull(true);
            cm.GetMemberMap(c => c.SuspendedByUserId).SetElementName(FieldNames.SuspendedByUserId).SetIgnoreIfNull(true);

            cm.GetMemberMap(c => c.Invites).SetElementName(FieldNames.Invites).SetIgnoreIfNull(true).SetShouldSerializeMethod(obj => ((Organization)obj).Invites.Any());
            cm.GetMemberMap(c => c.Usage).SetElementName(FieldNames.Usage).SetIgnoreIfNull(true).SetShouldSerializeMethod(obj => ((Organization)obj).Usage.Any());
            cm.GetMemberMap(c => c.OverageHours).SetElementName(FieldNames.OverageHours).SetIgnoreIfNull(true).SetShouldSerializeMethod(obj => ((Organization)obj).OverageHours.Any());


            if (!BsonClassMap.IsClassMapRegistered(typeof(UsageInfo)))
            {
                BsonClassMap.RegisterClassMap <UsageInfo>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.Date).SetIgnoreIfDefault(true);
                    cmm.GetMemberMap(c => c.Total).SetIgnoreIfDefault(true);
                    cmm.GetMemberMap(c => c.Blocked).SetIgnoreIfDefault(true);
                    cmm.GetMemberMap(c => c.Limit).SetIgnoreIfDefault(true);
                });
            }
        }
Пример #7
0
        private void MapClasses()
        {
            var conventionPack = new ConventionPack {
                new CamelCaseElementNameConvention()
            };

            ConventionRegistry.Register("camelCase", conventionPack, t => true);


            if (!BsonClassMap.IsClassMapRegistered(typeof(User)))
            {
                BsonClassMap.RegisterClassMap <User>(i =>
                {
                    i.AutoMap();
                    i.SetIgnoreExtraElements(true);
                }
                                                     );
            }
        }
Пример #8
0
        public static IEntityDefinition RegisterType(Type entityType)
        {
            if (IsRegistered(entityType))
            {
                throw new ArgumentException("Type is already registered", nameof(entityType));
            }

            var definition = new EntityDefinition
            {
                EntityType = entityType
            };

            MappingLock.EnterUpgradeableReadLock();
            try
            {
                if (!BsonClassMap.IsClassMapRegistered(entityType))
                {
                    MappingLock.EnterWriteLock();

                    try
                    {
                        var classMap = new BsonClassMap(entityType);
                        BsonClassMap.RegisterClassMap(classMap);

                        foreach (var processor in MappingProcessors)
                        {
                            processor.ApplyMapping(definition, classMap);
                        }
                    }
                    finally
                    {
                        MappingLock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                MappingLock.ExitUpgradeableReadLock();
            }

            return(SetEntityDefinition(definition));
        }
Пример #9
0
        private void Map()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(ArticleEntity)))
            {
                BsonClassMap.RegisterClassMap <ArticleEntity>(cm =>
                {
                    cm.AutoMap();
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(TranslationEntity)))
            {
                BsonClassMap.RegisterClassMap <TranslationEntity>(cm =>
                {
                    cm.AutoMap();
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(PublicationEntity)))
            {
                BsonClassMap.RegisterClassMap <PublicationEntity>(cm =>
                {
                    cm.AutoMap();
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(UserEntity)))
            {
                BsonClassMap.RegisterClassMap <UserEntity>(cm =>
                {
                    cm.AutoMap();
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(AuthRenewEntity)))
            {
                BsonClassMap.RegisterClassMap <AuthRenewEntity>(cm =>
                {
                    cm.AutoMap();
                });
            }
        }
Пример #10
0
 public Mongo2GoTest(MongoDBFixture mongoDBFixture)
 {
     this.mongoDBFixture = mongoDBFixture;
     if (!BsonClassMap.IsClassMapRegistered(typeof(TestDocument)))
     {
         try
         {
             BsonClassMap.RegisterClassMap <TestDocument>(
                 map =>
             {
                 map.AutoMap();
                 map.MapIdMember(c => c.TestDocumentId)
                 .SetIdGenerator(StringObjectIdGenerator.Instance);
             });
         }
         catch
         {
         }
     }
 }
Пример #11
0
 public static void CustomerMap()
 {
     if (!BsonClassMap.IsClassMapRegistered(typeof(Customer)))
     {
         BsonClassMap.RegisterClassMap <Customer>(map =>
         {
             map.MapProperty(x => x.CustomerId);
             map.MapProperty(x => x.CompanyName);
             map.MapProperty(x => x.ContactName);
             map.MapProperty(x => x.ContactTitle);
             map.MapProperty(x => x.Address);
             map.MapProperty(x => x.City);
             map.MapProperty(x => x.Region);
             map.MapProperty(x => x.PostalCode);
             map.MapProperty(x => x.Country);
             map.MapProperty(x => x.Phone);
             map.MapProperty(x => x.Fax);
         });
     }
 }
Пример #12
0
        private void MapClasses()
        {
            var conventionPack = new ConventionPack {
                new CamelCaseElementNameConvention()
            };

            ConventionRegistry.Register("camelCase", conventionPack, t => true);

            if (!BsonClassMap.IsClassMapRegistered(typeof(Produtos)))
            {
                BsonClassMap.RegisterClassMap <Produtos>(i =>
                {
                    i.AutoMap(); // Mapeia todas as propriedades automáticamente poderia fazer uma a uma
                    // i.MapProperty(f => f.DataNascimento);
                    // i.MapProperty(f => f.Localizacao);
                    // i.MapProperty(f => f.Sexo);
                    i.SetIgnoreExtraElements(true);
                });
            }
        }
Пример #13
0
        protected MongoDataService()
        {
            lock (this)
            {
                if (!BsonClassMap.IsClassMapRegistered(typeof(DataObject)))
                {
                    BsonClassMap.RegisterClassMap <DataObject>(t => t.MapIdMember(m => m.Id));
                }

                if (!BsonClassMap.IsClassMapRegistered(typeof(T)))
                {
                    BsonClassMap.RegisterClassMap <T>(t =>
                    {
                        t.AutoMap();

                        t.SetIgnoreExtraElements(true);
                    });
                }
            }
        }
        public ProductsRepositoryMongoDB()
        {
            _runner   = MongoDbRunner.Start();
            _client   = new MongoClient(_runner.ConnectionString);
            _database = _client.GetDatabase(DbName);

            if (!BsonClassMap.IsClassMapRegistered(typeof(Product)))
            {
                BsonSerializer.UseZeroIdChecker = true;
                BsonClassMap.RegisterClassMap <Product>(cm =>
                {
                    cm.AutoMap();
                    cm.SetIdMember(cm.GetMemberMap(p => p.CatalogNumber));
                    cm.GetMemberMap(p => p.Category).SetIgnoreIfNull(true);
                    cm.GetMemberMap(p => p.Vendor).SetIgnoreIfNull(true);
                });
            }

            _collection = _database.GetCollection <Product>(CollectionName);
        }
Пример #15
0
        public UserRepository(IMongoDatabase mongoDatabase, IRoleRepository roleRepository) : base(mongoDatabase)
        {
            _roleRepository = roleRepository ?? throw new ArgumentNullException(nameof(IRoleRepository));

            if (!BsonClassMap.IsClassMapRegistered(typeof(Claim)))
            {
                BsonClassMap.RegisterClassMap <Claim>(cm =>
                {
                    cm.SetIgnoreExtraElements(true);
                    cm.MapMember(c => c.Issuer);
                    cm.MapMember(c => c.OriginalIssuer);
                    cm.MapMember(c => c.Properties);
                    cm.MapMember(c => c.Subject);
                    cm.MapMember(c => c.Type);
                    cm.MapMember(c => c.Value);
                    cm.MapMember(c => c.ValueType);
                    cm.MapCreator(c => new Claim(c.Type, c.Value, c.ValueType, c.Issuer, c.OriginalIssuer, c.Subject));
                });
            }
        }
Пример #16
0
        public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
        {
            BsonDocument doc;

            if (BsonClassMap.IsClassMapRegistered(value.GetType()))
            {
                doc = value.ToBsonDocument();
                doc.Remove("_t");
                doc.InsertAt(0, new BsonElement("_t", value.GetType().AssemblyQualifiedName));
                AddTypeInformation(doc.Elements, value, string.Empty);
            }
            else
            {
                var str = JsonConvert.SerializeObject(value, SerializerSettings);
                doc = BsonDocument.Parse(str);
                ConvertMetaFormat(doc);
            }

            BsonSerializer.Serialize(context.Writer, doc);
        }
Пример #17
0
        public MongoTriggerLogger(string connectionString, string tablePrefix)
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(TriggerLogEntry)))
            {
                BsonClassMap.RegisterClassMap <TriggerLogEntry>(cm =>
                {
                    cm.AutoMap();
                    cm.MapField(x => x.Timestamp);
                    cm.MapField(x => x.Name);
                    cm.MapField(x => x.Kind);
                    cm.MapField(x => x.Group);
                });
            }

            var urlBuilder = new MongoUrlBuilder(connectionString);
            var client     = new MongoClient(urlBuilder.ToMongoUrl());

            this.tablePrefix = tablePrefix;
            this.database    = client.GetServer().GetDatabase(urlBuilder.DatabaseName);
        }
 public static void RegisterTypes(IEnumerable <Type> types, bool useAlias = true)
 {
     if (useAlias)
     {
         foreach (var t in types)
         {
             if (!BsonClassMap.IsClassMapRegistered(t))
             {
                 BsonClassMap.RegisterClassMap(new AliasClassMap(t));
             }
         }
     }
     else
     {
         foreach (var t in types)
         {
             BsonClassMap.LookupClassMap(t);
         }
     }
 }
Пример #19
0
        private void MapearClasses()
        {
            var conventionPack = new ConventionPack()
            {
                new CamelCaseElementNameConvention()
            };

            ConventionRegistry.Register("camelCase", conventionPack, t => true);
            // t => true -> aplica globalmente esta convenção
            // t => t.FullName.StartsWith("Your.Name.Space."));

            if (!BsonClassMap.IsClassMapRegistered(typeof(Infectado)))
            {
                BsonClassMap.RegisterClassMap <Infectado>(classMap =>
                {
                    classMap.AutoMap();
                    classMap.SetIgnoreExtraElements(true);
                });
            }
        }
Пример #20
0
        internal static void MapStatsClasses()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(EventStatsWithStackIds)))
            {
                BsonClassMap.RegisterClassMap <EventStatsWithStackIds>(cm2 => {
                    cm2.AutoMap();
                    cm2.GetMemberMap(c => c.StackIds).SetElementName("ids");
                    cm2.GetMemberMap(c => c.NewStackIds).SetElementName("newids").SetSerializationOptions(new ArraySerializationOptions(new RepresentationSerializationOptions(BsonType.ObjectId)));
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(EventStats)))
            {
                BsonClassMap.RegisterClassMap <EventStats>(cm2 => {
                    cm2.AutoMap();
                    cm2.GetMemberMap(c => c.Total).SetElementName("tot");
                    cm2.GetMemberMap(c => c.NewTotal).SetElementName("new");
                });
            }
        }
        public static IUnitOfWorkFactory BuildMongoDb(string url, bool reload = true)
        {
            var mongoUrl = new MongoUrl(url);
            var db       = new MongoClient(mongoUrl).GetServer();

            if (reload)
            {
                if (db.DatabaseExists(mongoUrl.DatabaseName))
                {
                    db.DropDatabase(mongoUrl.DatabaseName);
                }
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(IncEntityBase)))
            {
                BsonClassMap.RegisterClassMap <IncEntityBase>(map => map.UnmapProperty(r => r.Id));
            }

            return(new MongoDbUnitOfWorkFactory(new MongoDbSessionFactory(url)));
        }
Пример #22
0
        private void MapClasses()
        {
            //Entity:
            // Duas formas: uma com data annotation e outra com automaps

            var conventionPack = new ConventionPack {
                new CamelCaseElementNameConvention()
            };

            ConventionRegistry.Register("camelCase", conventionPack, t => true);

            if (!BsonClassMap.IsClassMapRegistered(typeof(Infectado)))
            {
                BsonClassMap.RegisterClassMap <Infectado>(i =>
                {
                    i.AutoMap();
                    i.SetIgnoreExtraElements(true);
                });
            }
        }
Пример #23
0
        public override void Startup()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(Error)))
            {
                BsonClassMap.RegisterClassMap <Error>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.Modules).SetElementName(FieldNames.Modules).SetIgnoreIfDefault(true);
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(InnerError)))
            {
                BsonClassMap.RegisterClassMap <InnerError>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.Message).SetElementName(FieldNames.Message).SetIgnoreIfNull(true);
                    cmm.GetMemberMap(c => c.Type).SetElementName(FieldNames.Type);
                    cmm.GetMemberMap(c => c.Code).SetElementName(FieldNames.Code);
                    cmm.GetMemberMap(c => c.Data).SetElementName(FieldNames.Data).SetShouldSerializeMethod(obj => ((InnerError)obj).Data.Any());
                    cmm.GetMemberMap(c => c.Inner).SetElementName(FieldNames.Inner);
                    cmm.GetMemberMap(c => c.StackTrace).SetElementName(FieldNames.StackTrace).SetShouldSerializeMethod(obj => ((InnerError)obj).StackTrace.Any());
                    cmm.GetMemberMap(c => c.TargetMethod).SetElementName(FieldNames.TargetMethod).SetIgnoreIfNull(true);
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(Module)))
            {
                BsonClassMap.RegisterClassMap <Module>(cmm => {
                    cmm.AutoMap();
                    cmm.SetIgnoreExtraElements(true);
                    cmm.GetMemberMap(c => c.ModuleId).SetElementName(FieldNames.ModuleId).SetIgnoreIfDefault(true);
                    cmm.GetMemberMap(c => c.Name).SetElementName(FieldNames.Name);
                    cmm.GetMemberMap(c => c.Version).SetElementName(FieldNames.Version).SetIgnoreIfNull(true);
                    cmm.GetMemberMap(c => c.IsEntry).SetElementName(FieldNames.IsEntry).SetIgnoreIfDefault(true);
                    cmm.GetMemberMap(c => c.CreatedDate).SetElementName(FieldNames.CreatedDate);
                    cmm.GetMemberMap(c => c.ModifiedDate).SetElementName(FieldNames.ModifiedDate);
                    cmm.GetMemberMap(c => c.Data).SetElementName(FieldNames.Data).SetShouldSerializeMethod(obj => ((Module)obj).Data.Any());
                });
            }
        }
Пример #24
0
        void RegisterClassMaps()
        {
            lock (ClassMapRegistrationLock)
            {
                if (BsonClassMap.IsClassMapRegistered(typeof(IdempotencyData)))
                {
                    _log.Debug("BSON class map for {type} already registered - not doing anything", typeof(IdempotencyData));
                    return;
                }

                _log.Debug("Registering BSON class maps for {type} and accompanying types", typeof(IdempotencyData));

                BsonClassMap.RegisterClassMap <IdempotencyData>(map =>
                {
                    map.MapCreator(obj => new IdempotencyData(obj.OutgoingMessages, obj.HandledMessageIds));
                    map.MapMember(obj => obj.HandledMessageIds);
                    map.MapMember(obj => obj.OutgoingMessages);
                });

                BsonClassMap.RegisterClassMap <OutgoingMessage>(map =>
                {
                    map.MapCreator(obj => new OutgoingMessage(obj.DestinationAddresses, obj.TransportMessage));
                    map.MapMember(obj => obj.DestinationAddresses);
                    map.MapMember(obj => obj.TransportMessage);
                });

                BsonClassMap.RegisterClassMap <OutgoingMessages>(map =>
                {
                    map.MapCreator(obj => new OutgoingMessages(obj.MessageId, obj.MessagesToSend));
                    map.MapMember(obj => obj.MessageId);
                    map.MapMember(obj => obj.MessagesToSend);
                });

                BsonClassMap.RegisterClassMap <TransportMessage>(map =>
                {
                    map.MapCreator(obj => new TransportMessage(obj.Headers, obj.Body));
                    map.MapMember(obj => obj.Headers);
                    map.MapMember(obj => obj.Body);
                });
            }
        }
        public static void Initialize()
        {
            var conventionPack = new ConventionPack
            {
                new CamelCaseElementNameConvention(),
                new NamedIdMemberConvention("Id"),
                new IgnoreExtraElementsConvention(true)
            };

            ConventionRegistry.Register("My Convention", conventionPack,
                                        type => type.FullName.StartsWith("DocumentSchemaMigration.Models"));

            if (!BsonClassMap.IsClassMapRegistered(typeof(Models.v2.Musician)))
            {
                BsonClassMap.RegisterClassMap <Models.v2.Musician>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(m => m.Bands).SetDefaultValue(Enumerable.Empty <string>);
                    cm.MapMember(m => m.Birthdate).SetDefaultValue(DateTime.MinValue);
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(Models.v3.Musician)))
            {
                BsonClassMap.RegisterClassMap <Models.v3.Musician>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(m => m.Bands).SetDefaultValue(Enumerable.Empty <string>);
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(Models.v4.Musician)))
            {
                BsonClassMap.RegisterClassMap <Models.v4.Musician>(cm =>
                {
                    cm.AutoMap();
                    cm.MapMember(m => m.Instruments).SetDefaultValue(Enumerable.Empty <Instrument>());
                    cm.MapExtraElementsMember(musician => musician.ExtraElements);
                });
            }
        }
Пример #26
0
        static MongoPatientTaskRepository()
        {
            #region Register ClassMap
            try {
                if (BsonClassMap.IsClassMapRegistered(typeof(GoalBase)) == false)
                {
                    BsonClassMap.RegisterClassMap <GoalBase>();
                }
            }
            catch { }

            try
            {
                if (BsonClassMap.IsClassMapRegistered(typeof(MEPatientTask)) == false)
                {
                    BsonClassMap.RegisterClassMap <MEPatientTask>();
                }
            }
            catch { }
            #endregion
        }
Пример #27
0
        protected EntityCollectionDefinition(IMongoConnectionHandler connectionHandler)
        {
            if (connectionHandler == null)
            {
                throw new ArgumentNullException("connectionHandler");
            }

            Collection = connectionHandler.Database.GetCollection <T>(typeof(T).Name.ToLower() + "s");

            // setup serialization
            if (!BsonClassMap.IsClassMapRegistered(typeof(Entity)))
            {
                BsonClassMap.RegisterClassMap <Entity>(
                    cm =>
                {
                    cm.AutoMap();
                    cm.SetIdMember(cm.GetMemberMap(c => c.Id));
                    cm.IdMemberMap.SetIdGenerator(StringObjectIdGenerator.Instance);
                });
            }
        }
Пример #28
0
 static MongoProgramRepository()
 {
     #region Register ClassMap
     try
     {
         if (BsonClassMap.IsClassMapRegistered(typeof(ProgramBase)) == false)
         {
             BsonClassMap.RegisterClassMap <ProgramBase>();
         }
     }
     catch { }
     try
     {
         if (BsonClassMap.IsClassMapRegistered(typeof(MEProgram)) == false)
         {
             BsonClassMap.RegisterClassMap <MEProgram>();
         }
     }
     catch { }
     #endregion
 }
Пример #29
0
        private void MapClasses()
        {
            // Define que o mapping utilizara o padrão CamelCase.
            var conventionPack = new ConventionPack {
                new CamelCaseElementNameConvention()
            };

            ConventionRegistry.Register("camelCase", conventionPack, t => true);

            // Se não tivermos nenhuma classe mapeada, para esse tipo, iremos mapear.
            if (!BsonClassMap.IsClassMapRegistered(typeof(Infected)))
            {
                BsonClassMap.RegisterClassMap <Infected>(i =>
                {
                    // Aqui podemos utilizar o MapField para definir configurações especificas
                    // o AutoMap efetua o mapeamento por convenção automaticamente.
                    i.AutoMap();
                    i.SetIgnoreExtraElements(true);
                });
            }
        }
Пример #30
0
        static MongoDbAuditStore()
        {
            if (BsonClassMap.IsClassMapRegistered(typeof(AuditDocument)))
            {
                return;
            }

            // easiest way to metadata since keys wont become element names, therefore subject to validation
            // will allow keys like $correlationId to be kept
            var headersSerializer = new DictionaryInterfaceImplementerSerializer <AuditHeaders, string, string>(
                DictionaryRepresentation.ArrayOfDocuments
                );

            BsonClassMap.RegisterClassMap <AuditDocument>(x =>
            {
                x.AutoMap();
                x.MapIdMember(doc => doc.AuditId);
                x.MapMember(doc => doc.Headers).SetSerializer(headersSerializer);
                x.MapMember(doc => doc.Custom).SetSerializer(headersSerializer);
            });
        }