public async Task <HttpStatusCode> ProcessMessageAsync(WebhookCacheOperation webhookCacheOperation, Guid eventId, Guid contentId, string apiEndpoint)
        {
            if (_sharedContentId != contentId)
            {
                logger.LogInformation($"Event Id: {eventId}, is not a shared content item we are subscribed to, so no content has been processed");
                return(HttpStatusCode.OK);
            }

            switch (webhookCacheOperation)
            {
            case WebhookCacheOperation.Delete:
                return(await webhookContentProcessor.DeleteContentAsync(contentId).ConfigureAwait(false));


            case WebhookCacheOperation.CreateOrUpdate:

                if (!Uri.TryCreate(apiEndpoint, UriKind.Absolute, out Uri? url))
                {
                    throw new InvalidDataException($"Invalid Api url '{apiEndpoint}' received for Event Id: {eventId}");
                }

                return(await webhookContentProcessor.ProcessContentAsync(url, contentId).ConfigureAwait(false));


            default:
                logger.LogError($"Event Id: {eventId} got unknown cache operation - {webhookCacheOperation}");
                return(HttpStatusCode.BadRequest);
            }
        }
예제 #2
0
        public async Task <HttpStatusCode> ProcessMessageAsync(WebhookCacheOperation webhookCacheOperation, Guid eventId, Guid contentId, string apiEndpoint)
        {
            var contentCacheStatus = contentCacheService.CheckIsContentItem(contentId);

            switch (webhookCacheOperation)
            {
            case WebhookCacheOperation.Delete:
                if (contentCacheStatus == ContentCacheStatus.ContentItem || contentCacheStatus == ContentCacheStatus.Both)
                {
                    return(await webhookContentProcessor.DeleteContentItemAsync(contentId).ConfigureAwait(false));
                }
                else
                {
                    return(await webhookContentProcessor.DeleteContentAsync(contentId).ConfigureAwait(false));
                }

            case WebhookCacheOperation.CreateOrUpdate:

                if (!Uri.TryCreate(apiEndpoint, UriKind.Absolute, out Uri? url))
                {
                    throw new InvalidDataException($"Invalid Api url '{apiEndpoint}' received for Event Id: {eventId}");
                }

                if (contentCacheStatus == ContentCacheStatus.ContentItem || contentCacheStatus == ContentCacheStatus.Both)
                {
                    return(await webhookContentProcessor.ProcessContentItemAsync(url, contentId).ConfigureAwait(false));
                }
                else
                {
                    return(await webhookContentProcessor.ProcessContentAsync(url, contentId).ConfigureAwait(false));
                }

            default:
                logger.LogError($"Event Id: {eventId} got unknown cache operation - {webhookCacheOperation}");
                return(HttpStatusCode.BadRequest);
            }
        }