private async void PickPageName() { if (string.IsNullOrWhiteSpace(this.release.Title)) { this.SetStatus(null); return; } this.SetStatus("Searching pages..."); string result = await Task.Run <string>(() => { List <string> pageNames = new List <string>(); pageNames.Add(this.release.Title + " (" + this.release.JoinedAlbumArtists + " album)"); pageNames.Add(this.release.Title + " (album)"); pageNames.Add(this.release.Title); foreach (string pageName in pageNames) { bool alreaadyHasAddress = false; this.Dispatcher.InvokeAction(() => { alreaadyHasAddress = !string.IsNullOrEmpty(this.textAddress.Text); }); if (alreaadyHasAddress) { return(null); } try { string url = WikipediaImporter.MakeSearchUrlFromPageName(pageName); WebClient client = new WebClient(); client.Headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1"; string page = client.DownloadString(url); if (page.Contains("but consider checking the search results below to see whether the topic is already")) { continue; } return(url); } catch (WebException) { } } return(null); }); if (string.IsNullOrEmpty(this.textAddress.Text)) { if (result == null) { this.SetStatus("Couldn't find Wikipedia page."); this.LoadPage("http://wikipedia.org"); } else { this.SetStatus(null); this.LoadPage(result); } } else { this.SetStatus(null); } }
private void btnWikipediaMatch_Click(object sender, RoutedEventArgs e) { this.UpdateRelease(); WikipediaImporter importer = new WikipediaImporter(this, this.release); if (importer.Import()) { this.detailsEditor.Release = null; this.detailsEditor.Release = this.release; this.RefreshAllDiscs(); } }