public List <IEvent> GetAllEvents(CompositeAggregateId aggregateId)
        {
            var  eventList  = new List <IEvent>();
            long sliceStart = 0;
            StreamEventsSlice currentEventSlice;

            do
            {
                currentEventSlice = _eventStoreConnection.ReadStreamEventsForwardAsync(aggregateId.CompositeId, sliceStart, 500, false).Result;

                if (currentEventSlice.Status == SliceReadStatus.StreamNotFound)
                {
                    throw new StreamNotFoundException(aggregateId.CompositeId);
                }

                if (currentEventSlice.Status == SliceReadStatus.StreamDeleted)
                {
                    throw new StreamDeletedException(aggregateId.CompositeId);
                }

                sliceStart = currentEventSlice.NextEventNumber;

                eventList.AddRange(currentEventSlice.Events.Select(data => data.Event.DeserializeEvent()).Where(@event => @event != null));
            } while (!currentEventSlice.IsEndOfStream);

            return(eventList);
        }
 public void SaveEvents(CompositeAggregateId aggregateId, IEnumerable <IEvent> events)
 {
     foreach (var @event in events)
     {
         AppendEventToEventStream(@event, aggregateId);
     }
 }
Exemple #3
0
 private bool SendEvent(CompositeAggregateId compositeId, IEnumerable <Event> events)
 {
     try
     {
         EventStore.SaveEvents(compositeId, events);
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Error($"Exception: {ex.Message} in {Assembly.GetExecutingAssembly().GetName().Name}");
         throw;
     }
 }
        private void AppendEventToEventStream(IEvent @event, CompositeAggregateId aggregateId)

        {
            var eventData = GetEventData(@event);

            try
            {
                TimeSpan timeout = KeepReconnecting ? TimeSpan.FromSeconds(30) : TimeSpan.FromMilliseconds(-1);

                _eventStoreConnection.AppendToStreamAsync(aggregateId.CompositeId, @event.ExpectedVersion, eventData).Wait(timeout);
            }
            catch (AggregateException ex)
            {
                throw;
            }
        }
Exemple #5
0
        public static bool SendEvent(IEventStore eventStore, CompositeAggregateId compositeId, IEnumerable <Event> events)
        {
            EventStore = eventStore;

            try
            {
                EventStore.SaveEvents(compositeId, events);
                return(true);
            }
            catch (ConnectionFailure conn)
            {
                Logger.Error($"Exception: {conn.Message} in {Assembly.GetExecutingAssembly().GetName()}");
                throw;
            }
            catch (AggregateException aggrEx)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error($"Exception: {ex.Message} in {Assembly.GetExecutingAssembly().GetName()}");
                throw;
            }
        }
 public List <IEvent> GetAllEventsToEventIdInclusive(CompositeAggregateId aggregateId, string eventId)
 {
     throw new NotImplementedException();
 }