Example #1
0
        protected async Task WriteEvents(PersistenceRequest request)
        {
            var events = request.Events;

            // serialize the events into raw events
            var rawEvents = UnpersistedRawEvent.FromUnpersistedEvents(events, _serializer);

            // writes all events to the store
            await _writer.WriteStreamAsync(request.Stream, request.ExpectedStreamSequence, rawEvents);

            // publishes the events in the order they were sent
            for (int i = 0, len = events.Count; i < len; i++)
            {
                var e              = events[i];
                var re             = rawEvents[i];
                var persistedEvent = PersistedEventFactory.FromUnpersistedEvent(re.GlobalSequence, e);

                // publish to the event stream
                _dispatcher.Tell(persistedEvent);
            }
        }
Example #2
0
        async Task Write(IReadOnlyList <BufferEntry> bufferEntries)
        {
            // creates a list of "Event + Sender" entries
            var entries = bufferEntries.SelectMany(entry => entry.Request.Events.Select(@event => new { Event = @event, Sender = entry.Sender })).ToList();

            // serialize the events into raw events
            var rawEvents = UnpersistedRawEvent.FromUnpersistedEvents(entries.Select(e => e.Event), _serializer);

            // writes to the store
            await _writer.WriteAsync(rawEvents);

            // sends the events to the dispatcher
            for (int i = 0, len = entries.Count; i < len; i++)
            {
                var sender = entries[i].Sender;
                var e      = entries[i].Event;
                var re     = rawEvents[i];

                var persistedEvent = PersistedEventFactory.FromUnpersistedEvent(re.GlobalSequence, e);

                _dispatcher.Tell(persistedEvent);
            }
        }