Ejemplo n.º 1
0
        static void Main()
        {
            var commandProcessor = new CommandQueueProcessor
                                        {
                                            Snapshots = new Queue<IMemento>()
                                        };
            var order = new Order
                                        {
                                            List = new List<IProduct>()
                                        };

            var addProductCommand = new AddProductCommand
                                        {
                                            Order = order,
                                            Product = new Product
                                                          {
                                                              Name = "First",
                                                              Count = 10,
                                                              Price = 100,
                                                          }
                                        };
            commandProcessor.AddCommandToExecute(addProductCommand);

            addProductCommand.Product = new Product
                                                 {
                                                     Count = 20,
                                                     Price = 200,
                                                     Name = "Secon"
                                                 };
            commandProcessor.AddCommandToExecute(addProductCommand);

            addProductCommand.Product = new Product
                                            {
                                                Count = 30,
                                                Price = 300,
                                                Name = "Third"
                                            };
            commandProcessor.AddCommandToExecute(addProductCommand);

            commandProcessor.Run();
            commandProcessor.Run();
            commandProcessor.Run();

            var getSumPriceCommand = new GetSumPriceCommand { Order = order };
            commandProcessor.AddCommandToExecute(getSumPriceCommand);

            Console.Write(order.ToString());
            Console.WriteLine(commandProcessor.Run());
            Console.WriteLine("\n");

            commandProcessor.Undo();
            commandProcessor.AddCommandToExecute(getSumPriceCommand);

            Console.Write(order.ToString());
            Console.WriteLine(commandProcessor.Run());
            Console.WriteLine("\n");

            commandProcessor.Undo();
            commandProcessor.AddCommandToExecute(getSumPriceCommand);

            Console.Write(order.ToString());
            Console.WriteLine(commandProcessor.Run());
            Console.WriteLine("\n");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var commandProcessor = new CommandQueueProcessor
                                        {
                                            Commands = new Queue<ICommand>()
                                        };
            var order = new Order
                                        {
                                            List = new List<IProduct>()
                                        };

            var addFirstProductCommand = new AddProductCommand
                                        {
                                            Order = order,
                                            Product = new Product
                                                          {
                                                              Name = "First",
                                                              Count = 10,
                                                              Price = 100,
                                                              Guid = Guid.NewGuid()
                                                          }
                                        };
            var addSecondProductCommand = new AddProductCommand
                                        {
                                            Order = order,
                                            Product = new Product
                                                          {
                                                              Name = "Secnd",
                                                              Count = 20,
                                                              Price = 200,
                                                              Guid = Guid.NewGuid()
                                                          }
                                        };
            var addThirdProductCommand = new AddProductCommand
                                        {
                                            Order = order,
                                            Product = new Product
                                                          {
                                                              Name = "Third",
                                                              Count = 30,
                                                              Price = 300,
                                                              Guid = Guid.NewGuid()
                                                          }
                                        };
            var getSumPriceCommand = new GetSumPriceCommand { Order = order };

            commandProcessor.AddCommandToExecute(addFirstProductCommand);
            commandProcessor.AddCommandToExecute(addSecondProductCommand);
            commandProcessor.AddCommandToExecute(addThirdProductCommand);

            commandProcessor.Run();
            commandProcessor.Run();
            commandProcessor.Run();

            commandProcessor.AddCommandToExecute(getSumPriceCommand);

            Console.Write(order.ToString());
            Console.WriteLine(commandProcessor.Run());
            Console.WriteLine("-----------------------------------------------------------------------");

            commandProcessor.Undo();
            commandProcessor.AddCommandToExecute(getSumPriceCommand);

            Console.Write(order.ToString());
            Console.WriteLine(commandProcessor.Run());
            Console.WriteLine("-----------------------------------------------------------------------");

            commandProcessor.Undo();
            commandProcessor.AddCommandToExecute(getSumPriceCommand);

            Console.Write(order.ToString());
            Console.WriteLine(commandProcessor.Run());
            Console.WriteLine("-----------------------------------------------------------------------");
        }