Пример #1
0
    public void Run(string[] args)
    {
        ProjectCommandLineApplication userJwts = new(_reporter)
        {
            Name = "dotnet user-jwts"
        };

        userJwts.HelpOption("-h|--help");

        // dotnet user-jwts list
        ListCommand.Register(userJwts);
        // dotnet user-jwts create
        CreateCommand.Register(userJwts);
        // dotnet user-jwts print ecd045
        PrintCommand.Register(userJwts);
        // dotnet user-jwts remove ecd045
        RemoveCommand.Register(userJwts);
        // dotnet user-jwts clear
        ClearCommand.Register(userJwts);
        // dotnet user-jwts key
        KeyCommand.Register(userJwts);

        // Show help information if no subcommand/option was specified.
        userJwts.OnExecute(() => userJwts.ShowHelp());

        try
        {
            userJwts.Execute(args);
        }
        catch (Exception ex)
        {
            _reporter.Error(ex.Message);
        }
    }
}
Пример #2
0
        /// <summary>
        /// 请求打印机状态
        /// </summary>
        /// <returns></returns>
        public int PrinterState()
        {
            int       err = 0;
            ErrorCode ec  = ErrorCode.None;

            byte[] cmdData = PrintCommand.RequestPrinterState();
            int    bytesWritten;

            ec = Writer.Write(cmdData, 2000, out bytesWritten);
            if (ec != ErrorCode.None)
            {
                err = (int)PrintError.SendFailure;
                return(err);
            }
            else if (bytesWritten != cmdData.Length)
            {
                err = (int)PrintError.SendFailure;
                return(err);
            }
            //读取数据
            byte[] readbyte = new byte[1];
            int    readLength;

            ErrorCode rec = Reader.Read(readbyte, 2000, out readLength);


            err = 1;
            return(err);
        }
Пример #3
0
        private static void GetCommandToExecute(string command, out ICommand commandToExecute, ExtractCommand extractCommand)
        {
            switch (command)
            {
            case "d":
                Console.Write("Enter delay between download calls: ");
                string timeOutInput = Console.ReadLine();

                if (!int.TryParse(timeOutInput, out int timeOut))
                {
                    timeOut = 2000;
                }

                commandToExecute = new DownloadCommand(timeOut, extractCommand.links);
                return;

            case "p":
                commandToExecute = new PrintCommand(extractCommand.links);
                return;

            case "s":
                commandToExecute = new SaveCommand(extractCommand.links, ReadSaveFilePath());
                return;
            }

            commandToExecute = null;
        }
Пример #4
0
        public MainWindowViewModel(IDataAccess dataAccess = null, IShoppingListManager shoppingListManager = null)
        {
            // prepare for Unit Test
            DataAccess          = dataAccess ?? new DataAccess();
            ShoppingListManager = shoppingListManager ?? new ShoppingListManager();

            // Get all data
            ShoppingLists = DataAccess.ToLoad();

            // set WeekDay
            DayWeekTime = DateTime.Today.DayOfWeek;
            // Textbox: placeholder
            WantBuy = "e.g. apple ...";
            // DataGrid: load data from Json, display on DataGrid todayShoppingList
            ToBuys = new ObservableCollection <ToBuy>(ShoppingListManager.TodayShoppingList(ShoppingLists));
            // ClearButton
            ClearCommand = new ClearCommand(this);
            // AddButton
            AddCommand = new AddCommand(this);
            // Remove item Button
            RemoveSelectedCommand = new RemoveSelectedCommand(this);
            // arrange Button
            ArrangeCommand = new ArrangeCommand(this);
            // Monday ... Sunday Button
            MondayCommand    = new MondayCommand(this);
            TuesdayCommand   = new TuesdayCommand(this);
            WednesdayCommand = new WednesdayCommand(this);
            ThursdayCommand  = new ThursdayCommand(this);
            FridayCommand    = new FridayCommand(this);
            SaturdayCommand  = new SaturdayCommand(this);
            SundayCommand    = new SundayCommand(this);
            // print Btn
            PrintCommand = new PrintCommand(this);
        }
Пример #5
0
        public void PrintCommandTest()
        {
            Console.WriteLine(@"PrintCommandTest");
            var cmd = new PrintCommand(this, PrintType.View);

            Assert.AreEqual(PrintType.View, cmd.PrintType);
        }
Пример #6
0
        static void Main(string[] args)
        {
            Square[] squares = new Square[20];

            squares[0] = new Square(0, 10);
            squares[1] = new Square(1, 15);

            Invoker invoker = new Invoker();

            AbstractCommand command = new MoveCommand(squares[0], 5, 5);

            invoker.execute(command);
            command = new ScaleCommand(squares[0], 2);
            invoker.execute(command);
            command = new PrintCommand(squares[0]);
            invoker.execute(command);

            command = new ScaleCommand(squares[1], 3);
            invoker.execute(command);
            command = new PrintCommand(squares[1]);
            invoker.execute(command);

            invoker.undo();
            command = new PrintCommand(squares[0]);
            invoker.execute(command);
            command = new PrintCommand(squares[1]);
            invoker.execute(command);
        }
