Exemple #1
0
        private void Status()
        {
            var t = new Thread(() =>
            {
                using (var client = new WebClient())
                {
                    var news = client.DownloadString("http://ll.leagueoflegends.com/pages/launcher/na").
                               Replace("refreshContent(", "").Replace(");", "");
                    var newsJson = JsonConvert.DeserializeObject <Rootobject>(news);
                    Client.RunOnUIThread(() =>
                    {
                        var item = new CurrentStatus
                        {
                            StatusLabel = { Content = "LOLServers" },
                            Tag         = new Uri("https://na.leagueoflegends.com")
                        };
                        item.UpdateStatus(
                            newsJson.status ? PatcherElements.Status.Down : PatcherElements.Status.Up);
                        item.MouseDown += (o, e) => Changed(o);
                        StatusView.Items.Add(item);
                    });
                    var request  = WebRequest.Create("http://legendaryclient.net");
                    var response = (HttpWebResponse)request.GetResponse();
                    Client.RunOnUIThread(() =>
                    {
                        var item = new CurrentStatus
                        {
                            StatusLabel = { Content = "LegendaryClient website" },
                            Tag         = new Uri("http://legendaryclient.net")
                        };
                        item.UpdateStatus(
                            response.StatusCode != HttpStatusCode.OK
                                    ? PatcherElements.Status.Down
                                    : PatcherElements.Status.Up);
                        item.MouseDown += (o, e) => Changed(o);
                        StatusView.Items.Add(item);
                    });

                    /*
                     * request = WebRequest.Create("http://forums.legendaryclient.net");
                     * response = (HttpWebResponse)request.GetResponse();
                     * Client.RunOnUIThread(() =>
                     * {
                     *  var item = new CurrentStatus
                     *  {
                     *      StatusLabel = { Content = "LegendaryClient forums" },
                     *      Tag = new Uri("http://forums.legendaryclient.net")
                     *  };
                     *  item.UpdateStatus(
                     *      response.StatusCode != HttpStatusCode.OK
                     *          ? PatcherElements.Status.Down
                     *          : PatcherElements.Status.Up);
                     *  item.MouseDown += (o, e) => Changed(o);
                     *  StatusView.Items.Add(item);
                     * });
                     * //*/
                    if (loaded)
                    {
                        return;
                    }
                    //Might as well load news
                    foreach (var n in newsJson.news)
                    {
                        Client.RunOnUIThread(() =>
                        {
                            var item = new NewsItem
                            {
                                TitleLabel = { Content = n.title },
                                TimeLabel  = { Content = n.date },
                                ContentBox = { Visibility = Visibility.Hidden },
                                Height     = 26,
                                Tag        = new Uri(n.url.Replace(@"\/", @"/")),
                                Width      = 300
                            };
                            item.MouseDown += (o, e) => Changed(o);
                            NewsBox.Items.Add(item);
                        });
                    }
                    foreach (var x in newsJson.community)
                    {
                        Client.RunOnUIThread(() =>
                        {
                            var item = new NewsItem {
                                TitleLabel = { Content = x.title }, Width = 300
                            };
                            item.ContentBox.AppendText(x.promoText);
                            item.TimeLabel.Visibility = Visibility.Hidden;
                            item.Tag = new Dictionary <string, object>
                            {
                                { "imgUrl", x.imageUrl.Replace(@"\/", @"/") },
                                { "thumbUrl", x.thumbUrl.Replace(@"\/", @"/") },
                                { "linkUrl", x.linkUrl.Replace(@"\/", @"/") }
                            };
                            item.MouseDown += (o, e) => Changed(o);
                            NewsBox.Items.Add(item);
                        });
                    }
                    loaded = true;
                }
            });

            t.Start();
        }