Ejemplo n.º 1
0
 private void CheckLinkValid(string url, bool isPageAdmin = false)
 {
     try
     {
         if (!string.IsNullOrEmpty(url) && !UrlChecked.Contains(url))
         {
             if (!isPageAdmin && (ListLinkNotValid.Count + ListLinkValid.Count) == 20)
             {
                 return;
             }
             UrlChecked.Add(url);
             HtmlWeb web = new HtmlWeb();
             HtmlAgilityPack.HtmlDocument doc = web.Load(url);
             if (doc != null && doc.DocumentNode != null)
             {
                 var itemCheck = new ValidateLink();
                 itemCheck.ItemLink = url;
                 var itemId = doc.DocumentNode.SelectSingleNode("//article").GetAttributeValue("id", "0");
                 itemCheck.ItemId   = int.Parse(itemId.Replace("post-", ""));
                 itemCheck.ItemName = doc.DocumentNode.SelectSingleNode("//h1[@class='entry-title']").InnerHtml;
                 var linkPrevious = doc.DocumentNode.SelectSingleNode("//div[@class='nav-previous']//a");
                 if (linkPrevious != null)
                 {
                     itemCheck.LinkPrevious = linkPrevious.GetAttributeValue("href", "Not found");
                 }
                 var linkNext = doc.DocumentNode.SelectSingleNode("//div[@class='nav-next']//a");
                 if (linkNext != null)
                 {
                     itemCheck.LinkNext = linkNext.GetAttributeValue("href", "Not found");
                 }
                 var tagA = doc.DocumentNode.SelectSingleNode("//div[@class='entry-content']//a");
                 itemCheck.HrefLinkCheck = tagA.GetAttributeValue("href", "Not found");
                 itemCheck.NameLinkCheck = tagA.InnerHtml;
                 doc = web.Load(itemCheck.HrefLinkCheck);
                 var strHtml = doc.DocumentNode.SelectSingleNode("//head/title").InnerHtml;
                 if (strHtml.Contains(CommonConstants.TitleError))
                 {
                     itemCheck.IsValid = false;
                     ListLinkNotValid.Add(itemCheck);
                 }
                 else
                 {
                     itemCheck.IsValid = true;
                     ListLinkValid.Add(itemCheck);
                 }
                 if (!isPageAdmin && (ListLinkNotValid.Count + ListLinkValid.Count) <= 20)
                 {
                     CheckLinkValid(itemCheck.LinkPrevious);
                     CheckLinkValid(itemCheck.LinkNext);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 2
0
 private void CheckLinkValidAdminPage(string url)
 {
     try
     {
         if (!string.IsNullOrEmpty(url) && !UrlChecked.Contains(url))
         {
             UrlChecked.Add(url);
             browser.Load(url);
             Thread.Sleep(5000);
             string strHtml = GetHTMLFromWebBrowser();
             HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
             doc.LoadHtml(strHtml);
             if (doc != null && doc.DocumentNode != null)
             {
                 var textArea = doc.DocumentNode.SelectSingleNode("//textarea[@class='wp-editor-area']").InnerHtml;
                 textArea = textArea.Replace("&lt;", "<").Replace("&gt;", ">");
                 doc.LoadHtml(textArea);
                 var     listTagA = doc.DocumentNode.SelectNodes("//a").ToList();
                 HtmlWeb web      = new HtmlWeb();
                 foreach (var tagA in listTagA)
                 {
                     var itemCheck = new ValidateLink();
                     itemCheck.ItemLink = url;
                     //itemCheck.ItemName = itemName;
                     //itemCheck.ItemId = IdItem;
                     var href = tagA.GetAttributeValue("href", "Not found");
                     if (href.ToLower().Contains("rapidgator"))
                     {
                         itemCheck.HrefLinkCheck = href;
                         itemCheck.NameLinkCheck = tagA.InnerHtml;
                         doc = web.Load(itemCheck.HrefLinkCheck);
                         var strHtmlRapidgator = doc.DocumentNode.SelectSingleNode("//head/title").InnerHtml;
                         if (strHtmlRapidgator.Contains(CommonConstants.TitleError))
                         {
                             itemCheck.IsValid = false;
                             ListLinkNotValid.Add(itemCheck);
                         }
                         else
                         {
                             itemCheck.IsValid = true;
                             ListLinkValid.Add(itemCheck);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
 private void CheckLinkValid(string url)
 {
     try
     {
         if (!string.IsNullOrEmpty(url) && !UrlChecked.Contains(url))
         {
             UrlChecked.Add(url);
             HtmlWeb web = new HtmlWeb();
             HtmlAgilityPack.HtmlDocument doc = web.Load(url);
             if (doc != null && doc.DocumentNode != null)
             {
                 var itemId   = doc.DocumentNode.SelectSingleNode("//article").GetAttributeValue("id", "0");
                 var IdItem   = int.Parse(itemId.Replace("post-", ""));
                 var itemName = doc.DocumentNode.SelectSingleNode("//h1[@class='entry-title ']").InnerHtml;
                 //var tagA = doc.DocumentNode.SelectSingleNode("//div[@class='entry-content']//a");
                 var ListTagA = doc.DocumentNode.SelectNodes("//div[@class='entry-content']//a").ToList();
                 foreach (var tagA in ListTagA)
                 {
                     var itemCheck = new ValidateLink();
                     itemCheck.ItemLink = url;
                     itemCheck.ItemName = itemName;
                     itemCheck.ItemId   = IdItem;
                     var href = tagA.GetAttributeValue("href", "Not found");
                     if (href.ToLower().Contains("rapidgator"))
                     {
                         itemCheck.HrefLinkCheck = href;
                         itemCheck.NameLinkCheck = tagA.InnerHtml;
                         doc = web.Load(itemCheck.HrefLinkCheck);
                         var strHtml = doc.DocumentNode.SelectSingleNode("//head/title").InnerHtml;
                         if (strHtml.Contains(CommonConstants.TitleError))
                         {
                             itemCheck.IsValid = false;
                             ListLinkNotValid.Add(itemCheck);
                         }
                         else
                         {
                             itemCheck.IsValid = true;
                             ListLinkValid.Add(itemCheck);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }