private void BookmarkMenu_Click(object sender, EventArgs e)
        {
            if (App.Settings.IsUrlBookmarked(_topic.Url))
            {
                App.Settings.RemoveReadingBookMark(_topic.Url);
                (ApplicationBar.MenuItems[4] as ApplicationBarMenuItem).Text = "加入书签"; //bookmark menu
            }
            else
            {
                MitbbsLink topicLink;

                if (_fullPage)
                {
                    if (_club)
                    {
                        topicLink = new MitbbsClubTopicLink()
                        {
                            Name = _topic.Title,
                            Url = _topic.Url,
                        };
                    }
                    else
                    {
                        topicLink = new MitbbsTopicLink()
                        {
                            Name = _topic.Title,
                            Url = _topic.Url,
                        };
                    }
                }
                else
                {
                    topicLink = new MitbbsSimpleTopicLinkMobile()
                    {
                        Name = _topic.Title,
                        Url = _topic.Url,
                        BoardName = _topic.BoardName,
                    };
                }

                if (_offline)
                {
                    topicLink.OfflineID = _offlineID.ToString();
                }

                App.Settings.AddReadingBookMark(topicLink);
                (ApplicationBar.MenuItems[4] as ApplicationBarMenuItem).Text = "删除书签"; //bookmark menu
            }
        }
Exemple #2
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            try
            {
                CalculateEnBoardName();

                IEnumerable<HtmlNode> titleNodes = RootNode.Descendants("title");
                foreach (HtmlNode titleNode in titleNodes)
                {
                    String titleText = HtmlUtilities.GetPlainHtmlText(titleNode.FirstChild.InnerText);
                    Match match = Regex.Match(titleText, _titleTemplate);
                    if (match.Success)
                    {
                        BoardName = match.Groups[1].Value.Trim();
                        break;
                    }
                    else
                    {
                        return false;
                    }
                }

                bool headNodeFound = false;
                var headNodes = from tbNode in RootNode.Descendants("table")
                                where (tbNode.Attributes.Contains("class") && tbNode.Attributes["class"].Value == "jiahui-4")
                                select tbNode;

                foreach (HtmlNode headNode in headNodes)
                {
                    foreach (HtmlNode linkNode in headNode.Descendants("a"))
                    {
                        String linkText = linkNode.GetLinkText();
                        String linkUrl = linkNode.GetLinkUrl(Url);

                        if (linkText == "首页")
                        {
                            FirstPageUrl = linkUrl;
                            headNodeFound = true;
                        }
                        else if (linkText == "上页")
                        {
                            PrevPageUrl = linkUrl;
                            headNodeFound = true;
                        }
                        else if (linkText == "下页")
                        {
                            NextPageUrl = linkUrl;
                            headNodeFound = true;
                        }
                        else if (linkText == "末页")
                        {
                            LastPageUrl = linkUrl;
                            headNodeFound = true;
                        }
                        else if (linkUrl.Contains("mitbbs_postdoc.php"))
                        {
                            NewPostUrl = linkUrl;
                            headNodeFound = true;
                        }
                    }

                    if (headNodeFound)
                    {
                        IsLoaded = true;
                        break;
                    }
                }

                headNodeFound = false;
                headNodes = from tbNode in RootNode.Descendants("td")
                            where (tbNode.Attributes.Contains("class") && tbNode.Attributes["class"].Value == "news-bg")
                            select tbNode;

                foreach (HtmlNode headNode in headNodes)
                {
                    foreach (HtmlNode linkNode in headNode.Descendants("a"))
                    {
                        String linkText = linkNode.GetLinkText();
                        String linkUrl = linkNode.GetLinkUrl(Url);

                        if (linkText == "俱乐部" || linkText == "版面")
                        {
                            BoardPageUrl = linkUrl;
                        }
                        else if (linkText == "文摘区")
                        {
                            CollectionPageUrl = linkUrl;
                            headNodeFound = true;
                        }
                        else if (linkText == "保留区")
                        {
                            ReservePageUrl = linkUrl;
                            headNodeFound = true;
                        }
                        //else if (linkText == "精华区")
                        //{
                        //    EssensePageUrl = linkUrl;
                        //    headNodeFound = true;
                        //}
                    }

                    if (headNodeFound)
                    {
                        IsLoaded = true;
                        break;
                    }
                }

                foreach (HtmlNode linkNode in RootNode.Descendants("a"))
                {
                    MitbbsClubTopicLink topicLink = new MitbbsClubTopicLink();
                    topicLink.ParentUrl = Url;

                    if (topicLink.LoadFromHtml(linkNode))
                    {
                        if (IgnoreReadHistory)
                        {
                            topicLink.IsRead = false;
                        }

                        if (HideTopArticle && topicLink.IsOnTop)
                        {
                            TopTopicLinks.Add(topicLink);
                        }
                        else
                        {
                            TopicLinks.Add(topicLink);
                        }
                        IsLoaded = true;
                    }
                }
            }
            catch (Exception e)
            {
                loadedEventArgs.Error = e;
            }
            finally
            {
                if (IsLoaded)
                {
                    if (BoardPageUrl == null)
                    {
                    }
                    else if (CollectionPageUrl == null)
                    {
                        BoardName = BoardName + " (文摘区)";
                    }
                    else if (ReservePageUrl == null)
                    {
                        BoardName = BoardName + " (保留区)";
                    }
                }
            }

            return IsLoaded;
        }