public static BsonDocument ToEmptyCommit(this CommitAttempt commit, Int64 checkpoint, String systemBucketName)
        {
            if (commit == null)
            {
                throw new ArgumentNullException(nameof(commit));
            }
            if (String.IsNullOrWhiteSpace(systemBucketName))
            {
                throw new ArgumentNullException(nameof(systemBucketName));
            }
            int streamRevisionStart = commit.StreamRevision - (commit.Events.Count - 1);

            var mc = new MongoCommit
            {
                CheckpointNumber   = checkpoint,
                CommitId           = commit.CommitId,
                CommitStamp        = commit.CommitStamp,
                Headers            = new Dictionary <String, Object>(),
                Events             = new BsonArray(Array.Empty <object>()),
                StreamRevisionFrom = 0,
                StreamRevisionTo   = 0,
                BucketId           = systemBucketName,
                StreamId           = systemBucketName + ".empty." + checkpoint,
                CommitSequence     = 1
            };

            return(mc.ToBsonDocument());
        }
        public static BsonDocument ToMongoCommit(this CommitAttempt commit, Int64 checkpoint, IDocumentSerializer serializer)
        {
            int streamRevision      = commit.StreamRevision - (commit.Events.Count - 1);
            int streamRevisionStart = streamRevision;

            IEnumerable <BsonDocument> events = commit
                                                .Events
                                                .Select(e =>
                                                        new BsonDocument
            {
                { MongoCommitFields.StreamRevision, streamRevision++ },
                { MongoCommitFields.Payload, BsonDocumentWrapper.Create(typeof(EventMessage), serializer.Serialize(e)) }
            });

            var mc = new MongoCommit
            {
                CheckpointNumber   = checkpoint,
                CommitId           = commit.CommitId,
                CommitStamp        = commit.CommitStamp,
                Headers            = commit.Headers,
                Events             = new BsonArray(events),
                StreamRevisionFrom = streamRevisionStart,
                StreamRevisionTo   = streamRevision - 1,
                BucketId           = commit.BucketId,
                StreamId           = commit.StreamId,
                CommitSequence     = commit.CommitSequence
            };

            return(mc.ToBsonDocument());
        }