Example #1
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 CeilingFanOffCommand(CeilingFan ceilingFan)
 {
     this.ceilingFan = ceilingFan;
 }
Example #3
0
 public CeilingFanHighCommand(CeilingFan ceilingFan)
 {
     _ceilingFan = ceilingFan;
 }
Example #4
0
 public CeilingFanOffCommand(CeilingFan fan)
 {
     _fan = fan;
 }
Example #5
0
 public CeilingFanLowCommand(CeilingFan ceilingFan) : base(ceilingFan)
 {
     _ceilingFan = ceilingFan;
 }
Example #6
0
 public CeilingFanSpeedUpCommand(CeilingFan f) => fan = f;
Example #7
0
 protected override void SetSpeed()
 {
     CeilingFan.Off();
 }
Example #8
0
        public void TestTurningOn()        //Command Pattern Client
        {
            //Command Pattern Invoker
            Remote remote = new Remote();

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor("");
            Stereo     stereo          = new Stereo("Living Room");

            LightOnCommand livingRoomLightOn =
                new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff =
                new LightOffCommand(livingRoomLight);
            LightOnCommand kitchenLightOn =
                new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff =
                new LightOffCommand(kitchenLight);

            CeilingFanOnCommand ceilingFanOn =
                new CeilingFanOnCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOff =
                new CeilingFanOffCommand(ceilingFan);

            GarageDoorUpCommand garageDoorUp =
                new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown =
                new GarageDoorDownCommand(garageDoor);

            StereoOnWithCDCommand stereoOnWithCD =
                new StereoOnWithCDCommand(stereo);
            StereoOffCommand stereoOff =
                new StereoOffCommand(stereo);

            remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remote.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remote.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remote.SetCommand(3, stereoOnWithCD, stereoOff);

            Assert.AreEqual("Living Room light is on",
                            remote.OnButtonWasPushed(0));
            Assert.AreEqual("Living Room light is off",
                            remote.OffButtonWasPushed(0));

            Assert.AreEqual("Kitchen light is on",
                            remote.OnButtonWasPushed(1));
            Assert.AreEqual("Kitchen light is off",
                            remote.OffButtonWasPushed(1));
            Assert.AreEqual("Living Room ceiling fan is on high",
                            remote.OnButtonWasPushed(2));
            Assert.AreEqual("Living Room ceiling fan is off",
                            remote.OffButtonWasPushed(2));
            Assert.AreEqual("Living Room stereo is on\n" +
                            "Living Room stereo is set for CD input\n" +
                            "Living Room Stereo volume set to 11",
                            remote.OnButtonWasPushed(3));
            Assert.AreEqual("Living Room stereo is off",
                            remote.OffButtonWasPushed(3));

//			Console.WriteLine(remote.toString());
        }
 protected override void SetSpeed()
 {
     CeilingFan.High();
 }
Example #10
0
 public CeilingFanLowCommand(CeilingFan cf)
 {
     this._ceilingFan = cf;
 }
 public CeilingFanHighCommand(CeilingFan cf)
 {
     ceilingFan = cf;
 }
 public CeilingFanMediumCommand(CeilingFan fan)
 {
     _fan = fan;
 }
 public CeilingFanHighCommand(CeilingFan cf)
 {
     this._ceilingFan = cf;
 }
 public CeilingFanOnCommand(CeilingFan ceilingFan)
 {
     this.CeilingFan = ceilingFan;
 }
Example #15
0
 public CeilingFanOffCommand(CeilingFan ceilingFan)
     : base(ceilingFan)
 {
 }
 public FanOnCommand(CeilingFan ceilingFan, int fanSpeed)
 {
     this._ceilingFan = ceilingFan;
     this._fanSpeed   = fanSpeed;
 }
 public CeilingFanHighCommand(CeilingFan ceilingFan) : base(ceilingFan)
 {
 } // ctor
Example #18
0
 public CeilingFanHighCommand(CeilingFan fan)
 {
     this.fan = fan;
 }
Example #19
0
 public CeilingFanOff(CeilingFan fan)
 {
     Fan = fan;
 }
Example #20
0
 public CeilingFanSpeedDownCommand(CeilingFan f) => fan = f;
