private async Task SaveEventAndOrderingContextChangesAsync(IntegrationEvent evt) { await ResilientTransaction.New(_productContext) .ExecuteAsync(async() => { await _productContext.SaveChangesAsync(); await _integrationEventLogService.SaveEventAsync(evt, _productContext.Database.CurrentTransaction.GetDbTransaction()); }); }
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt) { await ResilientTransaction.New(_catalogContext).ExecuteAsync(async() => { await _catalogContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction); }); }
public async Task AddAndSaveEventAsync(IntegrationEvent integrationEvent) { _logger.LogInformation( "----- Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", integrationEvent.Id, integrationEvent); await _eventLogService.SaveEventAsync(integrationEvent, _deliveryContext.GetCurrentTransaction()); }
public Task PublishThroughEventBusAsync(IEvent evt) { Task[] tasks = new Task[3]; tasks[0] = _eventLogService.SaveEventAsync(evt, _context.Database.CurrentTransaction.GetDbTransaction()); tasks[1] = _eventBus.Publish(evt); tasks[2] = _eventLogService.MarkEventAsPublishedAsync(evt); return(Task.WhenAll(tasks)); }
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent @event) { await ResilientTransaction.New(_catalogContext).ExecuteAsync(async() => { _logger.Information($"SaveEventAndCatalogContextChangesAsync {@event}"); await _catalogContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(@event, _catalogContext.Database.CurrentTransaction); }); }
public async Task SaveEventAndInventoryContextChangesAsync(IntegrationEvent evt) { await ResilientTransaction.New(_inventoryContext) .ExecuteAsync(async() => { await _inventoryContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, DbContextTransactionExtensions.GetDbTransaction(_inventoryContext.Database.CurrentTransaction)); }); }
public async Task AddAndSaveEventAsync(IntegrationEvent evt) { logger.LogInformation("----- Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id, evt); await eventLogService.SaveEventAsync( evt, dbContext.CurrentTransactionId ); }
public async Task <ActionResult> UpdateProductAsync([FromBody] CatalogItem productToUpdate) { var catalogItem = await _catalogContext.CatalogItems.SingleOrDefaultAsync(i => i.Id == productToUpdate.Id); if (catalogItem == null) { return(NotFound(new { Message = $"Item with id {productToUpdate.Id} not found." })); } var oldPrice = catalogItem.Price; var raiseProductPriceChangedEvent = oldPrice != productToUpdate.Price; // Update current product catalogItem = productToUpdate; _catalogContext.CatalogItems.Update(catalogItem); if (raiseProductPriceChangedEvent) // Save product's data and publish integration event through the Event Bus if price has changed { _logger.LogInformation(" [x] CatalogController.UpdateProduct(): Price has changed, integration event is being prepared..."); var productPriceChangeEvent = new ProductPriceChangedIntegrationEvent(productToUpdate.Id, oldPrice, productToUpdate.Price); var strategy = _catalogContext.Database.CreateExecutionStrategy(); _logger.LogInformation(" [x] CatalogController.UpdateProductAsync(): Beginning new transaction to save event and commit changes."); await strategy.Execute(async() => { using (var transaction = _catalogContext.Database.BeginTransaction()) { await _eventLogService.SaveEventAsync(productPriceChangeEvent, transaction); await _catalogContext.SaveChangesAsync(); transaction.Commit(); _logger.LogInformation(" [x] CatalogController.UpdateProductAsync(): Transaction ({0}) has been committed.", transaction.TransactionId); } }); try { await _eventLogService.MarkEventAsInProgressAsync(productPriceChangeEvent.Id); _eventBus.Publish(productPriceChangeEvent); await _eventLogService.MarkEventAsPublishedAsync(productPriceChangeEvent.Id); } catch (Exception e) { _logger.LogError(e, " [x] CatalogController.UpdateProductAsync(): Fail when publishing integration event {0}.", productPriceChangeEvent.Id); await _eventLogService.MarkEventAsFailedAsync(productPriceChangeEvent.Id); } } else // Just save the updated product because the Product's Price hasn't changed. { await _catalogContext.SaveChangesAsync(); } return(Ok()); }
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt) { _logger.LogInformation("----- CatalogIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); await ResilientTransaction.New(_gestaoNormasDbContext).ExecuteAsync(async() => { await _gestaoNormasDbContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _gestaoNormasDbContext.Database.CurrentTransaction); }); }
public async Task AddAndSaveEventAsync(IntegrationEvent evt) { _logger.LogInformation("----- IdentityIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); await ResilientTransaction.New((DbContext)_customIdentityDbContext).ExecuteAsync(async() => { // Achieving atomicity between original database operation and the IntegrationEventLog thanks to a local transaction await _customIdentityDbContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _customIdentityDbContext.Database.CurrentTransaction); }); }
private async Task SaveEventAndBusinessDbContextChangesAsync(IEvent evt) { //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_context) .ExecuteAsync(async() => { // Achieving atomicity between original ordering database operation and the IntegrationEventLog thanks to a local transaction await _context.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _context.Database.CurrentTransaction.GetDbTransaction()); }); }
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt) { _logger.LogInformation("----- CatalogIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_catalogContext).ExecuteAsync(async() => { // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction await _catalogContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction.GetDbTransaction()); }); }
public async Task SaveEventAndMovieContextChangesAsync(Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events.IntegrationEvent evt) { //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_movieContext) .ExecuteAsync(async() => { // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction await _movieContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _movieContext.Database.CurrentTransaction.GetDbTransaction()); }); }
public async Task DeleteEventAndOperacaoContextChangesAsync(IntegrationEvent evt) { var strategy = _moduloContext.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { using (var transaction = _moduloContext.Database.BeginTransaction()) { try { await _moduloContext.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _moduloContext.Database.CurrentTransaction.GetDbTransaction()); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); var sqlException = ex.InnerException as System.Data.SqlClient.SqlException; throw new Exception(sqlException.Number + "::" + sqlException.Message); } } }); }
public async Task SaveEventAndChangesAsync(IntegrationEvent evt) { _logger.LogInformation("----- POSIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); await ResilientTransaction.New(_posContext, _logger).ExecuteAsync(async() => { // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction try { if (await _posContext.SaveChangesAsync() <= 0) { _logger.LogError("----- POSIntegrationEventService {0}", "Not can saved in Db"); } } catch (DbUpdateException e) { _logger.LogError("***** Error In SaveChangesAsync Process {0}", e.Message); } await _eventLogService.SaveEventAsync(@event: evt, transaction: Guid.NewGuid()); }); }
public async Task SaveEventAsync(IntegrationEvent evt) { _logger.LogInformation("Saving integrationEvent: {IntegrationEventId}", evt.Id); await _eventLogService.SaveEventAsync(evt); }
public async Task <ActionResult> UpdateAsync([FromBody] RoomDTO roomDTO) { if (roomDTO == null) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Room data is null" })); } if (string.IsNullOrWhiteSpace(roomDTO.Name)) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Room name is empty" })); } var room = await roomRepository.GetByIdAsync(roomDTO.Id); if (room == null) { // return new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Room does not exist" }); return(NotFound(new ErrorDTO { ErrorMessage = "Room does not exist" })); } bool roomWithNameExists = roomRepository.GetAll().Any(r => r.Id != roomDTO.Id && r.Name == roomDTO.Name); if (roomWithNameExists) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Room with passed name does exist" })); } bool isRoomNameChanged = false, isRoomManagerChanged = false, isSlicesPerPizzaChanged = false; RoomNameChangedEvent roomNameChangedEvent = null; RoomManagerChangedEvent roomManagerChangedEvent = null; SlicesPerPizzaInRoomChangedEvent slicesPerPizzaInRoomChangedEvent = null; if (room.Name != roomDTO.Name) { isRoomNameChanged = true; room.Name = roomDTO.Name; roomNameChangedEvent = new RoomNameChangedEvent(room.Id, room.Name); } if (room.ManagerId != roomDTO.ManagerId) { isRoomManagerChanged = true; room.ManagerId = roomDTO.ManagerId; room.ManagerName = roomDTO.ManagerName; roomManagerChangedEvent = new RoomManagerChangedEvent(room.Id, room.Name, room.ManagerId, room.ManagerName); } if (room.SlicesPerPizza != roomDTO.SlicesPerPizza) { isSlicesPerPizzaChanged = true; room.SlicesPerPizza = roomDTO.SlicesPerPizza; slicesPerPizzaInRoomChangedEvent = new SlicesPerPizzaInRoomChangedEvent(room.Id, room.Name, room.SlicesPerPizza); } if (isRoomNameChanged || isRoomManagerChanged || isSlicesPerPizzaChanged) { // Publish integration events using (var transaction = session.BeginTransaction()) { await roomRepository.UpdateAsync(room.Id, room); if (isRoomNameChanged) { await integrationEventLogService.SaveEventAsync(roomNameChangedEvent); } if (isRoomManagerChanged) { await integrationEventLogService.SaveEventAsync(roomManagerChangedEvent); } if (isSlicesPerPizzaChanged) { await integrationEventLogService.SaveEventAsync(slicesPerPizzaInRoomChangedEvent); } transaction?.Commit(); } } return(NoContent()); }
public async Task SaveEventAsync(IntegrationEvent evt, System.Guid guid) { _logger.LogInformation("----- BotIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); await _eventLogService.SaveEventAsync(evt, guid); }
public async Task AddAndSaveEventAsync(IntegrationEvent evt) { var trans = _context.Database.CurrentTransaction.GetDbTransaction(); await _eventLogService.SaveEventAsync(evt, trans); }
public async Task AddEventsAsync(IntegrationEvent integrationEvent) { await _integrationEventLogService.SaveEventAsync(integrationEvent, _smarthubContext.Database.CurrentTransaction); }
public async Task SaveEventAsync(IntegrationEvent evt) { _logger.LogInformation("Saving integrationEvent: {IntegrationEventId}", evt.Id); await _eventLogService.SaveEventAsync(evt /*, _zeusContext.Database.CurrentTransaction*/); }
public async Task <IActionResult> RegisterAsync([FromBody] RegisterUserDTO registerUserDTO) { if (registerUserDTO == null) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Register data is null" })); } if (string.IsNullOrWhiteSpace(registerUserDTO.Email) || string.IsNullOrWhiteSpace(registerUserDTO.Password) || string.IsNullOrWhiteSpace(registerUserDTO.Password2)) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Email or password is empty" })); } if (registerUserDTO.Password.Length < 7) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Password is too short" })); } if (registerUserDTO.Password != registerUserDTO.Password2) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "Passwords are not equal" })); } var user = await userRepository.GetByEmailAsync(registerUserDTO.Email); if (user != null) { return(new BadRequestObjectResult(new ErrorDTO { ErrorMessage = "User does exist" })); } var passwordHash = passwordHasher.Hash(registerUserDTO.Email, registerUserDTO.Password); user = new User { Email = registerUserDTO.Email, PasswordHash = passwordHash }; using (var transaction = dbContext.Database.BeginTransaction()) { await userRepository.CreateAsync(user); await dbContext.SaveChangesAsync(); var userRegisteredEvent = new UserRegisteredEvent(user.Id, user.Email); await integrationEventLogService.SaveEventAsync(userRegisteredEvent); await dbContext.SaveChangesAsync(); transaction.Commit(); } return(NoContent()); }
public async Task AddAndSaveEventAsync(IntegrationEvent integrationEvent) { // TODO: SF: Pass the DbTransaction from IUnitOfWork ala OrderingContext await _eventLogService.SaveEventAsync(integrationEvent, null); }
public async Task AddAndSaveEventAsync(IntegrationEvent evt) { await eventLogService.SaveEventAsync(evt); }
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt) { await _catalogContext.SaveChangesAsync(); await _integrationEventLogService.SaveEventAsync(evt); }
public async Task AddAndSaveEventAsync(IntegrationEvent evt) { await _eventLogService.SaveEventAsync(evt, _attachmentContext.GetCurrentTransaction.GetDbTransaction()); }
public async Task AddAndSaveEventAsync <T>(T evt) where T : IntegrationEvent { await _eventLogService.SaveEventAsync(evt); }
public async Task AddAndSaveEventAsync(IntegrationEvent evt) { _logger.LogInformation("Adding integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id, evt); await _eventLogService.SaveEventAsync(evt, _productDbContext.GetCurrentTransaction()); }
public async Task AddAndSaveEventAsync(IntegrationEvent evt) { _logger.LogInformation("----- Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id, evt); await _eventLogService.SaveEventAsync(evt); }
/// <summary> /// Persist given event to integration event log database. /// For details on how the persisting works and why it might fail, refer to the class summary. /// </summary> /// <param name="@event">The integration event to persist.</param> /// <typeparam name="TEvent">The type of the integration event.</typeparam> public async Task AddAndSaveEventAsync <TEvent>(TEvent @event) where TEvent : IIntegrationEvent { _logger.LogDebug("Storing event for processing. Details: {0}", @event); await _integrationEventLogService.SaveEventAsync(@event, _dbContext.GetCurrentTransaction()); }