public FolderToWatermark(string folderPath, CodeCommentSymbols codeComments, Watermark mark) { if (String.IsNullOrEmpty(folderPath)) { throw new Exception("Folder path is empty"); } if (!Directory.Exists(folderPath)) { throw new Exception("Folder path does not exist"); } if (codeComments == null) { throw new Exception("No code comment symbols are available"); } if (mark == null) { throw new Exception("No watermark is available"); } _codeComments = codeComments; _folderPath = folderPath; _mark = mark; ReadFilesInsideFolder(); }
public void SettingsFileOneWithExtraSpaces() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\CommentSymbols-1-ExtraSpaces.txt"); Assert.AreEqual(1, fileSettings.CommentSymbols.Count()); Assert.IsNotNull(fileSettings.CommentSymbols[".css"]); Assert.AreEqual("/*", fileSettings.CommentSymbols[".css"].Item1); Assert.AreEqual("*/", fileSettings.CommentSymbols[".css"].Item2); }
public void SomeFilesInFolder() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\FolderToWaterMark\\CommentSymbols.txt"); FolderToWatermark folderToMark = new FolderToWatermark(Environment.CurrentDirectory + "\\..\\..\\Ressources\\FolderToWaterMark\\SomeFilesToRead", fileSettings, mark); Assert.AreEqual(3, folderToMark.FilesToProcessCount); Assert.AreEqual(0, folderToMark.FilesProcessedCount); }
public void SettingsFileExtraEmptyLines() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\CommentSymbols-ExtraEmptyLines.txt"); Assert.AreEqual(6, fileSettings.CommentSymbols.Count()); Assert.IsNotNull(fileSettings.CommentSymbols[".master"]); Assert.AreEqual(fileSettings.CommentSymbols[".master"].Item1, "<%--"); Assert.AreEqual(fileSettings.CommentSymbols[".master"].Item2, "--%>"); }
public void SettingsFileTabsBetweenItems() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\CommentSymbols-Tabs.txt"); Assert.AreEqual(2, fileSettings.CommentSymbols.Count()); Assert.IsNotNull(fileSettings.CommentSymbols[".css"]); Assert.AreEqual(fileSettings.CommentSymbols[".css"].Item1, "/*"); Assert.AreEqual(fileSettings.CommentSymbols[".css"].Item2, "*/"); Assert.IsNotNull(fileSettings.CommentSymbols[".cs"]); Assert.AreEqual(fileSettings.CommentSymbols[".cs"].Item1, "//"); Assert.AreEqual(fileSettings.CommentSymbols[".cs"].Item2, String.Empty); }
public FolderToWatermark(string folderPath, CodeCommentSymbols codeComments, Watermark mark) { if (String.IsNullOrEmpty(folderPath)) throw new Exception("Folder path is empty"); if (!Directory.Exists(folderPath)) throw new Exception("Folder path does not exist"); if (codeComments == null) throw new Exception("No code comment symbols are available"); if (mark == null) throw new Exception("No watermark is available"); _codeComments = codeComments; _folderPath = folderPath; _mark = mark; ReadFilesInsideFolder(); }
public void WatermarkValidFiles() { // Copy non watermarked files over foreach (var file in Directory.GetFiles(Environment.CurrentDirectory + "\\..\\..\\Ressources\\FolderToWaterMark\\SomeFilesToRead")) File.Copy(file, Path.Combine(Environment.CurrentDirectory + "\\..\\..\\Ressources\\FolderToWaterMark\\SomeFilesToWatermark", Path.GetFileName(file)), true); CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\FolderToWaterMark\\CommentSymbols.txt"); FolderToWatermark folderToMark = new FolderToWatermark(Environment.CurrentDirectory + "\\..\\..\\Ressources\\FolderToWaterMark\\SomeFilesToWatermark", fileSettings, mark); Assert.AreEqual(3, folderToMark.FilesToProcessCount); Assert.AreEqual(0, folderToMark.FilesProcessedCount); folderToMark.WaterMarkFiles(); //Assert.AreEqual(0, folderToMark.FilesToProcessCount); //Assert.AreEqual(3, folderToMark.FilesProcessedCount); //Assert.AreNotEqual(0, folderToMark.ThreadsUsedToProcessFiles); // Delete watermarked files //foreach (var file in Directory.GetFiles(Environment.CurrentDirectory + "\\..\\..\\Ressources\\FolderToWaterMark\\SomeFilesToWatermark")) // File.Delete(file); }
public void FolderIsEmpty() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(String.Empty); FolderToWatermark folderToMark = new FolderToWatermark(String.Empty, fileSettings, mark); }
public void FolderDoesNotExist() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(String.Empty); FolderToWatermark folderToMark = new FolderToWatermark("Folder does not exist", fileSettings, mark); }
public void SettingsFileTwo() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\CommentSymbols-2.txt"); Assert.AreEqual(2, fileSettings.CommentSymbols.Count()); Assert.IsNotNull(fileSettings.CommentSymbols[".cs"]); Assert.AreEqual("//", fileSettings.CommentSymbols[".cs"].Item1); Assert.AreEqual(String.Empty, fileSettings.CommentSymbols[".cs"].Item2); Assert.IsNotNull(fileSettings.CommentSymbols[".js"]); Assert.AreEqual("/*", fileSettings.CommentSymbols[".js"].Item1); Assert.AreEqual("*/", fileSettings.CommentSymbols[".js"].Item2); }
public void SettingsFileInvalidFormat() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\CommentSymbols-InvalidFormat.txt"); Assert.AreEqual(0, fileSettings.CommentSymbols.Count()); }
public void SettingsFileExists() { CodeCommentSymbols fileSettings = new CodeCommentSymbols(Environment.CurrentDirectory + "\\..\\..\\Ressources\\CommentSymbols-Empty.txt"); Assert.IsTrue(fileSettings.SettingFileWasLoaded); }
public void SettingsFileDoesNotExist() { CodeCommentSymbols fileSettings = new CodeCommentSymbols("file does not exist"); Assert.IsFalse(fileSettings.SettingFileWasLoaded); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("*****************************************************"); Console.WriteLine("* *"); Console.WriteLine("* Add watermark to source code *"); Console.WriteLine("* *"); Console.WriteLine("* This program will add a release number *"); Console.WriteLine("* at the top of all files inside a provided folder *"); Console.WriteLine("* location. *"); Console.WriteLine("* *"); Console.WriteLine("* The process will only update the file with *"); Console.WriteLine("* the extensions contained inside the following *"); Console.WriteLine("* file: CodeCommentsSymbols.txt. The comment *"); Console.WriteLine("* symbols can also be edited inside that same *"); Console.WriteLine("* file. *"); Console.WriteLine("* *"); Console.WriteLine("* The watermark format can be edited inside *"); Console.WriteLine("* Watermark.txt *"); Console.WriteLine("* *"); Console.WriteLine("* *"); Console.WriteLine("* Author: https://github.com/jdecuyper *"); Console.WriteLine("* Date: 2014-01-09 *"); Console.WriteLine("* *"); Console.WriteLine("*****************************************************"); Console.Write("\n\n"); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Black; // Ask for release number bool releaseNumberIsValid = false; string releaseNumber = String.Empty; while (!releaseNumberIsValid) { Console.ForegroundColor = ConsoleColor.White; Console.Write("# Provide release number: "); releaseNumber = Console.ReadLine(); Match releaseNumberMatch = Regex.Match(releaseNumber, @"\d+(?:\.\d+)+", RegexOptions.IgnoreCase); if (String.IsNullOrEmpty(releaseNumber)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Release number is invalid."); Console.WriteLine("Use a valid format (1.0, 7.45.3,...)"); continue; } if (!releaseNumberMatch.Success) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Release number is invalid."); Console.WriteLine("Use a valid format (1.0, 7.45.3,...)"); continue; } releaseNumberIsValid = true; } // Ask for folder name bool folderExists = false; string folderPath = String.Empty; while (!folderExists) { Console.ForegroundColor = ConsoleColor.White; Console.Write("# Provide folder path: "); folderPath = Console.ReadLine(); if (String.IsNullOrEmpty(folderPath)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Folder path number is invalid."); Console.WriteLine("Folder path can be a relative or absolute (C:\\foo or 1\\bar)"); continue; } if (!Directory.Exists(folderPath)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Folder path is invalid."); Console.WriteLine("Folder path can be a relative or absolute (C:\\foo or 1\\bar)"); continue; } folderExists = true; } // Start watermarking process Console.WriteLine(String.Empty); Console.WriteLine("# Start to watermark files with release v." + releaseNumber); Console.WriteLine("# Read valid extension list"); string fileSettingsAbsPath = Environment.CurrentDirectory + "\\" + CodeCommentSymbols.SETTINGS_FILE_NAME; CodeCommentSymbols codeComments = new CodeCommentSymbols(fileSettingsAbsPath); Console.WriteLine("# Read watermark"); Watermark mark = new Watermark(Environment.CurrentDirectory + "\\" + Watermark.WATERMARK_FILE_NAME, releaseNumber); if (mark.TextLines.Count > 0) { FolderToWatermark folderToProcess = new FolderToWatermark(folderPath, codeComments, mark); Console.WriteLine("# Files to process: " + folderToProcess.FilesToProcessCount); Console.WriteLine("# Start watermarking files..."); folderToProcess.WaterMarkFiles(); Console.WriteLine("# Watermarking has finished"); // Print result Console.WriteLine("# Threads used to process files: " + folderToProcess.ThreadsUsedToProcessFiles); Console.WriteLine("# Processed files: " + folderToProcess.FilesProcessedCount); if (folderToProcess.FilesThatCouldNotBeProcessed.Count > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Files that could not be processed: " + folderToProcess.FilesThatCouldNotBeProcessed.Count); Console.WriteLine("Check FilesThatCouldNotBeProcessed.txt for list of non processed files"); Console.ForegroundColor = ConsoleColor.White; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("No watermark could be found."); Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine("# Press any key to exit..."); Console.ReadLine(); }