Beispiel #1
0
        public ICommittedEvent Deserialize(Guid aggregateId, EventDocument doc)
        {
            var eventType = Type.GetType(doc.Metadata[MetadataKeys.EventClrType].AsString);
            var data      = JsonSerializer.Deserialize(doc.EventData.ToJson(), eventType, JsonSettings);
            var metadata  = JsonSerializer.Deserialize <Dictionary <string, object> >(doc.Metadata.ToJson());
            var version   = doc.Metadata[MetadataKeys.EventVersion].AsInt32;

            return(new CommittedEvent(aggregateId, version, data as IDomainEvent, new MetadataCollection(metadata)));
        }
Beispiel #2
0
        public EventDocument Serialize(IUncommittedEvent eventToSerialize)
        {
            var id        = eventToSerialize.Metadata.GetValue(MetadataKeys.EventId, value => Guid.Parse(value.ToString()));
            var eventType = eventToSerialize.Metadata.GetValue(MetadataKeys.EventName, value => value.ToString());
            var timestamp = eventToSerialize.Metadata.GetValue(MetadataKeys.Timestamp, value => (DateTime)value);

            var dataJson     = JsonSerializer.Serialize(eventToSerialize.Data, eventToSerialize.Data.GetType(), JsonSettings);
            var metadataJson = JsonSerializer.Serialize(eventToSerialize.Metadata, JsonSettings);

            var @event = new EventDocument
            {
                Id        = id,
                Timestamp = timestamp,
                EventType = eventType,
                Version   = eventToSerialize.Version,
                EventData = BsonDocument.Parse(dataJson),
                Metadata  = BsonDocument.Parse(metadataJson)
            };

            return(@event);
        }