private async Task HandleMessageAsync(Message message, CancellationToken cancellationToken) { var formatter = new BinaryFormatter(); if (message.Body == null) { await _subClient.AbandonAsync(message.SystemProperties.LockToken); return; } var objectStream = new MemoryStream(message.Body); var updateEvent = (ContentPageChangeEventArgs)formatter.Deserialize(objectStream); if (updateEvent.Title == null) { _logger.LogWarning($"Changeset {updateEvent.ChangesetId} has null title"); await _subClient.CompleteAsync(message.SystemProperties.LockToken); return; } var prevMeta = _cache.GetPageMetadata(updateEvent.Title); if (prevMeta != null && prevMeta.ChangeSetId > updateEvent.ChangesetId) { _logger.LogWarning($"Update to page {updateEvent.Title} has higher local rev, {prevMeta.ChangeSetId} > {updateEvent.ChangesetId}"); await _subClient.CompleteAsync(message.SystemProperties.LockToken); return; } try { var(meta, page) = await _apiClient.GetPageAsync(updateEvent.Title, updateEvent.ChangesetId); if (meta != null && page != null) { _cache.PutPageContent(updateEvent.Title, meta, page); await _subClient.CompleteAsync(message.SystemProperties.LockToken); _logger.LogInformation($"Updated page {updateEvent.Title} to rev {updateEvent.ChangesetId}"); } } catch (Exception exc) { _logger.LogError(exc, "MW getting update failed"); } }
public async Task <IActionResult> GetPage(string id) { if (id != null) { // Cache var cacheContent = _cache.GetPageContent(id); if (cacheContent != null) { return(File(cacheContent, ContentType)); } var(metadata, newContent) = await _apiService.GetPageAsync(id, null); if (newContent != null) { _cache.PutPageContent(id, metadata, newContent); return(File(newContent, ContentType)); } } return(NotFound()); }