예제 #1
0
        public void ShouldExtractSearchResultsFromGardenOrgWebPageSearch()
        {
            var data            = TestHelper.GetDataFile("garden-search.html");
            var gardenOrgParser = new GardenOrgSearchResultsParser();
            var searchResults   = gardenOrgParser.ParseData(data);

            Assert.NotNull(searchResults);
            Assert.Equal(20, searchResults.Count);
        }
예제 #2
0
        public async Task StartAsync(string queryTerm)
        {
            // Get some search results.
            var content = await _commsProxy.GetExternalContentAsync($"https://{_host}/plants/search/text/?q={queryTerm}");

            //Note: use Polly or some retry mechanism here - try..catch for now
            try
            {
                _progress = 20;

                if (string.IsNullOrWhiteSpace(content))
                {
                    _progress = 100;
                    return;
                }
                var searchResultParser = new GardenOrgSearchResultsParser();
                var searchResults      = searchResultParser.ParseData(content);
                if (searchResults?.Count == 0 || searchResults.All(r => string.IsNullOrEmpty(r.Href)))
                {
                    _logger.LogWarning("No results from GardenOrg query or invalid results return using term [{0}]", queryTerm);
                    _progress = 100;
                    return;
                }
                _progress = 40;

                // 1. Pass search results into next component to make additional queries against GardenOrg to create a GardenOrgPlantItem for each result
                foreach (var result in searchResults)
                {
                    var detailContent = await _commsProxy.GetExternalContentAsync($"https://{_host}{result.Href}");

                    var parsedDetail = new GardenOrgSearchResultDetailsParser().ParseData(detailContent);
                    // TODO: Add to list of results to return
                }
                _progress = 80;

                // 2. Store results into storage
                _progress = 100;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Problem querying GardenOrg site");
            }
        }