public static void MacroCommandTests() { var light = new Light("Living Room"); var tv = new TV("Living Room"); var stereo = new Stereo("Living Room"); var hottub = new Hottub(); var lightOn = new LightOnCommand(light); var stereoOn = new StereoOnWithCdCommand(stereo); var tvOn = new TvOnCommand(tv); var hottubOn = new HottubOnCommand(hottub); var lightOff = new LightOffCommand(light); var stereoOff = new StereoOffCommand(stereo); var tvOff = new TvOffCommand(tv); var hottubOff = new HottubOffCommand(hottub); IUndoableCommand[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; IUndoableCommand[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); var remoteControl = new RemoteControl(); remoteControl.SetCommand(1, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); Console.WriteLine("---Pushing Macro On-- -"); remoteControl.OnButtonWasPushed(1); Console.WriteLine("---Pushing Macro Off-- -"); remoteControl.OffButtonWasPushed(1); Console.ReadKey(); }
static void RemoteControlTestMacro() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); CeilingFan ceilingFan = new CeilingFan("Living Room"); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); CeilingFanHighCommand ceilingFanOn = new CeilingFanHighCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); ICommand[] partyOn = { livingRoomLightOn, ceilingFanOn, stereoOnWithCd }; ICommand[] partyOff = { livingRoomLightOff, ceilingFanOff, stereoOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); }
public void CommandExampleMacros() { RemoteControl remote = new RemoteControl(); // this is the invoker Light livingRoomLight = new Light("Living Room"); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); ICommand[] partyOn = { livingRoomLightOn, stereoOnWithCd }; ICommand[] partyOff = { livingRoomLightOff, stereoOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remote.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remote); Console.WriteLine("--- Pushing Macro On ---\n"); remote.OnButtonWasPushed(0); Console.WriteLine("--- Pushing Macro Off ---\n"); remote.OffButtonWasPushed(0); Console.WriteLine("--- Pushing Macro Undo ---\n"); // not working for every scenario remote.UndoButtonWasPushed(); Console.ReadLine(); }
static void RemoteControlTest() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanHighCommand ceilingFanOn = new CeilingFanHighCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCd, stereoOff); remoteControl.SetCommand(4, garageDoorUp, garageDoorDown); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.OnButtonWasPushed(4); remoteControl.OffButtonWasPushed(4); }
public void CommandExample() { RemoteControl remote = new RemoteControl(); // this is the invoker Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen Room"); GarageDoor garageDoor = new GarageDoor(""); CeilingFan ceilingFan = new CeilingFan("Living Room"); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnHighCommand ceilingFanOnHigh = new CeilingFanOnHighCommand(ceilingFan); CeilingFanOnMediumCommand ceilingFanOnMedium = new CeilingFanOnMediumCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remote.SetCommand(1, kitchenLightOn, kitchenLightOff); remote.SetCommand(2, ceilingFanOnHigh, ceilingFanOnMedium); remote.SetCommand(3, stereoOnWithCd, stereoOff); Console.WriteLine(remote); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); remote.OnButtonWasPushed(2); remote.OffButtonWasPushed(2); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(3); remote.OffButtonWasPushed(3); remote.UndoButtonWasPushed(); Console.ReadLine(); }
public static void UndoTest() { var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living Room"); var kitchenLight = new Light("Kitchen"); var ceilingFan = new CeilingFan("Living Room"); var garageDoor = new GarageDoor(); var stereo = new Stereo("Living Room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanHighCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorUpCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoOnWithCD = new StereoOnWithCdCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(1, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(2, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(3, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(4, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(4); remoteControl.OffButtonWasPushed(4); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); Console.ReadKey(); }
static void Main(string[] args) { var remoteControl = new Controllers.RemoteControl(); var livingRoonLight = new Light("Living Room"); var kitchenLight = new Light("Kitchen"); var ceilingFan = new CeilingFan("Living Room"); var garageDoor = new GarageDoor(); var stereo = new Stereo("Living Room"); var livingRoomLightOn = new LightOnCommand(livingRoonLight); var livingRoomLightOff = new LightOffCommand(livingRoonLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorUpCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoOnWithCd = new StereoOnWithCdCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCd, stereoOff); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPressed(0); remoteControl.OffButtonWasPressed(0); remoteControl.OnButtonWasPressed(1); remoteControl.OffButtonWasPressed(1); remoteControl.OnButtonWasPressed(2); remoteControl.OffButtonWasPressed(2); remoteControl.OnButtonWasPressed(3); remoteControl.OffButtonWasPressed(3); Console.ReadLine(); }
private void Command_Click(object sender, RoutedEventArgs e) { var remoteControl = new RemoteControl(); var light = new Light(); var garageDoor = new GarageDoor(); var stereo = new Stereo(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var garageOpen = new GarageDoorOpenCommand(garageDoor); var garageClose = new GarageDoorCloseCommand(garageDoor); var stereoOn = new StereoOnWithCdCommand(stereo); var stereoOff = new StereoOffWithCdCommand(stereo); remoteControl.SetCommand(0, lightOn, lightOff); remoteControl.SetCommand(1, garageOpen, garageClose); remoteControl.SetCommand(2, stereoOn, stereoOff); remoteControl.SetCommand(6, new MacroCommand(new ICommand[] { lightOn, garageOpen, stereoOn }), new MacroCommand(new ICommand[] { lightOff, garageClose, stereoOff })); Console.WriteLine(remoteControl.ToString()); }
static void Main(string[] args) { int numSlots = 5; BetterRemoteControl remote = new BetterRemoteControl(numSlots); Light livingRoomLight = new Light("Living Room"); Light kitchenLght = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor("Downstairs"); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(livingRoomLight); LightOffCommand kitchenLightOff = new LightOffCommand(livingRoomLight); CeilingFanHighCommand ceilingFanOnHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanOnMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanOnLow = new CeilingFanLowCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); Command[] partyOn = { livingRoomLightOn, ceilingFanOnHigh, stereoOnWithCd }; Command[] partyOff = { livingRoomLightOff, ceilingFanOff, stereoOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partOffMacro = new MacroCommand(partyOff); Command[] testPartyFanOn = { ceilingFanOnHigh, ceilingFanOnMedium, ceilingFanOnLow }; Command[] testPartyFanOff = { ceilingFanOff }; MacroCommand testPartyFanOnMacro = new MacroCommand(testPartyFanOn); MacroCommand testPartyFanOffMacro = new MacroCommand(testPartyFanOff); //remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); //remote.SetCommand(1, kitchenLightOn, kitchenLightOff); //remote.SetCommand(2, ceilingFanOnHigh, ceilingFanOff); //remote.SetCommand(3, garageOpen, garageClose); //remote.SetCommand(4, stereoOnWithCd, stereoOff); remote.SetCommand(0, ceilingFanOnHigh, ceilingFanOff); remote.SetCommand(1, ceilingFanOnMedium, ceilingFanOff); remote.SetCommand(2, ceilingFanOnLow, ceilingFanOff); remote.SetCommand(3, partyOnMacro, partOffMacro); remote.SetCommand(4, testPartyFanOnMacro, testPartyFanOffMacro); Console.WriteLine(remote); Console.WriteLine("\n Changing fan settings several times"); remote.OnButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OnButtonWasPushed(2); Console.WriteLine("\n Undoing fan settings several times"); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); Console.WriteLine("\nTurning on macro"); remote.OnButtonWasPushed(3); //Console.WriteLine("\nTurning off macro"); //remote.OffButtonWasPushed(3); Console.WriteLine("\nUndoing previous macro button push"); //Though this eventually calls 3 Undo()'s (one for each of the 3 classes in the MacroCommand's Command[]), the stack in //remote control class actually only has 1 object in it, the MacroCommand object remote.UndoButtonWasPushed(); //This won't get called because stack size is not > 0 remote.UndoButtonWasPushed(); Console.WriteLine("\nTesting out how fan's handle the macro class"); remote.OnButtonWasPushed(4); Console.WriteLine("\nUndoing the fan macro class"); remote.UndoButtonWasPushed(); //remote.OnButtonWasPushed(1); //remote.UndoButtonWasPushed(); //remote.OnButtonWasPushed(1); //remote.OffButtonWasPushed(1); //remote.OnButtonWasPushed(2); //remote.OffButtonWasPushed(2); //remote.OnButtonWasPushed(3); //remote.OffButtonWasPushed(3); //remote.OnButtonWasPushed(4); //remote.OffButtonWasPushed(4); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("SIMPLE REMOTE CONTROL"); var simpleRemoteControl = new SimpleRemoteControl(); var light = new Light("Living room"); var lightOn = new LightOnCommand(light); simpleRemoteControl.SetCommand(lightOn); simpleRemoteControl.ButtonWasPressed(); var garageDoorSimpleControl = new GarageDoor(); var garageOpen = new GarageDoorOpenCommand(garageDoorSimpleControl); simpleRemoteControl.SetCommand(garageOpen); simpleRemoteControl.ButtonWasPressed(); Console.WriteLine("REMOTE CONTROL"); var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living room"); var kitchenLight = new Light("Kitchen"); var ceilingFan = new CeilingFan("Living room"); var garageDoor = new GarageDoor(); var stereo = new Stereo("Living room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorOpen = new GarageDoorOpenCommand(garageDoor); var garageDoorClose = new GarageDoorCloseCommand(garageDoor); var stereoOnWithCd = new StereoOnWithCdCommand(stereo); var stereoOffWithCd = new StereoOffWithCdCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCd, stereoOffWithCd); Console.WriteLine(remoteControl.ToString()); Console.WriteLine("-----------------FUNÇÕES EXECUTANDO"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); Console.WriteLine(""); Console.WriteLine("REMOTE CONTROL WITH UNDO"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); Console.WriteLine(""); Console.WriteLine("REMOTE CONTROL WITH UNDO OF THE CEILING FAN"); var remoteControlCeilingFan = new RemoteControl(); var ceilingFanHigh = new CeilingFanHightCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); remoteControlCeilingFan.SetCommand(0, ceilingFanMedium, ceilingFanOff); remoteControlCeilingFan.SetCommand(1, ceilingFanHigh, ceilingFanOff); remoteControlCeilingFan.OnButtonWasPushed(0); remoteControlCeilingFan.OffButtonWasPushed(0); Console.WriteLine(remoteControlCeilingFan.ToString()); remoteControlCeilingFan.UndoButtonWasPushed(); //remoteControlCeilingFan.OnButtonWasPushed(0); remoteControlCeilingFan.OnButtonWasPushed(1); Console.WriteLine(remoteControlCeilingFan.ToString()); remoteControlCeilingFan.UndoButtonWasPushed(); Console.WriteLine(""); Console.WriteLine("MACRO COMAND (PARTY MODE)"); var tv = new Tv("Living room"); var hottub = new Hottub(); var tvOn = new TvOnCommand(tv); var tvOff = new TvOffCommand(tv); var hottubOn = new HottubOnCommand(hottub); var hottubOff = new HottubOffCommand(hottub); var commandsPartyOn = new List <ICommand>() { livingRoomLightOn, stereoOnWithCd, tvOn, hottubOn }; var commandsPartyOff = new List <ICommand>() { livingRoomLightOff, stereoOffWithCd, tvOff, hottubOff }; var partyOn = new MacroCommand(commandsPartyOn); var partyOff = new MacroCommand(commandsPartyOff); var remoteControlParty = new RemoteControl(); remoteControlParty.SetCommand(0, partyOn, partyOff); Console.WriteLine(remoteControlParty.ToString()); Console.WriteLine("PUSHING MACRO ON"); remoteControlParty.OnButtonWasPushed(0); Console.WriteLine("PUSHING MACRO OFF"); remoteControlParty.OffButtonWasPushed(0); Console.ReadKey(); }