//
        // Event data
        //

        internal static EventData GetAreaEventData(
            this EventStoreContext context,
            Event e,
            TimelinePosition cause,
            DateTimeOffset when,
            DateTimeOffset?whenOccurs,
            Id eventId,
            Id commandId,
            Id userId,
            FlowKey topic,
            Many <FlowKey> routes)
        {
            var type = context.GetEventType(e);

            var metadata = new AreaEventMetadata
            {
                Cause      = cause,
                When       = when,
                WhenOccurs = whenOccurs,
                CommandId  = commandId,
                UserId     = userId,
                Topic      = topic
            };

            metadata.ApplyRoutes(type, routes);

            return(new EventData(
                       eventId.IsUnassigned ? Guid.NewGuid() : Guid.Parse(eventId.ToString()),
                       type.ToString(),
                       isJson: true,
                       data: context.ToJson(e),
                       metadata: context.ToJson(metadata)));
        }
        internal static IEnumerable <EventData> GetNewEventData(
            this EventStoreContext context,
            TimelinePosition cause,
            FlowKey topic,
            Many <Event> newEvents) =>

        from e in newEvents
        select context.GetAreaEventData(
            e,
            cause,
            e.When,
            Event.Traits.WhenOccurs.Get(e),
            Event.Traits.EventId.Get(e),
            Event.Traits.CommandId.Get(e),
            Event.Traits.UserId.Get(e),
            topic,
            context.GetEventType(e).GetRoutes(e).ToMany());