예제 #1
0
        public void Store(BookOrder bookOrder)
        {
            using (var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113)))
            {
                connection.ConnectAsync().Wait();

                var latestEvent = connection.ReadStreamEventsBackwardAsync(GetStreamName(bookOrder.Id),
                                                                           0, 1, false).Result;

                using (var transaction = connection.StartTransactionAsync(GetStreamName(bookOrder.Id),
                                                                          latestEvent.LastEventNumber).Result)
                {
                    var events = bookOrder.DequeueAllEvents();

                    foreach (var ev in events)
                    {
                        string eventType = ev.GetEventType();
                        var    eventData = GetEventDataFor(ev, eventType);

                        transaction.WriteAsync(eventData).Wait();
                    }

                    transaction.CommitAsync().Wait();
                }
            }
        }
예제 #2
0
        public void Store(BookOrder bookOrder)
        {
            using (var connection = CreateConnection())
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    var events = bookOrder.DequeueAllEvents();

                    foreach (var ev in events)
                    {
                        HandleEvent(ev, connection);
                    }

                    transaction.Commit();
                }
            }
        }