Esempio n. 1
0
        public void DecodePurgeQueueTest()
        {
            string        args   = "purge";
            CommandBaseEx actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));

            Assert.IsNull(actual);

            args   = "purge ";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNull(actual);

            args   = "purge ?";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNull(actual);

            args   = "purge /p notapath";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
            Assert.AreEqual(((PurgeQueueCommandEx)actual).Path, ".\\private$\\notapath");

            args   = "purge /p FormatName:DIRECT=TCP:10.139.209.222\\private$\\notapath ";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
            Assert.AreEqual("FormatName:DIRECT=TCP:10.139.209.222\\private$\\notapath", ((PurgeQueueCommandEx)actual).Path);

            args   = "purge /p notapath garbage";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
        }
Esempio n. 2
0
        public void DecodeListCommandTest()
        {
            string        args   = "list";
            CommandBaseEx actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));

            Assert.IsNotNull(actual);

            args   = "list ";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);

            args   = "list ?";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNull(actual);

            args   = "list /h 127.0.0.1";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
            Assert.AreEqual(((ListQueuesCommand)actual).MachineName, "127.0.0.1");

            args   = "list /h localhost /u domain\\user /p password";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
            Assert.AreEqual("localhost", ((ListQueuesCommand)actual).MachineName);
            Assert.AreEqual("password", ((ListQueuesCommand)actual).Password);
            Assert.AreEqual("domain", ((ListQueuesCommand)actual).Domain);
            Assert.AreEqual("user", ((ListQueuesCommand)actual).UserName);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public static CommandBaseEx ParseQueueCommandEx(string[] args)
        {
            if (args.Length > 1 && args[1].ToLower() == ControlCommands.HelpCommand) //Display help
            {
                HelpClass.DisplayCommandHelp(args[0]);

                return(null);
            }

            //Check for common optional parameters
            // /c - count
            int?count = null;

            if (GetStringForKey(args, COUNT_KEY, false) != null && (count = GetIntForKey(args, COUNT_KEY)) == null)
            {
                return(null);
            }

            // /f - file name
            string filename = GetStringForKey(args, FILENAME_KEY, false);

            CommandBaseEx command = null;
            string        qname;

            switch (args[0].ToLower())
            {
            case QueueCommands.CreateCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new CreateQueueCommandEx(qname, GetKeyIndex(args, TRANSACTIONAL_KEY) != -1); break;

            case QueueCommands.DeleteCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new DeleteQueueCommandEx(qname); break;

            case QueueCommands.ExportCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new ExportQueueCommandEx(qname, filename); break;

            case QueueCommands.ExtractCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new ExtractQueueCommandEx(qname, filename); break;

            case QueueCommands.ImportCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new ImportQueueCommandEx(filename, qname); break;

            case QueueCommands.PurgeCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new PurgeQueueCommandEx(qname); break;

            case QueueCommands.PeekCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new PeekToConsoleQueueCommand(qname, count == 0 || count == null ? (int?)null : (int)count); break;

            case QueueCommands.ReadCommand: command = (qname = GetQueueName(args, QUEUENAME_KEY)) == null ? null : new ReadQueueCommandEx(qname, count == 0 || count == null ? (int?)null : count); break;

            case QueueCommands.ListCommand: command = DecodeListCommand(args); break;

            case QueueCommands.SendCommand: command = DecodeSendCommand(args); break;

            case QueueCommands.CopyCommand: command = DecodeCopyCommand(args); break;

            case ControlCommands.LoadCommand: command = DecodeLoadCommand(args); break;

            default: HelpClass.DisplayInvalidCommand(args[0]); break;
            }

            return(command);
        }
Esempio n. 5
0
        public void DecodeTest()
        {
            //string commandline = string.Empty;
            //IQueueCommand actual = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            //Assert.IsNull(actual);

            string        commandline = "garbage";
            CommandBaseEx actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));

            Assert.IsNull(actual);

            //Valid command + garbage
            commandline = "create+garbage";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNull(actual);

            //Valid create command
            commandline = "create /p queue";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNotNull(actual);

            //Valid delete command
            commandline = "delete /p queue";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNotNull(actual);

            //Valid purge command
            commandline = "purge /p queue";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNotNull(actual);

            //Valid list command
            commandline = "list";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNotNull(actual);

            //Valid send command command
            commandline = "send /p queue /m text";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNotNull(actual);

            //Valid peek command command
            commandline = "peek /p queue";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNotNull(actual);

            //Valid copy command command
            commandline = "copy /s queue /d queue";
            actual      = CommandLineParser.ParseQueueCommandEx(Parse(commandline));
            Assert.IsNotNull(actual);
        }
Esempio n. 6
0
        protected override bool First()
        {
            if (!File.Exists(_filename))
            {
                return(false);
            }

            using (StreamReader reader = new StreamReader(_filename))
            {
                string strCommand;

                while ((strCommand = reader.ReadLine()) != null)
                {
                    strCommand = strCommand.Trim();

                    //Cutoff comments
                    if (strCommand.IndexOf("//") != -1)
                    {
                        strCommand = strCommand.Substring(0, strCommand.IndexOf("//"));
                    }

                    //Skip if empty line or comment line
                    if (strCommand == "")
                    {
                        continue;
                    }

                    //Display command
                    Console.WriteLine(strCommand);

                    string[] parameters = CommandLineParser.Parse(strCommand);

                    if (parameters == null)
                    {
                        Logger.LogWarn(Resource.WARN_FAILEDTOPARSE, strCommand, _filename);

                        return(false);
                    }

                    CommandBaseEx command = CommandLineParser.ParseQueueCommandEx(parameters);
                    if (command != null)
                    {
                        this.AddChild(command);
                    }
                }
            }

            return(true);
        }
Esempio n. 7
0
        public void DecodeCreateQueueTest()
        {
            string        args   = "create";
            CommandBaseEx actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));

            Assert.IsNull(actual);

            args   = "create ";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNull(actual);

            args   = "create ?";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNull(actual);

            args   = "create /p notapath";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
            Assert.AreEqual(((CreateQueueCommandEx)actual).Path, ".\\private$\\notapath");

            args   = "create /p notapath ";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
            Assert.AreEqual(((CreateQueueCommandEx)actual).Path, ".\\private$\\notapath");
            Assert.IsFalse(((CreateQueueCommandEx)actual).Transactional);

            args   = "create /p notapath asdf";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);

            args   = "create /p notapath  /t";
            actual = CommandLineParser_Accessor.ParseQueueCommandEx(Parse(args));
            Assert.IsNotNull(actual);
            Assert.AreEqual(((CreateQueueCommandEx)actual).Path, ".\\private$\\notapath");
            Assert.IsTrue(((CreateQueueCommandEx)actual).Transactional);
        }
Esempio n. 8
0
        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);
        }