Exemple #1
0
        private async void buttonSearch_Click(object sender, RoutedEventArgs e)
        {
            MarvelCharacter.Clear();
            MarvelComic.Clear();
            MarvelEvents.Clear();
            loadComics.Visibility = Visibility.Collapsed;
            hideComics.Visibility = Visibility.Collapsed;
            loadEvents.Visibility = Visibility.Collapsed;
            hideEvents.Visibility = Visibility.Collapsed;
            SearchedComicDetailNameTextBlock.Text        = "";
            SearchedComicDetailDescriptionTextBlock.Text = "";
            SearchedComicBuyTextBlock.Text  = "";
            SearchedComicDetailImage.Source = null;

            var searchedCharacter = textBoxSearch.Text;

            Task  t = MarvelFacade.FindMarvelCharactersAsync(MarvelCharacter, searchedCharacter);
            await t;

            try
            {
                if (MarvelCharacter[0].id > 100)
                {
                    loadComics.Visibility = Visibility.Visible;
                    loadEvents.Visibility = Visibility.Visible;
                }
            }
            catch (Exception)
            {
                return;
            }
        }
Exemple #2
0
 private void hideSearchedComics_Click(object sender, RoutedEventArgs e)
 {
     MarvelComic.Clear();
     loadComics.Visibility = Visibility.Visible;
     hideComics.Visibility = Visibility.Collapsed;
     SearchedComicDetailNameTextBlock.Text        = "";
     SearchedComicDetailDescriptionTextBlock.Text = "";
     SearchedComicBuyTextBlock.Text  = "";
     SearchedComicDetailImage.Source = null;
 }
        public static async Task <List <MarvelComic> > GetComics()
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFile   file   = await folder.GetFileAsync("MarvelComics");

            IList <string> comicsJson = await FileIO.ReadLinesAsync(file);

            List <MarvelComic> comics = new List <MarvelComic>();

            foreach (var comicJson in comicsJson)
            {
                MarvelComic comic = JsonConvert.DeserializeObject <MarvelComic>(comicJson);
                comics.Add(comic);
            }

            return(comics);
        }
Exemple #4
0
        public static ObservableCollection <MarvelComic> CrawlComics()
        {
            ObservableCollection <MarvelComic> comics = new ObservableCollection <MarvelComic>();
            MarvelComic comic1 = new MarvelComic
            {
                Title       = "IronMan",
                Description = "IronMan Never Die",
                DateTime    = "2020/6/20",
                RelatedHero = "IronMan"
            };
            MarvelComic comic2 = new MarvelComic
            {
                Title       = "BatMan",
                Description = "I'm BatMan",
                DateTime    = "2000/6/20",
                RelatedHero = "BatMan"
            };
            MarvelComic comic3 = new MarvelComic
            {
                Title       = "AntMan",
                Description = "Become Bigger and Smaller",
                DateTime    = "2010/6/10",
                RelatedHero = "AntMan"
            };
            MarvelComic comic4 = new MarvelComic
            {
                Title       = "Spider Man: Legendary",
                Description = "Your friendly Neighbor",
                DateTime    = "2020/6/20",
                RelatedHero = "Spider Man"
            };
            MarvelComic comic5 = new MarvelComic
            {
                Title       = "Unstoppable Hulk",
                Description = "Hulk Smash",
                DateTime    = "2020/6/20",
                RelatedHero = "Hulk"
            };

            comics.Add(comic1);
            comics.Add(comic2);
            comics.Add(comic3);
            comics.Add(comic4);
            comics.Add(comic5);
            return(comics);
        }
