Beispiel #1
0
        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);
            });
        }
Beispiel #2
0
        public async Task SaveEventAndDbContextChangesAsync(IEnumerable <Event> events)
        {
            _logger.LogInformation("----- EventService - Saving changes and multiple events: {EventId}");

            //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 database operation and the EventLog thanks to a local transaction
                await _context.SaveChangesAsync();
                foreach (var @event in events)
                {
                    await _eventLogService.SaveEventAsync(@event, _context.Database.CurrentTransaction);
                }
            });
        }
Beispiel #3
0
        private async Task UpdateStateInternal(DocumentInfo document, InProcessDocumentState newState, string errorInfo,
                                               CancellationToken cancellationToken)
        {
            InProgressDocumentDbItem inProgressDocument = null;
            await ResilientTransaction.New(context).ExecuteAsync(async() =>
            {
                var(id, userIdentity) = document.Id;
                inProgressDocument    =
                    await context.InProgressDocuments.FindAsync(new object[] { id, userIdentity }, cancellationToken);
                if (inProgressDocument != null)
                {
                    context.InProgressDocuments.Update(inProgressDocument);
                }
                else
                {
                    inProgressDocument = new InProgressDocumentDbItem
                    {
                        Id           = id,
                        UserIdentity = userIdentity,
                    };
                    context.InProgressDocuments.Add(inProgressDocument);
                }

                inProgressDocument.ErrorInfo            = errorInfo;
                inProgressDocument.FileName             = document.FileName;
                inProgressDocument.State                = newState;
                inProgressDocument.LastStatusUpdateTime = DateTimeOffset.UtcNow;

                await context.SaveChangesAsync(cancellationToken);
            });

            if (inProgressDocument.State == newState)
            {
                await mediator.Publish(
                    new InProgressDocumentStateChanged(
                        new InProgressDocument(
                            document.Id,
                            inProgressDocument.FileName, inProgressDocument.State,
                            inProgressDocument.LastStatusUpdateTime, inProgressDocument.ErrorInfo)),
                    cancellationToken);
            }
        }
Beispiel #4
0
        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());
            });
        }
Beispiel #5
0
 public async Task <T> CreateTransactionAsync <T> (Func <Task <T> > action, CancellationToken ct)
 {
     return(await ResilientTransaction.New(_context).ExecuteAsync(action, ct));
 }