Example #21
0
 public CeilingFanHigh(CeilingFan fan)
 {
     Fan = fan;
 }
Example #22
0
 public CeilingFanOnHighCommand(CeilingFan ceilingFan)
 {
     this.ceilingFan = ceilingFan;
 }
        public static void Test()
        {
            RemoteControl remoteControl = new RemoteControl();

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor("Garage");
            Stereo     stereo          = new Stereo("Living Room");
            TV         tv     = new TV("Living Room");
            Hottub     hottub = new Hottub();

            LightOnCommand livingRoomLightOn =
                new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff =
                new LightOffCommand(livingRoomLight);
            LightOnCommand kitchenLightOn =
                new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff =
                new LightOffCommand(kitchenLight);

            CeilingFanOnCommand ceilingFanOn =
                new CeilingFanOnCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOff =
                new CeilingFanOffCommand(ceilingFan);

            GarageDoorUpCommand garageDoorUp =
                new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown =
                new GarageDoorDownCommand(garageDoor);

            StereoOnWithCDCommand stereoOnWithCD =
                new StereoOnWithCDCommand(stereo);
            StereoOffCommand stereoOff =
                new StereoOffCommand(stereo);

            TVOnCommand tvOn =
                new TVOnCommand(tv);
            TVOffCommand tvOff =
                new TVOffCommand(tv);

            HottubOnCommand hottubOn =
                new HottubOnCommand(hottub);
            HottubOffCommand hottubOff =
                new HottubOffCommand(hottub);



            Command[]    partyOn        = { livingRoomLightOn, stereoOnWithCD, tvOn, hottubOn };
            Command[]    partyOff       = { livingRoomLightOff, stereoOff, tvOff, hottubOff };
            MacroCommand partyOnCommand =
                new MacroCommand(partyOn);
            MacroCommand partyOffCommand =
                new MacroCommand(partyOff);

            remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.setCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.setCommand(3, stereoOnWithCD, stereoOff);
            remoteControl.setCommand(4, partyOnCommand, partyOffCommand);

            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("-------------------------------------------------------------- Party Mode On -----------------------------------------------");
            remoteControl.onButtonWasPushed(4);
            remoteControl.offButtonWasPushed(4);
            remoteControl.undoButtonPushed();
        }
 public CeilingFanMediumCommand(CeilingFan ceilingFan)
 {
     _ceilingFan = ceilingFan;
 }
 public void Execute()
 {
     PrevSpeed = CeilingFan.Speed;
     CeilingFan.SetOff();
 }
Example #26
0
/*        Esta clase contiene toda la lógica de nuestro patrón comando,
 *        analicémosla detenidamente
 */
        public static RemoteControl CreateControl()
        {
/*         Nuestro control es nuestro invocador, es el que da comandos y
 *         los demás los ejecutan, veámoslo un poco más de cerca
 *         entra a la clase RemoteControl Para analizarla
 */
            RemoteControl control = new RemoteControl();

/*          Como pudiste ver el control no tiene ningún conocimiento de como
 *          se realizan los comandos, lo único que hace es llamarlos y ejecutarlos,
 *
 *          el siguiente proceso crea a los recibidores o accionadores que son los
 *          que se encargan de ejecutar y hacer realidad nuestros comandos
 *
 *          entra en las clases para analizarlas
 */
            ILight     livingRoomLight = new LivingRoomLight();
            CeilingFan ceilingFan      = new CeilingFan();
            ILight     kitchenLight    = new KitchenLight();
            GarageDoor garageDoor      = new GarageDoor();
            Stereo     stereo          = new Stereo();
            ILight     allLights       = new AllLights();
            HotTub     hotTub          = new HotTub();
            TV         tv = new TV();

/*          Como pudiste observar cada uno de estos receptores define como
 *          ejecutar sus acciones; acontinuacionel en siguiente proceso podrás
 *          observar cómo se crean los comandos para ser almacenados dentro de nuestro
 *          control que funcionara como nuestro invocador.
 */
            //Este proceso crea los comandos, recibiendo como parametro
            //la clase que ejecutara el proceso(receptor)
            //Entra a LightsOnCommands para analizarlo
            LightsOnCommands  livingRoomLightsOn  = new LightsOnCommands(livingRoomLight);
            LightsOffCommands livingRoomLightsOff = new LightsOffCommands(livingRoomLight);
            LightsOnCommands  kitchenLightsOn     = new LightsOnCommands(kitchenLight);
            LightsOffCommands kitchenLightsOff    = new LightsOffCommands(kitchenLight);
            LightsOnCommands  allLightsOn         = new LightsOnCommands(allLights);
            LightsOffCommands allLightsOff        = new LightsOffCommands(allLights);

            CeilingFanLowCommand    ceilingFanOn     = new CeilingFanLowCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanHightCommand  ceilingFanHight  = new CeilingFanHightCommand(ceilingFan);
            CeilingFanOffCommand    ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            GarageDoorOpenCommand  garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garageDoor);

            StereoWithCDOnCommand  stereoWithCDOn  = new StereoWithCDOnCommand(stereo);
            StereoWithCDOffCommand stereoWithCDOff = new StereoWithCDOffCommand(stereo);

            HotTubOnCommand  hotTubOn  = new HotTubOnCommand(hotTub);
            HotTubOffCommand hotTubOff = new HotTubOffCommand(hotTub);

            TvOffCommand tvOff = new TvOffCommand(tv);
            TvOnCommand  tvOn  = new TvOnCommand(tv);

