Пример #1
0
        public async Task <PurgeResponse> PurgeAllAsync(PurgeAllRequest request)
        {
            var config = _configService.GetConfig();

            var apiRequest = new PurgeAllCacheRequest(true);

            var uri = new Uri($"{Endpoint}/zones/{config.CloudFlare.ZoneId}/purge_cache");

            try
            {
                var result = await FetchAsync <CloudFlareResponse <PurgeCacheResult>, PurgeAllCacheRequest>(uri, HttpMethod.Post, apiRequest);

                return(new PurgeResponse(
                           result: result.Success?PurgeResult.Success: PurgeResult.Fail,
                           failedUrls: null,
                           failMessages: (result.Messages ?? Array.Empty <string>()).Union(result.Errors?.Select(e => e.Message) ?? Array.Empty <string>()),
                           exception: null));
            }
            catch (Exception ex)
            {
                return(new PurgeResponse(
                           result: PurgeResult.Fail,
                           failedUrls: null,
                           failMessages: null,
                           exception: new AggregateException(ex)));
            }
        }
Пример #2
0
        public async Task <PurgeResponse> PurgeAll()
        {
            var request = new PurgeAllRequest();
            var result  = await _cdnService.PurgeAllAsync(request);

            return(result);
        }
Пример #3
0
        public async Task <PurgeResponse> PurgeAllAsync(PurgeAllRequest request)
        {
            var purgeTasks = _cdnApis.Where(c => c.IsEnabled())
                             .Select(cdn => cdn.PurgeAllAsync(request));

            var results = await Task.WhenAll(purgeTasks);

            return(PurgeResponse.Aggregate(results));
        }