Пример #7
0
        public ICommand CreateCommand(string commandName, IEngine engine)
        {
            ICommand command = null;

            Commands name;

            bool isValidCommandName = System.Enum.TryParse(commandName, out name);

            if (!isValidCommandName)
            {
                throw new ArgumentException("Invalid command name!");
            }

            switch (name)
            {
            case Commands.Add:
                command = new AddCommand(engine);
                break;

            case Commands.Create:
                command = new CreateCommand(engine);
                break;

            case Commands.Remove:
                command = new RemoveCommand(engine);
                break;

            case Commands.Print:
                command = new PrintCommand(engine);
                break;
            }

            return(command);
        }
Пример #8
0
 private void NotifyCommands()
 {
     CancelCommand.RaiseCanExecuteChanged();
     CheckoutCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     PreviewCommand.RaiseCanExecuteChanged();
     SearchProductCommand.RaiseCanExecuteChanged();
 }
 private void NotifyCommands()
 {
     EditCommand.RaiseCanExecuteChanged();
     DeleteCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     PreviewCommand.RaiseCanExecuteChanged();
     PaymentsCommand.RaiseCanExecuteChanged();
 }
Пример #10
0
        public void PrintCommand_GivenValidTextFile_IsPrintable()
        {
            var tempFile = TempFileHelper.CreateTempFile("PrintCommand", "test.txt");

            var printCommand = new PrintCommand(tempFile, "SomePrinter", new FileAssoc());

            Assert.IsTrue(printCommand.IsPrintable);
        }
Пример #11
0
        public void PrintCommand_GivenValidTextFile_AllowsPrintTo()
        {
            var tempFile = TempFileHelper.CreateTempFile("PrintCommand", "test.txt");

            var printCommand = new PrintCommand(tempFile, "SomePrinter", new FileAssoc());

            Assert.IsTrue(printCommand.CommandType == PrintType.PrintTo);
        }
Пример #12
0
        public void PrintCommand_GivenValidPrintOnlyFile_AllowsPrint()
        {
            string tempFile = TempFileHelper.CreateTempFile("PrintCommand", "test.ini");

            var printCommand = new PrintCommand(tempFile, "SomePrinter");

            Assert.IsTrue(printCommand.CommandType == PrintType.Print);
        }
Пример #13
0
        public void PrintCommand_GivenValidPrintOnlyFile_AllowsPrint()
        {
            var tempFile = TempFileHelper.CreateTempFile("PrintCommand", "test.ini");

            var printCommand = new PrintCommand(tempFile, "SomePrinter", new FileAssoc(), _printerHelper, _timeOut);

            Assert.IsTrue(printCommand.CommandType == PrintType.Print);
        }
Пример #14
0
        public void PrintCommand_GivenFileWithUnknownExtension_IsUnprintable()
        {
            var tempFile = TempFileHelper.CreateTempFile("PrintCommand", "test.unknownExtension");

            var printCommand = new PrintCommand(tempFile, "SomePrinter", new FileAssoc());

            Assert.IsFalse(printCommand.IsPrintable);
            Assert.AreEqual(PrintType.Unprintable, printCommand.CommandType);
        }
Пример #15
0
        public void CreatePrintCommand()
        {
            IList <IExpression> expressions = new IExpression[] { new ConstantExpression("foo") };
            PrintCommand        command     = new PrintCommand(expressions);

            Assert.IsNotNull(command);
            Assert.IsNotNull(command.Expressions);
            Assert.AreEqual(expressions, command.Expressions);
        }
Пример #16
0
        public async Task PrintMyMessage(PrintCommand command, Contexts contexts)
        {
            var messagesService = _messagesServiceFactory.Create(contexts);

            for (int i = 0; i < command.Times; i++)
            {
                await messagesService.SendMessage(command.Message);
            }
        }
        public void PrintCommand()
        {
            var command = ParseCommand("print 'Hello World'");

            Assert.IsTrue(command is PrintCommand);
            PrintCommand printCommand = (PrintCommand)command;

            Assert.AreEqual("Hello World", CastString(printCommand.variable.GetValue()).GetStringValue());
        }
Пример #18
0
 private void Check(InstagramImageViewModel image)
 {
     _checkedImage = image;
     foreach (var imageViewModel in Images.Where(x => x != _checkedImage))
     {
         imageViewModel.IsChecked = false;
     }
     PrintCommand.RaiseCanExecuteChanged();
 }