Exemple #5
0
        private async void loadSearchedComics_Click(object sender, RoutedEventArgs e)
        {
            ProgressRing.IsActive   = true;
            ProgressRing.Visibility = Visibility.Visible;

            var searchedCharacterId = MarvelCharacter[0].id;

            loadComics.Visibility = Visibility.Collapsed;
            hideComics.Visibility = Visibility.Visible;

            MarvelComic.Clear();

            await MarvelFacade.PopulateMarvelComicsAsync(searchedCharacterId, MarvelComic);

            ProgressRing.IsActive   = false;
            ProgressRing.Visibility = Visibility.Collapsed;
        }
        /// <summary>
        /// Fetches matching comic based on barcode isbn number.
        /// </summary>
        /// <param name="upc"></param>
        /// <returns></returns>
        public async Task <Comic> GetByCode(string upc)
        {
            MarvelResponse comicResponse = await _marvelClient.RequestComic("/comics", $"upc={upc}");

            MarvelComic comicData = comicResponse
                                    .Data
                                    .Results
                                    .FirstOrDefault();

            if (comicData is null)
            {
                return(new Comic());
            }

            Comic comic = MapResponseToComic(comicData, comicResponse.Copyright);

            return(comic);
        }
 /// <summary>
 /// Helper method to take care of repeat mapping logic.
 /// </summary>
 /// <param name="marvelComic"></param>
 /// <param name="copyright"></param>
 /// <returns><see cref="Comic"/></returns>
 private static Comic MapResponseToComic(MarvelComic marvelComic, string copyright)
 {
     return(new Comic {
         Id = marvelComic.Id,
         Copyright = copyright,
         IssueNumber = marvelComic.IssueNumber,
         Title = marvelComic.Title,
         Upc = marvelComic.Upc,
         Description = marvelComic.Description,
         Characters = marvelComic.Characters,
         Creators = marvelComic.Creators,
         Series = marvelComic.ComicSeries,
         PublishDates = marvelComic.Dates.ToList(),
         PageCount = marvelComic.PageCount,
         ResourceUri = marvelComic.ResourceUri,
         Thumbnail = $"{marvelComic.Thumbnail.Path}.{marvelComic.Thumbnail.Extension}",
         RelevantLinks = marvelComic.Urls
     });
 }