/*          para el modo fiesta necesitaremos un comando especial, que pueda recibir una
 *          serie de comandos y los ejecute, por eso fue creada la clase MacroCommand que
 *          ejecuta una serie de comandos.
 */
            ICommand[]   PartyModeCommandsOn  = { livingRoomLightsOn, stereoWithCDOn, tvOn, hotTubOn };
            ICommand[]   PartyModeCommandsOff = { livingRoomLightsOff, stereoWithCDOff, tvOff, hotTubOff };
            MacroCommand PartyModeOn          = new MacroCommand(PartyModeCommandsOn);
            MacroCommand PartyModeOff         = new MacroCommand(PartyModeCommandsOff);

            //Al almacenar los comandos en el control habilitamos la funcionalidad
            //para que sea ejecutada al presionar algún boton, ve a la clase principal
            //del proyecto y ve cómo se ejecuta cada una de las acciones
            control.OnCommands[0]  = livingRoomLightsOn;
            control.OffCommands[0] = livingRoomLightsOff;
            control.OnCommands[1]  = kitchenLightsOn;
            control.OffCommands[1] = kitchenLightsOff;
            control.OnCommands[2]  = allLightsOn;
            control.OffCommands[2] = allLightsOff;
            control.OnCommands[3]  = ceilingFanOn;
            control.OffCommands[3] = ceilingFanOff;
            control.OnCommands[4]  = ceilingFanMedium;
            control.OffCommands[4] = ceilingFanOff;
            control.OnCommands[5]  = ceilingFanHight;
            control.OffCommands[5] = ceilingFanOff;
            control.OnCommands[6]  = garageDoorOpen;
            control.OffCommands[6] = garageDoorClose;
            control.OnCommands[7]  = stereoWithCDOn;
            control.OffCommands[7] = stereoWithCDOff;
            control.OnCommands[8]  = PartyModeOn;
            control.OffCommands[8] = PartyModeOff;
            control.OnCommands[9]  = new NoCommand();
            control.OffCommands[9] = new NoCommand();
            return(control);
        }
 public CeilingFanLowCommand(CeilingFan cf)
 {
     ceilingFan = cf;
 }
 public CeilingFanOffCommand(CeilingFan ceilingFan)
 {
     _ceilingFan = ceilingFan;
 }
Example #29
0
 public CeilingFanLowCommand(CeilingFan ceilingFan)
 {
     this.ceilingFan = ceilingFan;
 }
Example #30
0
 public CeilingFanOffCommand(CeilingFan fan)
 {
     this.fan = fan;
 }
Example #31
0
 public CeilingFanLowCommand(CeilingFan ceilingFan) => _ceilingFan = ceilingFan;
 public CeilingFanTurnOnHighCommand(CeilingFan ceilingFan)
 {
     _ceilingFan = ceilingFan;
 }
 public CeilingFanTurnOffCommand(CeilingFan ceilingFan)
 {
     _ceilingFan = ceilingFan;
 }