Esempio n. 1
0
        public void ExecutePrintCommand()
        {
            PrintCommand command = new PrintCommand(new IExpression[] { new ConstantExpression("bar") });
            Machine      machine = new Machine();
            StringWriter writer  = new StringWriter();

            machine.Output = writer;

            command.Execute(machine, machine.Environment);

            Assert.AreEqual("bar\r\n", writer.ToString());
        }
Esempio n. 2
0
        public void PrintHello()
        {
            ICommand     command = new PrintCommand(new ConstantExpression("Hello"));
            StringWriter writer  = new StringWriter();

            lock (System.Console.Out)
            {
                TextWriter originalWriter = System.Console.Out;
                System.Console.SetOut(writer);

                command.Execute(null, null);

                System.Console.SetOut(originalWriter);
            }

            Assert.AreEqual("Hello", writer.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Обрабатывает нажатие клавиши.
        /// </summary>
        /// <param name="sender">Объект-отправитель.</param>
        /// <param name="e">Передаваемые данные.</param>
        public void OnPageKeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key == VirtualKey.Control)
            {
                _isCtrlKeyPressed = true;
            }

            if (_isCtrlKeyPressed)
            {
                switch (e.Key)
                {
                case VirtualKey.O: OpenCommand.Execute(null); break;

                case VirtualKey.P: PrintCommand.Execute(null); break;
                }
            }
        }
Esempio n. 4
0
        public void PrintNotesCommand()
        {
            var notebook   = new Notebook.Notebook.Notebook();
            var firstNote  = new PhoneNote("abc", "222-222");
            var secondNote = new PhoneNote("qwer", "222-333");
            var thirdNote  = new StudentNote("rrr", 123);

            notebook.Add(firstNote);
            notebook.Add(secondNote);
            notebook.Add(thirdNote);
            var printNotesCommand = new PrintCommand(notebook);

            using (var stringWriter = new StringWriter())
            {
                Console.SetOut(stringWriter);
                printNotesCommand.Execute();
                var expectedString = firstNote.ToString() + "\r\n" + secondNote.ToString() + "\r\n" +
                                     thirdNote.ToString() + "\r\n";
                Assert.AreEqual(true, stringWriter.ToString().Equals(expectedString));
            }

            Console.SetOut(new StreamWriter(Console.OpenStandardError()));
        }