Exemple #8
0
        public static ObservableCollection <MarvelComic> Search(string query)
        {
            ObservableCollection <MarvelComic> comics = new ObservableCollection <MarvelComic>();

            using (var reader = IndexReader.Open(Directory, true))
                using (var searcher = new IndexSearcher(reader))
                {
                    using (Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
                    {
                        /*需要更换*/
                        var queryParser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, new string[] { ConstantsHelper.DateTime,
                                                                                                                      ConstantsHelper.Description, ConstantsHelper.RelatedHero, ConstantsHelper.Title, ConstantsHelper.Detail }, analyzer);
                        //允许宽度查找
                        queryParser.AllowLeadingWildcard = true;

                        var parsedQuery = queryParser.Parse(query);

                        var collector = TopScoreDocCollector.Create(600, true);

                        searcher.Search(parsedQuery, collector);

                        var matches = collector.TopDocs().ScoreDocs;

                        foreach (var item in matches)
                        {
                            var         id    = item.Doc;
                            var         doc   = searcher.Doc(id);
                            MarvelComic comic = new MarvelComic
                            {
                                Title       = doc.GetField(ConstantsHelper.Title).StringValue,
                                Description = doc.GetField(ConstantsHelper.Description).StringValue,
                                DateTime    = doc.GetField(ConstantsHelper.DateTime).StringValue,
                                RelatedHero = doc.GetField(ConstantsHelper.RelatedHero).StringValue,
                                HeroBg      = doc.GetField(ConstantsHelper.HeroBg).StringValue,
                                Detail      = doc.GetField(ConstantsHelper.Detail).StringValue
                            };
                            comics.Add(comic);
                        }
                    }
                }
            return(comics);
        }
        public String Post([FromBody] JObject comic)
        {
            //Personaje pj = new Personaje(character, "marvel", "good", "mutant", "M", new int[] { 1, 2, 3, 4, 5, 6 }, new int[] { 1, 0, 0, 0, 0, 1 });

            /*JToken chars = comic.SelectToken("characters");
             * List<int> characters=new List<int>();
             * foreach (JToken ch in chars)
             * {
             *  characters.Add((int)(ch.ToString()));//characters[i] = comic.SelectToken("characters[0].marvel_id").ToObject<int>()
             * }*/
            new DB("MyDatabase", "localhost", 27017);
            var mc = new MarvelComic
            {
                Title      = comic.SelectToken("title").ToString(),
                Issue      = comic.SelectToken("issue").ToObject <int>(),
                Characters = comic.SelectToken("characters").ToObject <int[]>(),//comic.SelectToken("characters").ToObject<int[]>()//.ToString().Trim().Replace("\r\n", string.Empty).Replace("\\", string.Empty)
            };

            mc.Save();
            return(comic.SelectToken("characters").ToObject <int[]>()[0].ToString());
        }
        public static async Task GetFromComixologyPart(KeyValuePair <string, int> url)
        {
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            StorageFile   sampleFile    = await ApplicationData.Current.LocalFolder.CreateFileAsync("MarvelComics", CreationCollisionOption.OpenIfExists);

            List <string> Buffer      = new List <string>();
            int           currentPage = 1;
            string        currentUrl  = url.Key + currentPage;

            while (currentPage <= url.Value)
            {
                try
                {
                    HttpClient httpClient = new HttpClient();
                    var        html       = await httpClient.GetStringAsync(currentUrl);

                    HtmlDocument htmlDocument = new HtmlDocument();
                    htmlDocument.LoadHtml(html);

                    var items = htmlDocument.DocumentNode.Descendants("li")
                                .Where(node => node.GetAttributeValue("class", "").Equals("content-item"))
                                .ToList();
                    foreach (var item in items)
                    {
                        var img = item.Descendants("img").FirstOrDefault()
                                  .GetAttributeValue("src", "");
                        var title = item.Descendants("h5").FirstOrDefault()
                                    .InnerText;
                        var detail = item.Descendants("a").FirstOrDefault()
                                     .GetAttributeValue("href", "");

                        var heroList     = "";
                        var dateTime     = "";
                        var descriptions = "";


                        var detailUrl = item.Descendants("a")
                                        .Where(node => node.GetAttributeValue("class", "").Equals("content-details"))
                                        .FirstOrDefault().GetAttributeValue("href", "");
                        try
                        {
                            var detailHtml = await httpClient.GetStringAsync(detailUrl);

                            HtmlDocument detailHtmlDocument = new HtmlDocument();
                            detailHtmlDocument.LoadHtml(detailHtml);

                            descriptions = detailHtmlDocument.DocumentNode.Descendants("section")
                                           .Where(node => node.GetAttributeValue("class", "").Equals("item-description"))
                                           .FirstOrDefault().InnerText;

                            dateTime = detailHtmlDocument.DocumentNode.Descendants("div")
                                       .Where(node => node.GetAttributeValue("class", "").Equals("aboutText"))
                                       .ToList()[1].InnerText;
                            foreach (var hero in HeroPool)
                            {
                                if (descriptions.Contains(hero))
                                {
                                    heroList += hero + ".";
                                }
                            }
                            System.Diagnostics.Debug.WriteLine("-----------------");
                            System.Diagnostics.Debug.WriteLine(img);
                            System.Diagnostics.Debug.WriteLine(title);
                            System.Diagnostics.Debug.WriteLine(descriptions);
                            System.Diagnostics.Debug.WriteLine(heroList);
                            System.Diagnostics.Debug.WriteLine(dateTime);
                            System.Diagnostics.Debug.WriteLine("-----------------");

                            MarvelComic marvelComic = new MarvelComic
                            {
                                DateTime    = dateTime.ToString(),
                                Title       = title,
                                RelatedHero = heroList,
                                Description = descriptions,
                                HeroBg      = img,
                                Detail      = detail
                            };

                            if ((currentPage + 1) % 5 != 0)
                            {
                                Buffer.Add(JsonConvert.SerializeObject(marvelComic));
                            }
                            else
                            {
                                await FileIO.AppendLinesAsync(sampleFile, Buffer);

                                Buffer.Clear();
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
                currentPage++;
                totalPage++;
                OnProgressChanged?.Invoke(totalPage, CrwalerOptions.Comixology);
                currentUrl = url.Key + currentPage;
            }
            if (Buffer.Count != 0)
            {
                await FileIO.AppendLinesAsync(sampleFile, Buffer);

                Buffer.Clear();
            }
        }
        public static async Task GetFromFandom()
        {
            int        year       = startYear;
            HttpClient httpClient = new HttpClient();

            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            StorageFile   sampleFile    = await ApplicationData.Current.LocalFolder.CreateFileAsync("MarvelComics", CreationCollisionOption.ReplaceExisting);

            //C:\Users\Administrator\AppData\Local\Packages\951e17e0-73ce-478f-98e0-195a12edd6b2_75cr2b68sm664\LocalState
            List <string> Buffer = new List <string>();

            while (year <= endYear)
            {
                string categoryUrl = ConstantsHelper.fandomUrl + "/wiki/Category:" + year;
                try
                {
                    string html = await httpClient.GetStringAsync(categoryUrl);

                    HtmlDocument htmlDocument = new HtmlDocument();
                    htmlDocument.LoadHtml(html);
                    //System.Diagnostics.Debug.WriteLine(html);
                    var divs = htmlDocument.DocumentNode.Descendants("li")
                               .Where(node => node.GetAttributeValue("class", "").Contains("category-page__trending-page")).ToList();
                    foreach (var div in divs)
                    {
                        var img       = div.Descendants("img").FirstOrDefault().GetAttributeValue("src", "");
                        var title     = div.Descendants("figcaption").FirstOrDefault().InnerText;
                        var detailUrl = div.Descendants("a").FirstOrDefault().GetAttributeValue("href", "");
                        detailUrl = ConstantsHelper.fandomUrl + detailUrl;
                        try
                        {
                            string detailHtml = await httpClient.GetStringAsync(detailUrl);

                            HtmlDocument detailHtmlDocument = new HtmlDocument();
                            detailHtmlDocument.LoadHtml(detailHtml);

                            //Get Title And Fearture Heros
                            string heroList = "";
                            var    h2s      = detailHtmlDocument.DocumentNode.Descendants("h2")
                                              .Where(node => node.GetAttributeValue("id", "").Contains("AppearingHeader")).ToList();
                            foreach (var h2 in h2s)
                            {
                                var ul = h2.NextSibling;
                                while (ul.Name != "ul")
                                {
                                    ul = ul.NextSibling;
                                }
                                var lis = ul.Descendants("li");
                                foreach (var li in lis)
                                {
                                    var hero = li.Descendants("a")?.FirstOrDefault()?.InnerText;
                                    if (hero != null && hero.Trim() != "")
                                    {
                                        heroList += hero + ". ";
                                    }
                                }
                            }

                            //Get Details
                            var article = detailHtmlDocument.DocumentNode.Descendants("div")
                                          .Where(node => node.GetAttributeValue("id", "").Equals("WikiaArticle")).FirstOrDefault();
                            string detail = article.InnerHtml;

                            //Get Description
                            var span = detailHtmlDocument.DocumentNode.Descendants("span")
                                       .Where(node => node.GetAttributeValue("id", "").Equals("Notes")).FirstOrDefault();
                            var wrpper       = span?.ParentNode?.NextSibling?.NextSibling;
                            var descriptions = "";
                            if (wrpper != null)
                            {
                                if (wrpper.Name == "ul")
                                {
                                    var wrapperLis = wrpper.Descendants("li").ToList();
                                    foreach (var li in wrapperLis)
                                    {
                                        var note = li.InnerText;
                                        descriptions += note;
                                    }
                                }
                            }

                            if (heroList == "")
                            {
                                heroList = "Unknown";
                            }
                            if (descriptions == "")
                            {
                                descriptions = "Unknown";
                            }
                            MarvelComic marvelComic = new MarvelComic
                            {
                                DateTime    = year.ToString(),
                                Title       = title,
                                RelatedHero = heroList,
                                Description = descriptions,
                                HeroBg      = img,
                                Detail      = detail
                            };
                            if (year % 20 != 0)
                            {
                                Buffer.Add(JsonConvert.SerializeObject(marvelComic));
                            }
                            else
                            {
                                await FileIO.AppendLinesAsync(sampleFile, Buffer);

                                Buffer.Clear();
                            }

                            System.Diagnostics.Debug.WriteLine("-----------------");
                            System.Diagnostics.Debug.WriteLine(img);
                            System.Diagnostics.Debug.WriteLine(title);
                            System.Diagnostics.Debug.WriteLine(descriptions);
                            System.Diagnostics.Debug.WriteLine(heroList);
                            System.Diagnostics.Debug.WriteLine(year);
                            System.Diagnostics.Debug.WriteLine("-----------------");
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }

                year++;
                OnProgressChanged?.Invoke(year, CrwalerOptions.Fandom);
                await Task.Delay(10);
            }
        }
        public static async Task GetFromMarvelHq()
        {
            HttpClient httpClient = new HttpClient();

            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            StorageFile   sampleFile    = await ApplicationData.Current.LocalFolder.CreateFileAsync("MarvelComics", CreationCollisionOption.OpenIfExists);

            List <string> Buffer = new List <string>();

            try
            {
                string html = await httpClient.GetStringAsync(ConstantsHelper.marvelHqUrl);

                HtmlDocument htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(html);

                var lis = htmlDocument.DocumentNode.Descendants("li")
                          .Where(node => node.GetAttributeValue("class", "").Equals("col")).ToList();
                int currentIndex = 0;
                foreach (var li in lis)
                {
                    var img = li.Descendants("img")
                              .Where(node => node.GetAttributeValue("class", "")
                                     .Equals("_currentItem")).FirstOrDefault().GetAttributeValue("src", "");
                    var title = li.Descendants("a")
                                .FirstOrDefault().GetAttributeValue("data-title", "");
                    var descriptions = "";
                    var detail       = "";
                    var heroList     = "";
                    var year         = "Unkown";
                    var detailUrl    = li.Descendants("a")
                                       .FirstOrDefault().GetAttributeValue("href", "");
                    try
                    {
                        string detailHtml = await httpClient.GetStringAsync(detailUrl);

                        HtmlDocument detailHtmlDocument = new HtmlDocument();
                        detailHtmlDocument.LoadHtml(detailHtml);

                        descriptions = detailHtmlDocument.DocumentNode.Descendants("p")
                                       .Where(node => node.GetAttributeValue("id", "").Equals("comicDetailDesc"))
                                       .FirstOrDefault().InnerText;

                        detail = detailHtmlDocument.DocumentNode.Descendants("div")
                                 .Where(node => node.GetAttributeValue("itemprop", "").Equals("comic"))
                                 .FirstOrDefault().InnerHtml;

                        var heros = detailHtmlDocument.DocumentNode.Descendants("div")
                                    .Where(node => node.GetAttributeValue("data-modulename", "").Equals("Related Characters"))
                                    ?.FirstOrDefault()?.Descendants("li")
                                    ?.Where(node => node.GetAttributeValue("class", "").Equals("col"))?.ToList();

                        if (heros != null && heros.Count != 0)
                        {
                            foreach (var hero in heros)
                            {
                                heroList += hero.Descendants("a").FirstOrDefault().GetAttributeValue("data-title", "") + ".";
                            }
                        }


                        if (heroList == "")
                        {
                            heroList = "Unknown";
                        }

                        if (img == "")
                        {
                            img = "../Pictures/DefaultDetailBg.jpg";
                        }
                        System.Diagnostics.Debug.WriteLine("-----------------");
                        System.Diagnostics.Debug.WriteLine(img);
                        System.Diagnostics.Debug.WriteLine(title);
                        System.Diagnostics.Debug.WriteLine(descriptions);
                        System.Diagnostics.Debug.WriteLine(heroList);
                        System.Diagnostics.Debug.WriteLine(year);
                        System.Diagnostics.Debug.WriteLine("-----------------");

                        MarvelComic marvelComic = new MarvelComic
                        {
                            DateTime    = year.ToString(),
                            Title       = title,
                            RelatedHero = heroList,
                            Description = descriptions,
                            HeroBg      = img,
                            Detail      = detail
                        };

                        if ((currentIndex + 30 + 1) % 30 != 0)
                        {
                            Buffer.Add(JsonConvert.SerializeObject(marvelComic));
                        }
                        else
                        {
                            await FileIO.AppendLinesAsync(sampleFile, Buffer);

                            Buffer.Clear();
                        }
                        OnProgressChanged?.Invoke(currentIndex, CrwalerOptions.MarvelHQ);
                        currentIndex++;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                    }
                }
                if (Buffer.Count != 0)
                {
                    await FileIO.AppendLinesAsync(sampleFile, Buffer);

                    Buffer.Clear();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }