예제 #1
0
        public async static void ConfigureGpio()
        {
            try
            {
                await Bus1.Connect();
            }
            catch (Exception)
            {
                Debug.WriteLine("No se ha podido conectar con el dispositivo I2C 0x20.");
            }

            Bus1.SetPortDirection(0, 0x00);
            Bus1.SetPortDirection(1, 0x00);
            Bus1.WritePort(0, 0x00);
            Bus1.WritePort(1, 0x00);
            Reset.SetDriveMode(GpioPinDriveMode.Output);
            Reset.Write(GpioPinValue.High);
            Buzzer.SetDriveMode(GpioPinDriveMode.Output);
            Buzzer.Write(GpioPinValue.Low);
            EntranceRSw1.SetDriveMode(GpioPinDriveMode.Input);
            TerraceRSw2.SetDriveMode(GpioPinDriveMode.Input);
            GarageRSw3.SetDriveMode(GpioPinDriveMode.Input);
            BedroomCurtain.SetDriveMode(GpioPinDriveMode.Input);
            LivingRoomCurtain.SetDriveMode(GpioPinDriveMode.Input);
            BathroomCurtain.SetDriveMode(GpioPinDriveMode.Input);
            GarageDoor.SetDriveMode(GpioPinDriveMode.Input);
            LightSensor.SetDriveMode(GpioPinDriveMode.Input);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Light      light              = new Light();
            GarageDoor garage             = new GarageDoor();
            ICommand   lightOnCommand     = new LivingLightOnCommand(light);
            ICommand   lightOffCommand    = new LivingLightOffCommand(light);
            ICommand   garageOpenCommand  = new GarageDoorOpenCommand(garage);
            ICommand   garageCloseCommand = new GarageDoorCloseCommand(garage);

            ICommand[] macroOnCommands  = { lightOnCommand, garageOpenCommand };
            ICommand[] macroOffCommands = { lightOffCommand, garageCloseCommand };
            var        macroOn          = new MacroCommand(macroOnCommands);
            var        macroOff         = new MacroCommand(macroOffCommands);

            IList <ICommand> onCommands = new List <ICommand> {
                lightOnCommand, garageOpenCommand, macroOn
            };
            IList <ICommand> offCommands = new List <ICommand> {
                lightOffCommand, garageCloseCommand, macroOff
            };
            var remoteControl = new RemoteControl(onCommands, offCommands);

            remoteControl.ButtonOnPressed(1);
            remoteControl.ButtonOnPressed(3);
        }
예제 #3
0
        public static void RunTest()
        {
            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 commands = new List <IUndoableCommand>
            {
                new LightOnCommand(livingRoomLight),
                new LightOffCommand(livingRoomLight),
                new LightOnCommand(kitchenLight),
                new LightOffCommand(kitchenLight),
                new CeilingFanHighCommand(ceilingFan),
                new CeilingFanOffCommand(ceilingFan),
                new GarageDoorUpCommand(garageDoor),
                new GarageDoorDownCommand(garageDoor),
                new StereoOnWithCdCommand(stereo),
                new StereoOffCommand(stereo),
            };

            new CommandsQueue(commands, 2).ExecuteQueue();
            Console.ReadKey();
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl();
            //GarageDoor
            GarageDoor             garageDoor             = new GarageDoor();
            GarageDoorCloseCommand garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);
            GarageDoorOpenCommand  garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);
            Light           light           = new Light();
            LightOnCommand  lightOnCommand  = new LightOnCommand(light);
            LightOffCommand lightOffCommand = new LightOffCommand(light);



            remoteControl.SetCommand(0, garageDoorOpenCommand, garageDoorCloseCommand);
            remoteControl.SetCommand(1, lightOnCommand, lightOffCommand);



            remoteControl.OnButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(1);

            Console.WriteLine(remoteControl);

            remoteControl.OffButtonWasPushed(0);
            Console.ReadKey();
        }
예제 #6
0
        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);
        }
예제 #7
0
        private static void CallCommand()
        {
            string house = " house ";

            Remote remoteControl = new Remote();

            //clients
            Alarm      houseAlarm = new Alarm(house);
            CeilingFan ceilingFan = new CeilingFan(house);
            GarageDoor garageDoor = new GarageDoor(house);
            Hottub     hottub     = new Hottub();
            Light      light      = new Light(house);
            Stereo     stereo     = new Stereo(house);

            remoteControl.SetCommand(0, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(1, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(2, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(3, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(4, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(5, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));
            remoteControl.SetCommand(6, new AlarmOnCommand(houseAlarm), new AlarmOffCommand(houseAlarm));



            Console.WriteLine(remoteControl.OnButtonWasPushed(0));
        }
        public int[] GetResult(object input)
        {
            Actions[] actions = (Actions[])input;
            int[]     result  = new int[actions.Length + 1];

            GarageDoor door = new GarageDoor();

            result[0] = door.GetCodeCurrentState();

            for (int i = 0; i < actions.Length; i++)
            {
                if (actions[i] == Actions.Click)
                {
                    door.PressClick();
                }
                else
                {
                    door.Wait();
                }

                result[i + 1] = door.GetCodeCurrentState();
            }

            return(result);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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();
        }
예제 #11
0
        static void TryRemoteControl()
        {
            var remoteControl = new RemoteControl();

            var livingRoomLight = new Light("Living room");
            var kitchenLight    = new Light("Kitchen");
            var garageDoor      = new GarageDoor();
            var stereo          = new Stereo("Living room");

            var livingRoomLightOnCommand  = new LightsOnCommand(livingRoomLight);
            var livingRoomLightOffCommand = new LightsOffCommand(livingRoomLight);
            var kitchenLightOnCommand     = new LightsOnCommand(kitchenLight);
            var kitchenLightOffCommand    = new LightsOffCommand(kitchenLight);

            remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand);
            remoteControl.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand);

            Console.WriteLine(remoteControl);

            remoteControl.PressOnButton(0);
            remoteControl.PressOffButton(0);

            remoteControl.PressOnButton(1);
            remoteControl.PressOffButton(1);
        }
예제 #12
0
        static void Main(string[] args)
        {
            RemoteControl remote           = new RemoteControl();
            Light         kitchenRoomlight = new Light("Kitchen");
            Light         livingRoomLight  = new Light("Living Room");
            GarageDoor    garageDoor       = new GarageDoor("");
            Stereo        stereo           = new Stereo("Living Room");

            LightOnCommand  livingRoomLightOn   = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff  = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenRoomLightOn  = new LightOnCommand(kitchenRoomlight);
            LightOffCommand kitchenRoomLightOff = new LightOffCommand(kitchenRoomlight);

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

            StereoOnWidthCDCommand  stereoOnWidthCDCommand  = new StereoOnWidthCDCommand(stereo);
            StereoOffWidthCDCommand stereoOffWidthCDCommand = new StereoOffWidthCDCommand(stereo);

            ICommand[] partyOn  = { livingRoomLightOn, garageDoorUp, stereoOnWidthCDCommand, kitchenRoomLightOn };
            ICommand[] partyOff = { livingRoomLightOff, garageDoorDown, stereoOffWidthCDCommand, kitchenRoomLightOff };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand partyOffMacro = new MacroCommand(partyOff);

            remote.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remote);
            Console.WriteLine("--- Pushing Macro On ---");
            remote.onButtonWasPressed(0);
            Console.WriteLine("--- Pushing Macro Off ---");
            remote.offButtonWasPressed(0);

            Console.ReadKey();
        }
예제 #13
0
        private void button8_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = null;

            foreach (var buf in label)
            {
                if (buf.BackColor != Color.MediumTurquoise)
                {
                    buf.BackColor = Color.MediumTurquoise;
                }
            }

            if (flag == true)
            {
                label8.BackColor = Color.MediumSeaGreen;
                RemoteControl remoteControl = new RemoteControl();
                //GarageDoor
                GarageDoor             garageDoor             = new GarageDoor(richTextBox1);
                GarageDoorOpenCommand  garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);
                GarageDoorCloseCommand garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);
                remoteControl.SetCommand(0, garageDoorOpenCommand, garageDoorCloseCommand);
                remoteControl.OffButtonWasPushed(0);
                flag = false;
            }
            else
            {
                richTextBox1.Text = null;
                richTextBox1.Text = "Door is Close\nPress key open door";
            }
        }
예제 #14
0
        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();
        }
예제 #15
0
        public void GarageDoorTest()
        {
            Remotes    remote = new Remotes();
            GarageDoor door   = new GarageDoor();

            Assert.AreEqual(door.LightState, GarageDoor.LightStates.Off);
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Down);
            DoorUpCommand   doorUp   = new DoorUpCommand(door);
            DoorDownCommand doorDown = new DoorDownCommand(door);

            remote.SetCommand(doorUp);
            remote.ButtonWasPressed();

            // Make sure that the door went up and the light turned on
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);
            Assert.AreEqual(door.LightState, GarageDoor.LightStates.On);

            remote.ButtonWasPressed();

            // Make sure that the door stayed up and the light stayed on after a second door up command
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);
            Assert.AreEqual(door.LightState, GarageDoor.LightStates.On);

            door.AddObstruction();

            remote.SetCommand(doorDown);
            remote.ButtonWasPressed();

            // Make sure the door did not start closing when an obstruction was in the way
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);

            door.RemoveObstruction();
            remote.ButtonWasPressed();

            // Make sure that the door started ot go down when the button was pressed
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.GoingDown);

            door.AddObstruction();

            remote.ButtonWasPressed();

            // Make sure the door detected that something was in the way when is was coming down and went back up
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Up);

            door.RemoveObstruction();

            remote.ButtonWasPressed();
            remote.ButtonWasPressed();


            // Make sure that when there are no obstructions and the button is pressed twice that the door closes
            // and the light turns off
            Assert.AreEqual(door.DoorState, GarageDoor.DoorStates.Down);
            Assert.AreEqual(door.LightState, GarageDoor.LightStates.Off);
        }
예제 #16
0
        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_ForGarageDoor_GarageDoorIsOpen()
        {
            // Arrange
            var garageDoor            = new GarageDoor();
            var garageDoorOpenCommand = new GarageDoorOpenCommand(garageDoor);

            simpleRemoteControl.SetCommand(garageDoorOpenCommand);

            // Act
            string actual = simpleRemoteControl.ButtonWasPressed();

            // Assert
            Assert.That(actual, Is.EqualTo("Garage Door is Open"));
        }
예제 #19
0
        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);
        }
예제 #20
0
        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();
        }
예제 #21
0
        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());
        }
        public void RemoteControl_TestLambdaCommands()
        {
            RemoteControl control = new RemoteControl();
            GarageDoor    door    = new GarageDoor();

            Command <GarageDoor> openDoor = new Command <GarageDoor>(door,
                                                                     g => g.Up(), g => g.Down());
            Command <GarageDoor> closeDoor = new Command <GarageDoor>(door,
                                                                      g => g.Down(), g => g.Up());

            control.SetCommand(0, openDoor, closeDoor);
            control.ClickButtonOn(0);
            control.ClickButtonOff(0);
            control.UndoButtonClick();
        }
        public static void Run()
        {
            var remote = new SimpleRemoteControl();

            var light   = new Light();
            var lightOn = new LightOnCommand(light);

            remote.Command = lightOn;
            remote.ButtonWesPressed();

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

            remote.Command = garageDoorOpen;
            remote.ButtonWesPressed();
        }
예제 #24
0
        private static string ProcessSimpleRemote()
        {
            StringBuilder       sb                      = new StringBuilder();
            SimpleRemoteControl remote                  = new SimpleRemoteControl();
            Light                 light                 = new Light();
            LightOnCommand        lightOn               = new LightOnCommand(light);
            GarageDoor            garageDoor            = new GarageDoor();
            GarageDoorOpenCommand garageDoorOpenCommand = new GarageDoorOpenCommand(garageDoor);

            remote.Slot = lightOn;
            sb.AppendLine(remote.ButtonWasPressed());
            remote.Slot = garageDoorOpenCommand;
            sb.AppendLine(remote.ButtonWasPressed());

            return(sb.ToString());
        }
예제 #25
0
        public void Load()
        {
            SimpleRemoteControl remoteControl = new SimpleRemoteControl();

            Light          light   = new Light();
            LightOnCommand lightOn = new LightOnCommand(light);

            remoteControl.SetCommand(lightOn);
            remoteControl.ButtonWasPressed();

            GarageDoor          garageDoor            = new GarageDoor();
            GarageDoorUpCommand garageDoorOpenCommand = new GarageDoorUpCommand(garageDoor);

            remoteControl.SetCommand(garageDoorOpenCommand);
            remoteControl.ButtonWasPressed();
        }
