/// <summary> /// Convert a <see cref="Runtime.Grpc.Interaction.CommittedEventStream"/> to <see cref="CommittedEventStream"/> /// </summary> /// <param name="protobuf"><see cref="Runtime.Grpc.Interaction.CommittedEventStream"/> to convert from</param> /// <returns>Converted <see cref="CommittedEventStream"/></returns> public static CommittedEventStream ToCommittedEventStream(this Runtime.Grpc.Interaction.CommittedEventStream protobuf) { var eventSourceId = protobuf.Source.EventSource.ToConcept <EventSourceId>(); var artifactId = protobuf.Source.Artifact.ToConcept <ArtifactId>(); var versionedEventSource = new VersionedEventSource(eventSourceId, artifactId); var commitId = protobuf.Id.ToConcept <CommitId>(); var correlationId = protobuf.CorrelationId.ToConcept <CorrelationId>(); var timeStamp = protobuf.TimeStamp.ToDateTimeOffset(); var events = protobuf.Events.Select(_ => new EventEnvelope( _.Metadata.ToEventMetadata(), _.Event.ToPropertyBag() ) ).ToArray(); return(new CommittedEventStream( protobuf.Sequence, versionedEventSource, commitId, correlationId, timeStamp, new EventStream(events) )); }
/// <summary> /// Convert from <see cref="CommittedEventStream"/> to <see cref="Runtime.Grpc.Interaction.CommittedEventStream"/> /// </summary> /// <param name="committedEventStream"><see cref="CommittedEventStream"/> to convert from</param> /// <returns>The converted <see cref="Runtime.Grpc.Interaction.CommittedEventStream"/></returns> public static Runtime.Grpc.Interaction.CommittedEventStream ToProtobuf(this CommittedEventStream committedEventStream) { var protobuf = new Runtime.Grpc.Interaction.CommittedEventStream { Sequence = committedEventStream.Sequence, Source = committedEventStream.Source.ToProtobuf(), Id = committedEventStream.Id.ToProtobuf(), CorrelationId = committedEventStream.CorrelationId.ToProtobuf(), TimeStamp = committedEventStream.Timestamp.ToUnixTimeMilliseconds() }; committedEventStream.Events.Select(@event => { var envelope = new Runtime.Grpc.Interaction.EventEnvelope { Metadata = @event.Metadata.ToProtobuf() }; envelope.Event = @event.Event.ToProtobuf(); return(envelope); }).ForEach(protobuf.Events.Add); return(protobuf); }