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); }
static void Main(string[] args) { var livingRoomLight = new Light("LivingRoom"); var kitchenLight = new Light("Kitchen"); var garage = new GarageDoor("Main"); var fan = new CeilingFan("LivingRoom"); var remote = new SimpleRemoteControl("My Remote"); remote.SetCommand(0, livingRoomLight.On, livingRoomLight.Off); remote.SetCommand(1, kitchenLight.On, kitchenLight.Off); remote.SetCommand(2, garage.Up, garage.Down); remote.SetCommand(3, fan.High, fan.Off); Console.WriteLine(remote); var light1 = new Light("light1"); var light2 = new Light("light2"); var garage1 = new GarageDoor("garage1"); var fan1 = new CeilingFan("fan1"); Action command = () => { light1.On(); light2.On(); garage1.Up(); fan1.High(); }; remote.SetCommand(4, command, () => { }); remote.OnButtonWasPressed(4); }
static void Main(string[] args) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); GarageDoor garageDoor = new GarageDoor(); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor); remote.SetCommand(lightOn); remote.ButtonWasPressed(); remote.SetCommand(garageDoorOpen); remote.ButtonWasPressed(); }
static void Main(string[] args) { Light light = new Light(); Command lightBtn = new LightONCommand(light); SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl(); simpRemoteCntrl.SetCommand(lightBtn); simpRemoteCntrl.ButtonWasPressed(); }
static void Main(string[] args) { var remote = new SimpleRemoteControl(); var light = new Light(); var lightOnCommand = new LightOnCommand(light); remote.SetCommand(lightOnCommand); remote.ButtonWasPressed(); }
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); }
static void Main(string[] args) { var remote = new SimpleRemoteControl(7); var locationLivingRoom = new Location("LIVING ROOM"); var light = new Light(locationLivingRoom); var lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.ButtonPressed(); var locationGarage = new Location("GARAGE"); var garageDoor = new Gate(locationGarage); var garageDoorOpen = new GateOpenCommand(garageDoor); remote.SetCommand(garageDoorOpen); remote.ButtonPressed(); remote.UndoButtonPressed(); Console.ReadKey(); }
static void Main(string[] args) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.buttonWasPressed(); Console.ReadKey(); }
static void Main(string[] args) { Light light = new Light("Any"); Light kitchenLight = new Light("Kitchen"); Light livingRoomLight = new Light("Living room"); Light bedroomLight = new Light("Bedroom"); Command lightONBtn = new LightONCommand(light); Command lightOffBtn = new LightOFFCommand(light); Command kitchenLightON = new LightONCommand(kitchenLight); Command kitchenLightOFF = new LightOFFCommand(kitchenLight); Command livingRoomON = new LightONCommand(livingRoomLight); Command livingRoomOFF = new LightOFFCommand(livingRoomLight); SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl(); simpRemoteCntrl.SetCommand(0,lightONBtn,lightOffBtn); simpRemoteCntrl.SetCommand(1, kitchenLightON, kitchenLightOFF); simpRemoteCntrl.SetCommand(2, livingRoomON, livingRoomOFF); simpRemoteCntrl.OnButtonPushed(0); simpRemoteCntrl.OffButtonPushed(0); simpRemoteCntrl.OnButtonPushed(1); simpRemoteCntrl.OffButtonPushed(1); simpRemoteCntrl.OnButtonPushed(2); simpRemoteCntrl.OffButtonPushed(2); CeilingFan ceilingFanLivingRoom = new CeilingFan("Living Room"); Command ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFanLivingRoom); Command ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFanLivingRoom); simpRemoteCntrl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand); simpRemoteCntrl.OnButtonPushed(3); Console.WriteLine("\n Start of macro \n"); Command[] partyCommandsOn = new Command[] { lightONBtn,kitchenLightON,livingRoomON}; Command[] partyCommandsOff = new Command[] {lightOffBtn,kitchenLightOFF,livingRoomOFF }; MacroCommand macroCommandON = new MacroCommand(partyCommandsOn); MacroCommand macroCommandOff = new MacroCommand(partyCommandsOff); simpRemoteCntrl.SetCommand(0, macroCommandON, macroCommandOff); simpRemoteCntrl.OnButtonPushed(); simpRemoteCntrl.OffButtonPushed(); Console.WriteLine(simpRemoteCntrl.ToString()); }
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) { Light light = new Light("Any"); Light kitchenLight = new Light("Kitchen"); Light livingRoomLight = new Light("Living room"); Light bedroomLight = new Light("Bedroom"); Command lightONBtn = new LightONCommand(light); Command lightOffBtn = new LightOFFCommand(light); Command kitchenLightON = new LightONCommand(kitchenLight); Command kitchenLightOFF = new LightOFFCommand(kitchenLight); Command livingRoomON = new LightONCommand(livingRoomLight); Command livingRoomOFF = new LightOFFCommand(livingRoomLight); SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl(); simpRemoteCntrl.SetCommand(0, lightONBtn, lightOffBtn); simpRemoteCntrl.SetCommand(1, kitchenLightON, kitchenLightOFF); simpRemoteCntrl.SetCommand(2, livingRoomON, livingRoomOFF); simpRemoteCntrl.OnButtonPushed(0); simpRemoteCntrl.OffButtonPushed(0); simpRemoteCntrl.OnButtonPushed(1); simpRemoteCntrl.OffButtonPushed(1); simpRemoteCntrl.OnButtonPushed(2); simpRemoteCntrl.OffButtonPushed(2); CeilingFan ceilingFanLivingRoom = new CeilingFan("Living Room"); Command ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFanLivingRoom); Command ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFanLivingRoom); simpRemoteCntrl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand); simpRemoteCntrl.OnButtonPushed(3); Console.WriteLine("\n Start of macro \n"); Command[] partyCommandsOn = new Command[] { lightONBtn, kitchenLightON, livingRoomON }; Command[] partyCommandsOff = new Command[] { lightOffBtn, kitchenLightOFF, livingRoomOFF }; MacroCommand macroCommandON = new MacroCommand(partyCommandsOn); MacroCommand macroCommandOff = new MacroCommand(partyCommandsOff); simpRemoteCntrl.SetCommand(0, macroCommandON, macroCommandOff); simpRemoteCntrl.OnButtonPushed(); simpRemoteCntrl.OffButtonPushed(); Console.WriteLine(simpRemoteCntrl.ToString()); }