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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
        public void Start()
        {
            Light               light = new Light();
            Command             l     = new LightOnCommand(light);
            SimpleRemoteControl s     = new SimpleRemoteControl();

            s.SetOnCommand(l);
            s.ButtonPressed();
        }
예제 #5
0
        static void Main(string[] args)
        {
            Light               light           = new Light();
            Command             lightBtn        = new LightONCommand(light);
            SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl();

            simpRemoteCntrl.SetCommand(lightBtn);
            simpRemoteCntrl.ButtonWasPressed();
        }
예제 #6
0
        static void Main(string[] args)
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light          light       = new Light();
            LightOnCommand lightOn     = new LightOnCommand(light);

            remote.setCommand(lightOn);
            remote.buttonWasPressed();
        }
예제 #7
0
        static void Main(string[] args)
        {
            var remote = new SimpleRemoteControl();
            var light = new Light();

            var lightOnCommand = new LightOnCommand(light);

            remote.SetCommand(lightOnCommand);
            remote.ButtonWasPressed();
        }
예제 #8
0
        static void Main(string[] args)
        {
            var remote = new SimpleRemoteControl();
            var light  = new Light();

            var lightOnCommand = new LightOnCommand(light);

            remote.SetCommand(lightOnCommand);
            remote.ButtonWasPressed();
        }
예제 #9
0
        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();
        }
예제 #10
0
        public static void RunSimpleRemoteControl()
        {
            var remote  = new SimpleRemoteControl();
            var light   = new Light();
            var lightOn = new LightOnCommand(light);

            remote.Slot = lightOn;
            remote.ButtonWasPressed();

            var garageDoor     = new GarageDoor();
            var garageDoorOpen = new GarageDoorOpenCommand(garageDoor);

            remote.Slot = garageDoorOpen;
            remote.ButtonWasPressed();
        }
예제 #11
0
        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();
        }
예제 #13
0
        static void Main(string[] args)
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();

            Light            light          = new Light();
            SwitchOnCommand  switchOnLight  = new SwitchOnCommand(light);
            SwitchOffCommand switchOffLight = new SwitchOffCommand(light);
            Door             door           = new Door();
            SwitchOnCommand  openDoor       = new SwitchOnCommand(door);
            SwitchOffCommand closeDoor      = new SwitchOffCommand(door);

            remote.SetOnSlot(0, switchOnLight);
            remote.SetOffSlot(0, switchOffLight);
            remote.SetOnSlot(1, openDoor);
            remote.SetOffSlot(1, closeDoor);
            remote.OnButtonWasPressed(0);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(0);
            remote.OffButtonWasPressed(1);
            remote.UndoButtonWasPushed();

            Console.ReadKey();
        }
예제 #14
0
        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();
        }
예제 #15
0
 static void Main(string[] args)
 {
     Light light = new Light();
     Command lightBtn = new LightONCommand(light);
     SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl();
     simpRemoteCntrl.SetCommand(lightBtn);
     simpRemoteCntrl.ButtonWasPressed();
 }
예제 #16
0
        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();
        }
예제 #17
0
        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());
        }
예제 #18
0
        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());
        }