Exemplo n.º 1
0
        public static MitbbsLink CreateLinkInstance(HtmlNode rootNode, String ParentUrl)
        {
            MitbbsLink generalLink = new MitbbsLink();
            MitbbsLink linkInstance = null;

            if (!generalLink.LoadFromHtml(rootNode))
            {
                return null;
            }

            String url = generalLink.Url;

            if (url.StartsWith(_boardEssenceUrlPrefix))
            {
                linkInstance = new MitbbsBoardEssenceLink();
            }
            else if (url.StartsWith(_topicEssenceUrlPrefix))
            {
                linkInstance = new MitbbsTopicEssenceLink();
            }
            else if (url.StartsWith(_boardGroupUrlPrefix))
            {
                linkInstance = new MitbbsBoardGroupLink();
            }
            else if (url.StartsWith(_boardUrlPrefix))
            {
                linkInstance = new MitbbsBoardLinkMobile();
            }
            else if (url.StartsWith(_topicUrlPrefix))
            {
                linkInstance = new MitbbsSimpleTopicLinkMobile();
            }
            else
            {
                return null;
            }

            linkInstance.ParentUrl = ParentUrl;
            if (!linkInstance.LoadFromHtml(rootNode))
            {
                return null;
            }

            if (linkInstance is MitbbsBoardLinkMobile)
            {
                linkInstance = MitbbsBoardLink.CreateFromMobileLink(linkInstance as MitbbsBoardLinkMobile);
            }

            return linkInstance;
        }
Exemplo n.º 2
0
        public override bool LoadFromHtml(HtmlNode RootNode, DataLoadedEventArgs loadedEventArgs)
        {
            try
            {
                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)
                    {
                        ClubGroupName = match.Groups[1].Value;
                        break;
                    }
                    else
                    {
                        return false;
                    }
                }

                IEnumerable<HtmlNode> linkNodes = RootNode.Descendants("a");
                foreach (HtmlNode linkNode in linkNodes)
                {
                    MitbbsLink link = new MitbbsLink();
                    if (link.LoadFromHtml(linkNode))
                    {
                        if (link.Url.StartsWith(_pageNavUrlPrefix))
                        {
                            if (link.Name == "首页")
                            {
                                FirstPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, ParseJsUrl(link.Url));
                            }
                            else if (link.Name == "上页")
                            {
                                PrevPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, ParseJsUrl(link.Url));
                            }
                            else if (link.Name == "下页")
                            {
                                NextPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, ParseJsUrl(link.Url));
                            }
                            else if (link.Name == "末页")
                            {
                                LastPageUrl = HtmlUtilities.GetAbsoluteUrl(Url, ParseJsUrl(link.Url));
                            }

                            IsLoaded = true;
                        }
                        else
                        {
                            MitbbsClubLink clubLink = new MitbbsClubLink();
                            clubLink.ParentUrl = Url;

                            if (clubLink.LoadFromHtml(linkNode))
                            {
                                ClubLinks.Add(clubLink);
                                IsLoaded = true;
                            }
                        }
                    }

                }
            }
            catch (Exception e)
            {
                IsLoaded = false;
                loadedEventArgs.Error = e;
            }

            return IsLoaded;
        }