/// <summary> /// Scrapes the mapping between recipe url and recipe category. /// </summary> /// <param name="category">The recipe category.</param> private async Task ParseCategoryDetailsAsync(EatThisMuchCategory categoryPage) { do { var nextPageUrl = categoryPage.NextPage.ProperUrl; var currentPage = _pageFactory.Create <CategoryPage>(nextPageUrl); categoryPage = await _parseService .ParseAsync(currentPage) .CnfgAwait(); try { await _categoryRepo .AddAsync(categoryPage) .CnfgAwait(); _logger.ForContext(nameof(categoryPage), categoryPage, destructureObjects: true) .Information("EatThisMuch Category information added to Db"); } catch { _logger.Error("Failed adding Category info to DB"); } }while (!categoryPage.IsLastPage); }
/// <summary> /// </summary> /// <param name="uri">The Uri.</param> public async Task <Recipe> GetRecipeAsync(Uri uri) { var dbRecipe = await _recipeRepositry.GetByUrlAsync(uri.AbsoluteUri).CnfgAwait(); if (dbRecipe != null) { _logger.Information("{Uri} pulled from Db", uri.AbsoluteUri); return(dbRecipe); } var eatThisMuchRecipePage = _pageFactory.Create <RecipePage>(uri); var recipe = await _parseService.ParseAsync(eatThisMuchRecipePage).CnfgAwait(); // category info is located on other webpages therefore requires extra parsing. recipe.Categories = await _categoryProvider.GetCategoriesAsync(recipe.Url).CnfgAwait(); _logger.Information("{Uri} scraped from external site", uri.AbsoluteUri); return(recipe); }