Execute() public method

public Execute ( CharacterObservable, caller, CharacterObservable, interactWith, CommandManager, cm, GameManager, gm ) : void
caller CharacterObservable,
interactWith CharacterObservable,
cm CommandManager,
gm GameManager,
return void
Esempio n. 1
0
        public static void Behavioral_CommandDemo2()
        {
            //var videoEditor = new VideoEditor();
            //videoEditor.SetText("demo2 video text");
            //videoEditor.SetContrast(0.7f);
            //var result = videoEditor.ToString();
            //Console.WriteLine(result);

            var videoEditor = new VideoEditor();
            var history     = new Command.Demo2.History();

            var setTextCommand = new SetTextCommand("Video Title", videoEditor, history);

            setTextCommand.Execute();
            Console.WriteLine("TEXT: " + videoEditor);

            var setContrast = new SetContrastCommand(1, videoEditor, history);

            setContrast.Execute();
            Console.WriteLine("CONTRAST: " + videoEditor);

            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();
            Console.WriteLine("UNDO: " + videoEditor);

            undoCommand.Execute();
            Console.WriteLine("UNDO: " + videoEditor);

            undoCommand.Execute();
            Console.WriteLine("UNDO: " + videoEditor);
        }
Esempio n. 2
0
        static void TestUndoableCommand()
        {
            var history  = new Command.Editor.History();
            var document = new Command.Editor.HtmlDocument();

            document.Content = "Hello World";

            var boldCommand = new BoldCommand(document, history);

            boldCommand.Execute();

            System.Console.WriteLine(document.Content);

            document.Content = "This is Command Pattern";
            boldCommand      = new BoldCommand(document, history);
            boldCommand.Execute();

            System.Console.WriteLine(document.Content);

            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();

            System.Console.WriteLine(document.Content);

            undoCommand.Execute();
            System.Console.WriteLine(document.Content);
        }
Esempio n. 3
0
        /// <summary>
        /// Allows decouple a sender from a receiver. The sender will talk to the receive through a command. Commands can be undone and persisted.
        ///
        /// With Command its easy to build an independent framework that anyone can use. By creating a custom service which implements a base interface,
        /// any command can be run with the same method, depending on the service.
        /// </summary>
        static void Command()
        {
            // One command attached to an action.
            var service = new CustomerService();
            var command = new AddCustomerCommand(service);
            var button  = new Command.fx.Button(command);

            button.Click();

            // Multiple commands attached to an action.
            var composite = new CompositeCommand();

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

            // Using the undo mechanism. Multiple commands are implementing the same interface(s) and using the same history.
            var history  = new Command.editor.History();
            var document = new Command.editor.HtmlDocument();

            document.Content = "Hello";

            var boldCommand = new BoldCommand(document, history);

            boldCommand.Execute();

            Console.WriteLine(document.Content);

            var undoCommant = new UndoCommand(history);

            undoCommant.Execute();

            Console.WriteLine(document.Content);
        }
Esempio n. 4
0
        public override void Execute(object parameter)
        {
            UndoCommand undoCommand = new UndoCommand(Current.Controller);

            undoCommand.Execute();
            OnCanExecuteChanged(null);
        }
Esempio n. 5
0
 public virtual void Undo()
 {
     if (UndoCommand != null)
     {
         UndoCommand.Execute();
     }
 }
Esempio n. 6
0
        private static void UndoableCommandPattern()
        {
            var document = new Document {
                Content = "Some content"
            };

            Console.WriteLine("Before");
            Console.WriteLine(document.Content);

            var history     = new CommandHistory();
            var boldCommand = new BoldCommand(document, history);
            var button      = new Button(boldCommand);

            button.Click();

            Console.WriteLine("After");
            Console.WriteLine(document.Content);


            Console.WriteLine("After Undo");
            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();

            Console.WriteLine(document.Content);
        }
Esempio n. 7
0
        public void Throws_When_No_Canvas_Exist()
        {
            var command = new UndoCommand();

            Action test = () => command.Execute(null);

            test.Should().Throw <ArgumentNullException>();
        }
Esempio n. 8
0
        public void Calls_Canvas_Undo()
        {
            var mockCanvas = new Mock <ICanvas>();

            var command = new UndoCommand();

            command.Execute(mockCanvas.Object);

            mockCanvas.Verify(x => x.Undo(), Times.Once);
        }
