public async Task <Nothing> AppendAsync( AggregateId aggregateId, IReadOnlyList <IDomainEvent> domainEvents, long expectedVersion) { if (domainEvents.Count > 0) { var connection = await EventStoreConnectionProvider.GrabSingleEventStoreConnectionFor(_connectionString); var results = await connection.ConditionalAppendToStreamAsync( aggregateId.ToStreamName(_eventStoreName), expectedVersion, domainEvents.Select(e => e.ToEventData())); switch (results.Status) { case ConditionalWriteStatus.Succeeded: break; case ConditionalWriteStatus.VersionMismatch: throw new VersionMismatchException(aggregateId.ToStreamName(_eventStoreName), expectedVersion); case ConditionalWriteStatus.StreamDeleted: throw new StreamDeletedException(aggregateId.ToStreamName(_eventStoreName)); default: throw new ArgumentOutOfRangeException(); } } return(Nothing.NotAtAll); }
public async Task <IReadOnlyList <IDomainEvent> > AsyncLoadAllEventsFor(AggregateId aggregateId) { var connection = await EventStoreConnectionProvider.GrabSingleEventStoreConnectionFor(_connectionString); var resolvedEvents = await connection.ReadAllStreamEventsForward(aggregateId.ToStreamName(_eventStoreName)); return(resolvedEvents.Select(e => e.Event.ToDomainEvent()).ToList()); }
private IEventStoreSubscription EventStoreSubscriptionFrom(string streamName, long lastCheckpoint) { var connection = EventStoreConnectionProvider.GrabSingleEventStoreConnectionFor(_connectionString).Result; var eventStream = new BlockingCollection <IDomainEvent>(); var catchUpSubscription = connection.SubscribeToStreamFrom( streamName, lastCheckpoint == 0 ? (long?)null : lastCheckpoint, CatchUpSubscriptionSettings.Default, (_, x) => eventStream.Add(x.Event.ToDomainEvent())); return(new EventStoreSubscription(catchUpSubscription, eventStream)); }