public void SearchResultMultiLine_ToString_EqualsExpected() { var settings = new SearchSettings(); settings.Colorize = false; var formatter = new SearchResultFormatter(settings); var pattern = new Regex("Search"); var searchFile = new SearchFile(CsSearchPath, "Searcher.cs", FileType.Text); const int lineNum = 10; const int matchStartIndex = 15; const int matchEndIndex = 23; const string line = "\tpublic class Searcher"; var linesBefore = new List <string> { "namespace CsSearch", "{" }; var linesAfter = new List <string> { "\t{", "\t\tprivate readonly FileTypes _fileTypes;" }; var searchResult = new SearchResult(pattern, searchFile, lineNum, matchStartIndex, matchEndIndex, line, linesBefore, linesAfter); var expectedPath = CsSearchPath + "/Searcher.cs"; var expectedOutput = string.Format(new string('=', 80) + "\n" + "{0}: {1}: [{2}:{3}]\n" + new string('-', 80) + "\n" + " 8 | namespace CsSearch\n" + " 9 | {{\n" + "> 10 | public class Searcher\n" + " 11 | {{\n" + " 12 | private readonly FileTypes _fileTypes;\n", expectedPath, lineNum, matchStartIndex, matchEndIndex); var output = formatter.Format(searchResult); Assert.AreEqual(expectedOutput, output); }
public static void Collect(string locationpath, string collectpath, string jobname, string computername, string configpath, string outputfilename) { string logfile = string.Format("{0}.{1}.txt", computername, jobname); string message = "Start Collect mode...."; WriteLog(configpath, logfile, message); dropfile(outputfilename); //string logfile=string.Format("{0}.{1}.txt", computername, jobname); List <string> files = SearchFile.Search(locationpath); using (StreamWriter text = new StreamWriter(configpath + outputfilename)) { if ((files != null) && (files.Any())) { text.WriteLine("ComputerName, FilePath, Collected"); foreach (string f in files) { string flag = null; FileInfo fileinfo = new FileInfo(f); string filename = fileinfo.Name; string dir = System.IO.Path.GetDirectoryName(f); string partdir = dir.ToString().Replace(":", ""); string finalpath = partdir.TrimEnd('\\'); string destpath = string.Format("{0}\\{1}\\{2}\\{3}", collectpath, jobname, computername, finalpath); string destFile = System.IO.Path.Combine(destpath, filename); //Console.WriteLine("the partdir is :{0}, the final dir is {1},the destpath is {2}", partdir, finalpath, destpath); CopyFile(filename, dir, destpath); if (File.Exists(destFile)) { Console.WriteLine("The file: {0} successfully been copied to the collect path: {1}", f, collectpath); flag = "Success"; } else { flag = "Failed"; } text.WriteLine("{0},\"{1}\",{2}", computername, f, flag); } } else { text.WriteLine("Search operaton completed but no .pst file being found"); } } CopyFile(outputfilename, configpath, collectpath); WriteLog(configpath, logfile, "Collect operation completed, please check output in the csv file"); }
public static void Find(string locationpath, string collectpath, string jobname, string computername, string configpath, string outputfilename) { string logfile = string.Format("{0}.{1}.txt", computername, jobname); string message = "Start Find mode...."; WriteLog(configpath, logfile, message); dropfile(outputfilename); List <string> files = SearchFile.Search(locationpath); using (StreamWriter text = new StreamWriter(configpath + outputfilename)) { if ((files != null) && (files.Any())) { text.WriteLine("ComputerName, FilePath"); foreach (string f in files) { //Console.WriteLine("File Found:{0}", f); text.WriteLine("{0},\"{1}\"", computername, f); } } else { text.WriteLine("Search operaton completed but no .pst file being found"); } } CopyFile(outputfilename, configpath, collectpath); WriteLog(configpath, logfile, "Find operation completed, please check output in the csv file"); }
public void SearchResultSingleLineLongerColorize_ToString_EqualsExpected() { var settings = new SearchSettings(); settings.MaxLineLength = 100; settings.Colorize = true; var formatter = new SearchResultFormatter(settings); var pattern = new Regex("maxlen"); var searchFile = new SearchFile(".", "maxlen.txt", FileType.Text); const int lineNum = 1; const int matchStartIndex = 53; const int matchEndIndex = 59; const string line = "0123456789012345678901234567890123456789012345678901maxlen8901234567890123456789012345678901234567890123456789"; var linesBeforeAfter = new List <string>(); var searchResult = new SearchResult(pattern, searchFile, lineNum, matchStartIndex, matchEndIndex, line, linesBeforeAfter, linesBeforeAfter); const string expectedPath = "./maxlen.txt"; var expectedLine = "...89012345678901234567890123456789012345678901" + Color.Green + "maxlen" + Color.Reset + "89012345678901234567890123456789012345678901..."; var expectedOutput = string.Format("{0}: {1}: [{2}:{3}]: {4}", expectedPath, lineNum, matchStartIndex, matchEndIndex, expectedLine); var output = formatter.Format(searchResult); Assert.AreEqual(expectedOutput, output); }
private void ImplementOfTask2() { writeReadOfData.Write("\n=====Implement Task2====\n"); SearchFile currentFile = new SearchFile(writeReadOfData, logger); currentFile.SearchFileInDirectories(); }
public void TestFilterFile_IsHidden_False() { var settings = GetSettings(); var searcher = new Searcher(settings); var file = new FileInfo(".gitignore"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.False(searcher.FilterFile(sf)); }
public void TestFilterFile_NoExtensionsNoPatterns_True() { var settings = GetSettings(); var searcher = new Searcher(settings); var file = new FileInfo("FileUtil.cs"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.True(searcher.FilterFile(sf)); }
public void TestFilterFile_ArchiveNoSearchArchives_False() { var settings = GetSettings(); var searcher = new Searcher(settings); var file = new FileInfo("archive.zip"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.False(searcher.FilterFile(sf)); }
public void TestIsArchiveSearchFile_NoExtensionsNoPatterns_True() { var settings = GetSettings(); var searcher = new Searcher(settings); var file = new FileInfo("archive.zip"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.True(searcher.IsArchiveSearchFile(sf)); }
public void TestFilterFile_NonArchiveFileArchivesOnly_False() { var settings = GetSettings(); settings.ArchivesOnly = true; var searcher = new Searcher(settings); var file = new FileInfo("FileUtil.cs"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.False(searcher.FilterFile(sf)); }
public void TestFilterFile_NotIsSearchFile_False() { var settings = GetSettings(); settings.AddOutExtension("cs"); var searcher = new Searcher(settings); var file = new FileInfo("FileUtil.cs"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.False(searcher.FilterFile(sf)); }
public void TestIsArchiveSearchFile_DoesNotMatchOutPattern_True() { var settings = GetSettings(); settings.AddOutArchiveFilePattern("archives"); var searcher = new Searcher(settings); var file = new FileInfo("archive.zip"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.True(searcher.IsArchiveSearchFile(sf)); }
public void TestIsArchiveSearchFile_MatchesOutExtension_False() { var settings = GetSettings(); settings.AddOutArchiveExtension("zip"); var searcher = new Searcher(settings); var file = new FileInfo("archive.zip"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.False(searcher.IsArchiveSearchFile(sf)); }
public void TestIsSearchFile_MatchesOutPattern_False() { var settings = GetSettings(); settings.AddOutFilePattern("Search"); var searcher = new Searcher(settings); var file = new FileInfo("Searcher.cs"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.False(searcher.IsSearchFile(sf)); }
public void TestIsSearchFile_DoesNotMatchOutExtension_True() { var settings = GetSettings(); settings.AddOutExtension("java"); var searcher = new Searcher(settings); var file = new FileInfo("FileUtil.cs"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.True(searcher.IsSearchFile(sf)); }
public void TestFilterFile_ArchiveFileArchivesOnly_True() { var settings = GetSettings(); settings.ArchivesOnly = true; var searcher = new Searcher(settings); var file = new FileInfo("archive.zip"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.True(searcher.FilterFile(sf)); }
/// <summary>Gets the gamemodes file.</summary> /// <returns></returns> public static FileInfo GetGamemodesFile() { if (LazerInstallationPath.TryGetRelativeFile(GamemodesFile, out FileInfo SearchFile)) { if (!SearchFile.Exists) { SearchFile.Create(); } return(SearchFile); } return(null); }
public void TestFilterFile_IsArchiveSearchFile_True() { var settings = GetSettings(); settings.SearchArchives = true; settings.AddInArchiveExtension("zip"); var searcher = new Searcher(settings); var file = new FileInfo("archive.zip"); var sf = new SearchFile(file, _fileTypes.GetFileType(file)); Assert.True(searcher.FilterFile(sf)); }