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; } }
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; }
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); }
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(); }
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)); }
public UpdateDefinition <NoSqlPosition> UpdateLastPostion(EventStorePosition eventStorePosition) { return(Builders <NoSqlPosition> .Update.Set(p => p.LastPosition, eventStorePosition)); }
private NoSqlPosition(EventStorePosition eventStorePosition) { this.LastPosition = eventStorePosition; this.Id = Guid.NewGuid().ToString(); }
public static NoSqlPosition CreateNoSqlPosition(EventStorePosition eventStorePosition) { return(new NoSqlPosition(eventStorePosition)); }
public async Task InsertOneAsync(EventStorePosition entity) { await _mongoConfiguration.GetPositionCollection.InsertOneAsync(entity); }