Exemplo n.º 1
0
        private static void Main()
        {
            // Application_A
            var service = new CustomerService();
            var command = new AddCustomerCommand(service);
            var button  = new Button(command);

            button.Click();

            // Application_B
            var composite = new CompositeCommand();

            composite.Add(new ResizeCommand());
            composite.Add(new BlackAndWhiteCommand());

            composite.Execute();

            // Application_C
            var history  = new History();
            var document = new HtmlDocument
            {
                Content = "Hello World"
            };

            var boldCommand = new BoldCommand(document, history);

            boldCommand.Execute();
            System.Console.WriteLine(document.Content); // <b>Hello World</b>

            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();
            System.Console.WriteLine(document.Content); // Hello World
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var history  = new History();
            var document = new HtmlDocument();

            document.Content = "Hello World";
            var boldCommand = new BoldCommand(document, history);

            boldCommand.Execute();
            Console.WriteLine(document.Content);
            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();
            Console.WriteLine(document.Content);
            Console.ReadKey();

            //TODO: add more commands here
            var service = new CustomerService();
            var command = new AddCustomerCommand(service);
            var button  = new Button(command);

            button.Click();
            Console.ReadKey();

            var composite = new CompositeCommand();

            composite.Add(new ResizeCommand());
            composite.Add(new BlackAndWhiteCommand());
            composite.Execute();
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("- Command -");
            var           receiverService = new Receiver();
            var           playCommand     = new PlayCommand(receiverService);
            InvokerButton invokerButton   = new InvokerButton(playCommand);

            invokerButton.Click();
            Console.WriteLine("\n- Composite Command -");
            CompositeCommand compositeCommand = new CompositeCommand();

            compositeCommand.AddCommand(playCommand);
            compositeCommand.AddCommand(playCommand);
            compositeCommand.AddCommand(playCommand);
            InvokerButton invokerButton1 = new InvokerButton(compositeCommand);

            invokerButton1.Click();
            Console.WriteLine("\n- Undo Operation -");
            History         _history         = new History();
            var             receiverService1 = new Receiver();
            UndoableCommand undoableCommand  = new UndoableCommand(receiverService1, _history);

            undoableCommand.Execute();
            Console.WriteLine(receiverService1.Content);
            //undoableCommand.Unexecute();
            //Console.WriteLine(receiverService1.Content);
            UndoCommand undoCommand = new UndoCommand(_history);

            undoCommand.Execute();
            Console.WriteLine(receiverService1.Content);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // decoupling the customer service from the button
            // otherwise all code has to be retained in the button

            var service = new CustomerService();
            var command = new AddCustomerCommand(service);
            var button  = new Button(command);

            button.Click();

            var composite = new CompositeCommand();

            composite.Add(new ResizeCommand());
            composite.Add(new BlackAndWhiteCommand());
            composite.Execute();


            var history  = new History();
            var document = new HtmlDocument {
                Content = "Hello World"
            };

            var bold = new BoldCommand(document, history);

            bold.Execute();
            Console.WriteLine(document.Content);

            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();

            Console.WriteLine(document.Content);
        }