private void ChangeSpectatorRegion(BaseRegion region)
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                string spectatorJSON = "";
                using (WebClient client = new WebClient())
                {
                    spectatorJSON = client.DownloadString(region.SpectatorLink + "featured");
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(spectatorJSON);
                gameList = deserializedJSON["gameList"] as ArrayList;
            };

            worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                ParseSpectatorGames();
            };

            worker.RunWorkerAsync();
        }
        private void GetNews(BaseRegion region)
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                string newsJSON = "";
                using (WebClient client = new WebClient())
                {
                    newsJSON = client.DownloadString(region.NewsAddress);
                }
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(newsJSON);
                newsList = deserializedJSON["news"] as ArrayList;
                ArrayList promoList = deserializedJSON["promos"] as ArrayList;
                foreach (Dictionary<string, object> objectPromo in promoList)
                {
                    newsList.Add(objectPromo);
                }
            };

            worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                ParseNews();
            };

            worker.RunWorkerAsync();
        }
        public void ChangeSpectatorRegion(BaseRegion region)
        {
            try
            {
                // @TODO: Move to global worker to prevent mutiple requests on fast region switch
                var worker = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    try
                    {
                        string spectatorJson;
                        using (var client = new WebClient())
                        {
                            client.Encoding = System.Text.Encoding.UTF8;
                            spectatorJson = client.DownloadString(region.SpectatorLink + "featured");
                        }

                        var serializer = new JavaScriptSerializer();
                        var deserializedJson = serializer.Deserialize<Dictionary<string, object>>(spectatorJson);
                        GameList = deserializedJson["gameList"] as ArrayList;
                    }
                    catch (WebException)
                    {
                        Client.Log("Spectator JSON download timed out.");
                    }
                };

                worker.RunWorkerCompleted += (s, args) => ParseSpectatorGames();
                worker.RunWorkerAsync();
            }
            catch
            {
            }
        }
        private void ParseNews(BaseRegion region)
        {
            if (NewsList == null)
                return;

            if (NewsList.Count <= 0)
                return;

            string imageUri = string.Empty;
            foreach (Dictionary<string, object> pair in NewsList)
            {
                var item = new NewsItem
                {
                    Margin = new Thickness(0, 5, 0, 5)
                };
                foreach (var kvPair in pair)
                {
                    if (kvPair.Key == "title")
                        item.NewsTitle.Content = kvPair.Value;

                    if (kvPair.Key == "description")
                    {
                        if ((string)kvPair.Value == string.Empty)
                            continue;

                        imageUri =
                            ((string)kvPair.Value).Substring(
                                ((string)kvPair.Value).IndexOf("src", StringComparison.Ordinal) + 6);
                        if (imageUri.IndexOf("?itok", StringComparison.Ordinal) > 0)
                            imageUri = imageUri.Remove(imageUri.IndexOf("?itok", StringComparison.Ordinal));

                        string noHtml = Regex.Replace(((string)kvPair.Value), @"<[^>]+>|&nbsp;", "").Trim();
                        string noHtmlNormalised = Regex.Replace(noHtml, @"\s{2,}", " ");
                        string noXmlAmpersands = Regex.Replace(noHtmlNormalised, @"&amp;", "&");

                        item.DescriptionLabel.Text = noXmlAmpersands;
                    }

                    if (kvPair.Key == "link")
                        item.Tag = kvPair.Value;

                    // Image
                    if (!string.IsNullOrEmpty(imageUri))
                    {
                        var promoImage = new BitmapImage(new System.Uri("http://" + region.RegionName + ".leagueoflegends.com/" + imageUri, UriKind.Absolute));
                        item.PromoImage.Stretch = Stretch.Fill;
                        item.PromoImage.Source = promoImage;
                    }
                }
                NewsItemListView.Items.Add(item);
            }
        }
        private void GetNews(BaseRegion region)
        {
            var worker = new BackgroundWorker();
            worker.DoWork += delegate
            {
                string newsXml;
                using (var webClient = new WebClient())
                {
                    // To skip the 403 Error (Forbbiden)
                    try
                    {
                        webClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
                        webClient.Headers.Add("Content-Type", "text/html; charset=UTF-8");
                    }
                    catch
                    {
                    }

                    newsXml = webClient.DownloadString(region.NewsAddress);
                }
                string newsJson;
                try
                {
                    var xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(newsXml);
                    newsJson = JsonConvert.SerializeXmlNode(xmlDocument);
                }
                catch
                {
                    newsJson = newsXml;
                }
                var serializer = new JavaScriptSerializer();
                Dictionary<string, object> deserializedJson;
                try
                {
                    deserializedJson = serializer.Deserialize<Dictionary<string, object>>(newsJson);
                }
                catch
                {
                    deserializedJson = null;
                    return;
                }

                var rss = deserializedJson["rss"] as Dictionary<string, object>;
                if (rss == null)
                    return;

                var channel = rss["channel"] as Dictionary<string, object>;
                if (channel != null)
                    NewsList = channel["item"] as ArrayList;
            };

            worker.RunWorkerCompleted += delegate { ParseNews(region); };

            worker.RunWorkerAsync();
        }
        private void ChangeSpectatorRegion(BaseRegion region)
        {
            try {
                // @TODO: Move to global worker to prevent mutiple requests on fast region switch
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += delegate {
                    string spectatorJSON = "";
                    using (WebClient client = new WebClient()) {
                        spectatorJSON = client.DownloadString(region.SpectatorLink + "featured");
                    }
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(spectatorJSON);
                    gameList = deserializedJSON["gameList"] as ArrayList;
                };

                worker.RunWorkerCompleted += (s, args) => ParseSpectatorGames();
                worker.RunWorkerAsync();
            } catch { }
        }