예제 #26
0
        public void CommandExample()
        {
            RemoteControl remote = new RemoteControl(); // this is the invoker

            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen Room");
            GarageDoor garageDoor      = new GarageDoor("");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            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);

            CeilingFanOnHighCommand   ceilingFanOnHigh   = new CeilingFanOnHighCommand(ceilingFan);
            CeilingFanOnMediumCommand ceilingFanOnMedium = new CeilingFanOnMediumCommand(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, ceilingFanOnHigh, ceilingFanOnMedium);
            remote.SetCommand(3, stereoOnWithCd, stereoOff);

            Console.WriteLine(remote);

            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);
            remote.UndoButtonWasPushed();
            remote.OnButtonWasPushed(1);
            remote.OffButtonWasPushed(1);
            remote.OnButtonWasPushed(2);
            remote.OffButtonWasPushed(2);
            remote.UndoButtonWasPushed();
            remote.OnButtonWasPushed(3);
            remote.OffButtonWasPushed(3);
            remote.UndoButtonWasPushed();

            Console.ReadLine();
        }
        public static void Run()
        {
            // Invoker
            RemoteControl remoteControl = new RemoteControl();

            // Receivers
            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");

            // Commands
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            LightOnCommand  kitchenLightOn  = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

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

            CeilingFanOnLowCommand ceilingFanOnLow = new CeilingFanOnLowCommand(ceilingFan);
            CeilingFanOffCommand   ceilingFanOff   = new CeilingFanOffCommand(ceilingFan);

            GarageDoorOpenCommand  garageDoorUp   = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageDoorDown = new GarageDoorCloseCommand(garageDoor);



            // Set Commands
            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, stereoOnWithCD, stereoOff);
            remoteControl.SetCommand(3, ceilingFanOnLow, ceilingFanOff);
            remoteControl.SetCommand(4, garageDoorUp, garageDoorDown);

            Console.WriteLine(remoteControl);

            // Invoke Commands
            for (int i = 0; i < remoteControl.numberOfSlots; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                remoteControl.OffButtonWasPushed(i);
            }
        }
        public void TestTurningSimpleOn()//Command Pattern Client

        {
            //Command Pattern Invoker

            SimpleRemoteControl remote = new SimpleRemoteControl();



            //Command Pattern Receivers

            Light light = new Light("Kitchen");

            GarageDoor garageDoor = new GarageDoor("");



            //Commands for the receivers

            LightOnCommand lightOn = new LightOnCommand(light);

            GarageDoorUpCommand garageDoorOpen =

                new GarageDoorUpCommand(garageDoor);



            //Passing the light on command to the invoker

            remote.SetCommand(lightOn);

            //Simulate the button being pressed on the invoker

            Assert.AreEqual("Kitchen light is on", remote.ButtonWasPressed());



            //Passing the garage door open command to the invoker

            remote.SetCommand(garageDoorOpen);

            //Simulate the button being pressed on the invoker

            Assert.AreEqual("Garage door is up", remote.ButtonWasPressed());
        }
예제 #29
0
        static void TrySimpleRemoteControl()
        {
            Console.WriteLine("\n----- Simple remote control -----\n");

            var simpleRemoteControl = new SimpleRemoteControl();

            var light           = new Light("Living room");
            var lightsOnCommand = new LightsOnCommand(light);

            simpleRemoteControl.SetCommand(lightsOnCommand);
            simpleRemoteControl.PressTheButton();

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

            simpleRemoteControl.SetCommand(garageDoorOpenCommand);
            simpleRemoteControl.PressTheButton();
        }
        public void RemoteControl_ToString()
        {
            RemoteControl control = new RemoteControl();
            GarageDoor    door    = new GarageDoor();
            Light         light   = new Light();
            CeilingFan    fan     = new CeilingFan();

            GarageDoorOpenCommand  openGarageCommand  = new GarageDoorOpenCommand(door);
            GarageDoorCloseCommand closeGarageCommand = new GarageDoorCloseCommand(door);
            LightOffCommand        lightOffCommand    = new LightOffCommand(light);
            LightOnCommand         lightOnCommand     = new LightOnCommand(light);
            CeilingFanHighCommand  fanHighCommand     = new CeilingFanHighCommand(fan);
            CeilingFanOffCommand   fanOffCommand      = new CeilingFanOffCommand(fan);

            control.SetCommand(0, lightOnCommand, lightOffCommand);
            control.SetCommand(1, openGarageCommand, closeGarageCommand);
            control.SetCommand(2, fanHighCommand, fanOffCommand);
            Console.WriteLine(control.ToString());
        }
예제 #31
0
		public void TestSetup()
		{
			this.door = new GarageDoor();
		}
예제 #32
0
 public GarageDoorOpenCommand(GarageDoor garageDoor)
 {
     _garageDoor = garageDoor;
 }
예제 #33
0
 public GarageDoorCloseCommand(GarageDoor garageDoor)
 {
     _garageDoor = garageDoor;
 }