Esempio n. 1
0
        public async Task PurgeAsync(ICqrsEvent cqrsEvent, CancellationToken cancellationToken)
        {
            _logger.Debug($"Getting entity repository. TypeName: {cqrsEvent.SourceTypeName}");
            var sourceEntityType    = Type.GetType(cqrsEvent.SourceTypeName);
            var getRepositoryMethod = _cqrsRepositoryFactory.GetType().GetMethod("GetRepository");

            if (getRepositoryMethod != null)
            {
                var     genericMethodForSourceEntity = getRepositoryMethod.MakeGenericMethod(sourceEntityType);
                dynamic sourceEntityRepository       = genericMethodForSourceEntity.Invoke(_cqrsRepositoryFactory, null);
                _logger.Debug($"Built {nameof(CqrsRepositoryFactory)}");
                _logger.Debug($"Fetching entity by Id. Id: {cqrsEvent.SourceId}");
                using var uow = _unitOfWorkManager.Get();
                var cqrsEntity = await sourceEntityRepository.GetByIdAsync(cqrsEvent.SourceId, cancellationToken);

                var baseCqrsEntity = cqrsEntity as BaseCqrsEntity;
                _logger.Debug($"Fetched entity. Id: {cqrsEvent.SourceId}");
                var @event = baseCqrsEntity?.EventsToBeProcessed.FirstOrDefault(f => f.Id == cqrsEvent.Id);
                if (@event != null)
                {
                    _logger.Debug($"Removing event. Id: {@event.Id}");
                    baseCqrsEntity.RemoveEventToBeProcessed(@event);
                    await sourceEntityRepository.UpdateAsync(cqrsEntity, cancellationToken);

                    _logger.Debug("Removed event");
                }
                uow.Commit();
            }
        }
Esempio n. 2
0
        public async Task DispatchAsync(ICqrsEvent @event, CancellationToken cancellationToken = default)
        {
            _logger.Debug($"Publishing event to bus from EventDispatcher. Id: {@event.Id} SourceType: {@event.SourceTypeName}");
            await _bus.PublishAsync(@event, cancellationToken);

            _logger.Debug("Published event");
        }
Esempio n. 3
0
 private async Task PurgeEvent(ICqrsEvent cqrsEvent, CancellationToken cancellationToken)
 {
     try
     {
         await _eventPurger.PurgeAsync(cqrsEvent, cancellationToken);
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
     }
 }