public async Task <int> PublishEvents() { var events = _eventLogRepository.GetAll() .Where(x => !x.Published) .OrderBy(x => x.CreatedDateTime) .Take(50) .ToList(); foreach (var eventLog in events) { if (eventLog.EventType == "FILEENTRY_CREATED") { await _fileUploadedEventSender.SendAsync(new FileUploadedEvent { FileEntry = JsonSerializer.Deserialize <FileEntry>(eventLog.Message) }); } else if (eventLog.EventType == "FILEENTRY_DELETED") { await _fileDeletedEventSender.SendAsync(new FileDeletedEvent { FileEntry = JsonSerializer.Deserialize <FileEntry>(eventLog.Message) }); } else if (eventLog.EventType == "AUDIT_LOG_ENTRY_CREATED") { var logEntry = JsonSerializer.Deserialize <AuditLog.Contracts.DTOs.AuditLogEntryDTO>(eventLog.Message); await _externalAuditLogService.AddAsync(logEntry); } else { // TODO: Take Note } eventLog.Published = true; eventLog.UpdatedDateTime = _dateTimeProvider.OffsetNow; await _eventLogRepository.UnitOfWork.SaveChangesAsync(); } return(events.Count); }