private static bool Parse(string strCommand) { string[] args = CommandLineParser.Parse(strCommand); if (args.Length != 0) { switch (args[0].ToLower()) { case ControlCommands.ExitCommand: return(true); case ControlCommands.HelpCommand: HelpClass.DisplayCommands(); break; default: CommandBaseEx command = null; try { command = CommandLineParser.ParseQueueCommandEx(args); } catch (Exception ex) { Logger.LogError(ex, Resource.ERR_UNEXPECTEDERROR); } if (command != null) { //Measure execution time for each command Stopwatch stopwatch = Stopwatch.StartNew(); bool status = CommandBaseEx.Run(command); stopwatch.Stop(); ConsoleColor originalColor = Console.ForegroundColor; Console.ForegroundColor = status ? ConsoleColor.White : ConsoleColor.Red; Console.WriteLine(status ? "Complete in {0}" : "Failed after {0}", stopwatch.Elapsed); Console.ForegroundColor = originalColor; } //If command supports IDisposable, as most of them do, dispose it IDisposable dispose = command as IDisposable; if (dispose != null) { dispose.Dispose(); } break; } } return(false); }
public void DecodePeekCommandTest() { string args = "peek"; CommandBaseEx actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNull(actual); args = "peek "; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNull(actual); args = "peek ?"; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNull(actual); args = "peek /p notapath"; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNotNull(actual); Assert.AreEqual(".\\private$\\notapath", ((PeekQueueCommandEx)actual).Path); args = "peek /p notapath "; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNotNull(actual); Assert.AreEqual(((PeekQueueCommandEx)actual).Path, ".\\private$\\notapath"); args = "peek /p notapath /c garbage"; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNull(actual); args = "peek /p notapath /c 0"; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNotNull(actual); Assert.AreEqual((int?)null, ((PeekQueueCommandEx)actual).Count); args = "peek /p .\\private$\\notapath /c 10"; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNotNull(actual); Assert.AreEqual(".\\private$\\notapath", ((PeekQueueCommandEx)actual).Path); Assert.AreEqual(10, ((PeekQueueCommandEx)actual).Count); args = "peek /p FormatName:DIRECT=TCP:10.139.209.222\\private$\\notapath /c 0"; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); Assert.IsNotNull(actual); Assert.AreEqual(((PeekQueueCommandEx)actual).Path, "FormatName:DIRECT=TCP:10.139.209.222\\private$\\notapath"); Assert.AreEqual((int?)null, ((PeekQueueCommandEx)actual).Count); //Adding test to cover peek command failure on empty queue const string TEST_PEEK_QUEUE = ".\\private$\\test_peek_queue"; if (MessageQueue.Exists(TEST_PEEK_QUEUE)) { MessageQueue.Delete(TEST_PEEK_QUEUE); } MessageQueue.Create(TEST_PEEK_QUEUE); args = "peek /p " + TEST_PEEK_QUEUE; actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args)); CommandBaseEx.Run(actual); MessageQueue.Delete(TEST_PEEK_QUEUE); }