Ejemplo n.º 1
0
 private static long CalculateActualStreamLength(Option<Commit> lastCommitInStream)
 {
     return lastCommitInStream
         .Map(commit => commit.EventIndexInStreamStartsFrom + commit.EventIds.Count())
         .ValueOr(0);
 }
Ejemplo n.º 2
0
        private static Commit CreateCommit(
            Guid streamId,
            Option<Commit> lastCommitInStream,
            Option<Commit> lastCommitAllStreams,
            IEnumerable<EventContainer> identifiedEvents)
        {
            var indexInStream = lastCommitInStream
                .Map(commit => commit.IndexInStream + 1)
                .ValueOr(0);

            var indexInAllStreams = lastCommitAllStreams
                .Map(commit => commit.IndexInAllStreams + 1)
                .ValueOr(0);

            var eventsIds = identifiedEvents.Select(identifiedEvent => identifiedEvent.Id);

            var eventIndexInStream = lastCommitInStream
                .Map(commit => commit.EventIndexInStreamStartsFrom + commit.EventIds.Count())
                .ValueOr(0);

            var eventIndexInAllStreams = lastCommitAllStreams
                .Map(commit => commit.EventIndexInAllStreamsStartsFrom + commit.EventIds.Count())
                .ValueOr(0);

            return new Commit(
                streamId: streamId,
                indexInStream: indexInStream,
                indexInAllStreams: indexInAllStreams,
                eventIndexInStreamStartsFrom: eventIndexInStream,
                eventIndexInAllStreamsStartsFrom: eventIndexInAllStreams,
                eventIds: eventsIds);
        }