public async Task Save <T>(EventBatch <T> s) { Check.NotNull(s, nameof(T)); Check.Requires( s.Events.Count <= EventID.MaxEventSequence, nameof(s), "A single batch can contain at most {0} events.", EventID.MaxEventSequence ); StreamConfiguration config = _store.GetStreamConfig <T>(); // Now checked by the serializer itself... //RecordedEvent eventOfUnregisteredType = s.Events // .FirstOrDefault(x => !_serializationConfiguration.EventClasses.Contains(x.Event.GetType())); //if (eventOfUnregisteredType != null) { // throw new EventStoreConfigurationException( // $"Event type {eventOfUnregisteredType.Event.GetType().Name} was not configured. Call " + // $"RegisterEventClass when calling MongoEventStore.Configure."); //} if (s.Events.Any()) { EventIDGenerator idGenerator = await _store.GetBatch(); foreach (RecordedEvent e in s.Events) { e.ID = idGenerator.Next(); } await _transaction .GetCollection <RecordedEvent>(MongoEventStore.CollectionName) .InsertManyAsync(s.Events); StreamInfo info = new StreamInfo(s.StreamID); await _transaction .GetCollection <StreamInfo>(MongoEventStore.GetStreamInfoName(config)) .UpsertAsync(x => x.StreamID, info.StreamID, info); } }
public Task <bool> Exists <T>(StreamLocator <T> s) { StreamConfiguration config = _store.GetStreamConfig <T>(); return(_transaction.GetCollection <StreamInfo>(MongoEventStore.GetStreamInfoName(config)).Exists(i => i.StreamID, s.StreamID)); }
public MongoEventStoreTransaction(MongoEventStore store, IMongoFacadeTransaction transaction) { _store = store; _transaction = transaction; }