Esempio n. 5
0
        private void ParseCommand(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                return;
            }
            //NOTE: Parse in ascending length order!
            if (line.Substring(0, 1).Equals("#"))
            {
                return;
            }
            if (line.Length < 4)
            {
                Warn("invalid command: {0}", line);
                return;
            }

            if (line.Substring(0, 4).ToLower().Equals("quit") || line.Substring(0, 4).ToLower().Equals("exit"))
            {
                return;
            }

            var    idx = line.IndexOf(' ');
            string cmd;

            if (idx < 0)
            {
                idx = 0;
                cmd = line;
            }
            else
            {
                cmd = line.Substring(0, idx).ToLower();
            }

            var args = idx == 0 ? string.Empty : line.Substring(idx + 1).Trim();

            if (CR.abort.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new AbortCommand();
                c.Execute(context);
                StopTimer(CR.abort + " " + args);
                return;
            }
            if (CR.addalias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new AddAliasCommand();
                c.Execute(context, args);
                StopTimer(CR.addalias + " " + args);
                return;
            }
            if (CR.addindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new AddIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.addindex + " " + args);
                return;
            }
            if (CR.close.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CloseCommand();
                c.Execute(context, args);
                StopTimer(CR.close + " " + args);
                return;
            }
            if (CR.commit.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CommitCommand();
                c.Execute(context, args);
                StopTimer(CR.commit + " " + args);
                return;
            }
            if (CR.compactcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CompactContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.compactcontainer + " " + args);
                return;
            }
            if (CR.contextquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new ContextQueryCommand();
                c.Execute(context, args);
                StopTimer(CR.contextquery + " " + args);
                return;
            }
            if (CR.cquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CQueryCommand();
                c.Execute(context, args);
                StopTimer(CR.cquery + " " + args);
                return;
            }
            if (CR.createcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CreateContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.createcontainer + " " + args);
                return;
            }
            if (CR.delindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new DeleteIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.delindex + " " + args);
                return;
            }
            if (CR.echo.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                Msg(args);
                return;
            }
            if (CR.getdocuments.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new GetDocumentsCommand();
                c.Execute(context, args);
                StopTimer(CR.getdocuments + " " + args);
                return;
            }
            if (CR.getmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new GetMetadataCommand();
                c.Execute(context, args);
                StopTimer(CR.getmetadata + " " + args);
                return;
            }
            if (CR.help.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                var c = new HelpCommand();
                c.Execute(args);
                return;
            }
            if (CR.info.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new InfoCommand();
                c.Execute(context, args);
                StopTimer(CR.info + " " + args);
                return;
            }
            if (CR.listindexes.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new ListIndexesCommand();
                c.Execute(context, args);
                StopTimer(CR.listindexes + " " + args);
                return;
            }
            if (CR.lookupedgeindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new LookupEdgeIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.lookupedgeindex + " " + args);
                return;
            }
            if (CR.lookupindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new LookupIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.lookupindex + " " + args);
                return;
            }
            if (CR.lookupstats.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new LookupStatisticsCommand();
                c.Execute(context, args);
                StopTimer(CR.lookupstats + " " + args);
                return;
            }
            if (CR.opencontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new OpenContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.opencontainer + " " + args);
                return;
            }
            if (CR.preload.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new PreloadCommand();
                c.Execute(context, args);
                StopTimer(CR.preload + " " + args);
                return;
            }
            if (CR.prepare.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new PrepareCommand();
                c.Execute(context, args);
                StopTimer(CR.prepare + " " + args);
                return;
            }
            if (CR.print.IndexOf(cmd, 0, StringComparison.Ordinal) == 0 || cmd.ToLower().Equals("printnames"))
            {
                StartTimer();
                var c = new PrintCommand();
                c.Execute(context, cmd.Equals("printnames") ? "printnames " + args : args);
                StopTimer(cmd.Equals("printnames") ? "printNames" : CR.print);
                return;
            }
            if (CR.putdocuments.Equals(cmd))
            {
                StartTimer();
                var c = new PutDocumentsCommand();
                c.Execute(context, args);
                StopTimer(CR.putdocuments + " " + args);
                return;
            }
            if (CR.putdocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new PutDocumentCommand();
                c.Execute(context, args);
                StopTimer(CR.putdocument + " " + args);
                return;
            }
            if (CR.query.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new QueryCommand();
                c.Execute(context, args);
                StopTimer(CR.query + " " + args);
                return;
            }
            if (CR.queryplan.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new QueryPlanCommand();
                c.Execute(context, args);
                StopTimer(CR.queryplan + " " + args);
                return;
            }
            if (CR.reindexcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new ReindexContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.reindexcontainer + " " + args);
                return;
            }
            if (CR.removealias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new RemoveAliasCommand();
                c.Execute(context, args);
                StopTimer(CR.removealias + " " + args);
                return;
            }
            if (CR.removecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new RemoveContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.removecontainer + " " + args);
                return;
            }
            if (CR.removedocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new RemoveDocumentCommand();
                c.Execute(context, args);
                StopTimer(CR.removedocument + " " + args);
                return;
            }
            if (CR.run.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                var c = new RunCommand();
                c.Execute(context, args);
                var l2 = new List <string>(originalArgs)
                {
                    "-s", c.Script
                };
                StartTimer();
                Main(l2.ToArray());
                StopTimer(CR.run + " " + args);
                return;
            }
            if (CR.setautoindexing.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetAutoIndexingCommand();
                c.Execute(context, args);
                StopTimer(CR.setautoindexing + " " + args);
                return;
            }
            if (CR.setbaseuri.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetBaseUriCommand();
                c.Execute(context, args);
                StopTimer(CR.setbaseuri + " " + args);
                return;
            }
            if (CR.setignore.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                var c = new SetIgnoreCommand();
                c.Execute(context, args);
                ignoreErrors = c.Ignore;
                return;
            }
            if (CR.setlazy.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetLazyCommand();
                c.Execute(context, args);
                StopTimer(CR.setlazy + " " + args);
                return;
            }
            if (CR.setmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetMetadataCommand();
                c.Execute(context, args);
                StopTimer(CR.setmetadata + " " + args);
                return;
            }
            if (CR.setnamespace.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetNamespaceCommand();
                c.Execute(context, args);
                StopTimer(CR.setnamespace + " " + args);
                return;
            }
            if (CR.setprojection.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetProjectionCommand();
                c.Execute(context, args);
                StopTimer(CR.setprojection + " " + args);
                return;
            }
            if (CR.setquerytimeout.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetQueryTimeoutCommand();
                c.Execute(context, args);
                StopTimer(CR.setquerytimeout + " " + args);
                return;
            }
            if (CR.setvariable.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetVariableCommand();
                c.Execute(context, args);
                StopTimer(CR.setvariable + " " + args);
                return;
            }
            if (CR.setverbose.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetVerboseCommand();
                c.Execute(context, args);
                StopTimer(CR.setverbose + " " + args);
                return;
            }
            if (CR.sync.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                context.Sync();
                StopTimer(CR.sync + " " + args);
                return;
            }
            if (CR.time.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                time = true;
                ParseCommand(args);
                return;
            }
            if (CR.transaction.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new TransactionCommand();
                c.Execute(context, args);
                StopTimer(CR.transaction + " " + args);
                return;
            }
            if (CR.upgradecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new UpgradeContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.upgradecontainer + " " + args);
                return;
            }

            Warn("Command not recognized: {0}", cmd);
        }
Esempio n. 6
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            var command = new PrintCommand();

            command.Execute(VD);
        }