Beispiel #1
0
        private async Task SearchMobyGames(string term)
        {
            var scraper = new Scraper(Application.Current.ScraperWebClient());

            var entries = await Task.Run(() => scraper.Search(term));

            var disambiguationDialog = new GameDisambiguationDialog(entries)
            {
                Owner = editGameViewModel.ParentWindow
            };

            if (disambiguationDialog.ShowDialog() != true)
            {
                return;
            }

            var url = disambiguationDialog.SelectedResult.Url;

            if (disambiguationDialog.SelectedResult.Releases.Any())
            {
                // Find the first release that matches our preferred platforms.
                foreach (var platform in PlatformPriorities)
                {
                    var matchingRelease =
                        disambiguationDialog.SelectedResult.Releases
                        .FirstOrDefault(release => release.Platform.Equals(platform, StringComparison.OrdinalIgnoreCase));

                    if (matchingRelease == null || string.IsNullOrEmpty(matchingRelease.Url))
                    {
                        continue;
                    }

                    url = matchingRelease.Url;
                }
            }

            var gameEntry = scraper.GetGame(url);

            GetSpecs(gameEntry);

            GetScreenshots(gameEntry);

            editGameViewModel.GameScreenshots.Clear();

            editGameViewModel.Title             = gameEntry.Name;
            editGameViewModel.GameMobyGamesSlug = gameEntry.Slug;
            editGameViewModel.GameLinks.Add(gameEntry.Url);

            var publisher = editGameViewModel.Publishers.ToList().Find(p => p.Slug == gameEntry.Publisher.Slug);

            if (publisher == null)
            {
                publisher = new Publisher
                {
                    Name  = gameEntry.Publisher.Name,
                    Slug  = gameEntry.Publisher.Slug,
                    Links = new List <string> {
                        gameEntry.Publisher.Url
                    }
                };

                editGameViewModel.Publishers.Add(publisher);
            }

            editGameViewModel.GamePublisher = publisher;

            var developerCollection = editGameViewModel.Developers.ToList();

            foreach (var devEntry in gameEntry.Developers)
            {
                var developer = developerCollection.Find(d => d.Slug == devEntry.Slug);

                if (developer == null)
                {
                    developer = new Developer
                    {
                        Name  = devEntry.Name,
                        Slug  = devEntry.Slug,
                        Links = new List <string> {
                            devEntry.Url
                        },
                    };

                    editGameViewModel.Developers.Add(developer);
                }

                editGameViewModel.GameDevelopers.Add(developer);
            }
        }
        private async Task SearchMobyGames(string term)
        {
            var scraper = new Scraper(Application.Current.ScraperWebClient());

            var entries = await Task.Run(() => scraper.Search(term));

            var disambiguationDialog = new GameDisambiguationDialog(entries)
            {
                Owner = editGameViewModel.ParentWindow
            };

            if (disambiguationDialog.ShowDialog() != true)
            {
                return;
            }

            var gameEntry = scraper.GetGame(disambiguationDialog.SelectedResult.Slug);

            GetSpecs(gameEntry);

            GetScreenshots(gameEntry);

            editGameViewModel.GameScreenshots.Clear();

            editGameViewModel.Title             = gameEntry.Name;
            editGameViewModel.GameMobyGamesSlug = gameEntry.Slug;
            editGameViewModel.GameLinks.Add(gameEntry.Url);

            var publisher = editGameViewModel.Publishers.ToList().Find(p => p.Slug == gameEntry.Publisher.Slug);

            if (publisher == null)
            {
                publisher = new Publisher
                {
                    Name  = gameEntry.Publisher.Name,
                    Slug  = gameEntry.Publisher.Slug,
                    Links = new List <string> {
                        gameEntry.Publisher.Url
                    }
                };

                editGameViewModel.Publishers.Add(publisher);
            }

            editGameViewModel.GamePublisher = publisher;

            var developerCollection = editGameViewModel.Developers.ToList();

            foreach (var devEntry in gameEntry.Developers)
            {
                var developer = developerCollection.Find(d => d.Slug == devEntry.Slug);

                if (developer == null)
                {
                    developer = new Developer
                    {
                        Name  = devEntry.Name,
                        Slug  = devEntry.Slug,
                        Links = new List <string> {
                            devEntry.Url
                        },
                    };

                    editGameViewModel.Developers.Add(developer);
                }

                editGameViewModel.GameDevelopers.Add(developer);
            }
        }