Last active
August 29, 2015 13:56
-
-
Save DinisCruz/8915366 to your computer and use it in GitHub Desktop.
Scripts to fix broken links in TeamMentor.Net 2.0 and 3.5 libraries (after a number of articles were removed)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var otherHrefsFound = (Dictionary<string, List<Article_WS>> )_otherHrefsFound; | |
var okList = (Dictionary<string, List<Article_WS>> )_okList; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
var articlesToProcess = (List<Article_WS> )_articlesToProcess; | |
var stats = "{0} \n target: {1} \n # of articles: {2} \n - Other Href:{3}\n - OK: {4}\n- Not OK {5} ".format( | |
teamMentor.WebSite_Url.str(), target,articlesToProcess.size(), | |
otherHrefsFound.size(), okList.size(), notokList.size()); | |
return stats; | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var otherHrefsFound = (Dictionary<string, List<Article_WS>> )_otherHrefsFound; | |
var okList = (Dictionary<string, List<Article_WS>> )_okList; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
var articlesToProcess = (List<Article_WS> )_articlesToProcess; | |
var articleToFix = notokList.first(); | |
return articleToFix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var otherHrefsFound = (Dictionary<string, List<Article_WS>> )_otherHrefsFound; | |
var okList = (Dictionary<string, List<Article_WS>> )_okList; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
var articlesToProcess = (List<Article_WS> )_articlesToProcess; | |
var articleToFix = notokList.first(); | |
var link = articleToFix.Key; | |
var articles = articleToFix.Value; | |
return articles.first().content(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
var articleToFix = notokList.first(); | |
var link = articleToFix.Key; | |
var articles = articleToFix.Value; | |
var htmlDocument = articles.first() | |
.content() | |
.htmlDocument(); | |
return htmlDocument; | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
var articleToFix = notokList.first(); | |
var link = articleToFix.Key; | |
var articles = articleToFix.Value; | |
var htmlDocument = articles.first() | |
.content() | |
.htmlDocument(); | |
return htmlDocument.links().outerHtml(); | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
var articleToFix = notokList.first(); | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
//return "url: {0} text: {1}".format(brokenLinkUrl,brokenLinkText); | |
var articles = articleToFix.Value; | |
var htmlDocument = articles.first() | |
.content() | |
.htmlDocument(); | |
return htmlDocument.links().where( | |
(link)=> link.outerHtml().contains(brokenLinkUrl) && | |
link.innerHtml().contains(brokenLinkText)); | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() | |
: ""; | |
}; | |
var articleToFix = notokList.first(); | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
return getHtmlTextToRemove(articles.first().content(), | |
brokenLinkUrl, | |
brokenLinkText); | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() | |
: ""; | |
}; | |
var articleToFix = notokList.first(); | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
var targetHtml = articles.first().content(); | |
var htmlToRemove = getHtmlTextToRemove(targetHtml, | |
brokenLinkUrl, | |
brokenLinkText); | |
"test browser".popupWindow().add_WebBrowser() | |
.set_Text(targetHtml) | |
.insert_Below().add_SourceCodeEditor() | |
.set_Text(targetHtml); | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() + ":::" + linkToRemove.ParentNode.outerHtml() | |
: ""; | |
}; | |
var articleToFix = notokList.first(); | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
var targetHtml = articles.first().content(); | |
var htmlToRemove = getHtmlTextToRemove(targetHtml, | |
brokenLinkUrl, | |
brokenLinkText); | |
var popupWindow = "DataGrivView with links to remove".popupWindow(); | |
var dataGridView = popupWindow.add_DataGridView() | |
.add_Columns("Url To remove", | |
"Article Title to remove", | |
"Html to remove", | |
"Html to remove (Parent Node)"); | |
var foundLink = htmlToRemove.split(":::").first(); | |
var parentNode = htmlToRemove.split(":::").second(); | |
dataGridView.add_Row(brokenLinkUrl, brokenLinkText, foundLink, parentNode); | |
/*"test browser".popupWindow().add_WebBrowser() | |
.set_Text(targetHtml) | |
.insert_Below().add_SourceCodeEditor() | |
.set_Text(targetHtml);*/ | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() + ":::" + linkToRemove.ParentNode.outerHtml() | |
: ""; | |
}; | |
var popupWindow = "DataGrivView with links to remove".popupWindow(); | |
var dataGridView = popupWindow.add_DataGridView() | |
.add_Columns("Url To remove", | |
"Article Title to remove", | |
"Html to remove", | |
"Html to remove (Parent Node)"); | |
//var articleToFix = notokList.first(); | |
foreach(var articleToFix in notokList) | |
{ | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
foreach(var article in articles) | |
{ | |
var targetHtml = article.content(); | |
var htmlToRemove = getHtmlTextToRemove(targetHtml, | |
brokenLinkUrl, | |
brokenLinkText); | |
var foundLink = htmlToRemove.split(":::").first(); | |
var parentNode = htmlToRemove.split(":::").second(); | |
dataGridView.add_Row(brokenLinkUrl, brokenLinkText, foundLink, parentNode); | |
} | |
} | |
/*"test browser".popupWindow().add_WebBrowser() | |
.set_Text(targetHtml) | |
.insert_Below().add_SourceCodeEditor() | |
.set_Text(targetHtml);*/ | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() + ":::" + linkToRemove.ParentNode.outerHtml() | |
: ""; | |
}; | |
/*var popupWindow = "DataGrivView with links to remove".popupWindow(); | |
var dataGridView = popupWindow.add_DataGridView() | |
.add_Columns("Url To remove", | |
"Article Title to remove", | |
"Html to remove", | |
"Html to remove (Parent Node)"); | |
*/ | |
foreach(var articleToFix in notokList) | |
{ | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
foreach(var article in articles) | |
{ | |
var targetHtml = article.content(); | |
var htmlToRemove = getHtmlTextToRemove(targetHtml, | |
brokenLinkUrl, | |
brokenLinkText); | |
var foundLink = htmlToRemove.split(":::").first(); | |
var parentNode = htmlToRemove.split(":::").second(); | |
if (parentNode.split("<li>").size() >0 ) | |
return foundLink.line().line() + | |
parentNode.line().line() + | |
parentNode.tidyHtml(); | |
//dataGridView.add_Row(brokenLinkUrl, brokenLinkText, foundLink, parentNode); | |
} | |
} | |
/*"test browser".popupWindow().add_WebBrowser() | |
.set_Text(targetHtml) | |
.insert_Below().add_SourceCodeEditor() | |
.set_Text(targetHtml);*/ | |
//using O2.XRules.Database.Utils | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() + ":::" + linkToRemove.ParentNode.outerHtml() | |
: ""; | |
}; | |
var popupWindow = "DataGrivView with links to remove".popupWindow(); | |
var dataGridView = popupWindow.add_DataGridView() | |
.add_Columns("Url To remove", | |
"Article Title to remove", | |
"Html to remove (ParentNode)", | |
"Html to remove (Fixed)", | |
"Html to remove (size)"); | |
foreach(var articleToFix in notokList) | |
{ | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
foreach(var article in articles) | |
{ | |
var targetHtml = article.content(); | |
var htmlToRemove = getHtmlTextToRemove(targetHtml, | |
brokenLinkUrl, | |
brokenLinkText); | |
var foundLink = htmlToRemove.split(":::").first(); | |
var parentNode = htmlToRemove.split(":::").second(); | |
var liSplit = parentNode.split("<li>"); | |
if (liSplit.size() < 2 ) | |
continue; // this shouldn't really happen | |
if (liSplit.size() == 2 ) // scenario 1 : easy to handle , just remove parentNode | |
{ | |
htmlToRemove = parentNode; | |
//remove parentNode | |
} | |
else // scenario 2 : first last LI tag then remove foundLink from parentNode | |
{ | |
var withoutLastLITag = parentNode.subString(0, parentNode.indexLast("</li>")); | |
var withoutFoundLink = withoutLastLITag.subString_After(foundLink); | |
htmlToRemove = parentNode.remove(withoutFoundLink); | |
//return withoutFoundLink.line().line() + parentNode; | |
} | |
dataGridView.add_Row(brokenLinkUrl, brokenLinkText, parentNode, htmlToRemove, htmlToRemove.size()); | |
} | |
} | |
/*"test browser".popupWindow().add_WebBrowser() | |
.set_Text(targetHtml) | |
.insert_Below().add_SourceCodeEditor() | |
.set_Text(targetHtml);*/ | |
//using O2.XRules.Database.Utils | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() + ":::" + linkToRemove.ParentNode.outerHtml() | |
: ""; | |
}; | |
//var popupWindow = "DataGrivView with links to remove".popupWindow(); | |
/*var dataGridView = popupWindow.add_DataGridView() | |
.add_Columns("Url To remove", | |
"Article Title to remove", | |
"Html to remove (ParentNode)", | |
"Html to remove (Fixed)", | |
"Html to remove (size)"); | |
*/ | |
foreach(var articleToFix in notokList) | |
{ | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
foreach(var article in articles) | |
{ | |
var targetHtml = article.content(); | |
var htmlData = getHtmlTextToRemove(targetHtml, | |
brokenLinkUrl, | |
brokenLinkText); | |
var htmlToReplace = ""; | |
var htmlToReplaceWith = ""; | |
var foundLink = htmlData.split(":::").first(); | |
var parentNode = htmlData.split(":::").second(); | |
var liSplit = parentNode.split("<li>"); | |
if (liSplit.size() < 2 ) | |
continue; // this shouldn't really happen | |
if (liSplit.size() == 2 ) // scenario 1 : easy to handle , just remove parentNode | |
{ | |
htmlToReplace = parentNode; | |
htmlToReplaceWith = ""; | |
} | |
else // scenario 2 : first last LI tag then remove foundLink from parentNode | |
{ | |
var withoutLastLITag = parentNode.subString(0, parentNode.indexLast("</li>")); | |
var withoutFoundLink = withoutLastLITag.subString_After(foundLink); | |
htmlToReplace = parentNode; | |
htmlToReplaceWith = parentNode.remove(withoutFoundLink);; | |
//return withoutFoundLink.line().line() + parentNode; | |
} | |
"Replacing from article {0} with Title '{1}' the content '{2}' with '{3}".info( | |
article.Id, | |
article.Title, | |
htmlToReplace, | |
htmlToReplaceWith); | |
//check that htmlToReplace is there and htmlToReplaceWith is not there | |
if(targetHtml.contains(htmlToReplace).isFalse() ||targetHtml.contains(htmlToReplaceWith).isTrue() && htmlToReplaceWith.valid()) | |
return "Error on {0} with {1}".format(targetHtml , htmlToReplace); | |
// finally do the replacement | |
} | |
} | |
return "All Good"; | |
/*"test browser".popupWindow().add_WebBrowser() | |
.set_Text(targetHtml) | |
.insert_Below().add_SourceCodeEditor() | |
.set_Text(targetHtml);*/ | |
//using O2.XRules.Database.Utils | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teamMentor = (API_TeamMentor_WebServices)_teamMentor; | |
var target = (string)_target; | |
var notokList = (Dictionary<string, List<Article_WS>> )_notokList; | |
var targetArticles = (from articles in notokList.Values | |
from article in articles | |
select article).unique(); | |
foreach(var article in targetArticles) | |
article.Content = null; | |
//targetArticles.refreshContents(); | |
//return targetArticles.size(); | |
Func<string, string,string,string> getHtmlTextToRemove = | |
(htmlToSearch, url, text)=> | |
{ | |
var htmlDocument = htmlToSearch.htmlDocument(); | |
var linkToRemove = (from link in htmlDocument.links() | |
where link.outerHtml().contains(url) && | |
link.innerHtml().contains(text) | |
select link).first(); | |
return linkToRemove.notNull() | |
? linkToRemove.outerHtml() + ":::" + linkToRemove.ParentNode.outerHtml() | |
: ""; | |
}; | |
//var popupWindow = "DataGrivView with links to remove".popupWindow(); | |
/*var dataGridView = popupWindow.add_DataGridView() | |
.add_Columns("Url To remove", | |
"Article Title to remove", | |
"Html to remove (ParentNode)", | |
"Html to remove (Fixed)", | |
"Html to remove (size)"); | |
*/ | |
foreach(var articleToFix in notokList)//.take(5)) | |
{ | |
var articles = articleToFix.Value; | |
var brokenLinkUrl = articleToFix.Key.split(":::").first().trim(); | |
var brokenLinkText = articleToFix.Key.split(":::").second().trim(); | |
foreach(var article in articles) | |
{ | |
var targetHtml = article.content(); | |
var htmlData = getHtmlTextToRemove(targetHtml, | |
brokenLinkUrl, | |
brokenLinkText); | |
if(htmlData =="") | |
continue; | |
var htmlToReplace = ""; | |
var htmlToReplaceWith = ""; | |
var foundLink = htmlData.split(":::").first(); | |
var parentNode = htmlData.split(":::").second(); | |
var liSplit = parentNode.split("<li>"); | |
if (liSplit.size() < 2 ) | |
continue; // this shouldn't really happen | |
if (liSplit.size() == 2 ) // scenario 1 : easy to handle , just remove parentNode | |
{ | |
htmlToReplace = parentNode; | |
htmlToReplaceWith = ""; | |
} | |
else // scenario 2 : first last LI tag then remove foundLink from parentNode | |
{ | |
var withoutLastLITag = parentNode.subString(0, parentNode.indexLast("</li>")); | |
var withoutFoundLink = withoutLastLITag.subString_After(foundLink); | |
var afterFirstLI = "<li>" + withoutFoundLink.subString_After("<li>"); | |
htmlToReplace = parentNode; | |
htmlToReplaceWith = afterFirstLI; //parentNode.remove(withoutFoundLink);; | |
} | |
"Replacing from article {0} with Title '{1}' the content:\n '{2}' \n ** with:\n '{3}".info( | |
article.Id, | |
article.Title, | |
htmlToReplace, | |
htmlToReplaceWith); | |
//check that htmlToReplace is there and htmlToReplaceWith is not there | |
//if(targetHtml.contains(htmlToReplace).isFalse() ||targetHtml.contains(htmlToReplaceWith).isTrue() && htmlToReplaceWith.valid()) | |
// return "[Before replace] Error on {0} with {1}".format(targetHtml , htmlToReplace); | |
// finally do the replacement | |
var fixedHtml = targetHtml.replace(htmlToReplace, htmlToReplaceWith); | |
if(fixedHtml.contains(htmlToReplace).isTrue() ||fixedHtml.contains(htmlToReplaceWith).isFalse() && htmlToReplaceWith.valid()) | |
return "[After replace] Error on {0} with {1}".format(targetHtml , htmlToReplace); | |
//return "stop"; | |
article.content(fixedHtml); | |
// article.content(targetHtml); // use this to create a clean commit with the current line endings format | |
} | |
} | |
return "All Good"; | |
/*"test browser".popupWindow().add_WebBrowser() | |
.set_Text(targetHtml) | |
.insert_Below().add_SourceCodeEditor() | |
.set_Text(targetHtml);*/ | |
//using O2.XRules.Database.Utils | |
//using FluentSharp.For_HtmlAgilityPack | |
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll | |
//O2Ref:tmp6759.tmp | |
//using SecurityInnovation.TeamMentor; | |
//O2Tag_SetInvocationParametersToDynamic | |
//O2Ref:Microsoft.CSharp.dll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment