Ejemplo n.º 1
0
        public override void Map(BsonClassMap <StatusEventDto> cm)
        {
            cm.SetDiscriminator("status");

            cm.MapProperty(p => p.FromStatus).SetElementName("fromStatus");
            cm.MapProperty(p => p.ToStatus).SetElementName("toStatus");
        }
        public override void Map(BsonClassMap <PriorityEventDto> cm)
        {
            cm.SetDiscriminator("priority");

            cm.MapProperty(p => p.FromPriority).SetElementName("fromPriority");
            cm.MapProperty(p => p.ToPriority).SetElementName("toPriority");
        }
Ejemplo n.º 3
0
        protected override void Configure(BsonClassMap <Money> builder)
        {
            builder.AutoMap();

            builder.MapProperty("Amount");
            builder.MapProperty("Currency");
        }
Ejemplo n.º 4
0
        public override void Map(BsonClassMap <TicketEventDto> cm)
        {
            cm.MapIdProperty(x => x.Id);

            cm.MapProperty(x => x.TicketId).SetElementName("ticketId");
            cm.MapProperty(x => x.Created).SetElementName("created");
            cm.MapProperty(x => x.UserId).SetElementName("userId");
        }
Ejemplo n.º 5
0
 public override void Map(BsonClassMap <FileUpload> cm)
 {
     cm.MapProperty(f => f.Created).SetElementName("created");
     cm.MapProperty(f => f.Id).SetElementName("id");
     cm.MapProperty(f => f.Name).SetElementName("name");
     cm.MapProperty(f => f.Type).SetElementName("type");
     cm.MapProperty(f => f.Data).SetElementName("data");
 }
Ejemplo n.º 6
0
        public override void Map(BsonClassMap <FileDto> cm)
        {
            cm.MapIdProperty(x => x.Id);

            cm.MapProperty(f => f.Created).SetElementName("created");
            cm.MapProperty(f => f.Id).SetElementName("id");
            cm.MapProperty(f => f.Name).SetElementName("name");
            cm.MapProperty(f => f.Type).SetElementName("type");
        }
Ejemplo n.º 7
0
        public override void Map(BsonClassMap <HistoricalReadModel> config)
        {
            config.MapProperty(t => t.CreatedBy).SetElementName("CreatedBy");
            config.MapProperty(t => t.CreatedAt).SetElementName("CreatedAt")
            .SetSerializer(new DateTimeSerializer(DateTimeKind.Local));

            config.MapProperty(t => t.UpdatedBy).SetElementName("UpdatedBy");
            config.MapProperty(t => t.UpdatedAt).SetElementName("UpdatedAt")
            .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 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 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");
        }
Ejemplo n.º 11
0
        public override void Map(BsonClassMap <Todo> cm)
        {
            cm.AutoMap();

            //every doc has to have an id
            cm.MapIdField(x => x.Id);
            cm.MapProperty(x => x.State);
            cm.MapProperty(x => x.IsDone);
            cm.SetIgnoreExtraElements(true);


            // will set the element name to "sp" in the stored documents

            //unmap the property.. now we won't save it
        }
Ejemplo n.º 12
0
 public static BsonMemberMap MapRequired <TInstance, TProperty>(
     this BsonClassMap <TInstance> mapper,
     Expression <Func <TInstance, TProperty> > propertyExpression)
     where TInstance : class =>
 mapper
 .MapProperty(propertyExpression)
 .SetIsRequired(true);
