Beispiel #1
0
        public static async Task <CharacterPhpInfo> LoadMarvelWikiaPhpInfoByName(
            string name)
        {
            string feedUrl = "http://marvel.wikia.com/api.php?action=parse&page={0}&format=json";

            feedUrl = String.Format(feedUrl, name);
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(feedUrl);
            HttpResponseMessage response = await client.GetAsync(feedUrl);

            String str = await response.Content.ReadAsStringAsync();

            Parse parse = JsonConvert.DeserializeObject <RootWikiSearch>(str).parse;


            CharacterPhpInfo info = new CharacterPhpInfo(parse);
            HtmlDocument     doc  = new HtmlDocument();

            doc.LoadHtml(info.text);
            info.text = ParseHtmlCodeWithCss(FormattingMarvelWikia(doc));

            return(info);
        }
Beispiel #2
0
        /// <summary>
        /// Method to GET all data from sources
        /// </summary>
        /// <returns></returns>
        public async Task <HtmlWebViewSource> GetDataFromSuggestion()
        {
            ShowWiki = false;
            var  html  = new HtmlWebViewSource();
            bool error = false;

            try
            {
                String searchtitle = String.Empty;
                bool   is616       = false;
                if (SelectedSuggestionToShow != null)
                {
                    if (!SelectedSuggestionToShow.Title.EndsWith("(Earth-616)"))
                    {
                        searchtitle = SelectedSuggestionToShow.Title;
                    }
                    else
                    {
                        searchtitle = SelectedSuggestionToShow.Title.Replace(" (Earth-616)", "");
                        is616       = true;
                    }
                }
                else
                {
                    return(null);
                }

                var names = await WikiaApiService.Instance.GetNames(SelectedSuggestionToShow.Title);

                names = names.OrderBy(n => n.NumericId).ToList();
                string           titlewithoutspecialchars = SelectedSuggestionToShow.Title.Replace("_", "");
                var              found = names.Where(n => n.Title == titlewithoutspecialchars).FirstOrDefault();
                CharacterPhpInfo art   = null;
                if (found != null)
                {
                    art = await WikiaApiService.Instance.GetArticleById(found.Id);
                }
                else
                {
                    art = await WikiaApiService.Instance.GetArticleByName(SelectedSuggestionToShow.Title);
                }

                if (is616)
                {
                    found = names.Where(n => (n.Url.EndsWith("_(Earth-616)"))).FirstOrDefault();
                    if (found != null)
                    {
                        var history = names.Where(n => n.Url.EndsWith("(Earth-616)/Expanded_History")).FirstOrDefault();
                        if (history != null)
                        {
                            found.Title = found.Title.Replace(" (Earth-616)", "");
                            art         = await WikiaApiService.Instance.GetArticleById(history.Id);
                        }
                        else
                        {
                            art = await WikiaApiService.Instance.GetArticleByName(SelectedSuggestionToShow.Title);
                        }
                    }
                    else
                    {
                        art = await WikiaApiService.Instance.GetArticleByName(SelectedSuggestionToShow.Title);
                    }
                }

                String name = String.Empty;
                if (SelectedSuggestion != null)
                {
                    name = SelectedSuggestion.Title;
                }
                else
                if (SelectedSuggestionToShow != null)
                {
                    name = SelectedSuggestionToShow.Title;
                }

                FindAnotherData(name);

                html.Html = art.text;
                ShowWiki  = true;
                return(html);
            } catch (Exception ex)
            {
                error = true;
            }

            if (error)
            {
                var art = await WikiaApiService.Instance.GetArticleByName(SelectedSuggestion.Title);

                ShowWiki  = true;
                html.Html = art.text;
            }

            ShowWiki = true;
            return(html);
        }