예제 #1
0
        public async Task SaveLastPositionAsync(EventStorePosition position)
        {
            try
            {
                var filter          = Builders <NoSqlPosition> .Filter.Empty;
                var documentResults = await this._documentUnitOfWork.NoSqlPositionRepository.FindAsync(filter);

                if (!documentResults.Any())
                {
                    var noSqlDocument = NoSqlPosition.CreateNoSqlPosition(position);
                    await this._documentUnitOfWork.NoSqlPositionRepository.InsertOneAsync(noSqlDocument);
                }
                else
                {
                    if (position.CommitPosition > documentResults.First().LastPosition.CommitPosition)
                    {
                        var update = documentResults.First().UpdateLastPostion(position);
                        filter = Builders <NoSqlPosition> .Filter.Eq("_id", documentResults.First().Id);

                        await this._documentUnitOfWork.NoSqlPositionRepository.UpdateOneAsync(filter, update);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #2
0
 private NoSqlEvents(Guid eventGuid, Guid aggregateId, string eventType,
                     string aggregateType, EventStorePosition position, AccountInfo who, When when)
 {
     this.Id            = eventGuid.ToString();
     this.AggregateId   = aggregateId.ToString("N");
     this.AggregateType = aggregateType;
     this.EventType     = eventType;
     this.Who           = who.ToJson();
     this.When          = when.GetValue();
     this.Position      = position;
 }
예제 #3
0
        private async Task <EventStorePosition> CreateDefaultPosition()
        {
            var defaultPosition = new EventStorePosition()
            {
                Id              = CombGuid.Generate(),
                CommitPosition  = Position.Start.CommitPosition,
                PreparePosition = Position.Start.PreparePosition,
                CreatedOn       = DateTime.UtcNow,
            };
            await _mongoConfiguration.GetPositionCollection.InsertOneAsync(defaultPosition);

            var createdPosition = await _mongoConfiguration.GetPositionCollection
                                  .Find(x => true)
                                  .FirstOrDefaultAsync();

            return(createdPosition);
        }
        private async Task <EventStorePosition> CreateDefaultPosition()
        {
            var defaultPosition = new EventStorePosition()
            {
                Id              = CombGuid.Generate(),
                CommitPosition  = Position.Start.CommitPosition,
                PreparePosition = Position.Start.PreparePosition,
                CreatedOn       = DateTime.UtcNow,
            };

            await _dbContext.EventStorePositions.AddAsync(defaultPosition);

            await _dbContext.SaveChangesAsync();

            var createdPosition = await _dbContext.EventStorePositions.FirstOrDefaultAsync();

            return(createdPosition);
        }
예제 #5
0
        public async Task CreateEventsAsync(Guid eventGuid, Guid aggregateId, string eventType, string aggregateType,
                                            EventStorePosition position, AccountInfo who, When when)
        {
            try
            {
                var filter = Builders <NoSqlEvents> .Filter.Eq("_id", eventGuid.ToString());

                var documentsResult = await this._documentUnitOfWork.NoSqlEventsRepository.FindAsync(filter);

                if (documentsResult.Any())
                {
                    return;
                }

                var noSqlDocument = NoSqlEvents.CreateNoSqlEvents(eventGuid, aggregateId, eventType, aggregateType,
                                                                  position, who, when);
                await this._documentUnitOfWork.NoSqlEventsRepository.InsertOneAsync(noSqlDocument);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private async Task PersistPositionAsync(EventStoreContext container)
        {
            try
            {
                var positionWriteService = container.Container.ResolveOptional <IPositionWriteService>();
                if (positionWriteService == null)
                {
                    return;
                }

                var position = new EventStorePosition()
                {
                    Id              = container.ResolvedEvent.Event.EventId,
                    CommitPosition  = container.ResolvedEvent.OriginalPosition.Value.CommitPosition,
                    PreparePosition = container.ResolvedEvent.OriginalPosition.Value.PreparePosition,
                    CreatedOn       = DateTime.UtcNow,
                };
                await positionWriteService.InsertOneAsync(position);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public async Task InsertOneAsync(EventStorePosition entity)
        {
            await _dbContext.EventStorePositions.AddAsync(entity);

            await _dbContext.SaveChangesAsync();
        }
예제 #8
0
 public static NoSqlEvents CreateNoSqlEvents(Guid eventGuid, Guid aggregateId, string eventType,
                                             string aggregateType, EventStorePosition position, AccountInfo who, When when)
 {
     return(new NoSqlEvents(eventGuid, aggregateId, eventType, aggregateType, position, who, when));
 }
예제 #9
0
 public UpdateDefinition <NoSqlPosition> UpdateLastPostion(EventStorePosition eventStorePosition)
 {
     return(Builders <NoSqlPosition> .Update.Set(p => p.LastPosition, eventStorePosition));
 }
예제 #10
0
 private NoSqlPosition(EventStorePosition eventStorePosition)
 {
     this.LastPosition = eventStorePosition;
     this.Id           = Guid.NewGuid().ToString();
 }
예제 #11
0
 public static NoSqlPosition CreateNoSqlPosition(EventStorePosition eventStorePosition)
 {
     return(new NoSqlPosition(eventStorePosition));
 }
예제 #12
0
 public async Task InsertOneAsync(EventStorePosition entity)
 {
     await _mongoConfiguration.GetPositionCollection.InsertOneAsync(entity);
 }