public static IEnumerable <Envelope <MessageContext, object> > Deserialize(RecordedEvent recordedEvent, ILookup <string, Type> typeLookup, JsonSerializerSettings settings = null) { var additionalMetadata = EventSerializer.DeserializeMetadata(recordedEvent, settings); var message = EventSerializer.Deserialize(recordedEvent, typeLookup, settings); var streamContext = new StreamContext(recordedEvent.EventNumber, recordedEvent.EventStreamId); var messageContext = new MessageContext(recordedEvent.EventId, streamContext, additionalMetadata); yield return(Envelope.Create(messageContext, message)); }
public static async Task <WriteResult> Write(Envelope <MessageContext, WriteToStream> envelope, IEventStoreConnection connection, JsonSerializerSettings settings) { var eventData = EventSerializer.Serialize(envelope.Body.Id, envelope.Body.Data, envelope.Body.Metadata, settings); envelope.Body.Metadata["$correlationId"] = envelope.Header.MetadataLookup["$correlationId"].FirstOrDefault(); envelope.Body.Metadata["$causationId"] = envelope.Header.EventId; envelope.Body.Metadata["tenantId"] = envelope.Header.MetadataLookup["tenantId"].FirstOrDefault(); return(await connection.AppendToStreamAsync(envelope.Body.StreamId, ExpectedVersion.Any, eventData)); }