Ejemplo n.º 1
0
        static StaticData()
        {
            IsLogin = false;
            acitem  = new ACItem();

            IsShowImage = Settings.GetValueOrDefault <bool>("IsShowImage", false);
        }
        private void EasyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            EasyListBox lb = sender as EasyListBox;

            if (lb.SelectedIndex != -1)
            {
                ACItem item = lb.SelectedItem as ACItem;
                StaticData.acitem = item;
                NavigationService.Navigate(new Uri("/ACWZ;component/DetailPage.xaml", UriKind.RelativeOrAbsolute));
            }
            lb.SelectedIndex = -1;
        }
        private async Task getList()
        {
            islistbusy          = true;
            indicator.IsVisible = true;
            try
            {
                using (Stream stream = await new HttpHelp().Get(string.Format(StaticData.collection, page)))
                {
                    StreamReader sr     = new StreamReader(stream);
                    string       str    = sr.ReadToEnd();
                    JObject      result = JObject.Parse(str);

                    if (!(bool)result["success"])
                    {
                        if ((string)result["message"] != null)
                        {
                            MessageBox.Show((string)result["message"]);
                        }
                        indicator.IsVisible = false;
                        return;
                    }

                    int totalPage = (int)result["totalpage"];

                    foreach (JObject content in (result["contents"] as JArray))
                    {
                        ACItem item = new ACItem();
                        item.title  = (string)content["title"];
                        item.href   = (string)content["url"];
                        item.dis    = (string)content["comments"];
                        item.time   = (string)content["releaseDate"];
                        item.name   = (string)content["username"];
                        item.beizhu = (string)content["description"];
                        collectionlist.Add(item);
                    }

                    if (page < totalPage)
                    {
                        page++;
                    }
                    else
                    {
                        page = 0;
                    }
                }
            }
            catch (Exception) { }
            islistbusy          = false;
            indicator.IsVisible = false;
        }
Ejemplo n.º 4
0
        private async Task <ObservableCollection <ACItem> > getList(ObservableCollection <ACItem> list, string url)
        {
            try
            {
                indicator.IsVisible = true;
                var request = (HttpWebRequest)WebRequest.Create(new Uri(url));
                request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
                var response = await request.GetResponseAsync();

                var doc = new HtmlDocument();
                doc.Load(response.GetResponseStream());


                var node = getListNode(doc);
                if (node != null)
                {
                    foreach (var item in node.ChildNodes)
                    {
                        if (item.Name.Equals("div"))
                        {
                            var listtemp = new List <HtmlNode>();
                            foreach (var label in item.ChildNodes)
                            {
                                if (label.Name.Equals("a") || label.Name.Equals("div"))
                                {
                                    listtemp.Add(label);
                                }
                            }

                            ACItem acitem = new ACItem();
                            acitem.title  = listtemp[1].InnerText;
                            acitem.href   = listtemp[0].Attributes[2].Value;
                            acitem.dis    = listtemp[2].ChildNodes[3].InnerText;
                            acitem.time   = listtemp[1].Attributes[3].Value;
                            acitem.name   = HtmlHelp.NoHTML(listtemp[2].ChildNodes[1].InnerText);
                            acitem.beizhu = HtmlHelp.NoHTML(listtemp[3].InnerText);
                            list.Add(acitem);
                        }
                    }
                }
                indicator.IsVisible = false;
            }
            catch (WebException) { MessageBox.Show("网络不给力啊~"); }
            catch (Exception) { }
            indicator.IsVisible = false;
            return(list);
        }