static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); Light light1 = new Light("Living Room"); Light light2 = new Light("Kitchen"); Stereo stereo1 = new Stereo("Living Room"); Stereo stereo2 = new Stereo("Kitchen"); LightOnCommand lightOnCommand1 = new LightOnCommand(light1); LightOffCommand lightOffCommand1 = new LightOffCommand(light1); LightOnCommand lightOnCommand2 = new LightOnCommand(light2); LightOffCommand lightOffCommand2 = new LightOffCommand(light2); StereoOnCommand stereoOnCommand1 = new StereoOnCommand(stereo1); StereoOffCommand stereoOffCommand1 = new StereoOffCommand(stereo1); StereoOnCommand stereoOnCommand2 = new StereoOnCommand(stereo2); StereoOffCommand stereoOffCommand2 = new StereoOffCommand(stereo2); remoteControl.SetCommand(0, lightOnCommand1, lightOffCommand1); remoteControl.SetCommand(1, lightOnCommand2, lightOffCommand2); remoteControl.SetCommand(2, stereoOnCommand1, stereoOffCommand1); remoteControl.SetCommand(3, stereoOnCommand2, stereoOffCommand2); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); remoteControl.OnButtonWasPushed(3); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(3); Console.ReadKey(); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); Light light = new Light(); Television tv = new Television(); ICommand lightOnCommand = new LightOnCommand(light); ICommand lightOffCommand = new LightOffCommand(light); ICommand tvOnCommand = new TVOnCommand(tv); ICommand tvOffCommand = new TVOffCommand(tv); ICommand justWhatEverCommand = new JustWhatEverCommandAvailableCommand( new List <ICommand>() { lightOnCommand, tvOnCommand } ); remote.SetCommand(lightOnCommand, lightOffCommand, 0); remote.SetCommand(tvOnCommand, tvOffCommand, 1); remote.SetCommand(justWhatEverCommand, new NoCommand(), 2); Console.WriteLine($"{remote.ToString()}"); remote.OnButtonPress(2); remote.OffButtonPress(2); Console.ReadLine(); }
static void Main(string[] args) { RemoteControl RemoteControl = new RemoteControl(); Light light = new Light("Living Room"); LightOnCommand lightOn = new LightOnCommand(light); LightOfCommand lightOf = new LightOfCommand(light); CeilingFan ceiling = new CeilingFan("Living Room"); CeilingFanLowcommand fanLowcommand = new CeilingFanLowcommand(ceiling); CeilingFanHighCommand chigh = new CeilingFanHighCommand(ceiling); CeilingFanOfcommand fanOfcommand = new CeilingFanOfcommand(ceiling); GarrageDoor gd = new GarrageDoor("Garrage"); GarageDoorOpenCommand gopen = new GarageDoorOpenCommand(gd); GarageDoorCloseCommand gclose = new GarageDoorCloseCommand(gd); ICommand[] partyOn = { lightOn, gopen, chigh }; ICommand[] partyOff = { lightOf, gclose, fanLowcommand }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); RemoteControl.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(RemoteControl); Console.WriteLine("-----Pushing Macro On----"); RemoteControl.OnButtonWasPressed(0); Console.WriteLine("--------- Pushing Macro Of------"); RemoteControl.OffButtonWasPressed(0); }
static void Main(string[] args) { var remote = new SimpleRemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var garageDoor = new GarageDoor(); var garageDoorOpen = new GarageDoorOpenCommand(garageDoor); var garageDoorClose = new GarageDoorCloseCommand(garageDoor); var stereo = new Stereo(); var stereoOnWithCD = new StereoOnWithCdCommand(stereo); var stereoOn = new StereoOnCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remote.SetCommand(lightOn); remote.ButtonWasPressed(); remote.SetCommand(garageDoorOpen); remote.ButtonWasPressed(); Console.WriteLine("\n-----Newer Universal Remote-----\n"); var universalRemote = new RemoteControl(); universalRemote.AddCommand("Light", lightOn, lightOff); universalRemote.AddCommand("GarageDoor", garageDoorOpen, garageDoorClose); universalRemote.AddCommand("Stereo", stereoOn, stereoOff); universalRemote.AddCommand("StereoWithCD", stereoOnWithCD, stereoOff); Console.WriteLine(universalRemote.ToString()); Input(universalRemote); }
public void should_turn_on_light_when_press_first_on_button() { var light = new Light(); var remoteControl = new RemoteControl(light, null, null); remoteControl.On(1); Assert.True(light.Status); }
public void should_turn_on_ceiling_when_press_second_on_button() { var ceiling = new Ceiling(); var remoteControl = new RemoteControl(null, ceiling, null); remoteControl.On(2); Assert.Equal(CeilingSpeed.High, ceiling.GetSpeed()); }
public void should_turn_on_stereo_when_press_third_on_button() { var stereo = new Stereo(); var remoteControl = new RemoteControl(null, null, stereo); remoteControl.On(3); Assert.True(stereo.StereoStatus); Assert.True(stereo.CdStatus); Assert.Equal(11, stereo.Volume); }
static void Main(string[] args) { Console.WriteLine("***Command Pattern Demonstration***\n"); /*Client holds both the Invoker and Command Objects*/ RemoteControl invoker = new RemoteControl(); Game gameName = new Game("Golf"); //Command to start the game GameStartCommand gameStartCommand = new GameStartCommand(gameName); //Command to stop the game GameStopCommand gameStopCommand = new GameStopCommand(gameName); Console.WriteLine("**Starting the game and performing undo immediately.**"); invoker.SetCommand(gameStartCommand); invoker.ExecuteCommand(); //Performing undo operation Console.WriteLine("\nUndoing the previous command now."); invoker.UndoCommand(); Console.WriteLine("\n**Starting the game again.Then stopping it and undoing the stop operation.**"); invoker.SetCommand(gameStartCommand); invoker.ExecuteCommand(); //Stop command to finish the game invoker.SetCommand(gameStopCommand); invoker.ExecuteCommand(); //Performing undo operation Console.WriteLine("\nUndoing the previous command now."); invoker.UndoCommand(); //#region OPTIONAL FOR YOU ////Doing the same series of steps for another game //Console.WriteLine("\nPlaying another game now.(Optional for you)"); //gameName = new Game("Soccer"); ////Command to start the game //gameStartCommand = new GameStartCommand(gameName); ////Command to stop the game //gameStopCommand = new GameStopCommand(gameName); ////Starting the game //invoker.SetCommand(gameStartCommand); //invoker.ExecuteCommand(); ////Stopping the game //invoker.SetCommand(gameStopCommand); //invoker.ExecuteCommand(); ////Performing undo operation //Console.WriteLine("Undoing the previous command now."); //invoker.UndoCommand(); //#endregion Console.ReadKey(); }
static void Main(string[] args) { Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); RemoteControl rc = new RemoteControl(); rc.SetCommand(lightOn); rc.Invoke(); }
static void Main(string[] args) { RemoteControlSetup remoteSetup = new RemoteControlSetup(); RemoteControl remote = remoteSetup.InitializeRemote(); ILogger logger = new CloudLogger(); LogManager logManager = new LogManager(logger); logger.Log("Hi Logger!"); }
static void Main(string[] args) { Light light = new Light(); RemoteControl remoteControl = new RemoteControl(); remoteControl.SetCommand(0, new LightOnCommand(light)); remoteControl.SetCommand(1, new LightOffCommand(light)); remoteControl.OnButtonClick(0); remoteControl.OnButtonClick(1); remoteControl.OnClickUndo(); }
static void Main(string[] args) { Console.WriteLine("1 ON | 1 OFF Remote example"); RemoteControl remoteControl = new RemoteControl(1); // Creating objects to control Light garageLight = new Light("Garage Light"); // Creating commands for objects to control LightOnCommand garageLightOnCommand = new LightOnCommand(garageLight); LightOffCommand garageLightOffCommand = new LightOffCommand(garageLight); // Loading commands into the remoteControl remoteControl.SetCommand(0, garageLightOnCommand, garageLightOffCommand); // Simulating button clicks remoteControl.OnPushed(0); remoteControl.OffPushed(0); Console.WriteLine("Undo test:"); remoteControl.UndoPushed(); /* * MACRO COMMAND EXAMPLE */ Console.WriteLine("1 ON | 1 OFF Remote macro example"); // Creating objects to control ICommand[] onCommandCollection = new ICommand[5]; ICommand[] offCommandCollection = new ICommand[5]; for (int i = 0; i < 5; i++) { Light light = new Light("Light #" + (i + 1)); onCommandCollection[i] = new LightOnCommand(light); } for (int i = 0; i < 5; i++) { Light light = new Light("Light #" + (i + 1)); offCommandCollection[i] = new LightOffCommand(light); } // Inserting command collection into a Macro Command MacroCommand lightsOnMacro = new MacroCommand(onCommandCollection); MacroCommand lightsOffMacro = new MacroCommand(offCommandCollection); // Loading macro commands into the remoteControl remoteControl.SetCommand(0, lightsOnMacro, lightsOffMacro); // Simulating button clicks remoteControl.OffPushed(0); remoteControl.OnPushed(0); Console.WriteLine("Undo macro test:"); remoteControl.UndoPushed(); }
public static void Main(String[] args) { // get the singleton only instance of the remote control RemoteControl remoteControl = RemoteControl.getInstance(); // create all the receiver devices in their proper locations Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo <string, string, object, int> stereo = new Stereo <string, string, object, int>("Living Room"); // create all the light command objects LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); // create the on and off commands for the ceiling fan CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); // create the up and down commands for the garage door GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); // create the stereo on and off commands StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); // load commands into the remote slots remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); // print each remote slot and the command that it is assigned to Console.WriteLine(remoteControl); // push on and off button through each slot remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); for (int i = 0; i < remoteControl.OnCommands.Length; i++) { remoteControl.UndoButtonWasPushed(); } }
static void Main(string[] args) { var lamp = new Lamp(); var remote = new RemoteControl(lamp); Console.WriteLine(lamp.Description()); remote.ClickOn(); Console.WriteLine(lamp.Description()); remote.ClickOff(); Console.WriteLine(lamp.Description()); Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); }
static void Main(string[] args) { var remoteControl = new RemoteControl(); var light = new Light(); var garageGate = new GarageGate(); remoteControl.SetCommand(new LightCommand(light), new GarageGateCommand(garageGate)); remoteControl.PushButton(); remoteControl.PushButton(); Console.Read(); }
private static void CommandsExamples() { // creating receivers var livingRoomLight = new Light("Living Room"); var kitchenLight = new Light("Kitchen"); var livingRoomCeilingFan = new CeilingFan("Living Room"); var stereo = new Stereo(""); // creating commands var livingRoomLightOnCommand = new LightOnCommand(livingRoomLight); var livingRoomLightOffCommand = new LightOffCommand(livingRoomLight); var kitchenLightOnCommand = new LightOnCommand(kitchenLight); var kitchenLightOffCommand = new LightOffCommand(kitchenLight); var stereoOnCommand = new StereoOnCommand(stereo); var stereoOffCommand = new StereoOffCommand(stereo); // Macro Command var myCommand = new MacroCommand(new ICommand[] { kitchenLightOnCommand, stereoOnCommand, livingRoomLightOffCommand }); // create remove control & assign commands var remoteControl = new RemoteControl(); remoteControl.SetCommand(0, livingRoomLightOnCommand); remoteControl.SetCommand(1, livingRoomLightOffCommand); remoteControl.SetCommand(2, kitchenLightOnCommand); remoteControl.SetCommand(3, kitchenLightOffCommand); remoteControl.SetCommand(4, stereoOnCommand); remoteControl.SetCommand(5, stereoOffCommand); // run commands //for (int i = 0; i < 6; i++) // remoteControl.Run(i); //remoteControl.Run(0); //remoteControl.Run(0); //remoteControl.Run(0); //remoteControl.Undo(); //remoteControl.Undo(); //remoteControl.Undo(); //remoteControl.Undo(); myCommand.Execute(); Console.WriteLine("------------------"); myCommand.Undo(); //Console.WriteLine(remoteControl); }
static void Main(string[] args) { var bulb = new Bulb(); var turnOn = new TurnOn(bulb); var turnOff = new TurnOff(bulb); var remote = new RemoteControl(); remote.Submit(turnOn); // Bulb has been lit! remote.Submit(turnOff); // Darkness! Console.ReadLine(); }
static void Main(string[] args) { char playCommand = 'o'; char pauzeCommand = 'p'; char samsung = 'g'; char sony = 'y'; char execute = 'e'; char undo = 'u'; char stop = 's'; RemoteControl control = new RemoteControl(); char input = Console.ReadKey().KeyChar; while (input != stop) { if (input == playCommand) { control.SetCommand(new PlayCommand()); } else if (input == pauzeCommand) { control.SetCommand(new PauzeCommand()); } else if (input == execute) { control.PressExecute(); } else if (input == undo) { control.PressUnDo(); } else if (input == sony) { control.setPlayer(new SonyMoviePlayer()); } else if (input == samsung) { control.setPlayer(new SamsungMoviePlayer()); } input = Console.ReadKey().KeyChar; } Console.WriteLine("Now stopping"); Console.ReadKey(); }
private static void Main() { var remote = new RemoteControl(3); var bike = new Garage("Bike"); var bikeDoorClose = new GarageDoorCloseCommand(bike); var bikeDoorOpen = new GarageDoorOpenCommand(bike); var car = new Garage("Car"); var carDoorClose = new GarageDoorCloseCommand(car); var carDoorOpen = new GarageDoorOpenCommand(car); var garageButton = new OnOffStruct { On = bikeDoorOpen, Off = bikeDoorClose }; remote[0] = garageButton; remote.PushOn(0); remote.PushUndo(); remote.PushUndo(); remote.PushOff(0); Console.WriteLine(); var light = new Light("Hall"); ICommand[] partyOn = { new LightOffCommand(light), bikeDoorOpen, carDoorOpen }; ICommand[] partyOff = { new LightOnCommand(light), bikeDoorClose, carDoorClose }; remote[2] = new OnOffStruct { On = new MacroCommand(partyOn), Off = new MacroCommand(partyOff) }; try { remote.PushOn(2); Console.WriteLine(); remote.PushOff(2); } catch (Exception) { Console.WriteLine("Oops"); } }
public RemoteControl InitializeRemote() { VolumeControl volume = new VolumeControl(); ICommand volumeCommand = new VolumeChangeCommand(volume); ChannelControl channel = new ChannelControl(); ICommand channelCommand = new ChannelChangeCommand(channel); RemoteControl remote = new RemoteControl(); remote.RegisterCommand(volumeCommand); remote.RegisterCommand(channelCommand); remote.ExecuteButtonPressed(volumeCommand); remote.UndoButtonPressed(channelCommand); return remote; }
static void Input(RemoteControl universalRemote) { Console.WriteLine("------------------------------------------"); Console.WriteLine("Type the button name and [on|off] (ex. GarageDoor on)"); var input = Console.ReadLine(); // Get string from user if (input != null) { var inputs = input.Split(' '); if (inputs[1] == "on") { universalRemote.TurnOn(inputs[0]); } else { universalRemote.TurnOff(inputs[0]); } } Input(universalRemote); }
public RemoteControl InitializeRemote() { VolumeControl volume = new VolumeControl(); ICommand volumeCommand = new VolumeChangeCommand(volume); ChannelControl channel = new ChannelControl(); ICommand channelCommand = new ChannelChangeCommand(channel); RemoteControl remote = new RemoteControl(); remote.RegisterCommand(volumeCommand); remote.RegisterCommand(channelCommand); remote.ExecuteButtonPressed(volumeCommand); remote.UndoButtonPressed(channelCommand); return(remote); }
static void Main(string[] args) { Light kitchenLight = new Light("Kitchen"); Light livingRoomLight = new Light("Living room"); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); LightOnCommand LivingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); RemoteControl remote = new RemoteControl(); remote.setCommand(0, kitchenLightOn, kitchenLightOff); remote.setCommand(1, LivingRoomLightOn, livingRoomLightOff); Console.WriteLine(remote.ToString()); remote.onButtonWasPushed(0); remote.offButtonWasPushed(0); remote.onButtonWasPushed(1); remote.offButtonWasPushed(1); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); GarageDoor garageDoor = new GarageDoor(); GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, garageOpen, garageClose); Console.WriteLine(remote); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); remote.OnButtonWasPushed(1); remote.UndoButtonWasPushed(); CeilingFan ceilingFan = new CeilingFan("Living Room"); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remote.SetCommand(0, ceilingFanMedium, ceilingFanOff); remote.SetCommand(1, ceilingFanHigh, ceilingFanOff); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); Console.WriteLine(remote); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(1); Console.WriteLine(remote); remote.UndoButtonWasPushed(); Console.Read(); }
static void Main(string[] args) { var remote = new SimpleRemoteControl(); remote.SetCommand(new LightOnCommand(new Light())); remote.ButtonWasPressed(); remote.SetCommand(new GarageDoorOpenCommand(new GarageDoor())); remote.ButtonWasPressed(); // LAMBDA STYLE Console.WriteLine("LAMBDA STYLE"); var remoteControl = new RemoteControl(); // invoker var livingRoomLight = new Light(); // reciever remoteControl.SetCommand(0, () => livingRoomLight.TurnOn(), () => livingRoomLight.TurnOff()); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); }
public static void Main(string[] args) { IMoviePlayer sonyp = new SonyMoviePlayer(); ICommand sonyPause = new PauseCommand(sonyp); ICommand sonyPlay = new PlayCommand(sonyp); RemoteControl sonyRemote = new RemoteControl(); sonyRemote.Command = sonyPlay; IMoviePlayer samp = new SamsungMoviePlayer(); ICommand samPause = new PauseCommand(samp); ICommand samPlay = new PlayCommand(samp); RemoteControl samRemote = new RemoteControl(); samRemote.Command = samPlay; sonyRemote.PressExecute(); sonyRemote.PressUndo(); samRemote.PressExecute(); samRemote.Command = samPause; samRemote.PressExecute(); }
static void Main(string[] args) { var remoteControl = new RemoteControl(); var ceilingFan = new CeilingFan("Living room"); var ceilingFanLowCommand = new CeilingFanLowCommand(ceilingFan); var ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFan); var ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(0, ceilingFanMediumCommand, ceilingFanOffCommand); remoteControl.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.PressOnButton(0); remoteControl.PressOffButton(0); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); remoteControl.PressOnButton(1); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); }
static void Main(string[] args) { //SimpleRemoteControl remote = new SimpleRemoteControl(); //Light light = new Light(); //GarageDoor garageDoor = new GarageDoor(); //LightOnCommand lightOn = new LightOnCommand(light); //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); //remote.setCommand(lightOn); //remote.buttonWasPressed(); //remote.setCommand(garageOpen); //remote.buttonWasPressed(); RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); GarageDoor garageDoor = new GarageDoor(); Stereo stereo = new Stereo("Living Room"); CeilingFan ceilingFan = new CeilingFan("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.setCommand(2, garageOpen, garageClose); remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD); remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff); remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff); remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff); Console.WriteLine(remoteControl.toString()); 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(); remoteControl.onButtonWasPushed(5); remoteControl.offButtonWasPushed(5); Console.WriteLine(remoteControl); remoteControl.undoButtonWasPushed(); remoteControl.onButtonWasPushed(4); Console.WriteLine(remoteControl); remoteControl.undoButtonWasPushed(); #region marco command Command[] partyOn = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD }; Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD }; MacroCommand partyOnCommand = new MacroCommand(partyOn); MacroCommand partyOffCommand = new MacroCommand(partyOff); remoteControl.setCommand(6, partyOnCommand, partyOffCommand); remoteControl.onButtonWasPushed(6); remoteControl.offButtonWasPushed(6); remoteControl.undoButtonWasPushed(); #endregion Console.ReadLine(); }
static void Main(string[] args) { // Setup 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(); // Command initialization var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanLow = new CeilingFanLowCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorOpenCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoWithCd = new StereoWithCdCommand(stereo); var stereoOff = new StereoOffCommand(stereo); // Remote setup remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(3, ceilingFanHigh, ceilingFanOff); remoteControl.SetCommand(4, stereoWithCd, stereoOff); // Remote with undo Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); Console.WriteLine(remoteControl); // Macro commands ICommand[] partyOn = { kitchenLightOn, livingRoomLightOn, stereoWithCd, ceilingFanMedium }; ICommand[] partyOff = { kitchenLightOff, livingRoomLightOff, stereoOff, ceilingFanOff }; var partyOnMacro = new MacroCommand(partyOn); var partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(5, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); Console.WriteLine("--- Pushing Macro On---"); remoteControl.OnButtonWasPushed(5); Console.WriteLine("--- Pushing Macro Off---"); remoteControl.OffButtonWasPushed(5); Console.WriteLine("--- Pushing Macro Undo---"); remoteControl.UndoButtonWasPushed(); // Ceiling fan multiple undo remoteControl.OnButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); remoteControl.UndoButtonWasPushed(); // Setting remote using lambdas instead of small classes }
static void Main(string[] args) { /* * The command pattern: encapsulates a request as an object, thereby letting you parameterize other objects with different request, queue or log requests, and support undoable operations */ /* * Simple Test */ //RemoteControl remote = new RemoteControl(); //ILight light = new Light(); //LightOnCommand lightOn = new LightOnCommand(light); //remote.SetCommand(lightOn); //remote.ButtonWasPressed(); /* * Remote control */ /*RemoteControl remoteControl = new RemoteControl(); * * ILight livingRoomLight = new Light("Living Room"); * * ILight kitchenLight = new Light("Kitchen"); * * IStereo stereo = new Stereo("Living Room"); * * LightOnCommand lightOnCommand = new LightOnCommand(livingRoomLight); * LightOffCommand lightOffCommand = new LightOffCommand(livingRoomLight); * * LightOnCommand kitcheLightOnCommand = new LightOnCommand(kitchenLight); * LightOffCommand kitchenOffCommand = new LightOffCommand(kitchenLight); * * StereoOnWithCdCommand stereoOnWithCdCommand = new StereoOnWithCdCommand(stereo); * StereoOffWithCdCommand stereoOffWithCdCommand = new StereoOffWithCdCommand(stereo); * * remoteControl.SetCommand(0, lightOnCommand, lightOffCommand); * remoteControl.SetCommand(1, kitcheLightOnCommand, kitchenOffCommand); * remoteControl.SetCommand(2, stereoOnWithCdCommand, stereoOffWithCdCommand); * * Console.WriteLine(remoteControl); * * remoteControl.OnButtonWasPushed(0); * remoteControl.OffButtonWasPushed(0); * * remoteControl.OnButtonWasPushed(1); * remoteControl.OffButtonWasPushed(1); * * remoteControl.OnButtonWasPushed(2); * remoteControl.OffButtonWasPushed(2);*/ /* * Remote control with undo */ RemoteControl remoteControl = new RemoteControl(); ILight livingRoomLight = new Light("Living room"); LightOnCommand lightOnCommand = new LightOnCommand(livingRoomLight); LightOffCommand lightOffCommand = new LightOffCommand(livingRoomLight); remoteControl.SetCommand(0, lightOnCommand, lightOffCommand); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); Console.ReadKey(); }
static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan livingRoomCeilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(); Stereo livingRoomStereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOnCommand = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOffCommand = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOnCommand = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOffCommand = new LightOffCommand(kitchenLight); CeilingFanOnCommand livingRoomCeilingFanOnCommand = new CeilingFanOnCommand(livingRoomCeilingFan); CeilingFanOffCommand livingRoomCeilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan); GarageDoorUpCommand garageDoorUpCommand = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDownCommand = new GarageDoorDownCommand(garageDoor); StereoWithCDCommand livingRoomStereoWithCDCommand = new StereoWithCDCommand(livingRoomStereo); StereoOffCommand livingRoomStereoOffCommand = new StereoOffCommand(livingRoomStereo); // MAIN //remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand); //remoteControl.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand); //remoteControl.SetCommand(2, livingRoomCeilingFanOnCommand, livingRoomCeilingFanOffCommand); //remoteControl.SetCommand(3, livingRoomStereoWithCDCommand, livingRoomStereoOffCommand); //Console.WriteLine(remoteControl.ToString()); //Console.ReadLine(); //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.ReadLine(); // UNDO //remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //Console.WriteLine(remoteControl.ToString()); //remoteControl.UndoButtonWasPushed(); //remoteControl.OffButtonWasPushed(0); //remoteControl.OnButtonWasPushed(0); //Console.WriteLine(remoteControl.ToString()); //remoteControl.UndoButtonWasPushed(); //CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(livingRoomCeilingFan); //CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(livingRoomCeilingFan); //CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(livingRoomCeilingFan); //remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff); //remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //remoteControl.UndoButtonWasPushed(); //remoteControl.OnButtonWasPushed(1); //remoteControl.UndoButtonWasPushed(); //Console.ReadLine(); // MACRO COMMAND ICommand[] partyOn = new ICommand[] { livingRoomLightOnCommand, garageDoorUpCommand }; ICommand[] partyOff = new ICommand[] { livingRoomLightOffCommand, garageDoorDownCommand }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); Console.ReadLine(); }
static void Main(string[] args) { var simpleRemoteControl = new SimpleRemoteControl(); var light = new Light("Bedroom"); var lightOnCommand = new LightOnCommand(light); simpleRemoteControl.SetCommand(lightOnCommand); simpleRemoteControl.ButtonWasPressed(); var door = new GarageDoor(""); var garageDoorOpenCommand = new GarageDoorOpenCommand(door); simpleRemoteControl.SetCommand(garageDoorOpenCommand); simpleRemoteControl.ButtonWasPressed(); Console.WriteLine(); 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 livingRoomLightOnCommand = new LightOnCommand(livingRoomLight); var livingRoomLightOffCommand = new LightOffCommand(livingRoomLight); var kitchenLightOnCommand = new LightOnCommand(kitchenLight); var kitchenLightOffCommand = new LightOffCommand(kitchenLight); var ceilingFanOnCommand = new CeilingFanOnCommand(ceilingFan); var ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); var garageDoorUpCommand = new GarageDoorOpenCommand(garageDoor); var garageDoorDownCommand = new GarageDoorCloseCommand(garageDoor); var stereoOnWithCdCommand = new StereoOnWithCdCommand(stereo); var stereoOffCommand = new StereoOffCommand(stereo); var remote = new RemoteControl(); remote.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand); remote.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand); remote.SetCommand(2, ceilingFanOnCommand, ceilingFanOffCommand); remote.SetCommand(3, stereoOnWithCdCommand, stereoOffCommand); Console.WriteLine(remote.ToString()); Console.WriteLine(); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); remote.OnButtonWasPushed(2); remote.OffButtonWasPushed(2); remote.OnButtonWasPushed(3); remote.OffButtonWasPushed(3); Console.WriteLine(); Console.WriteLine("------------ Remote with Undo ------------"); var remoteWithUndo = new RemoteControlWithUndo(); var sunRoomLight = new Light("Sun Room"); var sunRoomLightOnCommand = new LightOnCommand(sunRoomLight); var sunRoomLightOffCommand = new LightOffCommand(sunRoomLight); remoteWithUndo.SetCommand(0, sunRoomLightOnCommand, sunRoomLightOffCommand); remoteWithUndo.OnButtonWasPushed(0); remoteWithUndo.OffButtonWasPushed(0); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); remoteWithUndo.OffButtonWasPushed(0); remoteWithUndo.OnButtonWasPushed(0); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); Console.WriteLine(); Console.WriteLine("------------ Ceiling Fan with Undo ------------"); remoteWithUndo = new RemoteControlWithUndo(); var ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFan); ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); remoteWithUndo.SetCommand(0, ceilingFanMediumCommand, ceilingFanOffCommand); remoteWithUndo.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteWithUndo.OnButtonWasPushed(0); remoteWithUndo.OffButtonWasPushed(0); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); remoteWithUndo.OnButtonWasPushed(1); Console.WriteLine(remoteWithUndo.ToString()); remoteWithUndo.UndoButtonWasPushed(); Console.WriteLine(); Console.WriteLine("------------ Party Mode (Macro Commands) ------------"); remoteWithUndo = new RemoteControlWithUndo(); ICommand[] partyOn = { livingRoomLightOnCommand, stereoOnWithCdCommand, ceilingFanMediumCommand }; ICommand[] partyOff = { livingRoomLightOffCommand, stereoOffCommand, ceilingFanOffCommand }; var partyOnMacro = new MacroCommand(partyOn); var partyOffMacro = new MacroCommand(partyOff); remoteWithUndo.SetCommand(0, partyOnMacro, partyOffMacro); remoteWithUndo.OnButtonWasPushed(0); Console.WriteLine(); remoteWithUndo.OffButtonWasPushed(0); Console.ReadLine(); }
static void Main(string[] args) { /*var remote = new SimpleRemoteControl(); * * var light = new Light(); * var garageDoor = new GarageDoor(); * * var lightOnCommand = new LigthOnCommand(light); * var garageOpenCommand = new GarageDoorOpenCommand(garageDoor); * * remote.SetCommand(lightOnCommand); * remote.ButtonWasPressed(); * remote.SetCommand(garageOpenCommand); * remote.ButtonWasPressed();*/ var remoteControl = new RemoteControl(); var livigRoomLight = 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(livigRoomLight); var livingRoomLightOff = new LightOffCommand(livigRoomLight); var kitchenRoomLightOn = new LightOnCommand(kitchenLight); var kitchenRoomLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorOpenCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoOnWithCD = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenRoomLightOn, kitchenRoomLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl); 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("-----------------------------------------------------"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine(remoteControl); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); Console.WriteLine("-----------------------------------------------------"); var tv = new TV("Living room"); var hottub = new Hottub(); var stereoOn = new StereoOnCommand(stereo); var tvOn = new TVOnCommand(tv); var hottubOn = new HottubOnCommand(hottub); var tvOff = new TVOffCommand(tv); var hottubOff = new HottubOffCommand(hottub); ICommand[] partyOn = { livingRoomLightOn, stereoOn, tvOn, hottubOn }; ICommand[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff }; var partyOnMacro = new MacroCommand(partyOn); var partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); Console.WriteLine("---Pushing Macro On---"); remoteControl.OnButtonWasPushed(0); Console.WriteLine("---Pushing Macro Off---"); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); }
static void Main(string[] args) { Console.WriteLine("-----------SimpleRemoteControl-------------"); SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light("Light"); LightOnCommand lightOn = new LightOnCommand(light); remote.setCommand(lightOn); remote.buttonWasPressed(); Console.WriteLine(""); RemoteControl remotControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); 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); StereoOnWithCDCommand StereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); StereoOffCommand StereoOffCommand = new StereoOffCommand(stereo); remotControl.setCommand(0, livingRoomLightOn, livingRoomLightOff); remotControl.setCommand(1, kitchenLightOn, kitchenLightOff); remotControl.setCommand(2, StereoOnWithCDCommand, StereoOffCommand); Console.WriteLine(remotControl.toString()); remotControl.onButtonWasPushed(0); remotControl.offButtonWasPushed(0); remotControl.onButtonWasPushed(1); remotControl.offButtonWasPushed(1); remotControl.onButtonWasPushed(2); remotControl.offButtonWasPushed(2); Console.WriteLine(""); RemoteControlWithUndo undoRemotControl = new RemoteControlWithUndo(); Light livingRoomUndoLight = new Light("Living Room"); LightOnCommand livingRoomUndoLightOn = new LightOnCommand(livingRoomUndoLight); LightOffCommand livingRoomUndoLightOff = new LightOffCommand(livingRoomUndoLight); undoRemotControl.setCommand(0, livingRoomUndoLightOn, livingRoomUndoLightOff); undoRemotControl.onButtonWasPushed(0); undoRemotControl.offButtonWasPushed(0); Console.WriteLine(undoRemotControl.toString()); undoRemotControl.undoButtonWasPushed(); undoRemotControl.onButtonWasPushed(0); undoRemotControl.offButtonWasPushed(0); Console.WriteLine(undoRemotControl.toString()); undoRemotControl.undoButtonWasPushed(); }