public CommandPatternApp() { // Add each command to the command history and you can undo all the commands // by just iterating over the history and hitting Undo List <IDeviceButton> commandsHistory = new List <IDeviceButton>(); var phone = new MobilePhone(); var turnOnCommand = new TurnOnDevice(phone); var turnOffCommand = new TurnOffDevice(phone); var turnOffButton = new MobileButton(turnOffCommand); var turnOnButton = new MobileButton(turnOnCommand); IncreaseVolume increaseVolumeCommand = new IncreaseVolume(phone); MobileButton increaseVolumeButton = new MobileButton(increaseVolumeCommand); DecreaseVolume decreaseVolumeCommand = new DecreaseVolume(phone); MobileButton decreaseVolumeButton = new MobileButton(decreaseVolumeCommand); turnOffButton.Press(); turnOnButton.Press(); turnOffButton.Press(); //increaseVolumeButton.Press(); // Will throw exception turnOnButton.Press(); increaseVolumeButton.Press(); increaseVolumeButton.Press(); decreaseVolumeButton.Press(); // Example of undoing using array // Last two command commandsHistory.Add(increaseVolumeButton); commandsHistory.Add(decreaseVolumeButton); commandsHistory.ForEach(command => { command.UndoPress(); }); // Done // Undo commands individualy //increaseVolumeButton.UndoPress(); //decreaseVolumeButton.UndoPress(); }
public async Task Accept(TurnOffDevice msg) { await _hueClient.TurnDeviceOffAsync(msg.HueDevice); }