public async Task <ProjectionReadModel> RetrieveProjectionInfo()
        {
            var collection = _db.GetCollection <ProjectionReadModel>("readmodel");

            ProjectionReadModel info = null;

            var filter = new BsonDocument();

            using (var cursor = await collection.FindAsync(filter))
            {
                info = await cursor.FirstOrDefaultAsync();
            }

            if (info == null)
            {
                info = new ProjectionReadModel()
                {
                    Id      = Guid.NewGuid(),
                    Version = -1
                };
            }

            _logger.DebugWithContext("Retrieved projection info from DB", info);

            return(info);
        }
        public async Task UpdateProjectionInfo(ProjectionReadModel model)
        {
            _logger.DebugWithContext("Updating projection info", model);

            var collection = _db.GetCollection <ProjectionReadModel>("readmodel");

            var filter  = new BsonDocument();
            var options = new UpdateOptions {
                IsUpsert = true
            };

            await collection.ReplaceOneAsync(filter, model, options);
        }
Exemplo n.º 3
0
        protected async override Task <long> GetStartEventPosition()
        {
            _info = await _infoRepo.RetrieveProjectionInfo();

            return(_info.Version + 1);
        }