/// <summary> /// Convert a <see cref="grpc.CommittedEventStream"/> to <see cref="CommittedEventStream"/>. /// </summary> /// <param name="protobuf"><see cref="grpc.CommittedEventStream"/> to convert from.</param> /// <returns>Converted <see cref="CommittedEventStream"/>.</returns> public static CommittedEventStream ToCommittedEventStream(this grpc.CommittedEventStream protobuf) { var eventSourceId = protobuf.Source.EventSource.To <EventSourceId>(); var artifactId = protobuf.Source.Artifact.To <ArtifactId>(); var versionedEventSource = new VersionedEventSource(eventSourceId, artifactId); var commitId = protobuf.Id.To <CommitId>(); var correlationId = protobuf.CorrelationId.To <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="grpc.CommittedEventStream"/>. /// </summary> /// <param name="committedEventStream"><see cref="CommittedEventStream"/> to convert from.</param> /// <returns>The converted <see cref="grpc.CommittedEventStream"/>.</returns> public static grpc.CommittedEventStream ToProtobuf(this CommittedEventStream committedEventStream) { var protobuf = new grpc.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 grpc.EventEnvelope { Metadata = @event.Metadata.ToProtobuf() }; envelope.Event = @event.Event.ToProtobuf(); return(envelope); }).ForEach(protobuf.Events.Add); return(protobuf); }