protected void CheckNextItem()
        {
            _currentLink = null;
            while (_watchList.Count > 0)
            {
                _currentLink = _watchList[0];
                _watchList.RemoveAt(0);

                if (!_currentLink.HasNewContent)
                {
                    break;
                }
            }

            if (_currentLink != null && !String.IsNullOrEmpty(_currentLink.LastVisitedUrl))
            {
                if (DateTime.Now - _currentLink.AccessDate > TimeSpan.FromDays(5))
                {
                    OldContentDetected = true;
                }

                _topic.LoadFromUrl(_web, _currentLink.LastVisitedUrl);
            }
            else
            {
                DataLoadedEventArgs args = new DataLoadedEventArgs();

                if (CheckCompleted != null)
                {
                    CheckCompleted(this, args);
                }
            }
        }
        public void StartCheck(HtmlWeb web, List<MitbbsLink> watchList)
        {
            OldContentDetected = false;
            CheckIsSuccessful = false;

            _web = web;

            _watchList = new List<MitbbsLink>();
            foreach (var link in watchList)
            {
                _watchList.Add(link);
            }

            _currentLink = null;

            _topic = new MitbbsTopic();
            _topic.TopicLoaded += Topic_Loaded;

            CheckNextItem();
        }
Exemple #3
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;
        }
        private void InsertLink(MitbbsLink link, ObservableCollection<MitbbsLink> links)
        {
            if (!link.Name.EndsWith("*"))
            {
                link.Name += " *";
            }

            for (int i = 0; i < links.Count; i++)
            {
                if (link.Name == links[i].Name || link.Url == links[i].Url)
                {
                    return;
                }

                if (CompareBoardNames(link.Name, links[i].Name) < 0)
                {
                    links.Insert(i, link);
                    return;
                }
            }

            links.Add(link);
        }
 public void InsertMyBoard(MitbbsLink boardLink)
 {
     if (boardLink is MitbbsBoardLinkBase)
     {
         InsertLink(boardLink, MyBoards);
     }
     else if (boardLink is MitbbsClubLink)
     {
         InsertLink(boardLink, MyClubs);
     }
 }
        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;
        }