public void Find(List <string> files, string TheWord) { int allresult = 0; foreach (string file in files) { CanBeOpen canBeOpen = FormatIs(file); if (canBeOpen.TakeCanI()) { WriteInFile("Start reading file: " + file, true); answer answ = ToOpener(file, canBeOpen.TakeFormat(), TheWord); if (answ.ResultCount() == 0) { WriteInFile("result not found.", false); } else { allresult += answ.ResultCount(); WriteInFile("found " + answ.ResultCount().ToString() + " results", false); foreach (var result in answ.AllResultsData()) { WriteInFile(result, true); } } } else { WriteInFile("File have wrong format: " + file, true); } WriteInFile("", true); } }
private answer ToOpener(string path, string format, string TheWord) { answer thisansw = new answer(); if (format == acceptFormats[0] || format == acceptFormats[1])//.txt .tex { Easyread(thisansw, path, TheWord); } else if (format == acceptFormats[2]) //.pdf { PdfReader(thisansw, path, TheWord); } return(thisansw); }
public void Find(List <string> files, string TheWord, string path) { int allresult = 0; WriteInFile("Find:" + TheWord, true); WriteInFile("Source:" + path, true); foreach (string file in files) { CanBeOpen canBeOpen = FormatIs(file); if (canBeOpen.TakeCanI()) { answer answ = ToOpener(file, canBeOpen.TakeFormat(), TheWord); if (answ.ResultCount() == 0) { //WriteInFile("result not found.", false); } else { WriteInFile("-----", true); WriteInFile("In file: " + file.Substring(path.Length), true); allresult += answ.ResultCount(); //WriteInFile("found " + answ.ResultCount().ToString() + " results", false); foreach (var result in answ.AllResultsData()) { WriteInFile(result, true); } WriteInFile("", true); } } else { //WriteInFile("File have wrong format: " + file, true); } //WriteInFile("", true); } WriteInFile("Results:" + allresult, true); }
private void Easyread(answer thisansw, string path, string TheWord) { try { if (File.ReadAllText(path).Contains(TheWord)) { string AllData = File.ReadAllText(path); AllData = GetClean(AllData); foreach (Match mtch in Regex.Matches(AllData, TheWord)) { takesting tkstr = new takesting(); GetIndexs(tkstr, mtch, AllData); string answ = AllData.Substring(tkstr.GetStarti(), tkstr.GetLasti()); thisansw.addResult(answ); } } } catch (Exception) { WriteInFile("ERROR:" + path, true); throw; } }//txt, tex
}//txt, tex private void PdfReader(answer thisansw, string path, string TheWord) { try { /* * if (File.ReadAllText(path).Contains(TheWord)) * { * string AllData = File.ReadAllText(path); * AllData = GetClean(AllData); * foreach (Match mtch in Regex.Matches(AllData, TheWord)) * { * takesting tkstr = new takesting(); * GetIndexs(tkstr, mtch, AllData); * string answ = AllData.Substring(tkstr.GetStarti(), tkstr.GetLasti()); * thisansw.addResult(answ); * } * }*/ } catch (Exception) { WriteInFile("ERROR:" + path, true); throw; } }//pdf