Пример #1
0
        public static List <UnpersistedRawEvent> FromUnpersistedEvents(IEnumerable <UnpersistedEvent> events, ISerializer serializer)
        {
            Argument.Requires(events != null);
            Argument.Requires(serializer != null);

            return(events.Select(e =>
            {
                var format = EvenStorageFormatAttribute.GetStorageFormat(e.DomainEvent.GetType());
                var metadata = serializer.SerializeMetadata(e.Metadata);
                var payload = serializer.SerializeEvent(e.DomainEvent, format);

                var re = new UnpersistedRawEvent(e.EventID, e.Stream, e.EventType, e.UtcTimestamp, metadata, payload, format);

                return re;
            }).ToList());
        }
Пример #2
0
        public static List<UnpersistedRawEvent> FromUnpersistedEvents(IEnumerable<UnpersistedEvent> events, ISerializer serializer)
        {
            Argument.Requires(events != null);
            Argument.Requires(serializer != null);

            return events.Select(e =>
            {
                var format = EvenStorageFormatAttribute.GetStorageFormat(e.DomainEvent.GetType());
                var metadata = serializer.SerializeMetadata(e.Metadata);
                var payload = serializer.SerializeEvent(e.DomainEvent, format);

                var re = new UnpersistedRawEvent(e.EventID, e.Stream, e.EventType, e.UtcTimestamp, metadata, payload, format);

                return re;
            }).ToList();
        }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }