/// <summary> /// Get all <see cref="IEvent{TAuthenticationToken}"/> instances for the given <paramref name="correlationId"/>. /// </summary> /// <param name="correlationId">The <see cref="IMessage.CorrelationId"/> of the <see cref="IEvent{TAuthenticationToken}"/> instances to retrieve.</param> public override IEnumerable <EventData> Get(Guid correlationId) { if (!EventStoreByCorrelationId.Contains(correlationId.ToString("N"))) { Logger.LogDebug(string.Format("The event store has no items by the correlationId '{0:N}'.", correlationId)); return(Enumerable.Empty <EventData>()); } CacheItem item = EventStoreByCorrelationId.GetCacheItem(correlationId.ToString("N")); if (item == null) { Logger.LogDebug(string.Format("The event store had some items by the correlationId '{0:N}' but doesn't now.", correlationId)); return(Enumerable.Empty <EventData>()); } var events = item.Value as IEnumerable <EventData>; if (events == null) { if (item.Value == null) { Logger.LogDebug(string.Format("The event store had some items by the correlationId '{0:N}' but it was null.", correlationId)); } else { Logger.LogWarning(string.Format("The event store had some items by the correlationId '{0:N}' but it was of type {1}.", correlationId, item.Value.GetType())); } return(Enumerable.Empty <EventData>()); } IEnumerable <EventData> query = events.OrderBy(eventData => eventData.Timestamp); return(query.ToList()); }
/// <summary> /// Persist the provided <paramref name="eventData"/> into storage. /// </summary> /// <param name="eventData">The <see cref="EventData"/> to persist.</param> protected override void PersistEvent(EventData eventData) { IList <EventData> events = new List <EventData>(); // By correlationId first Guid correlationId = eventData.CorrelationId; object item = EventStoreByCorrelationId.AddOrGetExisting(correlationId.ToString("N"), events, GetDetaultCacheItemPolicy()); if (item != null) { events = item as IList <EventData>; if (events == null) { Logger.LogWarning(string.Format("The event store had some items by the correlationId '{0:N}' but it doesn't now.", correlationId)); throw new Exception(string.Format("The event store had some items by the correlationId '{0:N}' but it doesn't now.", correlationId)); } } events.Add(eventData); // Reset the variable for it's next usage events = new List <EventData>(); // By type next string streamName = eventData.AggregateId; item = EventStoreByType.AddOrGetExisting(streamName, events, GetDetaultCacheItemPolicy()); if (item != null) { events = item as IList <EventData>; if (events == null) { Logger.LogWarning(string.Format("The event store had an item by id '{0}' but it doesn't now.", streamName)); throw new Exception(string.Format("The event store had an item by id '{0}' but it doesn't now.", streamName)); } } events.Add(eventData); }