public static bool LoadWikiDataHosted(string uri) { if (uri.StartsWith("//")) { uri = MorebitsDotNet.GetProtocol() + ":" + uri; } WebClient loader = new WebClient(); loader.Headers.Add("User-Agent", MorebitsDotNet.UserAgent); loader.Encoding = Encoding.UTF8; string result; try { result = loader.DownloadString(new Uri(uri)); } catch (Exception) { MorebitsDotNet.DefaultErrorHandler(Localization.GetString("FailedToLoadHostedLocalWikiData", uri)); return(false); } LocalWikiData.LoadWikiData(result); return(true); }
private void hostedListLoader_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { WebClient loader = new WebClient(); loader.Headers.Add("User-Agent", MorebitsDotNet.UserAgent); try { string result = loader.DownloadString(new Uri("http://en.wikipedia.org/w/index.php?action=raw&ctype=text/css&title=User:This,%20that%20and%20the%20other/FtCG%20local%20wiki%20data%20files.css")); Invoke((MethodInvoker) delegate() { try { cboLocalDataHosted.Items.Clear(); cboLocalDataHosted.ForeColor = SystemColors.WindowText; foreach (string line in result.Split('\n')) { string[] parts = line.Split('|'); if (parts.Length == 2) { HostedLocalWikiDataEntry item = new HostedLocalWikiDataEntry(parts[0], parts[1]); cboLocalDataHosted.Items.Add(item); if (Settings.LocalWikiDataHosted.StartsWith(item.displayName + "|")) { cboLocalDataHosted.SelectedItem = item; } } } if (cboLocalDataHosted.Items.Count > 0 && cboLocalDataHosted.SelectedIndex == -1) { cboLocalDataHosted.SelectedIndex = 0; } } catch (Exception) { MorebitsDotNet.DefaultErrorHandler(Localization.GetString("FailedToLoadHostedLocalWikiDataList")); } }); } catch (Exception ex) { if (!(ex is InvalidOperationException)) { MorebitsDotNet.DefaultErrorHandler(Localization.GetString("FailedToLoadHostedLocalWikiDataList")); } } }