示例#1
0
        public BookOrder Get(Guid orderId)
        {
            BookOrderFactory factory = new BookOrderFactory();

            BookOrderResult result = new BookOrderResult();

            using (var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113)))
            {
                connection.ConnectAsync().Wait();

                StreamEventsSlice currentSlice;
                long nextSliceStart = StreamPosition.Start;
                List <RecordedEvent> recordedEvents = new List <RecordedEvent>();
                do
                {
                    currentSlice = connection.ReadStreamEventsForwardAsync(
                        GetStreamName(orderId), nextSliceStart,
                        200, false).Result;

                    nextSliceStart = currentSlice.NextEventNumber;

                    recordedEvents.AddRange(currentSlice.Events.Select(e => e.Event));
                } while (!currentSlice.IsEndOfStream);

                result.BookOrder = factory.Create(recordedEvents);
            }

            return(result.BookOrder);
        }
示例#2
0
        public BookOrder Create(IEnumerable <RecordedEvent> recordedEvents)
        {
            BookOrderResult result = new BookOrderResult();

            foreach (var recordedEvent in recordedEvents)
            {
                foreach (var handler in _bookOrderEventHandlers)
                {
                    if (handler.CanHandle(recordedEvent))
                    {
                        handler.Handle(recordedEvent, result);
                        break;
                    }
                }
            }

            return(result.BookOrder);
        }