示例#1
0
        private void DoUpdate()
        {
            NewFilesList.Clear();
            List <string> lstLinks = new List <string>();

            HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
            WebRequest request = WebRequest.Create(HTMLLink);

            htmlDocument.Load(request.GetResponse().GetResponseStream());
            string             buildNewLink = null;
            bool               moveToRoot   = false;
            HtmlNodeCollection links        = htmlDocument.DocumentNode.SelectNodes("//a");

            foreach (HtmlNode link in links)
            {
                HtmlAttribute att = link.Attributes["href"];

                if (att == null)
                {
                    continue;
                }
                string newLink = att.Value;
                if (!MatchUpdateSign(newLink))
                {
                    continue;
                }
                if (!newLink.StartsWith("http://"))
                {
                    if (newLink.StartsWith("/"))
                    {
                        newLink    = newLink.Remove(0, 1);
                        moveToRoot = true;
                    }
                    if (newLink.StartsWith("wenxue"))
                    {
                        newLink = newLink.Substring(newLink.LastIndexOf("/") + 1);
                    }

                    if (!moveToRoot)
                    {
                        buildNewLink = HTMLLink.Substring(0, HTMLLink.LastIndexOf("/") + 1) + newLink;
                    }
                    else
                    {
                        buildNewLink = HTMLLink.Substring(0, HTMLLink.IndexOf("/", 7) + 1) + newLink;
                        moveToRoot   = false;
                    }
                }
                else
                {
                    buildNewLink = newLink;
                }

                if (!FilesList.Contains(buildNewLink))
                {
                    NewFilesList.Add(buildNewLink);
                }
            }

            if (SortBeforeDownload)
            {
                NewFilesList = DoSort(NewFilesList);
            }
            PreviousStepCount = GetPreviousStepCount();
        }
示例#2
0
        private void DoUpdate()
        {
            NewFilesList.Clear();
            NewChapterNamesList.Clear();
            List <string> lstLinks = new List <string>();

            //Trust all certificates
            System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
            WebRequest request = WebRequest.Create(HTMLLink);

            htmlDocument.Load(request.GetResponse().GetResponseStream(), ContentEncoding);
            string             buildNewLink = null;
            bool               moveToRoot   = false;
            HtmlNodeCollection links        = htmlDocument.DocumentNode.SelectNodes("//a");

            foreach (HtmlNode link in links)
            {
                HtmlAttribute att = link.Attributes["href"];

                if (att == null)
                {
                    continue;
                }
                string newLink = att.Value;
                if (!MatchUpdateSign(newLink))
                {
                    continue;
                }
                if (!newLink.StartsWith("http://") && !newLink.StartsWith("https://"))
                {
                    if (newLink.StartsWith("/"))
                    {
                        newLink    = newLink.Remove(0, 1);
                        moveToRoot = true;
                    }
                    if (newLink.StartsWith("wenxue"))
                    {
                        newLink = newLink.Substring(newLink.LastIndexOf("/") + 1);
                    }

                    if (!moveToRoot)
                    {
                        buildNewLink = HTMLLink.Substring(0, HTMLLink.LastIndexOf("/") + 1) + newLink;
                    }
                    else
                    {
                        int startPoint = HTMLLink.StartsWith("https") ? 8 : 7;
                        buildNewLink = HTMLLink.Substring(0, HTMLLink.IndexOf("/", startPoint) + 1) + newLink;
                        moveToRoot   = false;
                    }
                }
                else
                {
                    buildNewLink = newLink;
                }

                if (!FilesList.Contains(buildNewLink))
                {
                    NewFilesList.Add(buildNewLink);
                    NewChapterNamesList.Add(GetUTF8Content(HTMLLink, link.InnerHtml, ContentEncoding));
                }
            }

            if (SortBeforeDownload)
            {
                NewFilesList = DoSort(NewFilesList);
            }
            PreviousStepCount = GetPreviousStepCount();
        }