Esempio n. 9
0
        public void Rollback()
        {
            object temp = new object();

            while (undoCommand.CanExecute(temp))
            {
                UndoCommand.Execute(temp);
            }

            ResetRedoChangeLog();
        }
        public void OnExecuteShouldInformPlayerThatAMementoIsNotAvailableWhenThereIsntOneSaved()
        {
            var ctx = new CommandContext(new Logger(), new Board(5, 5, new RandomGenerator()), 2, 2, new BoardMemory(), Highscore.GetInstance(), new HighscoreProcessor());

            var cmd = new UndoCommand();

            cmd.Execute(ctx);

            var expected = ctx.Messages["invalidsave"];

            Assert.AreEqual(expected, ctx.CurrentMessage);
        }
Esempio n. 11
0
        public void ExecuteCommand_NoParams_ExpectedResult()
        {
            // arrange
            Mock <ICommandHistory> _historyMock = new Mock <ICommandHistory>();

            UndoCommand testUndoCommand = new UndoCommand(_historyMock.Object);

            // act

            testUndoCommand.Execute();
            // assert
            _historyMock.Verify(h => h.Undo(), Times.Once());
        }
Esempio n. 12
0
        static void CommandPattern()
        {
            Console.WriteLine("\n\nCommandPattern Pattern");
            var history        = new History();
            var exampleService = new ExampleService("Initial value");
            var exampleCommand = new ExampleCommand(history, exampleService);
            var undoCommand    = new UndoCommand <string>(history);

            Console.WriteLine(exampleService.GetContent());
            exampleCommand.Execute();
            Console.WriteLine(exampleService.GetContent());
            undoCommand.Execute();
            Console.WriteLine(exampleService.GetContent());
        }
Esempio n. 13
0
        public CommandPatternMain()
        {
            var boldCommand = new BoldCommand(_htmlDocument, _history);
            var undoCommand = new UndoCommand(_history);

            _htmlDocument.Content = "Hello World!";

            Console.WriteLine(_htmlDocument.Content);


            boldCommand.Execute();
            Console.WriteLine(_htmlDocument.Content);

            undoCommand.Execute();
            Console.WriteLine(_htmlDocument.Content);
        }
Esempio n. 14
0
    void Start()
    {
        boxTransform = GetComponent <Transform>();
        commandBag   = new ShuffleBag <Command>(commandList.Count);
        foreach (Command c in commandList)
        {
            commandBag.Add(c, 1);
        }
        //Command binding has to happen in the start function
        ShuffleInputs(commandBag);
        buttonR = new UndoCommand();

        //set the ui buttons for shuffle and undo

        UndoButton.onClick.AddListener(() => { buttonR.Execute(boxTransform, buttonR); });
        ShuffleButton.onClick.AddListener(() => { ShuffleInputs(commandBag); });
    }
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);


            CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo,
                                                   (sender, ce) =>
            {
                var undo      = UndoStack.Pop();
                _isUndoHandle = true;
                if (!(UndoCommand?.CanExecute(null) ?? true))
                {
                    return;
                }
                else
                {
                    UndoCommand?.Execute(null);
                }
                undo.UndoAction(undo);
            },
                                                   (sender, ce) =>
            {
                ce.CanExecute = UndoStack.Any();
            }));

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo,
                                                   (sender, ce) =>
            {
                var redo      = RedoStack.Pop();
                _isUndoHandle = false;
                if (!(RedoCommand?.CanExecute(null) ?? true))
                {
                    return;
                }
                else
                {
                    RedoCommand?.Execute(null);
                }
                redo.RedoAction(redo);
            },
                                                   (sender, ce) =>
            {
                ce.CanExecute = RedoStack.Any();
            }));
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            History      history  = new History();
            HtmlDocument document = new HtmlDocument();

            document.Content = "Hello World";

            BoldCommand boldCommand = new BoldCommand(document: document, history);

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

            UndoCommand undoCommand = new UndoCommand(history);

            undoCommand.Execute();

            Console.WriteLine(document.Content);
        }
Esempio n. 17
0
        public static void Run()
        {
            var history  = new CommandsHistory();
            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);
        }
