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); }
static void Main(string[] args) { var addCustomerCommand = new AddCustomerCommand(new CustomerService()); var button = new Button(addCustomerCommand); button.Click(); // Because we are representing each individual task using a command object, // we can combine these commands inside a composite object and re-execute them later on. var compositeCommand = new CompositeCommand(); compositeCommand.Add(new ResizeCommand()); compositeCommand.Add(new BlackAndWhiteCommand()); compositeCommand.Execute(); var history = new Solution.UndoableCommands.History(); var htmlDocument = new HtmlDocument(); htmlDocument.Content = "Hello World!"; var boldCommand = new BoldCommand(htmlDocument, history); boldCommand.Execute(); Console.WriteLine(htmlDocument.Content); //boldCommand.Unexecute(); var undoCommand = new Solution.UndoableCommands.UndoCommand(history); undoCommand.Execute(); Console.WriteLine(htmlDocument.Content); Console.WriteLine("--- Exercise ---"); var exeHistory = new Exercise.End.History(); var videoEditor = new VideoEditor(); var setTextCommand = new SetTextCommand("Hello World!", videoEditor, exeHistory); setTextCommand.Execute(); Console.WriteLine(videoEditor.Text); //setTextCommand.Undo(); var exeUndoCommand = new Exercise.End.UndoCommand(exeHistory); exeUndoCommand.Execute(); Console.WriteLine(videoEditor.Text); Console.ReadLine(); }