Example #1
0
        public void WriteEvents(IStreamIdentifier streamIdentifier, long expectedVersion, ICollection <IDomainEvent> events)
        {
            var commitHeaders = new Dictionary <string, object>
            {
                { Settings.CommitIdHeader, Guid.NewGuid() },
                { Settings.AggregateClrTypeHeader, streamIdentifier.AggregateClrTypeName() },
                { Settings.AggregateIdHeader, streamIdentifier.AggregateIdentifier() }
            };

            var newEvents = events.Cast <object>().ToList();

            var preparedEvents = PrepareEvents(newEvents, commitHeaders).ToList();

            connection.AppendToStreamAsync(streamIdentifier.StreamIdentifier(), expectedVersion, preparedEvents).Wait();
        }
Example #2
0
        private ICollection <IDomainEvent> ReadEventsInternal(IStreamIdentifier stream)
        {
            List <IDomainEvent> eventsForAggregate = new List <IDomainEvent>();

            StreamEventsSlice currentSlice;
            var nextSliceStart = 0L;

            do
            {
                currentSlice = connection
                               .ReadStreamEventsForwardAsync(stream.StreamIdentifier(), nextSliceStart, Settings.ReadPageSize, false)
                               .Result;
                nextSliceStart = currentSlice.NextEventNumber;

                foreach (var evnt in currentSlice.Events)
                {
                    IDomainEvent aggrEvent = (IDomainEvent)Serializer.DeserializeEvent(evnt.OriginalEvent.Metadata, evnt.OriginalEvent.Data);
                    eventsForAggregate.Add(aggrEvent);
                }
            } while (!currentSlice.IsEndOfStream);

            return(eventsForAggregate);
        }