private static void Main() { var remote = new RemoteControl(); 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); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, garageDoorOpen, garageDoorClose); Console.WriteLine(remote); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); Console.WriteLine(remote); Console.ReadKey(); }
public void MacroCommandtest() { Remote remote = new Remote(); Light light = new Light(); Stero stero = new Stero(); Fan fan = new Fan(); LightOnCommand lightOn = new LightOnCommand(light); SteroOnWithCDCommand steroOn = new SteroOnWithCDCommand(stero); FanHighCommand fanOn = new FanHighCommand(fan); LightOffCommand lightOff = new LightOffCommand(light); SteroOffCommand steroOff = new SteroOffCommand(stero); FanOffCommand fanOff = new FanOffCommand(fan); MacroCommand macroCommandOn = new MacroCommand(new ICommand[] { lightOn, steroOn, fanOn }); MacroCommand macroCommandOff = new MacroCommand(new ICommand[] { lightOff, steroOff, fanOff }); remote.SetCommnd(0, macroCommandOn, macroCommandOff); remote.OnButtonPressed(0); Assert.AreEqual(Light.States.On, light.CurrentState); Assert.AreEqual(Stero.State.CD, stero.CurrentState); Assert.AreEqual((int)11, stero.Volume); Assert.AreEqual(Fan.Speed.High, fan.CurrentSpeed); remote.OffButtonPressed(0); Assert.AreEqual(Light.States.Off, light.CurrentState); Assert.AreEqual(Stero.State.Off, stero.CurrentState); Assert.AreEqual((int)0, stero.Volume); Assert.AreEqual(Fan.Speed.Off, fan.CurrentSpeed); }
public static void RunRemoteControl() { var remote = new RemoteControl(); 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 stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, garageDoorOpen, garageDoorClose); remote.SetCommand(2, stereoOnWithCD, stereoOff); System.Console.WriteLine(remote); remote.OnButtonWasPressed(0); remote.OffButtonWasPressed(0); remote.OnButtonWasPressed(1); remote.OffButtonWasPressed(1); remote.OnButtonWasPressed(2); remote.OffButtonWasPressed(2); }
public static void RunRemoteControlWithMacroCommand() { 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 stereoOff = new StereoOffCommand(stereo); var macroOnCommand = new MacroCommand(new ICommand[] { lightOn, garageDoorOpen, stereoOnWithCD }); var macroOffCommand = new MacroCommand(new ICommand[] { lightOff, garageDoorClose, stereoOff }); var remote = new RemoteControl(); remote.SetCommand(0, macroOnCommand, macroOffCommand); System.Console.WriteLine(remote); System.Console.WriteLine("--- Pushing Macro on ---"); remote.OnButtonWasPressed(0); System.Console.WriteLine("--- Pushing Macro off ---"); remote.OffButtonWasPressed(0); }
static void Main(string[] args) { var remote = new RemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var stereo = new Stereo(); var stereoOn = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffWithCDCommand(stereo); var ceilingFan = new CeilingFan("Living Room"); var ceilingFanHighOn = new CeilingFanHighCommand(ceilingFan); var macro = new MacroCommand(new ICommand[] {lightOn, stereoOn}); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(2, stereoOn, stereoOff); remote.SetCommand(3, ceilingFanHighOn, new NoComand()); remote.SetCommand(4, macro, new NoComand()); remote.OnButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OnButtonWasPushed(2); remote.OffButtonWasPushed(0); remote.OffButtonWasPushed(1); remote.OffButtonWasPushed(2); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(3); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(4); remote.UndoButtonWasPushed(); Console.ReadKey(); }
public void CommandTest() { RemoteControl remoteControl = new RemoteControl(); Light light = new Light("Living Room"); TV tv = new TV("Living Room"); Stereo stereo = new Stereo("Living Room"); Hottub hottub = new Hottub(); LightOnCommand lightOn = new LightOnCommand(light); StereoOnCommand stereoOn = new StereoOnCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); LightOffCommand lightOff = new LightOffCommand(light); StereoOffCommand stereoOff = new StereoOffCommand(stereo); TVOffCommand tvOff = new TVOffCommand(tv); HottubOffCommand hottubOff = new HottubOffCommand(hottub); ICommand[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; ICommand[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand 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); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); Light livingroomLight = new Light(); LightOnCommand livingroomLightOnCommand = new LightOnCommand(livingroomLight); LightOffCommand livingroomLightOffCommand = new LightOffCommand(livingroomLight); Light bedroomLight = new Light(); LightOnCommand bedroomLightOnCommand = new LightOnCommand(bedroomLight); LightOffCommand bedroomLightOffCommand = new LightOffCommand(bedroomLight); remote.SetCommand(0, livingroomLightOnCommand, livingroomLightOffCommand); remote.SetCommand(1, bedroomLightOnCommand, bedroomLightOffCommand); Console.WriteLine($"Livingroom light: {livingroomLight.State}"); Console.WriteLine($"Bedroom light: {livingroomLight.State}"); remote.OnButtonPressed(0); Console.WriteLine($"Livingroom light: {livingroomLight.State}"); remote.OffButtonPressed(0); Console.WriteLine($"Livingroom light: {livingroomLight.State}"); remote.OnButtonPressed(1); Console.WriteLine($"Bedroom light: {bedroomLight.State}"); remote.OffButtonPressed(1); Console.WriteLine($"Bedroom light: {bedroomLight.State}"); Console.ReadKey(); }
private static string ProcessRemoteControlWithUndo() { StringBuilder sb = new StringBuilder(); RemoteControlWithUndo remoteControlWithUndo = new RemoteControlWithUndo(); Light livingRoomLight = new Light("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); remoteControlWithUndo.OnCommands[0] = livingRoomLightOn; remoteControlWithUndo.OffCommands[0] = livingRoomLightOff; sb.AppendLine(remoteControlWithUndo.OnButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.OffButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.ToString()); sb.AppendLine(remoteControlWithUndo.UndoButtonWasPushed()); sb.AppendLine(remoteControlWithUndo.OffButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.OnButtonWasPushed(0)); sb.AppendLine(remoteControlWithUndo.ToString()); sb.AppendLine(remoteControlWithUndo.UndoButtonWasPushed()); return(sb.ToString()); }
private static string ProcessMacroCommand() { StringBuilder sb = new StringBuilder(); RemoteControl remoteControl = new RemoteControl(); Light light = new Light("Living Room"); Stereo stereo = new Stereo(); LightOnCommand lightOn = new LightOnCommand(light); StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo); LightOffCommand lightOff = new LightOffCommand(light); StereoOffCommand stereoOff = new StereoOffCommand(stereo); ICommand[] partyOn = { lightOn, stereoOn }; ICommand[] partyOff = { lightOff, stereoOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.OnCommands[0] = partyOnMacro; remoteControl.OffCommands[0] = partyOffMacro; sb.AppendLine(remoteControl.ToString()); sb.AppendLine("--- Pushing Macro On ---"); sb.AppendLine(remoteControl.OnButtonWasPushed(0)); sb.AppendLine("--- Pushing Macro Off ---"); sb.AppendLine(remoteControl.OffButtonWasPushed(0)); return(sb.ToString()); }
public void Load() { RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); Light light = new Light(); TV tv = new TV(); Hottub hottub = new Hottub(); 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); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCd = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); LightOnCommand lightOn = new LightOnCommand(light); StereoOnCommand stereoOn = new StereoOnCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); LightOffCommand lightOff = new LightOffCommand(light); TVOffCommand tvOff = new TVOffCommand(tv); HottubOffCommand hottubOff = new HottubOffCommand(hottub); Command[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; Command[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff); remoteControl.SetCommand(3, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(4, stereoOnWithCd, stereoOff); remoteControl.SetCommand(5, garageDoorUp, garageDoorDown); remoteControl.SetCommand(6, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); for (int i = 0; i <= 6; i++) { remoteControl.OnButtonWasPushed(i); remoteControl.OffButtonWasPushed(i); remoteControl.UndoButtonWasPushed(); } }
static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); Light bedroomLight = new Light("卧室灯"); Light kitchenLight = new Light("厨房灯"); CeilingFan ceilingFan = new CeilingFan("吊扇"); LightOnCommand bedroomLightOnCommand = new LightOnCommand(bedroomLight); LightOffCommand bedroomLightOffCommand = new LightOffCommand(bedroomLight); LightOffCommand kitchenLightOffCommand = new LightOffCommand(kitchenLight); LightOnCommand kitchenLightOnCommand = new LightOnCommand(kitchenLight); FanOnCommand ceilingFanHighCommand = new FanOnCommand(ceilingFan, CeilingFan.HighSpeed); FanOnCommand ceilingFanMediumCommand = new FanOnCommand(ceilingFan, CeilingFan.MediumSpeed); FanOnCommand ceilingFanLowCommand = new FanOnCommand(ceilingFan, CeilingFan.LowSpeed); FanOffCommand ceilingFanOffCommand = new FanOffCommand(ceilingFan); remoteControl.SetCommond(0, bedroomLightOnCommand, bedroomLightOffCommand); remoteControl.SetCommond(1, kitchenLightOnCommand, kitchenLightOffCommand); remoteControl.SetCommond(2, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.SetCommond(3, ceilingFanMediumCommand, ceilingFanOffCommand); remoteControl.SetCommond(4, ceilingFanLowCommand, bedroomLightOnCommand); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(4); }
public static void Start() { var remoteControl = new RemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var stereo = new Stereo(); var stereoOn = new StereoOnCommand(stereo); var stereoOff = new StereoOffCommand(stereo); var ceililngFan = new CeilingFan("Kitchen room"); var ceililngFanLowOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Low); var ceililngFanMediumOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Medium); var ceililngFanHighOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.High); var ceililngFanOff = new CeilingFanOffCommand(ceililngFan); var partyOn = new MacroCommand(new ICommand[] { lightOn, stereoOn }); var partyOff = new MacroCommand(new ICommand[] { lightOff, stereoOff }); remoteControl.SetCommand(2, lightOn, lightOff); remoteControl.SetCommand(3, stereoOn, stereoOff); remoteControl.SetCommand(4, ceililngFanLowOn, ceililngFanOff); remoteControl.SetCommand(5, ceililngFanMediumOn, ceililngFanOff); remoteControl.SetCommand(6, ceililngFanHighOn, ceililngFanOff); remoteControl.SetCommand(1, partyOn, partyOff); remoteControl.P(); RemoteControlPressButtons(remoteControl); }
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 Main(string[] args) { // Control the light var remote = new RemoteController(); // Invoker var light = new Light(); // Receiver var lightOn = new LightOnCommand(light); // Command var lightOff = new LightOffCommand(light); // Command remote.SetCommand(lightOn); remote.ActivateCommand(); remote.SetCommand(lightOff); remote.ActivateCommand(); // Control the garage door var garageDoor = new GarageDoor(); // Receiver var doorUp = new GarageDoorUpCommand(garageDoor); // Command var doorDown = new GarageDoorDownCommand(garageDoor); // Command // Invoker ---> Command ----> Receiver remote.SetCommand(doorUp); remote.ActivateCommand(); remote.SetCommand(doorDown); remote.ActivateCommand(); Console.ReadKey(); }
private void button9_Click(object sender, EventArgs e) { richTextBox1.Text = null; foreach (var buf in label) { if (buf.BackColor != Color.MediumTurquoise) { buf.BackColor = Color.MediumTurquoise; } } label9.BackColor = Color.MediumSeaGreen; if (label9.BackColor == Color.MediumSeaGreen & flag == true) { RemoteControl remoteControl = new RemoteControl(); Light light = new Light(richTextBox1); LightOnCommand lightOnCommand = new LightOnCommand(light); LightOffCommand lightOffCommand = new LightOffCommand(light); remoteControl.SetCommand(1, lightOnCommand, lightOffCommand); remoteControl.OffButtonWasPushed(1); flag = false; } else { richTextBox1.Text = null; richTextBox1.Text = "Light is Off\nPress key On light"; } }
static void Main(string[] args) { RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); Light livingRoomLight = new Light(false, "Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); CeilingFan livingRoomCeilingFan = new CeilingFan("Living Room", CeilingFan.Off); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(livingRoomCeilingFan); CeilingFanLowCommand ceilingFanLowCommand = new CeilingFanLowCommand(livingRoomCeilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan); remoteControl.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.SetCommand(2, ceilingFanLowCommand, ceilingFanOffCommand); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); }
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(); }
public static void Main(string[] args) { Console.Clear(); Console.WriteLine(); Console.WriteLine("Chapter6 - Command"); Console.WriteLine(); SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.ButtonWasPressed(); RemoteControl rc = new RemoteControl(); Console.WriteLine(rc.ToString()); Light lightInBedroom = new Light(); LightOnCommand lightInBedroom_OnCommand = new LightOnCommand(lightInBedroom); LightOffCommand lightInBedroom_OffCommand = new LightOffCommand(lightInBedroom); Stereo myStereo = new Stereo(); StereoOnWithCDCommand myStereo_On = new StereoOnWithCDCommand(myStereo); StereoOffWithCDCommand myStereo_Off = new StereoOffWithCDCommand(myStereo); CeilingFan fan = new CeilingFan("Living room"); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(fan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(fan); MacroCommand macroCommand_On = new MacroCommand(new ICommand[] { lightInBedroom_OnCommand, myStereo_On, ceilingFanHighCommand }); MacroCommand macroCommand_Off = new MacroCommand(new ICommand[] { lightInBedroom_OffCommand, myStereo_Off, ceilingFanOffCommand }); rc.SetCommand(0, lightInBedroom_OnCommand, lightInBedroom_OffCommand); rc.SetCommand(1, myStereo_On, myStereo_Off); rc.SetCommand(2, ceilingFanHighCommand, ceilingFanOffCommand); rc.SetCommand(6, macroCommand_On, macroCommand_Off); Console.WriteLine(rc.ToString()); rc.OnButtonWasPressed(0); rc.OnButtonWasPressed(1); rc.OffButtonWasPressed(0); rc.UndoButtonWasPressed(); rc.OnButtonWasPressed(2); rc.UndoButtonWasPressed(); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Call macro command"); rc.OnButtonWasPressed(6); rc.OffButtonWasPressed(6); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Macro command finished"); Console.WriteLine(); Console.WriteLine(rc.ToString()); Console.ReadKey(); }
static void Main(string[] args) { var control = new RemoteControl(); var tv = new TV(); var kitchenLight = new Light("Kitchen"); var yardLight = new Light("Yard"); var livingRoomLight = new Light("Living Room"); var bathroomLight = new Light("Bathroom"); var bedroomLight = new Light("Bedroom"); var lightOnKitchen = new LightOnCommand(kitchenLight); var lightOnYard = new LightOnCommand(yardLight); var lightOnLivingR = new LightOnCommand(livingRoomLight); var lightOnBathR = new LightOnCommand(bathroomLight); var lightOnBedR = new LightOnCommand(bedroomLight); var lightOffKitchen = new LightOffCommand(kitchenLight); var lightOffYard = new LightOffCommand(yardLight); var lightOffLivingR = new LightOffCommand(livingRoomLight); var lightOffBathR = new LightOffCommand(bathroomLight); var lightOffBedR = new LightOffCommand(bedroomLight); control.SetCommand(Slot.Num0, new TVOnCommand(tv), new TVOffCommand(tv)); control.SetCommand(Slot.Num1, lightOnKitchen, lightOffKitchen); control.SetCommand(Slot.Num2, lightOnYard, lightOffYard); control.SetCommand(Slot.Num3, new MacroCommand(lightOnKitchen, lightOnYard, lightOnLivingR, lightOnBathR, lightOnBedR), new MacroCommand(lightOffKitchen, lightOffYard, lightOffLivingR, lightOffBathR, lightOffBedR)); Console.WriteLine(control.ToString() + '\n'); control.OnButtonPressed(Slot.Num0); control.OffButtonPressed(Slot.Num0); control.OnButtonPressed(Slot.Num1); control.OffButtonPressed(Slot.Num1); control.OnButtonPressed(Slot.Num2); control.OffButtonPressed(Slot.Num2); Console.WriteLine('\n'); control.UndoButtonPressed(); control.UndoButtonPressed(); control.UndoButtonPressed(); Console.WriteLine('\n'); control.OnButtonPressed(Slot.Num4); Console.WriteLine('\n'); control.OnButtonPressed(Slot.Num3); control.UndoButtonPressed(); Console.ReadKey(); }
private void Button1_Click(object sender, EventArgs e) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.setCommand(lightOn); salida.Text = remote.buttonWasPressed(); }
static void Main(string[] args) { var remoteControl = new SimpleRemoteControl(); var light = new Light(); var lightOnCommand = new LightOnCommand(light); remoteControl.setCommand(lightOnCommand); remoteControl.buttonWasPressed(); }
public void Light_On_Command_Test() { //receiver Light light = new Light(); LightOnCommand lightOnCommand = new LightOnCommand(light); CommandInvoker invoker = new CommandInvoker(); invoker.SetCommand(lightOnCommand); invoker.CommandOn(); }
static void Main(string[] args) { var remote = new SimpleRemoteControl(); var light = new Light(); var lightOnCommand = new LightOnCommand(light); remote.SetCommand(lightOnCommand); remote.ButtonWasPressed(); }
private void Form1_Load(object sender, EventArgs e) { panel1.BackColor = Color.DarkGray; lightOnCommand = new LightOnCommand(light); lightOffCommand = new LightOffCommand(light); remote.SetCommand(lightOnCommand); remote2.SetCommand(lightOffCommand); light.onActiveChanged += Lightning; }
public void MutiCommand_Execute() { Doctor doctor = new Doctor(); DoctorMakeAdvice doctorMakeAdvice = new DoctorMakeAdvice(doctor); Light light = new Light(); LightOnCommand lightOnCommand = new LightOnCommand(light); MultiCommand multiCommand = new MultiCommand(new ICommand[] { doctorMakeAdvice, lightOnCommand }); multiCommand.Execute(); }
public static void Run() { var remoteControl = new RemoteControlWithUndo(); var livingRoomLight = new Light("Living Room"); var ceilingFan = new CeilingFan("Living Room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(); remoteControl.OffButtonWasPushed(1); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(1); Console.WriteLine(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(); remoteControl.OffButtonWasPushed(2); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(2); Console.WriteLine(); }
public static void Test() { var remote = new SimpleRemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var garageDoor = new GarageDoor(); var garagedoorOpenCommand = new GarageDoorOpenCommand(garageDoor); remote.SetCommand(lightOn); remote.ButtonWasPressed(); remote.SetCommand(garagedoorOpenCommand); remote.ButtonWasPressed(); }
public static void Run() { var remote = new SimpleRemoteControl(); var light = new Light(); var garageDoor = new GarageDoor(); var lightOn = new LightOnCommand(light); var garageOpen = new GarageDoorUpCommand(garageDoor); remote.SetCommand(lightOn); remote.ButtonWasPressed(); Console.WriteLine(); remote.SetCommand(garageOpen); remote.ButtonWasPressed(); }
public void ButtonWasPressed_ForLight_LightIsOn() { // Arrange var light = new Light(); var lightOn = new LightOnCommand(light); simpleRemoteControl.SetCommand(lightOn); // Act string actual = simpleRemoteControl.ButtonWasPressed(); // Assert Assert.That(actual, Is.EqualTo("Light is On")); }
public static void Run() { 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 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); Console.WriteLine(); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(); remoteControl.OffButtonWasPushed(1); Console.WriteLine(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(); remoteControl.OffButtonWasPushed(2); Console.WriteLine(); remoteControl.OnButtonWasPushed(3); Console.WriteLine(); remoteControl.OffButtonWasPushed(3); }
private static string ProcessRemoteControl() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garage = new GarageDoor(); Stereo stereo = new Stereo(); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOnCommand = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garage); GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garage); StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); remoteControl.OnCommands[0] = livingRoomLightOn; remoteControl.OnCommands[1] = kitchenLightOn; remoteControl.OnCommands[2] = ceilingFanOnCommand; remoteControl.OnCommands[3] = stereoOnWithCDCommand; remoteControl.OffCommands[0] = livingRoomLightOff; remoteControl.OffCommands[1] = kitchenLightOff; remoteControl.OffCommands[2] = ceilingFanOffCommand; remoteControl.OffCommands[3] = stereoOffCommand; StringBuilder sb = new StringBuilder(); sb.AppendLine(remoteControl.ToString()); sb.AppendLine(remoteControl.OnButtonWasPushed(0)); sb.AppendLine(remoteControl.OffButtonWasPushed(0)); sb.AppendLine(remoteControl.OnButtonWasPushed(1)); sb.AppendLine(remoteControl.OffButtonWasPushed(1)); sb.AppendLine(remoteControl.OnButtonWasPushed(2)); sb.AppendLine(remoteControl.OffButtonWasPushed(2)); sb.AppendLine(remoteControl.OnButtonWasPushed(3)); sb.AppendLine(remoteControl.OffButtonWasPushed(3)); return(sb.ToString()); }
static void Main(string[] args) { var remoteControl = new RemoteControl(); var light = new Light("Living Roon"); var tv = new TV("Living Room"); var stereo = new Stereo("Living Room"); var hottub = new Hottub(); var garageDoor = new GarageDoor(string.Empty); var lightOnCommand = new LightOnCommand(light); var lightOffCommand = new LightOffCommand(light); var stereoOnCommand = new StereoOnCommand(stereo); var stereoOffCommand = new StereoOffCommand(stereo); var tvOnCommand = new TVOnCommand(tv); var tvOffCommand = new TVOffCommand(tv); var hottubOnCommand = new HottubOnCommand(hottub); var hottubOffCommand = new HottubOffCommand(hottub); var partyOn = new ICommand[] { lightOnCommand, stereoOnCommand, tvOnCommand, hottubOnCommand }; var partyOff = new ICommand[] { lightOffCommand, stereoOffCommand, tvOffCommand, hottubOffCommand }; var partyOnMacro = new MacroCommand(partyOn); var partyOffMacro = new MacroCommand(partyOff); //remoteControl.SetCommand(0, lightOnCommand, lightOffCommand); //remoteControl.SetCommand(1, tvOnCommand, tvOffCommand); //remoteControl.SetCommand(2, stereoOnCommand, stereoOffCommand); //remoteControl.SetCommand(3, hottubOnCommand, hottubOffCommand); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); remoteControl.SetCommand(6, new GarageDoorUpCommand(garageDoor), new GarageDoorDownCommand(garageDoor)); Console.WriteLine(remoteControl); remoteControl.OnButtonPressed(2); remoteControl.OnButtonPressed(0); remoteControl.OnButtonPressed(3); remoteControl.OnButtonPressed(1); remoteControl.OffButtonPressed(2); remoteControl.OffButtonPressed(0); remoteControl.OffButtonPressed(3); remoteControl.OffButtonPressed(1); remoteControl.OnButtonPressed(6); remoteControl.UndoButtonPressed(); Console.Read(); }
static void Main(string[] args) { Remote remote = new Remote(); Light livingroomlight = new Light("livingroom"); LightOnCommand livingroomlighton = new LightOnCommand(livingroomlight); LightOffCommand livingroomlightoff = new LightOffCommand(livingroomlight); remote.SetCommand(0, livingroomlighton, livingroomlightoff); remote.OnButtonWasPushed(0); //livingroom light is on SimpleRemoteControl remote2 = new SimpleRemoteControl(); remote2.SetCommand(livingroomlighton); remote2.ButtonWasPressed(); //livingroom light is on string z = Console.ReadLine(); }