VersionedEventSource GetVersionFromCommits(EventSourceKey eventSource)
        {
            var builder   = Builders <BsonDocument> .Sort;
            var sort      = builder.Ascending(Constants.VERSION);
            var commitDoc = _config.Commits.Find(eventSource.ToFilter()).Sort(sort).Limit(1).ToList().SingleOrDefault();

            if (commitDoc == null)
            {
                return(new VersionedEventSource(EventSourceVersion.NoVersion, eventSource));
            }

            return(commitDoc.ToCommittedEventStream().Source);
        }
        /// <inheritdoc />
        public EventSourceVersion GetCurrentVersionFor(EventSourceKey eventSource)
        {
            var builder = Builders <BsonDocument> .Sort;
            var filter  = eventSource.ToFilter();
            var sort    = builder.Descending(VersionConstants.COMMIT);
            var version = _config.Commits.Find <BsonDocument>(filter).Sort(sort).Limit(1).FirstOrDefault();

            if (version == null)
            {
                return(EventSourceVersion.NoVersion);
            }

            return(version.ToEventSourceVersion());
        }
 /// <inheritdoc />
 public Commits FetchFrom(EventSourceKey eventSourceKey, CommitVersion commitVersion)
 {
     return(FindCommitsWithSorting(eventSourceKey.ToFilter() & commitVersion.ToFilter()));
 }
 /// <inheritdoc />
 public Commits Fetch(EventSourceKey eventSourceKey)
 {
     return(FindCommitsWithSorting(eventSourceKey.ToFilter()));
 }