diff --git a/HashingCmd/Program.cs b/HashingCmd/Program.cs index eb5bb14ebc1fc594b128d7193f244b0c6b8037c0..b26375e7636e70701effed9dfdaa3794d15a1563 100644 --- a/HashingCmd/Program.cs +++ b/HashingCmd/Program.cs @@ -34,15 +34,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using System.Text; -using System.Threading.Tasks; using System.Xml; -using System.Xml.Linq; using System.Xml.Schema; -using System.Xml.XPath; -using TUGraz.VectoCommon.Exceptions; -using TUGraz.VectoCore.InputData.FileIO.XML.Declaration; using TUGraz.VectoCore.Utils; using TUGraz.VectoHashing; @@ -68,7 +62,12 @@ hashingcmd.exe -r: read hash from file and write to stdout "; - static Dictionary<string, HashingAction> actions = new Dictionary<string, HashingAction>(); + private static readonly Dictionary<string, HashingAction> Actions = new Dictionary<string, HashingAction> { + { "-v", VerifyHashAction }, + { "-c", ComputeHashAction }, + { "-r", ReadHashAction }, + { "-s", CreateHashedFileAction } + }; static bool _validateXML; private static bool xmlValid = true; @@ -81,10 +80,6 @@ hashingcmd.exe Console.Write(Help); return 0; } - actions["-v"] = VerifyHashAction; - actions["-c"] = ComputeHashAction; - actions["-r"] = ReadHashAction; - actions["-s"] = CreateHashedFileAction; if (args.Contains("-x")) { _validateXML = true; @@ -97,16 +92,16 @@ hashingcmd.exe return 0; } foreach (var file in fileList) { - WriteLine("processing " + Path.GetFileName(file)); + Console.Error.WriteLine("processing " + Path.GetFileName(file)); if (!File.Exists(Path.GetFullPath(file))) { - WriteLine("file " + Path.GetFullPath(file) + " not found!"); + Console.Error.WriteLine("file " + Path.GetFullPath(file) + " not found!"); continue; } foreach (var arg in args) { - if (actions.ContainsKey(arg)) { + if (Actions.ContainsKey(arg)) { try { var h = VectoHash.Load(file); - actions[arg](Path.GetFullPath(file), h); + Actions[arg](Path.GetFullPath(file), h); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(e.Message); @@ -127,7 +122,9 @@ hashingcmd.exe Environment.ExitCode = Environment.ExitCode != 0 ? Environment.ExitCode : 1; } #if DEBUG - Console.WriteLine("done."); + Console.Error.WriteLine("done."); + + if (!Console.IsInputRedirected) Console.ReadKey(); #endif return Environment.ExitCode; @@ -138,18 +135,18 @@ hashingcmd.exe var destination = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + "_hashed.xml"); if (File.Exists(destination)) { - WriteLine("hashed file already exists. overwrite? (y/n) "); + Console.Error.WriteLine("hashed file already exists. overwrite? (y/n) "); var key = Console.ReadKey(true); while (!(key.KeyChar == 'y' || key.KeyChar == 'n')) { - WriteLine("overwrite? (y/n) "); + Console.Error.WriteLine("overwrite? (y/n) "); key = Console.ReadKey(true); } if (key.KeyChar == 'n') { return; } - WriteLine("overwriting file " + Path.GetFileName(destination)); + Console.Error.WriteLine("overwriting file " + Path.GetFileName(destination)); } else { - WriteLine("creating file " + Path.GetFileName(destination)); + Console.Error.WriteLine("creating file " + Path.GetFileName(destination)); } var result = h.AddHash(); var writer = new XmlTextWriter(destination, Encoding.UTF8) { @@ -189,7 +186,7 @@ hashingcmd.exe } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine("Failed to validate hashed XML file!"); + Console.WriteLine("Failed to validate hashed XML file!"); Console.Error.WriteLine(e.Message); if (e.InnerException != null) { Console.Error.WriteLine(e.InnerException.Message); diff --git a/Tools/GraphDrawer/Program.cs b/Tools/GraphDrawer/Program.cs index 357400d5e3c0f5ed6a4e52a73f5a9ae83a57e017..81b9d3dffe88a8920675e49a6727d40efaa3cfc0 100644 --- a/Tools/GraphDrawer/Program.cs +++ b/Tools/GraphDrawer/Program.cs @@ -47,24 +47,24 @@ Tool for plotting graphs comparing Vecto 2.2 and Vecto 3 private static void Main(string[] args) { if (args.Contains("--split")) { - Console.WriteLine("plotting graphs splitted by distance"); + Console.Error.WriteLine("plotting graphs splitted by distance"); var idx = Array.FindIndex(args, x => x == "--split"); var lenght = int.Parse(args[idx + 1]); var success = true; var start = 0; do { - Console.WriteLine("plotting {0} - {1}", start / 1000, (start + lenght) / 1000); + Console.Error.WriteLine("plotting {0} - {1}", start / 1000, (start + lenght) / 1000); success = GraphWriter.WriteDistanceSlice(args[0], args[1], start, start + lenght); start += lenght; } while (success); - Console.WriteLine("plotting full cycle"); + Console.Error.WriteLine("plotting full cycle"); GraphWriter.Write(args[0], args[1]); - Console.WriteLine("done"); + Console.Error.WriteLine("done"); return; } - Console.WriteLine("plotting graphs..."); + Console.Error.WriteLine("plotting graphs..."); GraphWriter.Write(args[0], args[1]); - Console.WriteLine("done"); + Console.Error.WriteLine("done"); } } } \ No newline at end of file diff --git a/Tools/LicenceHeader/Program.cs b/Tools/LicenceHeader/Program.cs index 43c86f1e110e81419718f3c1bab52f830f09529f..b0d34707c3118d6d7e440adab685377d452b7ac5 100644 --- a/Tools/LicenceHeader/Program.cs +++ b/Tools/LicenceHeader/Program.cs @@ -47,13 +47,13 @@ namespace LicenceHeader private static void Main() { Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("Updating Licence-Headers in Sourcefiles."); + Console.Error.WriteLine("Updating Licence-Headers in Sourcefiles."); Console.ResetColor(); - Console.WriteLine(); - Console.WriteLine("Search Directory: {0}", Path.GetFullPath(SolutionRootDirectory)); - Console.WriteLine("Filter: *.cs"); - Console.WriteLine("Excluded Dirs: \\obj, \\bin"); - Console.WriteLine("Header-File: {0}", Path.GetFullPath("header.txt")); + Console.Error.WriteLine(); + Console.Error.WriteLine("Search Directory: {0}", Path.GetFullPath(SolutionRootDirectory)); + Console.Error.WriteLine("Filter: *.cs"); + Console.Error.WriteLine("Excluded Dirs: \\obj, \\bin"); + Console.Error.WriteLine("Header-File: {0}", Path.GetFullPath("header.txt")); var licence = File.ReadAllText("header.txt", Encoding.UTF8); var re = new Regex("^.*?(?=using|namespace)", RegexOptions.Singleline); @@ -74,14 +74,15 @@ namespace LicenceHeader var count = 0; foreach (var f in updatedFiles) { count++; - Console.WriteLine(f.Substring(SolutionRootDirectory.Length - 1)); + Console.Error.WriteLine(f.Substring(SolutionRootDirectory.Length - 1)); } - Console.WriteLine(); + Console.Error.WriteLine(); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Finished. Updated {0} files.", count); Console.ResetColor(); + if (!Console.IsInputRedirected) Console.ReadKey(); } } diff --git a/VectoConsole/Program.cs b/VectoConsole/Program.cs index 93e6e4a3c0a8c10e8a08a32b27e9d9e2801ac7c1..c24a86067cb4d81e5338625bf783b71edba0c86f 100644 --- a/VectoConsole/Program.cs +++ b/VectoConsole/Program.cs @@ -44,7 +44,6 @@ using NLog.Targets; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration; @@ -236,7 +235,7 @@ Examples: WriteLine(@"Detected cycles:", ConsoleColor.White); foreach (var cycle in _jobContainer.GetCycleTypes()) { - WriteLine(string.Format(@" {0}: {1}", cycle.Name, cycle.CycleType)); + WriteLineStdOut(string.Format(@" {0}: {1}", cycle.Name, cycle.CycleType)); } WriteLine(); @@ -288,7 +287,9 @@ Examples: } #if DEBUG - Console.WriteLine("done."); + Console.Error.WriteLine("done."); + + if (!Console.IsInputRedirected) Console.ReadKey(); #endif return Environment.ExitCode; @@ -299,7 +300,7 @@ Examples: if (_quiet && !_debugEnabled) { return; } - Console.WriteLine(); + Console.Error.WriteLine(); } private static void WriteLine(string message, ConsoleColor foregroundColor = ConsoleColor.Gray) @@ -308,6 +309,16 @@ Examples: return; } Console.ForegroundColor = foregroundColor; + Console.Error.WriteLine(message); + Console.ResetColor(); + } + + private static void WriteLineStdOut(string message, ConsoleColor foregroundColor = ConsoleColor.Gray) + { + if (_quiet && !_debugEnabled) { + return; + } + Console.ForegroundColor = foregroundColor; Console.WriteLine(message); Console.ResetColor(); } @@ -380,7 +391,7 @@ Examples: if (WarningMessages.Any()) { Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(@"Warnings: {0,5}", WarningMessages.Count); + Console.Error.WriteLine(@"Warnings: {0,5}", WarningMessages.Count); Console.ResetColor(); } else { Console.WriteLine(""); @@ -394,10 +405,10 @@ Examples: private static void PrintTimings(Dictionary<string, double> timings) { - Console.WriteLine(); - Console.WriteLine(@"---- timing information ----"); + Console.Error.WriteLine(); + Console.Error.WriteLine(@"---- timing information ----"); foreach (var timing in timings) { - Console.WriteLine(@"{0,-20}: {1:F2}s", timing.Key, timing.Value / 1000); + Console.Error.WriteLine(@"{0,-20}: {1:F2}s", timing.Key, timing.Value / 1000); } } }