Esempio n. 18
0
        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Z && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
            {
                UndoCommand.Execute(null);
            }
            else if (e.Key == Key.Y && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
            {
                RedoCommand.Execute(null);
            }

            else if (e.Key == Key.N && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
            {
                NewFlowCommand.Execute(null);
            }
            else if (e.Key == Key.O && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
            {
                OpenFlowCommand.Execute(null);
            }
            else if (e.Key == Key.S && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control | ModifierKeys.Shift))
            {
                SaveAllFlowsCommand.Execute(null);
            }
            else if (e.Key == Key.S && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
            {
                SaveFlowCommand.Execute(null);
            }

            else if (e.Key == Key.F5 && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Shift))
            {
                StopFlowCommand.Execute(null);
            }
            else if (e.Key == Key.F5)
            {
                RunFlowCommand.Execute(null);
            }
            else if (e.Key == Key.F10)
            {
                StepFlowCommand.Execute(null);
            }
        }
Esempio n. 19
0
        public void Undo()
        {
            var currentMark = new TimeMarker(10);
            var markers = new List<TimeMarker>
                {
                    currentMark,
                    new TimeMarker(1),
                };
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.CanRollBack)
                    .Returns(true);
                history.Setup(h => h.MarkersInThePast())
                    .Returns(markers);
                history.Setup(h => h.Current)
                    .Returns(currentMark);
                history.Setup(h => h.RollBackTo(It.IsAny<TimeMarker>(), It.IsAny<TimelineTraveller>()))
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
                projectLink.Setup(p => p.HasActiveProject())
                    .Returns(true);
            }

            Func<string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new UndoCommand(projectLink.Object, timerFunc);
            command.Execute(null);

            history.Verify(h => h.RollBackTo(It.IsAny<TimeMarker>(), It.IsAny<TimelineTraveller>()), Times.Once());
        }
Esempio n. 20
0
        public void Undo()
        {
            ICommand command = new UndoCommand("Undo", this);

            command.Execute();
        }
Esempio n. 21
0
 private void _undoButton_Click(object sender, EventArgs e)
 {
     _undoCommand.Execute();
 }
Esempio n. 22
0
 protected virtual void OnUndoActivated(object sender, System.EventArgs e)
 {
     UndoCommand command = new UndoCommand ("Undo", this);
     command.Execute ();
 }
