static void Main(string[] args)
        {
            Console.WriteLine("Hello Command Pattern!");

            Message message = new Message("555000123", "555888000", "Hello World!");

            ICommand command1 = new PrintCommand(message.Content, 4);

            ICommand command2 = new SendCommand(message.From, message.To, message.Content);

            // ...

            Queue <ICommand> commands = new Queue <ICommand>();

            commands.Enqueue(command1);
            commands.Enqueue(command2);


            while (commands.Count > 0)
            {
                ICommand command = commands.Dequeue();

                if (command.CanExecute())
                {
                    command.Execute();
                }
            }


            //if (message.CanPrint())
            //{
            //    message.Print();
            //}
        }
        private static void CanExecuteTest()
        {
            ICommand command = new SendCommand(from: "", to: "555888000", content: "Hello World!");

            if (command.CanExecute())
            {
                command.Execute();
            }

            command = new PrintCommand(content: "Hello World!");

            if (command.CanExecute())
            {
                command.Execute();
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            _receiver = new CreateReceiver();
            Command command = new CreateCommand(
                _receiver, new CreateArgs {
                InvoiceType = "c",
                BillingDate = DateTime.UtcNow
            });

            var invoker = new Invoker(command);

            invoker.Execute();

            _receiver = new CancelReceiver();
            command   = new CancelCommand(
                _receiver, new CancelArgs {
                InvoiceCode   = "310987289304",
                InvoiceNumber = 34156934,
                InvoiceType   = "s",
                CancelReason  = "Invoice missing!",
                CancelMan     = "Iori",
                CancelDate    = DateTime.UtcNow
            });

            invoker = new Invoker(command);
            invoker.Execute();

            _receiver = new PrintReceiver();
            command   = new PrintCommand(
                _receiver, new PrintArgs {
                InvoiceCode   = "310987289304",
                InvoiceNumber = 34156934,
                InvoiceType   = "s"
            });

            invoker = new Invoker(command);
            invoker.Execute();

            Console.ReadKey();
        }