Пример #19
0
 private void RaiseCanExecuteCommands()
 {
     NextMonthCommand.RaiseCanExecuteChanged();
     PreviousMonthCommand.RaiseCanExecuteChanged();
     RemoveUserCommand.RaiseCanExecuteChanged();
     CurrentMonthCommand.RaiseCanExecuteChanged();
     SearchCommand.RaiseCanExecuteChanged();
     ClearAllCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
 }
        public void PrintCommand()
        {
            var program = MDKFactory.CreateProgram <Program>();
            var command = program.ParseCommand("print 'Hello World'");

            Assert.IsTrue(command is PrintCommand);
            PrintCommand printCommand = (PrintCommand)command;

            Assert.AreEqual("Hello World", CastString(printCommand.variable.GetValue()).GetTypedValue());
        }
Пример #21
0
        public void PrintDocument()
        {
            Command = new InkPrintCommand();
            Command.ExecutePrint(Document);

            Command = new LaserPrintCommand();
            Command.ExecutePrint(Document);
            Console.ReadKey();
            return;
        }
Пример #22
0
        public void PrintOnlyFile_GivenWithoutSettingsDefaultPrinter_ThrowsException()
        {
            var tempFile = TempFileHelper.CreateTempFile("PrintCommand", "test.ini");

            var printCommand = new PrintCommand(tempFile, "SomePrinter", new FileAssoc());

            printCommand.ProcessWrapperFactory = new MockProcessWrapperFactory(true);

            Assert.Throws <InvalidOperationException>(() => printCommand.Print());
        }
 private void InvalidateCommands()
 {
     SaveCommand.RaiseCanExecuteChanged();
     DeleteCommand.RaiseCanExecuteChanged();
     CancelCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     GetAccountCommand.RaiseCanExecuteChanged();
     EditOrderItemCommand.RaiseCanExecuteChanged();
     DeleteOrderItemCommand.RaiseCanExecuteChanged();
     NewOrderItemCommand.RaiseCanExecuteChanged();
 }
Пример #24
0
        private void Check(CheckableImageWrapper image)
        {
            if (_checkedImages.Value.Contains(image))
            {
                _checkedImages.Value.Remove(image);
                return;
            }

            _checkedImages.Value.Add(image);
            PrintCommand.RaiseCanExecuteChanged();
        }
Пример #25
0
        static PrintCommand CreatePrintCommand(ParsingInfo info)
        {
            PrintCommand cmd = new PrintCommand();

            var args = info.MultipleChildren("arg");

            foreach (var arg in args)
            {
                cmd.ArgList.Add(CreateArg(arg));
            }
            return(cmd);
        }
Пример #26
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());
        }
        public void PrintCommandVariable()
        {
            var command = ParseCommand("print {a}");

            Assert.IsTrue(command is PrintCommand);
            PrintCommand printCommand = (PrintCommand)command;

            Assert.IsTrue(printCommand.variable is InMemoryVariable);
            InMemoryVariable variable = (InMemoryVariable)printCommand.variable;

            Assert.AreEqual("a", variable.variableName);
        }
 private void InvalidateCommands()
 {
     SaveCommand.RaiseCanExecuteChanged();
     DeleteCommand.RaiseCanExecuteChanged();
     CancelCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     CloseCommand.RaiseCanExecuteChanged();
     GetAccountCommand.RaiseCanExecuteChanged();
     EditInvoiceItemCommand.RaiseCanExecuteChanged();
     DeleteInvoiceItemCommand.RaiseCanExecuteChanged();
     NewInvoiceItemCommand.RaiseCanExecuteChanged();
 }
Пример #29
0
 public override void AfterItemPermissionsCompleted()
 {
     base.AfterItemPermissionsCompleted();
     NewCommand.RaiseCanExecuteChanged();
     EditCommand.RaiseCanExecuteChanged();
     SaveCommand.RaiseCanExecuteChanged();
     SearchCommand.RaiseCanExecuteChanged();
     DeleteCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     CancelCommand.RaiseCanExecuteChanged();
     ExportCommand.RaiseCanExecuteChanged();
 }
Пример #30
0
        public void Run_ThrowsException_InputStackIsIncorrect()
        {
            // Arrange
            CommandContext context = new CommandContext();

            var pop = new PrintCommand(context);

            // Act
            void result() => pop.Run();

            // Assert
            Assert.Throws <CommandExecutionException>(result);
        }
Пример #31
0
        public void PrintCommandHasPrint()
        {
            ICommand command = new PrintCommand();

            Assert.IsTrue( command.AppliesTo( "?fire" ) );
        }
Пример #32
0
        public void PrintCommandWontPrintIrrelevant()
        {
            ICommand command = new PrintCommand();
            var comm = new TestCommunicator();
            int count = 0;
            comm.DisplayCalled += ( a, e ) =>
            {
                count++;
            };
            var rs = new RuleSet()
                {
                    Rules = new[] { new Rule( new[] { "fire", "water" }, "water" ) }
                };
            var controller = new AlchemyController( rs );
            command.Run( "?fire3", controller, comm );

            Assert.AreEqual( 0, count );
        }