private static void ProcessError(string vsErrorType, string result) { cFile oFile = new cFile("error.txt"); oFile.Write("___________"); oFile.Write(vsErrorType + " Failed got back: " + result); oFile.Write("___________"); }
public List <string> IdentifyLinks(string vsfileName) { cFile oFile = new cFile("ExtractedLinks"); List <string> oLinks = new List <string>(); StreamReader sr = new StreamReader(vsfileName); string input; string pattern = @"<A[^>]*?HREF\s*=\s*""([^""]+)""[^>]*?>([\s\S]*?)<\/A>"; Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase); while (sr.Peek() >= 0) { input = sr.ReadLine(); MatchCollection matches = rgx.Matches(input); if (matches.Count > 0) { foreach (Match match in matches) { oLinks.Add(match.Value); oFile.Write(match.Value); } } } sr.Close(); return(oLinks); }
public bool WriteLinks() { cFile oFile = new cFile(msExportedLinkPath); try { string sOutput = "" + msUrlList[0]; //oFile.FileName = msExportedLinkPath; for (int i = 1; i < msUrlList.Count; i++) { sOutput += Environment.NewLine + msUrlList[i]; } oFile.Write(sOutput); Parallel.For(0, sFileList.Count, x => { oFile.FileName = sFileList[x]; oFile.Delete(); }); return(true); } catch (Exception ex) { oFile.WriteLog(ex.Message, "WriteLinksError.log"); return(false); throw ex; } }
public bool test3(string vsURL) { cWeb oWeb = new cWeb(); string htmlContent = oWeb.GrabPageToString(vsURL); // Obtain the document interface IHTMLDocument2 htmlDocument = (IHTMLDocument2) new mshtml.HTMLDocument(); // Construct the document htmlDocument.write(htmlContent); //htmlDocument. List <IHTMLElement> oOut = new List <IHTMLElement>(); // Extract all elements IHTMLElementCollection allElements = htmlDocument.all; cFile oFile = new cFile("ele.txt"); // Iterate all the elements and display tag names foreach (IHTMLElement element in allElements) { oFile.Write(element.tagName); } return(false); }
public bool ReadLinksFromHtmlFiles() { foreach (var sFile in oFilesList) { try { ReadHtmlFile(sFile); } catch (Exception ex) { cFile oFile = new cFile("error.log"); oFile.Write(sFile); oFile.Write(ex.Message); } } return(true); }
public void SaveLinks() { cFile oFile = new cFile(output); foreach (var sUrl in oUrListList) { oFile.Write(sUrl); } }
public bool Save(string vsFileName) { try { cFile oFiler = new cFile(vsFileName); oFiler.Write(mstrName + "|" + mstrFileName + "|" + mstrLinkDefine); return(true); } catch (Exception ex) { throw ex; } }
private void GetSummary(HtmlAgilityPack.HtmlDocument document) { //this simply works because InnerText is iterative for all child nodes HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("html/body/div[4]/div/div/table/tbody/tr/td/table/tbody/tr[1]/td/div[1]/text()"); //but to be more accurate you can use the next line instead //HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//td[@class='title']/a"); string result = ""; result = ""; if (GetData(nodes, ref result)) { oFFdotNetFic.Summary = result; } else { cFile oFile = new cFile("error.txt"); oFile.Write("___________"); oFile.Write("Summary Failed got back: " + result); oFile.Write("___________"); } }
public bool LoadLinksFromFileToList(string vsPath) { try { cFile oLogger = new cFile("Error.txt"); oLogger.Write("++++++++++++++++++++++++++"); oLogger.Write(vsPath); oLogger.Write("++++++++++++++++++++++++++"); cFile oFile = new cFile(vsPath); //oFile.FileName = ; string pattern = "\r\n|\n"; String sNewUrlList = oFile.Read(); string[] sTs = Regex.Split(sNewUrlList, pattern); foreach (string sT in sTs) { } for (int iCnt1 = 0; iCnt1 < sTs.Count(); iCnt1++) { oLogger.Write("-----" + iCnt1.ToString() + "-----"); string sUrl1 = sTs[iCnt1]; oLogger.Write(sUrl1); oLogger.Write("-----" + iCnt1.ToString() + "-----"); CheckLink(sUrl1); } return(true); } catch (Exception ex) { throw ex; } //throw new NotImplementedException(); }
public bool LoadLinksFromFile(string vsPath) { try { cFile oLogger = new cFile("Error.txt"); oLogger.Write("++++++++++++++++++++++++++"); oLogger.Write(vsPath); oLogger.Write("++++++++++++++++++++++++++"); cFile oFile = new cFile(vsPath); //oFile.FileName = ; List <String> sNewUrlList = oFile.ReadList(); for (int iCnt1 = 0; iCnt1 < sNewUrlList.Count(); iCnt1++) { oLogger.Write("-----" + iCnt1.ToString() + "-----"); string sUrl1 = sNewUrlList[iCnt1]; oLogger.Write(sUrl1); oLogger.Write("-----" + iCnt1.ToString() + "-----"); if (sUrl1.Length >= 28) { sUrl1 = FixFFdotNet(sUrl1); } if (sUrl1.Length >= 5) { msUrlList.Add(sUrl1);; } } return(true); } catch (Exception ex) { throw ex; } //throw new NotImplementedException(); }
public bool Load() { if (File.Exists(msFileName)) { string[] oLinkCatRecord = null; cFile oFile = new cFile(msFileName); try { string sInput = oFile.Read(); // oLinkCatRecord = sInput.Split(Convert.ToChar(Constants.vbCrLf)); oLinkCatRecord = sInput.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string linkRow in oLinkCatRecord) { if (linkRow.Trim().Length > 3) { // Process a student record cLinkCategory oLinkCategory = new cLinkCategory(); string[] sLinkFields = null; sLinkFields = linkRow.Split('|'); var _with3 = oLinkCategory; _with3.Name = sLinkFields[0]; _with3.FileName = sLinkFields[1]; _with3.LinkDefine = sLinkFields[2]; oCatagories.Add(oLinkCategory); // Add(oLinkCategory); } } return(true); } catch (Exception ex) { //MessageBox.Show(ex.Message); cFile oLog = new cFile("error.log"); oLog.Write(ex.Message); } } else { File.Create("LinkCategories.txt"); Load(); } return(false); }
private void GetAuthor(HtmlAgilityPack.HtmlDocument document) { throw new NotImplementedException(); //this simply works because InnerText is iterative for all child nodes HtmlAgilityPack.HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("Date XPath"); //but to be more accurate you can use the next line instead //HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//td[@class='title']/a"); string result = ""; result = ""; if (GetData(nodes, ref result)) { //oFFdotNetFic.ChapterText oFFdotNetFic.LastUpdated1 = result; } else { cFile oFile = new cFile("error.txt"); oFile.Write("___________"); oFile.Write("LastUpdated1 Failed got back: " + result); oFile.Write("___________"); } }
private bool GetData(HtmlNodeCollection nodes, ref string result) { List <string> results = new List <string>(); foreach (HtmlNode item in nodes) { results.Add(item.InnerText); result = item.InnerText; cFile oFile = new cFile("nodes.txt"); oFile.Write("___________"); oFile.Write(item.XPath.ToString()); oFile.Write(result); oFile.Write("___________"); } if (results.Count == 1) { result = results[0].ToString(); return(true); } return(false); throw new NotImplementedException(); }
private async Task GetLinkValues(string folder, cFile oFile) { List <Task> oTasks = new List <Task>(); foreach (string fileName in Directory.GetFiles(folder, "*.txt", SearchOption.AllDirectories)) { Task oTask = ProcessFile(fileName); oTask.Start(); lblOutput.Text = fileName; oTasks.Add(oTask); oFile.Write(fileName); //SQLGenerator.GenerateSQLTransactions(Path.GetFullPath(fileName)); } await oTasks[0]; }
public bool SaveLinks(string vsFilePath) { try { var oFile = new cFile(vsFilePath); foreach (var sUrl in oUrListList) { oFile.Write(sUrl); } } catch (Exception) { return(false); } return(true); }
private void importSortTextFileLinks() { cFile oFile = new cFile("FilesLoaded"); try { string startupPath = Application.StartupPath; using (FolderBrowserDialog dialog = new FolderBrowserDialog()) { dialog.Description = "Open a folder which contains the xml output"; // dialog.ShowNewFolderButton = false; // dialog.RootFolder = Environment.SpecialFolder.MyComputer; if (dialog.ShowDialog() == DialogResult.OK) { string folder = dialog.SelectedPath; lblOutput.Text = dialog.SelectedPath; foreach (string fileName in Directory.GetFiles(folder, "*.txt", SearchOption.AllDirectories)) { oTool.ExportedLinkPath = "Input.txt"; List <string> sUrls = oTool.GetLinksFromFile(fileName); oTool.WriteLinks(sUrls); oTool.AddUrlList(sUrls); oFile.Write(fileName); //SQLGenerator.GenerateSQLTransactions(Path.GetFullPath(fileName)); } oTool.Sort(); } } //using (OpenFileDialog dialog = new OpenFileDialog()) //{ // dialog.Filter = "xml files (*.xml)|*.xml"; // dialog.Multiselect = false; // dialog.InitialDirectory = "."; // dialog.Title = "Select file (only in XML format)"; // if (dialog.ShowDialog() == DialogResult.OK) // { // SQLGenerator.GenerateSQLTransactions(Application.StartupPath + Settings.Default.xmlFile); // } //} lblOutput.Text = "done"; } catch (Exception exc) { MessageBox.Show("Import failed because " + exc.Message + " , please try again later."); } }
public void writeChildren(HtmlNode vNode) { cFile oFile = new cFile("nodes.txt"); foreach (HtmlNode link in vNode.ChildNodes) { oFile.Write("--"); oFile.Write("-----------------------------"); oFile.Write("-----------------------------"); oFile.Write("--"); oFile.Write(link.Name.ToString()); oFile.Write(link.XPath.ToString()); oFile.Write(link.InnerHtml); // writeChildren(link); } }
public bool WriteLinks() { try { cFile oFile = new cFile(msExportedLinkPath); //oFile.FileName = msExportedLinkPath; for (int iCnt = 0; iCnt < msUrlList.Count(); iCnt++) { oFile.Write(msUrlList[iCnt]); } return(true); } catch (Exception ex) { return(false); throw ex; } }
private Task ProcessFile(string fileName) { cFile oFile = new cFile("log"); // use await here, like so Task task = new Task(() => { try { cUrlTool voTool = new cUrlTool(); voTool.GetLinksFromFile(fileName); voTool.WriteLinks(); } catch (Exception ex) { oFile.Write(ex.Message); } }); //Task<List<String>> voTask = new Task<List<String>>(() => GetLinksFromFile(vsFilepath)); return(task); }
public bool ReadWriteHtmlFile(string vsFile) { //Read bookmarks from file try { cFile oFile = new cFile(vsFile); cFile oWrite = new cFile("out.txt"); cFile oLog = new cFile("log.log"); var bookmarks = oHtmlReader.Read(oFile.ReadFileStream()); foreach (var b in bookmarks.AllLinks) { oWrite.Write(b.Url); } oLog.Write(vsFile); } catch (Exception) { return(false); } return(true); }