Ejemplo n.º 13
0
        public EventStore(IEventPublisher publisher, CQRSCode.ReadModel.Repository.MongoOptions mongoOptions, IList <EventType> events)
        {
            _publisher = publisher;

            if (!BsonClassMap.IsClassMapRegistered(@events[0].Type))
            {
                // Insuffisant car quand les entités sont enregistrées en tant que IEvent, seuls les champs de l'interface sont persistés
                // BsonClassMap.RegisterClassMap<ProductCreated>(cm => { cm.AutoMap(); cm.unmap } );
                // BsonClassMap.RegisterClassMap<OfferCreated>();
                // BsonClassMap.RegisterClassMap<OfferStockSet>();

                // BsonClassMap.RegisterClassMap<EventBase>(cm => {
                //     cm.MapIdProperty(eb => eb._id).SetIdGenerator(MongoDB.Bson.Serialization.IdGenerators.BsonObjectIdGenerator.Instance);
                // });

                // Impossible d'utiliser automap et de définir un autre champ ID que .Id
                // BsonClassMap.RegisterClassMap<OfferCreated>(cm =>
                // {
                //     cm.MapProperty(o => o.Id); // Nécessaire de mapper en tant que simple propriété afin que ce champ ne soit pas défini comme l'ID du document (_id) dans Mongo
                //     cm.AutoMap();
                //     //cm.GetMemberMapForElement("_id").SetIdGenerator(MongoDB.Bson.Serialization.IdGenerators.BsonObjectIdGenerator.Instance);
                // });

                foreach (var @event in events)
                {
                    BsonClassMap m = new BsonClassMap(@event.Type);
                    @event.Type.GetProperties().ToList().ForEach(p => m.MapProperty(p.Name));
                    BsonClassMap.RegisterClassMap(m);
                }
            }

            _client     = new MongoClient(mongoOptions.ConnectionString);
            _database   = _client.GetDatabase(mongoOptions.Database);
            _collection = _database.GetCollection <IEvent>("events");
        }
Ejemplo n.º 14
0
 public static BsonMemberMap MapOptional <TInstance, TProperty>(
     this BsonClassMap <TInstance> mapper,
     Expression <Func <TInstance, TProperty> > propertyExpression)
     where TInstance : class =>
 mapper
 .MapProperty(propertyExpression)
 .SetIgnoreIfNull(true);
Ejemplo n.º 15
0
        public override void Map(BsonClassMap <PriorityDto> cm)
        {
            cm.MapIdProperty(x => x.Id);

            cm.MapProperty(x => x.Name)
            .SetElementName("name");
        }
Ejemplo n.º 16
0
 private static void MapProperties <T>(PropertyInfo[] propertyInfos, BsonClassMap <T> c) where T : IDomainEvent
 {
     foreach (var property in propertyInfos)
     {
         c.MapProperty(property.Name);
     }
 }
Ejemplo n.º 17
0
        protected override void Configure(BsonClassMap <TTN> builder)
        {
            builder.AutoMap();

            builder.MapCreator(x => new TTN(x.Value));

            builder.MapProperty(x => x.Value);
        }
Ejemplo n.º 18
0
 public static BsonMemberMap MapOffsetDateTime <T>(
     this BsonClassMap <T> mapper,
     Expression <Func <T, OffsetDateTime?> > datetimePropertyExpression)
     where T : class =>
 mapper
 .MapProperty(datetimePropertyExpression)
 .SetIgnoreIfNull(true)
 .SetSerializer(NullableOffsetDateTimeMongoSerializer.Instance);
Ejemplo n.º 19
0
 public static BsonMemberMap MapOffsetDateTime <T>(
     this BsonClassMap <T> mapper,
     Expression <Func <T, OffsetDateTime> > datetimePropertyExpression,
     bool isRequired = true)
     where T : class =>
 mapper
 .MapProperty(datetimePropertyExpression)
 .SetIsRequired(isRequired)
 .SetSerializer(OffsetDateTimeMongoSerializer.Instance);
Ejemplo n.º 20
0
 public static BsonMemberMap MapGuid <T>(
     this BsonClassMap <T> mapper,
     Expression <Func <T, Guid> > guidPropertyExpression,
     bool isRequired = true)
     where T : class =>
 mapper
 .MapProperty(guidPropertyExpression)
 .SetIsRequired(isRequired)
 .SetSerializer(GuidMongoSerializer.Instance);
