Esempio n. 1
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            bool isHomeLoaded = false;

            try
            {
                IEnumerable<HtmlNode> divNodes = RootNode.Descendants("div");
                int counter = 0;
                foreach (HtmlNode divNode in divNodes)
                {
                    if (divNode.Attributes.Contains("id") && divNode.Attributes["id"].Value == "mnpage_first")
                    {
                        if (counter == 3)
                        {
                            // because the mitbbs mobile home page is mal-formated
                            // we have to do some special handling for the hot boards
                            // section
                            //
                            ExtractHotBoardEntries(divNode);
                        }
                        else
                        {
                            HtmlNodeCollection listNodes = divNode.ChildNodes[1].ChildNodes;
                            for (int i = 0; i < listNodes.Count; i++)
                            {
                                HtmlNode listNode = listNodes[i];

                                if (listNode.Name == "li")
                                {
                                    MitbbsSimpleTopicLinkMobile topicLink = new MitbbsSimpleTopicLinkMobile();
                                    topicLink.ParentUrl = Url;

                                    if (topicLink.LoadFromHtml(listNode))
                                    {
                                        switch (counter)
                                        {
                                            case 0:
                                                TopArticles.Add(topicLink);
                                                break;
                                            case 1:
                                                HotArticles.Add(topicLink);
                                                break;
                                            case 2:
                                                RecommendedArticles.Add(topicLink);
                                                break;
                                        }
                                    }
                                }
                            }
                        }

                        counter++;

                        if (counter >= 4)
                        {
                            isHomeLoaded = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                loadedEventArgs.Error = e;
            }

            return isHomeLoaded;
        }
Esempio n. 2
0
        public bool LoadFromHtml(HtmlNode rootNode, DataLoadedEventArgs loadedArgs)
        {
            bool isUserHomeLoaded = false;

            try
            {
                IEnumerable<HtmlNode> divNodes = rootNode.Descendants("div");
                foreach (HtmlNode divNode in divNodes)
                {
                    if (divNode.Attributes["id"].Value == "wenzhangyudu")
                    {
                        HtmlNodeCollection liNodes = divNode.ChildNodes[1].ChildNodes;
                        for (int i = 0; i < liNodes.Count; i++)
                        {
                            HtmlNode liNode = liNodes[i];
                            if (liNode.Name == "li")
                            {
                                String bText = "";
                                IEnumerable<HtmlNode> bNodes = liNode.Descendants("b");
                                foreach (HtmlNode bNode in bNodes)
                                {
                                    bText = HtmlUtilities.GetPlainHtmlText(bNode.FirstChild.InnerText);
                                    break;
                                }

                                IEnumerable<HtmlNode> linkNodes = liNode.Descendants("a");

                                foreach (HtmlNode linkNode in linkNodes)
                                {
                                    String linkText = HtmlUtilities.GetPlainHtmlText(linkNode.FirstChild.InnerText);

                                    if (linkText == "站内邮箱")
                                    {
                                        MailboxUrl = linkNode.Attributes["href"].Value;
                                        isUserHomeLoaded = true;
                                    }
                                    else if(bText != "")
                                    {
                                        if (bText == "我的讨论区:")
                                        {
                                            MitbbsBoardLinkMobile boardLink = new MitbbsBoardLinkMobile();
                                            boardLink.ParentUrl = Url;
                                            if (boardLink.LoadFromHtml(linkNode))
                                            {
                                                MyBoards.Add(MitbbsBoardLink.CreateFromMobileLink(boardLink));
                                            }
                                        }
                                        else if (bText == "我的最新文章:")
                                        {
                                            MitbbsSimpleTopicLinkMobile topicLink = new MitbbsSimpleTopicLinkMobile();
                                            topicLink.ParentUrl = Url;
                                            if (topicLink.LoadFromHtml(linkNode))
                                            {
                                                MyArticles.Add(MitbbsSimpleTopicLink.CreateFromMobileLink(topicLink));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception e)
            {
                loadedArgs.Error = e;
            }

            return isUserHomeLoaded;
        }