public IEnumerable <DomainEvent> GetEventsByEventTypes(IEnumerable <Type> domainEventTypes, Guid aggregateRootId)
        {
            var selector = Query.And(Query.In("_t", new BsonArray(domainEventTypes.Select(t => t.Name))),
                                     Query.EQ("AggregateRootId", aggregateRootId));

            return(IOExceptionRetriable.Run(() => GetEventsCollection().Find(selector)));
        }
        public IEnumerable <DomainEvent> GetEventsByEventTypes(IEnumerable <Type> domainEventTypes)
        {
            var array    = domainEventTypes.Select(t => t.Name);
            var selector = Query.In("_t", new BsonArray(array));

            return(IOExceptionRetriable.Run(() => GetEventsCollection().Find(selector)));
        }
 public void Insert(IEnumerable <DomainEvent> domainEvents)
 {
     if (domainEvents.Any())
     {
         IOExceptionRetriable.Run(() => GetEventsCollection().InsertBatch(domainEvents));
     }
 }
        public IEnumerable <DomainEvent> GetEventsByEventTypes(IEnumerable <Type> domainEventTypes, DateTime startDate, DateTime endDate)
        {
            var selector = Query.And(Query.In("_t", new BsonArray(domainEventTypes.Select(t => t.Name))),
                                     Query.GTE("EventDate", startDate),
                                     Query.LT("EventDate", endDate));

            return(IOExceptionRetriable.Run(() => GetEventsCollection().Find(selector)));
        }
 public IEnumerable <DomainEvent> GetEvents(Guid aggregateRootId, int startSequence)
 {
     return(IOExceptionRetriable.Run(() => GetEventsCollection()
                                     .AsQueryable <DomainEvent>()
                                     .Where(e => e.AggregateRootId == aggregateRootId)
                                     .Where(e => e.Sequence >= startSequence)
                                     .ToList()));
 }
 public Snapshot GetSnapshot(Guid aggregateRootId)
 {
     return(IOExceptionRetriable.Run(() =>
                                     GetSnapShotCollection()
                                     .AsQueryable <Snapshot>()
                                     .SingleOrDefault(s => s.AggregateRootId == aggregateRootId)
                                     ));
 }
        public void SaveSnapshot <TSnapshot>(TSnapshot snapshot) where TSnapshot : Snapshot
        {
            var query = Query.EQ("_id", snapshot.AggregateRootId);

            IOExceptionRetriable.Run(() =>
                                     GetSnapShotCollection()
                                     .Update(query, Update.Replace(snapshot), UpdateFlags.Upsert)
                                     );
        }
        public void DeleteEventsByEventType(IEnumerable <Type> domainEventTypes)
        {
            var selector = Query.In("_t", new BsonArray(domainEventTypes.Select(t => t.Name)));

            IOExceptionRetriable.Run(() => GetEventsCollection().Remove(selector));
        }