Esempio n. 23
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter 1 for Factory Pattern. \n" +
                              "Enter 2 for Observer Pattern.");
            int choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
            case 1:
                var ef = new EmployeeFactory();
                Console.WriteLine(ef.GetEmployee(1).GetBonus());
                Console.ReadLine();
                break;

            case 2:
                var observable = new TemperatureMonitor();
                var observer   = new TemperatureReporter();
                observer.Subscribe(observable);
                observable.GetTemperature();
                break;

            case 3:
                var editor  = new Editor();
                var history = new Momento.History();

                editor.SetContent("a");
                history.Push(editor.CreateState());
                editor.SetContent("b");
                history.Push(editor.CreateState());
                editor.SetContent("c");
                history.Push(editor.CreateState());
                editor.Restore(history.Pop());
                editor.Restore(history.Pop());

                Console.WriteLine(editor.GetContent());
                break;

            case 4:

                Canvas canvas = new Canvas();
                canvas.SelectTool(new BrushTool());
                canvas.MouseDown();
                canvas.MouseUp();
                break;

            case 5:

                BrowseHistory browseHistory = new BrowseHistory();
                browseHistory.Push("www.google.com");
                browseHistory.Push("www.yahoo.com");
                browseHistory.Push("www.reddif.com");
                browseHistory.Push("www.youtube.com");

                IIterator <string> iterator = browseHistory.CreateIterator();
                while (iterator.HasNext())
                {
                    var url = iterator.Current();
                    Console.WriteLine(url);
                    iterator.next();
                }
                break;

            case 6:
                //The difference between State and Strategy pattern is that in state pattern there is only a single state of the object and the behaviour is determined by the implementation injected.
                //In strategy pattern there could be multiple behaviours in form of multiple properties inside class such as IFilter & ICompression. The implementation injected further changes the behaviour.
                PhotoProcessor photoProcessor = new PhotoProcessor(new BnW(), new JPEG());
                photoProcessor.ProcessPhoto();
                break;

            case 7:     //template
                AbstractPreFlightCheckList flightChecklist = new F16PreFlightCheckList();
                flightChecklist.runChecklist();

                break;

            case 8:     //command
                var service = new CustomerService();
                var command = new AddCustomerCommand(service);
                var button  = new Command.Button(command);
                button.click();

                var composite = new CompositeCommand();
                composite.Add(new ResizeCommand());
                composite.Add(new BlackAndWHiteCommand());
                var button2 = new Command.Button(composite);
                button2.click();

                var commandHisotry = new Command.Undo.History();

                var doc = new Command.Undo.HtmlDocument();
                doc.SetContent("Hello World");
                var boldCommand = new BoldCommand(doc, commandHisotry);
                boldCommand.Execute();
                Console.WriteLine(doc.GetContent());

                var undoCommand = new UndoCommand(commandHisotry);
                undoCommand.Execute();
                Console.WriteLine(doc.GetContent());

                break;

            case 9:     //Observer
                DataSource dataSource = new DataSource();
                dataSource.AddObserver(new Chart());
                dataSource.AddObserver(new SpreadSheet(dataSource));
                dataSource.SetValue("value changed");
                break;

            case 10:     //Mediator //the pattern is applied to encapsulate or centralize the interactions amongst a number of objects
                var dialog = new ArticlesDialogBox();
                dialog.SimulateUsserInteraction();
                break;

            case 11:     //Chain of Responsibility
                //autehnticator --> logger --> compressor --> null
                var compressor    = new Compressor(null);
                var logger        = new Logger(compressor);
                var authenticator = new Authenticator(logger);
                var server        = new WebServer(authenticator);
                server.handle(new HttpRequest()
                {
                    UserName = "******", Password = "******"
                });
                break;

            case 12:     //Visitor
                var document = new Visitor.HtmlDocument();
                document.Add(new HeadingNode());
                document.Add(new AnchorNode());
                document.Execute(new HighlighOperation());
                break;

            case 13:     // Composite
                var shape1 = new Shape();
                var shape2 = new Shape();
                var group1 = new Group();
                group1.Add(shape1);
                group1.Add(shape2);
                var group2 = new Group();
                var shape3 = new Shape();
                group2.Add(shape3);
                group1.Add(group2);
                group1.render();
                break;

            case 14:     //Adapter
                Image       image       = new Image();
                ImageViewer imageViewer = new ImageViewer(image);
                imageViewer.Apply(new SepiaFilter());
                imageViewer.Apply(new FancyAdapter(new FancyFilter()));
                break;

            case 15:     //Decorator
                var cloudStream  = new CloudStream();
                var encryptData  = new EncryptStream(cloudStream);
                var compressData = new CompressStream(encryptData);
                compressData.write("some random data");
                break;

            case 16:     //Facade
                NotificationService notificationService = new NotificationService();
                notificationService.Send("Hello..", "17.0.0.1");
                break;

            case 17:     //Flyweight
                PointService pointService = new PointService(new PointFactory());
                var          points       = pointService.getPoints();
                foreach (var p in points)
                {
                    p.draw();
                }
                break;

            case 18:     //Bridge
                AdvancedRemoteControl remote = new AdvancedRemoteControl(new SonyTv());
                remote.setChannel(1);
                break;

            case 19:     //Proxy
                Library       lib       = new Library();
                List <string> bookNames = new List <string>()
                {
                    "a", "b", "c"
                };
                foreach (var book in bookNames)
                {
                    lib.eBooks.Add(book, new EBookProxy(book));
                }
                lib.OpenEbook("a");
                break;

            case 20:     //Factory Method
                FactoryMethod.Employee emp          = new FactoryMethod.Employee();
                BaseEmployeeFactory    permanentEmp = new PermanentEmployeeFactory(emp);
                permanentEmp.ApplySalary();
                Console.WriteLine(emp.HouseAllowance);
                break;

            case 21:     //Abstract Factory
                AbstractFactory.Employee emp1 = new AbstractFactory.Employee();
                emp1.EmployeeTypeID = 1;
                emp1.JobDescription = "Manager";
                EmployeeSystemFactory esf = new EmployeeSystemFactory();
                var computerFactory       = esf.Create(emp1);
                Console.WriteLine($"{computerFactory.GetType()}, {computerFactory.Processor()}, {computerFactory.SystemType()}, {computerFactory.Brand()}");
                break;

            case 22:     //Builder
                Builder.IToyBuilder toyBuilder  = new Builder.PremiumToyBuilder();
                Builder.ToyDirector toyDirector = new Builder.ToyDirector(toyBuilder);
                toyDirector.CreateFullFledgedToy();
                Console.WriteLine(toyDirector.GetToy());
                break;

            case 23:     //Fluent Builder
                //Difference of implementation is visible in Director class.
                FluentBuilder.IToyBuilder toyBuilder1  = new FluentBuilder.PremiumToyBuilder();
                FluentBuilder.ToyDirector toyDirector1 = new FluentBuilder.ToyDirector(toyBuilder1);
                toyDirector1.CreateFullFledgedToy();
                Console.WriteLine(toyDirector1.GetToy());
                break;

            case 24:    //Object Pool
                ObjectPool <OneExpensiveObjToCreate> objPool = new ObjectPool <OneExpensiveObjToCreate>();
                OneExpensiveObjToCreate obj = objPool.Get();
                objPool.Release(obj);
                break;
            }

            Console.ReadLine();
        }