Ejemplo n.º 21
0
 public static void GetClassMap(BsonClassMap cm)
 {
     cm.MapProperty(nameof(Rounds));
     cm.MapProperty(nameof(AttackerCasualties));
     cm.MapProperty(nameof(DefenderCasualties));
     cm.MapProperty(nameof(DuelTies));
     cm.MapProperty(nameof(Duels));
     cm.MapProperty(nameof(AttackerVictory));
     cm.MapProperty(nameof(AverageLevelDifference));
     cm.MapProperty(nameof(TacticalAdvantage));
 }
Ejemplo n.º 22
0
        public override void Map(BsonClassMap <TicketDto> cm)
        {
            cm.MapIdProperty(x => x.Id);

            cm.MapProperty(x => x.Description)
            .SetElementName("description");

            cm.MapProperty(x => x.Priority)
            .SetElementName("priority");

            cm.MapProperty(x => x.Status)
            .SetElementName("status");

            cm.MapProperty(x => x.Title)
            .SetElementName("title");

            cm.MapProperty(x => x.Files)
            .SetElementName("files");
        }
        public override void Map(BsonClassMap <MyClass> cm)
        {
            cm.AutoMap();

            //every doc has to have an id
            cm.MapIdField(x => x.Id).SetIdGenerator(new StringObjectIdGenerator());

            cm.MapProperty(x => x.SomeProperty)
            .SetElementName("sp");     // will set the element name to "sp" in the stored documents

            //unmap the property.. now we won't save it
            cm.UnmapProperty(x => x.SomeOtherProperty);
        }
Ejemplo n.º 24
0
        protected override void Configure(BsonClassMap <Order> builder)
        {
            builder.MapProperty(x => x.Identifier);
            builder.MapProperty(x => x.Price);
            builder.MapProperty(x => x.Description);
            builder.MapProperty(x => x.Status);

            builder.MapProperty(x => x.SenderLocation);
            builder.MapProperty(x => x.RecipientLocation);
            builder.MapProperty(x => x.CurrentLocation);

            builder.MapField("_cargos").SetElementName(nameof(Order.Cargos));
        }
Ejemplo n.º 25
0
        public static void RequirePropertySetters <T>(this BsonClassMap <T> classMap)
        {
            var properties = typeof(T).GetProperties(
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
                );

            foreach (var property in properties.Where(p => p.CanRead && !p.CanWrite))
            {
                throw new ArgumentException(
                          $"Setters are required on property {property.Name} in class {typeof(T)} to allow snapshots"
                          );
            }

            foreach (var property in properties.Where(p => p.CanRead && p.CanWrite))
            {
                classMap.MapProperty(property.Name);
            }
        }
        public void Apply(BsonClassMap classMap)
        {
            var readOnlyProperties = classMap
                                     .ClassType
                                     .GetTypeInfo()
                                     .GetProperties(_bindingFlags)
                                     .Where(propInfo => IsReadOnlyProperty(classMap, propInfo))
                                     .ToList();

            foreach (var property in readOnlyProperties)
            {
                classMap.MapMember(property);
            }

            if (classMap.ClassType.Name.Equals("Event"))
            {
                classMap.MapField("_version");
                classMap.MapProperty("Version");
            }
        }
        public override void Map(BsonClassMap <CommentEventDto> cm)
        {
            cm.SetDiscriminator("comment");

            cm.MapProperty("Comment").SetElementName("comment");
        }
Ejemplo n.º 28
0
 protected override void Configure(BsonClassMap <CargoNumber> builder)
 {
     builder.MapProperty(x => x.Number).SetSerializer(new GuidSerializer());
 }
Ejemplo n.º 29
0
 protected override void MapEntity(BsonClassMap <Person> cm)
 {
     cm.MapIdField(x => x.Id).SetIdGenerator(new ObjectIdGenerator());
     cm.MapProperty(x => x.Name);
     cm.MapProperty(x => x.Age);
 }
Ejemplo n.º 30
0
 public override void Map(BsonClassMap <FileContentDto> cm)
 {
     cm.MapProperty(f => f.Data).SetElementName("data");
 }