예제 #1
0
        private void parse_TopicIndex(object sender, HtmlDocumentLoadCompleted e)
        {
            if (e.Document != null)
            {
                IList<HtmlNode> hnc = e.Document.DocumentNode.DescendantNodes().ToList();

                foreach (HtmlNode node in hnc)
                {
                    if (node.Name.ToLower() == "h2")
                    {
                        TalkOriginsTopicCategoryViewModel t = new TalkOriginsTopicCategoryViewModel();

                        foreach (HtmlNode i in node.DescendantNodes().ToList())
                        {
                            if (i.Name.ToLower() == "a" && i.Attributes.Count > 0)
                            {
                                if (i.Attributes[0].Name.ToLower() == "name")
                                {
                                    t.CategoryShort = i.Attributes[0].Value;
                                }
                            }
                            else if (i.Name.ToLower() == "#text" && i.InnerText != t.CategoryShort)
                            {

                                t.Topic = i.InnerText.Replace(":", "").Trim();

                            }
                        }
                        if (node.NextSibling != null && node.NextSibling.Name.ToLower() == "ul")
                        {
                            foreach (HtmlNode ul in node.NextSibling.DescendantNodes().ToList())
                            {
                                if (ul.Name.ToLower() == "a" && ul.Attributes.Count > 0 && ul.Attributes[0].Name.ToLower() == "href")
                                {
                                    TalkOriginsTopicViewModel totvm = new TalkOriginsTopicViewModel();
                                    totvm.Title = ul.InnerText;
                                    totvm.Href = ul.Attributes[0].Value;
                                    t.TOTopics.Add(totvm);
                                }
                            }
                        }
                        TOCategoryTopics.Add(t);
                    }
                }
            }
            this.IsDataLoaded = true;
            NotifyPropertyChanged("TopicsRetrived");
        }
예제 #2
0
        public void LoadTopicData()
        {
            TOCategoryTopics.Clear();
            if (this.ICTOStarred.Count == 0)
            {
                IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
                if (settings.Contains(STARREDITEMS))
                {

                    ObservableCollection<StarredItems> list = (ObservableCollection<StarredItems>)settings[STARREDITEMS];
                    if (list != null && list.Count > 0)
                    {

                        foreach (StarredItems si in list)
                        {
                            this.ICTOStarred.Add(si);
                        }
                        NotifyPropertyChanged("StarredItemsLoaded");
                    }
                }
            }
            if (DeviceNetworkInformation.IsNetworkAvailable)
            {
                HtmlWeb webGet = new HtmlWeb();
                webGet.LoadCompleted += parse_TopicIndex;
                webGet.LoadAsync(Url_TOTopics);
            }
            else
            {
                TalkOriginsTopicCategoryViewModel t = new TalkOriginsTopicCategoryViewModel();
                t.Topic = "Data connection error, tap here to reload Topics";
                TOCategoryTopics.Add(t);
                NotifyPropertyChanged("TopicsRetrived");
            }
        }