Пример #1
0
        private IList <Recipe> GetPageRecipes(Topic topic, ApiPage page, string json)
        {
            if (!page.Loaded)
            {
                var link = GetLink(topic.Id, page.Page);
                json = HttpClient.LoadHtml(link, "Error while loading recipes.", true);
            }

            var recipesResult = JObject.Parse(json);
            var results       = recipesResult["response"]["results"].Children().ToList();

            var recipes = results.Where(r => r["record_type"].Value <string>() == "Recipe").Select(r => GetRecipe(topic, r)).ToList();

            return(recipes);
        }
Пример #2
0
        private IList <Review> GetRecipePageReviews(Recipe recipe, ApiPage page, string json)
        {
            if (!page.Loaded)
            {
                var link = GetReviewLink(recipe.Id, page.Page);
                json = HttpClient.LoadHtml(link, "Error while loading reviews.", true);
            }

            var reviewsResult = JObject.Parse(json);
            var results       = reviewsResult["data"]["items"].Children().ToList();

            var reviews =
                results.Where(r => r["type"].Value <string>() == "review")
                .Select(r => JsonConvert.DeserializeObject <Review>(r.ToString()))
                .ToList();

            return(reviews);
        }
Пример #3
0
        /// <summary>
        /// Gets all mods that are available online.
        /// </summary>
        /// <returns>Returns a list of online available mods.</returns>
        public static async Task <List <ModInfo> > GetModsAsync(IProgress <Tuple <double, string> > progress, CancellationToken cancellationToken)
        {
            var result = new List <ModInfo>();

            progress.Report(new Tuple <double, string>(0, App.Instance.GetLocalizedResourceString("ParsingFirstPageDescription")));

            string currentPageUrl = ModsUrl;

            while (!string.IsNullOrEmpty(currentPageUrl))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }

                ModInfo[] pageResult = await Task.Run(() =>
                {
                    string document = WebHelper.GetDocument(currentPageUrl, null);
                    if (!string.IsNullOrEmpty(document))
                    {
                        ApiPage currentPage = JsonHelper.Deserialize <ApiPage>(document);

                        int pageNumber             = currentPage.Info.PageNumber;
                        int pageCount              = currentPage.Info.PageCount;
                        string progressDescription = string.Format(App.Instance.GetLocalizedResourceString("ParsingPageDescription"), pageNumber + 1, pageCount);
                        progress.Report(new Tuple <double, string>((double)pageNumber / pageCount, progressDescription));

                        currentPageUrl = currentPage.Info.Links.NextPage;
                        return(currentPage.Mods);
                    }

                    currentPageUrl = null;
                    return(null);
                });

                if (pageResult != null)
                {
                    result.AddRange(pageResult);
                }
            }

            return(result);
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RouteHandler"/> class.
 /// </summary>
 /// <param name="page">The page.</param>
 public RouteHandler(ApiPage page)
 {
     _page = page;
 }