public async Task ReadEventsAsync() { ConnectionState.EnsureConnectionIsActive(); if (m_streamCursor.EndOfStream) { throw new InvalidOperationException("Stream \"{0}\" is empty.".FormatString(StreamName)); } await m_streamCursor.FetchSlice(); m_readedEvents = new List <JournaledEvent>(m_streamCursor.Slice.Count); foreach (var journaledEvent in m_streamCursor.Slice) { m_readedEvents.Add(m_mutationPipeline.Mutate(journaledEvent)); } }
public async Task AppendEventsAsync(IReadOnlyCollection <JournaledEvent> events) { Require.NotNull(events, "events"); ConnectionState.EnsureConnectionIsActive(); if (events.Count == 0) { return; } var fromVersion = m_endOfStream.Version; var mutatedEvents = new List <JournaledEvent>(events.Count); mutatedEvents.AddRange(events.Select(journaledEvent => m_mutationPipeline.Mutate(journaledEvent))); await m_pendingNotification.AddAsync(StreamName, fromVersion, mutatedEvents.Count); m_endOfStream = await m_journal.AppendEventsAsync(StreamName, m_endOfStream, mutatedEvents); await m_notificationHub.NotifyAsync(new EventStreamUpdated(StreamName, fromVersion, m_endOfStream.Version)); await m_pendingNotification.DeleteAsync(StreamName, fromVersion); }