コード例 #1
0
        private async Task Handle(
            bool withGarden,
            IObserver <FetchResponse> observer,
            CancellationToken cancellationToken,
            int page       = 1,
            int totalPages = 1)
        {
            if (page > totalPages)
            {
                return;
            }

            _logger.LogInformation("Fetching page {0} of {1}", page, totalPages);
            try
            {
                HouseOfferResponse houseOffer = await _httpRetryPolicy.ExecuteAsync(() =>
                                                                                    _houseOfferProvider.GetOffers(cancellationToken, withGarden, page: page)
                                                                                    );

                await _houseOfferRepository.SaveHouseOffer(houseOffer.Offers);

                FetchResponse response = new FetchResponse((int)houseOffer.Paging.ProgressPercentage(),
                                                           FetchStatus.APIRetrieve);
                observer.OnNext(response);
                await Handle(withGarden, observer, cancellationToken, page + 1, (int)houseOffer.Paging.TotalPages);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Skipping page {0} of {1}", page, totalPages);
                FetchResponse response = new FetchResponse(0, FetchStatus.Skipped);
                observer.OnNext(response);
                await Handle(withGarden, observer, cancellationToken, page + 1, totalPages);
            }
        }
コード例 #2
0
        private async Task <HouseOfferResponse> GetHttpResponseMessageContent(
            HttpResponseMessage httpResponseMessage)
        {
            string content = await httpResponseMessage.Content.ReadAsStringAsync();

            HouseOfferResponse houseOfferResponse = JsonSerializer.Deserialize <HouseOfferResponse>(content);

            return(houseOfferResponse);
        }