Example #1
0
        private static MongoEventCommit BuildCommit(Guid commitId, string streamName, long expectedVersion, ICollection <EventData> events)
        {
            var commitEvents = new MongoEvent[events.Count];

            var i = 0;

            foreach (var e in events)
            {
                var mongoEvent = MongoEvent.FromEventData(e);

                commitEvents[i++] = mongoEvent;
            }

            var mongoCommit = new MongoEventCommit
            {
                Id                = commitId,
                Events            = commitEvents,
                EventsCount       = events.Count,
                EventStream       = streamName,
                EventStreamOffset = expectedVersion,
                Timestamp         = EmptyTimestamp
            };

            return(mongoCommit);
        }
Example #2
0
        public static IEnumerable <StoredEvent> Filtered(this MongoEventCommit commit, long streamPosition)
        {
            var eventStreamOffset = commit.EventStreamOffset;

            var commitTimestamp = commit.Timestamp;
            var commitOffset    = 0;

            foreach (var @event in commit.Events)
            {
                eventStreamOffset++;

                if (eventStreamOffset >= streamPosition)
                {
                    var eventData     = @event.ToEventData();
                    var eventPosition = new StreamPosition(commitTimestamp, commitOffset, commit.Events.Length);

                    yield return(new StoredEvent(commit.EventStream, eventPosition, eventStreamOffset, eventData));
                }

                commitOffset++;
            }
        }