public Task SaveEventAsync(IntegrationEvent @event)
        {
            var eventLogEntry = new IntegrationEventLogEntry(@event);

            //something about transaction
            _eventLogContext.IntegrationEventLogs.Add(eventLogEntry);
            return(_eventLogContext.SaveChangesAsync());
        }
예제 #2
0
        private async Task UpdateStatus(Guid id, EventState state)
        {
            var eventLogEntry = _dbContext.IntegrationEventLogs.Single(i => i.EventId == id);

            eventLogEntry.EventState = state;

            _dbContext.IntegrationEventLogs.Update(eventLogEntry);

            await _dbContext.SaveChangesAsync();
        }
        public Task SaveEventAsync(IntegrationEvent @event /*, IDbContextTransaction transaction*/)
        {
            //if (transaction == null) throw new ArgumentNullException(nameof(transaction));

            var eventLogEntry = new IntegrationEventLogEntry(@event, /*transaction.TransactionId*/ new Guid());

            //_integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);
            return(_integrationEventLogContext.SaveChangesAsync());
        }
예제 #4
0
        public Task MarkEventAsPublishedAsync(IntegrationEvent @event)
        {
            var eventLogEntry = _integrationEventLogContext.IntegrationEventLogs.Single(ie => ie.EventId == @event.Id);

            eventLogEntry.TimesSent++;
            eventLogEntry.State = EventStateEnum.Published;

            _integrationEventLogContext.IntegrationEventLogs.Update(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
예제 #5
0
        public async Task MarkEventAsPublishedAsync(IntegrationEvent @event)
        {
            var eventLog = GetValidEventById(@event.Id);

            try
            {
                eventLog.MarkAsPublished();
                await _integrationEventLogContext.SaveChangesAsync();
            }
            catch (Exception exception)
            {
                throw new FailToChangeEventStateException(eventLog, exception);
            }
        }
예제 #6
0
        public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            _integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction()); //using same transaction to save eventlog
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
예제 #7
0
        public Task SaveEventAsync(IntegrationEvent @event, DbTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction", $"A {typeof(DbTransaction).FullName} is required as a pre-requisite to save the event.");
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event);

            _integrationEventLogContext.Database.UseTransaction(transaction);
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
예제 #8
0
        private async Task UpdateEventStatusAsync(Guid eventId, EventStateEnum status)
        {
            var eventLogEntry = _context.IntegrationEventLogs.Single(ie => ie.EventId == eventId);

            eventLogEntry.State = status;

            if (status == EventStateEnum.InProgress)
            {
                eventLogEntry.TimesSent++;
            }

            _context.IntegrationEventLogs.Update(eventLogEntry);

            await _context.SaveChangesAsync();
        }
        public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction), $"{typeof(DbTransaction).FullName} is required as a pre-requisite to save the event.");
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            _context.Database.UseTransaction(transaction.GetDbTransaction());
            _context.IntegrationEventLogs.Add(eventLogEntry);

            throw new Exception("Testing atomicity");

            return(_context.SaveChangesAsync());
        }
예제 #10
0
        /// <summary>
        /// Save event to log along with the transaction during which the event was created.
        /// </summary>
        /// <param name="@event">The integration event to save.</param>
        /// <param name="transaction">The transaction during which the event was created.</param>
        public Task SaveEventAsync(IIntegrationEvent @event, IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);

            // Set the datebase transaction to the provided instance, this ensure integration events
            // are logged in the same transaction as the domain data change that spawned the event.
            _integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
            _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

            return(_integrationEventLogContext.SaveChangesAsync());
        }
        public Task MarkEventAsPublishedAsync(IntegrationEvent @event)
        {
            try
            {
                var eventLogEntry = _integrationEventLogContext.IntegrationEventLogs.Single(e => e.ID == @event.ID.ToString());

                eventLogEntry.TimesSent++;
                eventLogEntry.State = EventStateEnum.Published;

                _integrationEventLogContext.IntegrationEventLogs.Update(eventLogEntry);

                return(_integrationEventLogContext.SaveChangesAsync());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
예제 #12
0
        public async Task SaveApplicationContextAndEventLogsContextChangesAsync()
        {
            var resilientTransaction = ResilientTransaction.Create(_dbContext);

            await resilientTransaction.ExecuteAsync(async() =>
            {
                await _dbContext.SaveChangesAsync();
                await _integrationEventLogContext.SaveChangesAsync();
            });
        }
예제 #13
0
        public async Task AddIntegrationEventToLog(IntegrationEvent @event, IDbContextTransaction transaction)
        {
            var integrationEventLogEntry = new IntegrationEventLogEntry(@event, Guid.NewGuid());

            _context.IntegrationEventLogs.Add(integrationEventLogEntry);

            _logger.LogInformation(" [x] OrderingIntegrationService.AddIntegrationEventToLog(): Added integration event to integrationEventLog: {0}",
                                   JsonConvert.SerializeObject(@event));

            await _context.SaveChangesAsync();
        }
        public Task SaveEventAsync(IntegrationEvent integrationEvent, IDbContextTransaction transaction)
        {
            try
            {
                if (transaction == null)
                {
                    throw new ArgumentNullException(nameof(transaction));
                }

                var eventLogEntry = new IntegrationEventLogEntry(integrationEvent, transaction.TransactionId);

                _integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
                _integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);

                return(_integrationEventLogContext.SaveChangesAsync());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #15
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new CQRSDomainException($"Request with {id} already exists") :
                                new ClientRequest()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTimeOffset.UtcNow
                                };

            _context.Add(request);
            await _context.SaveChangesAsync();
        }