/// <summary>
        /// Converts the <see cref="CommittedAggregateEvents" /> to <see cref="Contracts.CommittedAggregateEvents" />s.
        /// </summary>
        /// <param name="committedAggregateEvents">The committed events.</param>
        /// <returns>The converted <see cref="Contracts.CommittedAggregateEvents" />.</returns>
        public static Contracts.CommittedAggregateEvents ToProtobuf(this CommittedAggregateEvents committedAggregateEvents)
        {
            var protobuf = new Contracts.CommittedAggregateEvents
            {
                AggregateRootId      = committedAggregateEvents.AggregateRoot.Value.ToProtobuf(),
                EventSourceId        = committedAggregateEvents.EventSource.ToProtobuf(),
                AggregateRootVersion = committedAggregateEvents.AsEnumerable().LastOrDefault()?.AggregateRootVersion
            };

            protobuf.Events.AddRange(committedAggregateEvents.Select(_ => _.ToProtobuf()));
            return(protobuf);
        }
Exemple #2
0
    protected static Contracts.CommittedAggregateEvents with_committed_events(params Contracts.CommittedAggregateEvents.Types.CommittedAggregateEvent[] events)
    {
        var aggregate_version_after_commit = number_of_events_in_aggregate_when_commit_happened + (ulong)events.Length;
        var result = new Contracts.CommittedAggregateEvents
        {
            AggregateRootId = aggregate_root_id.ToProtobuf(),
            EventSourceId   = event_source_id,
            // The aggregate root version of the committed aggregate events is the version of the last event, meaning the aggregate root version before commit happened + number of events - 1
            AggregateRootVersion = aggregate_version_after_commit - 1
        };

        result.Events.AddRange(events);
        return(result);
    }
    /// <summary>
    /// Converts the <see cref="Contracts.CommittedAggregateEvents"/> to <see cref="CommittedAggregateEvents"/>.
    /// </summary>
    /// <param name="committedAggregateEvents">The committed events.</param>
    /// <returns>The converted <see cref="CommittedAggregateEvents"/>.</returns>
    public static CommittedAggregateEvents ToCommittedEvents(this Contracts.CommittedAggregateEvents committedAggregateEvents)
    {
        var version = committedAggregateEvents.AggregateRootVersion + 1 - (ulong)committedAggregateEvents.Events.Count;

        return(new CommittedAggregateEvents(
                   committedAggregateEvents.EventSourceId,
                   committedAggregateEvents.AggregateRootId.ToGuid(),
                   committedAggregateEvents.Events.Select(_ => new CommittedAggregateEvent(
                                                              new Artifact(committedAggregateEvents.AggregateRootId.ToGuid(), ArtifactGeneration.First),
                                                              version++,
                                                              _.EventLogSequenceNumber,
                                                              _.Occurred.ToDateTimeOffset(),
                                                              committedAggregateEvents.EventSourceId,
                                                              _.ExecutionContext.ToExecutionContext(),
                                                              _.EventType.ToArtifact(),
                                                              _.Public,
                                                              _.Content)).ToList()));
    }