Esempio n. 1
0
        static void Main(string[] args)
        {
            RemoteControlInfo remoteControl = new RemoteControlInfo();

            LightInfo       livingRoomLight    = new LightInfo("Living Room");
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            Console.WriteLine("--== Living Room Light ==--");
            remoteControl.OnButtonWasPushed(0);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine();

            CeilingFanInfo        drawingRoomCeilingFan     = new CeilingFanInfo("Drawing Room");
            CeilingFanHighCommand drawingRoomCeilingFanHigh = new CeilingFanHighCommand(drawingRoomCeilingFan);
            CeilingFanLowCommand  drawingRoomCeilingFanLow  = new CeilingFanLowCommand(drawingRoomCeilingFan);

            remoteControl.SetCommand(1, drawingRoomCeilingFanHigh, drawingRoomCeilingFanLow);
            Console.WriteLine("--== Drawing Room Ceiling Fan ==--");
            remoteControl.OnButtonWasPushed(1);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OffButtonWasPushed(1);


            Console.ReadLine();
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var remoteControl = new RemoteControl();

            var light      = new Light();
            var stereo     = new Stereo();
            var garageDoor = new GarageDoor();
            var ceilingFan = new CeilingFan();

            var lightOnCommand         = new LightOnCommand(light);
            var lightOffCommand        = new LightOffCommand(light);
            var stereoOnWithCdCommand  = new StereoOnWithCDCommand(stereo);
            var stereoOnWithDvdCommand = new StereoOnWithDVDCommand(stereo);
            var stereoOffCommand       = new StereoOffCommand(stereo);
            var garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);
            var garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);
            var ceilingFanHighCommand  = new CeilingFanHighCommand(ceilingFan);
            var ceilingFanLowCommand   = new CeilingFanLowCommand(ceilingFan);
            var ceilingFanOffCommand   = new CeilingFanOffCommand(ceilingFan);
            var partyOnCommand         = new MacroCommand(lightOnCommand, stereoOnWithDvdCommand, ceilingFanHighCommand, garageDoorOpenCommand);
            var partyOffCommand        = new MacroCommand(lightOffCommand, stereoOffCommand, ceilingFanOffCommand, garageDoorCloseCommand);

            remoteControl.SetCommand(0, lightOnCommand, lightOffCommand);
            remoteControl.SetCommand(1, garageDoorOpenCommand, garageDoorCloseCommand);
            remoteControl.SetCommand(2, stereoOnWithCdCommand, stereoOffCommand);
            remoteControl.SetCommand(3, stereoOnWithDvdCommand, stereoOffCommand);

            remoteControl.OnButtonPressed(0);
            remoteControl.OffButtonPressed(0);
            remoteControl.OnUndoButtonPressed();
            remoteControl.OnButtonPressed(1);
            remoteControl.OffButtonPressed(1);
            remoteControl.OnButtonPressed(2);
            remoteControl.OffButtonPressed(2);
            remoteControl.OnUndoButtonPressed();
            remoteControl.OnButtonPressed(3);
            remoteControl.OnUndoButtonPressed();
            remoteControl.OffButtonPressed(3);

            remoteControl.OnUndoButtonPressed();
            remoteControl.OnUndoButtonPressed();
            remoteControl.OnUndoButtonPressed();
            remoteControl.OnUndoButtonPressed();

            Console.WriteLine();

            remoteControl.SetCommand(2, ceilingFanLowCommand, ceilingFanOffCommand);
            remoteControl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand);
            remoteControl.SetCommand(4, partyOnCommand, partyOffCommand);

            remoteControl.OnButtonPressed(2);
            remoteControl.OnButtonPressed(3);
            remoteControl.OnUndoButtonPressed();
            remoteControl.OffButtonPressed(3);
            remoteControl.OnButtonPressed(4);
            remoteControl.OffButtonPressed(4);
            remoteControl.OnUndoButtonPressed();

            Console.ReadLine();
        }
        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();
        }
Esempio n. 5
0
        static void TryRemoteControlWithUndoingForCeilingFan()
        {
            Console.WriteLine("\n----- Remote control with Undo for ceiling fan -----\n");

            var remoteControl = new RemoteControl();

            var ceilingFan = new CeilingFan("Living room");

            var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            var ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            var ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff);

            remoteControl.PressOnButton(0);
            remoteControl.PressOffButton(0);
            Console.WriteLine(remoteControl);
            remoteControl.PressUndoButton();

            Console.WriteLine();

            remoteControl.PressOnButton(1);
            Console.WriteLine(remoteControl);
            remoteControl.PressUndoButton();
        }
Esempio n. 6
0
        static void RemoteControlTestMacro()
        {
            RemoteControl remoteControl = new RemoteControl();

            Light                 livingRoomLight    = new Light("Living Room");
            CeilingFan            ceilingFan         = new CeilingFan("Living Room");
            Stereo                stereo             = new Stereo("Living Room");
            LightOnCommand        livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand       livingRoomLightOff = new LightOffCommand(livingRoomLight);
            CeilingFanHighCommand ceilingFanOn       = new CeilingFanHighCommand(ceilingFan);
            CeilingFanOffCommand  ceilingFanOff      = new CeilingFanOffCommand(ceilingFan);
            StereoOnWithCdCommand stereoOnWithCd     = new StereoOnWithCdCommand(stereo);
            StereoOffCommand      stereoOff          = new StereoOffCommand(stereo);

            ICommand[] partyOn  = { livingRoomLightOn, ceilingFanOn, stereoOnWithCd };
            ICommand[] partyOff = { livingRoomLightOff, ceilingFanOff, stereoOff };

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

            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.UndoButtonWasPushed();
            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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();
        }
        static void Main(string[] args)
        {
            var remoteControl = new RemoteControl();

            //var livingRoomLight = new Light("Living room");
            //var kitchenLight = new Light("Kithen");
            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 ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan);
            var ceilingFanHighCommand   = new CeilingFanHighCommand(ceilingFan);
            var ceilingFanOffCommand    = new CeilingFanOffCommand(ceilingFan);

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

            // we are going to fill all these commands into remote control
            //remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            //remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanMediumCommand, ceilingFanOffCommand);
            remoteControl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand);
            //remoteControl.SetCommand(3, garageDoorUp, garageDoorDown);

            // print our remote control
            //System.Console.WriteLine(remoteControl);

            // pushing the buttons!!!
            remoteControl.OnButtonPressed(2);
            remoteControl.OffButtonPressed(2);
            System.Console.WriteLine(remoteControl);
            remoteControl.UndoButtonPressed();
            remoteControl.OnButtonPressed(3);
            System.Console.WriteLine(remoteControl);
            remoteControl.UndoButtonPressed();

            System.Console.ReadKey();
        }
Esempio n. 10
0
        static void RemoteControlTest()
        {
            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();
            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);

            CeilingFanHighCommand ceilingFanOn  = new CeilingFanHighCommand(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);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCd, stereoOff);
            remoteControl.SetCommand(4, garageDoorUp, garageDoorDown);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            remoteControl.OnButtonWasPushed(2);
            remoteControl.UndoButtonWasPushed();
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OffButtonWasPushed(2);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            remoteControl.OnButtonWasPushed(4);
            remoteControl.OffButtonWasPushed(4);
        }
Esempio n. 11
0
        public static void UndoTest()
        {
            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 CeilingFanHighCommand(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(1, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(2, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(3, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(4, stereoOnWithCD, stereoOff);

            Console.WriteLine(remoteControl);

            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OnButtonWasPushed(2);
            remoteControl.OffButtonWasPushed(2);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
            remoteControl.OnButtonWasPushed(4);
            remoteControl.OffButtonWasPushed(4);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            int numberOfSlots = 7;

            // create command invoker:
            RemoteControl remoteControl = new RemoteControl(numberOfSlots);

            // create command receivers:
            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("LivingRoom");

            // create living room light commands:
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            // feed invoker with living room light commands:
            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);

            // create living room ceiling fan commands:
            CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan);
            CeilingFanOffCommand  ceilingFanOff  = new CeilingFanOffCommand(ceilingFan);

            // feed invoker with living room ceiling fan commands:
            remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff);

            // feed invoker with kitchen light commands (using lambdas):
            remoteControl.SetCommand(2, new Command(() => kitchenLight.On(), () => kitchenLight.Off()),
                                     new Command(() => kitchenLight.Off(), () => kitchenLight.On()));

            // show command settings:
            WriteLine(remoteControl);

            // simulate user behaviour:
            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            remoteControl.UndoButtonWasPushed();

            remoteControl.OnButtonWasPushed(2);
            remoteControl.UndoButtonWasPushed();

            // keep console open:
            ReadLine();
        } // Main
        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());
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            RemoteControl   Remote   = new RemoteControl();
            Light           Light    = new Light();
            LightOnCommand  LightOn  = new LightOnCommand(Light);
            LightOffCommand LightOff = new LightOffCommand(Light);

            CeilingFan              Fan       = new CeilingFan("Living room");
            CeilingFanHighCommand   FanHigh   = new CeilingFanHighCommand(Fan);
            CeilingFanLowCommand    FanLow    = new CeilingFanLowCommand(Fan);
            CeilingFanMediumCommand FanMedium = new CeilingFanMediumCommand(Fan);
            CeilingFanOffCommand    FanOff    = new CeilingFanOffCommand(Fan);

            GarageDoor             GarageDoor      = new GarageDoor();
            GarageCloseDoorCommand GarageCloseDoor = new GarageCloseDoorCommand(GarageDoor);
            GarageOpenDoorCommand  GarageOpenDoor  = new GarageOpenDoorCommand(GarageDoor);

            ICommand[]   OnCommands      = { LightOn, FanHigh, GarageOpenDoor };
            ICommand[]   OffCommands     = { LightOff, FanOff, GarageCloseDoor };
            MacroCommand MacroOnCommand  = new MacroCommand(OnCommands);
            MacroCommand MacroOffCommand = new MacroCommand(OffCommands);

            Remote.SetCommand(0, LightOn, LightOff);
            Remote.SetCommand(1, FanMedium, FanOff);
            Remote.SetCommand(2, FanHigh, FanOff);
            Remote.SetCommand(3, MacroOnCommand, MacroOnCommand);

            Console.WriteLine(Remote.ToString());

            Remote.OnButtonPressed(3);
            Remote.UndoButtonWasPressed();
            //Remote.OnButtonPressed(0);
            //Remote.UndoButtonWasPressed();
            //Remote.OnButtonPressed(1);
            //Remote.OffButtonPressed(1);
            //Console.WriteLine(Remote.ToString());
            //Remote.UndoButtonWasPressed();
            //Remote.OnButtonPressed(2);
            //Console.WriteLine(Remote.ToString());
            //Remote.UndoButtonWasPressed();
        }
Esempio n. 15
0
        static void RemoteControlTestCeilingFan()
        {
            RemoteControl remoteControl = new RemoteControl();

            CeilingFan ceilingFan = new CeilingFan("Living Room");
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanHighCommand   ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            CeilingFanOffCommand    ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();

            remoteControl.OnButtonWasPushed(1);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();
        }
        public void MacroCommandTestMethod()
        {
            Light           livingRoomLight    = new Light("Living Room");
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            CeilingFan            livingRoomCeilingFan  = new CeilingFan("Living Room");
            CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(livingRoomCeilingFan);
            CeilingFanOffCommand  ceilingFanOffCommand  = new CeilingFanOffCommand(livingRoomCeilingFan);

            ICommand[] study     = { livingRoomLightOn, ceilingFanHighCommand };
            ICommand[] stopStudy = { livingRoomLightOn, ceilingFanHighCommand };

            MacroCommand studyMacro     = new MacroCommand(study);
            MacroCommand stopStudyMacro = new MacroCommand(stopStudy);

            RemoteControl remoteControl = new RemoteControl(totalSlots: 1);

            remoteControl.SetCommand(0, studyMacro, stopStudyMacro);

            remoteControl.OnButtonWasPushed(0);
        }
        public void SimpleCommandPatternTestMethod()
        {
            RemoteControl remoteControl = new RemoteControl(totalSlots: 7);

            Light           livingRoomLight    = new Light("Living Room");
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            CeilingFan            livingRoomCeilingFan  = new CeilingFan("Living Room");
            CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(livingRoomCeilingFan);
            CeilingFanOffCommand  ceilingFanOffCommand  = new CeilingFanOffCommand(livingRoomCeilingFan);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand);

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

            remoteControl.UndoButtonWasPressed();
        }
        public void RemoteControl_Undo()
        {
            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);

            control.ClickButtonOn(0);
            control.ClickButtonOn(1);
            control.ClickButtonOff(2);
            control.UndoButtonClick();
        }
Esempio n. 19
0
        public static void CeilingFanTest()
        {
            var remoteControl    = new RemoteControl();
            var ceilingFan       = new CeilingFan("Living Room");
            var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            var ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            var ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            remoteControl.SetCommand(1, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff);

            remoteControl.OnButtonWasPushed(1);
            remoteControl.OffButtonWasPushed(1);
            Console.WriteLine(remoteControl);

            remoteControl.UndoButtonWasPushed();
            remoteControl.OnButtonWasPushed(2);

            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPushed();

            Console.ReadKey();
        }
        public void RemoteControl_Macro()
        {
            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);

            List <ICommand> onCommands = new List <ICommand>()
            {
                new GarageDoorOpenCommand(door),
                new LightOnCommand(light),
                new CeilingFanHighCommand(fan)
            };

            List <ICommand> offCommands = new List <ICommand>()
            {
                new GarageDoorCloseCommand(door),
                new LightOffCommand(light),
                new CeilingFanOffCommand(fan)
            };

            MacroCommand onMacro  = new MacroCommand(onCommands);
            MacroCommand offMacro = new MacroCommand(offCommands);

            control.SetCommand(0, onMacro, offMacro);
            control.ClickButtonOn(0);
            control.ClickButtonOff(0);
            control.UndoButtonClick();
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            SimpleRemoteControl control = new SimpleRemoteControl();

            // Объекты
            Garage     garage     = new Garage();
            Stereo     stereo     = new Stereo();
            CeilingFan ceilingFan = new CeilingFan("BedRoom");

            // Команды над объектами
            GarageDoorOpenCommand  garageDoorOpen  = new GarageDoorOpenCommand(garage);
            GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garage);

            CeilingFanHighCommand   ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanOffCommand    ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

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

            // Запоминаем кнопки на пульте
            control.SetCommands(0, garageDoorOpen, garageDoorClose);
            control.SetCommands(1, stereoOnWithCD, stereoOff);
            control.SetCommands(2, ceilingFanMedium, ceilingFanOff);
            control.SetCommands(3, ceilingFanHigh, ceilingFanOff);

            control.OnButtonWasPressed(0);
            Thread.Sleep(1000);
            control.OnButtonWasPressed(1);
            Console.WriteLine("Играет музыка");
            Thread.Sleep(2500);
            control.undoButtonWasPushed();
            Thread.Sleep(1000);
            control.OffButtonWasPressed(0);
            Thread.Sleep(1000);
            control.OnButtonWasPressed(2);
            Thread.Sleep(1000);
            control.OffButtonWasPressed(2);
            Thread.Sleep(1000);
            control.undoButtonWasPushed();
            Thread.Sleep(1000);
            control.OnButtonWasPressed(3);
            Thread.Sleep(1000);
            control.OffButtonWasPressed(3);
            Thread.Sleep(1000);

            Console.WriteLine("---Часть 3---");
            Light           light    = new Light();
            LightOnCommand  lightOn  = new LightOnCommand(light);
            LightOffCommand lightOff = new LightOffCommand(light);

            ICommand[] _partyOn  = { garageDoorOpen, lightOn, stereoOnWithCD };
            ICommand[] _partyOff = { garageDoorClose, lightOff, stereoOff };

            MacroCommand macroCommandOn  = new MacroCommand(_partyOn);
            MacroCommand macroCommandOff = new MacroCommand(_partyOff);

            control.SetCommands(4, macroCommandOn, macroCommandOff);
            control.OnButtonWasPressed(4);
            Console.WriteLine("Вырубание");
            control.OffButtonWasPressed(4);
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            int numSlots = 5;
            BetterRemoteControl remote = new BetterRemoteControl(numSlots);

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

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

            CeilingFanHighCommand   ceilingFanOnHigh   = new CeilingFanHighCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanOnMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanLowCommand    ceilingFanOnLow    = new CeilingFanLowCommand(ceilingFan);
            CeilingFanOffCommand    ceilingFanOff      = new CeilingFanOffCommand(ceilingFan);

            GarageDoorOpenCommand  garageOpen  = new GarageDoorOpenCommand(garageDoor);
            GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor);

            StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo);
            StereoOffCommand      stereoOff      = new StereoOffCommand(stereo);

            Command[]    partyOn      = { livingRoomLightOn, ceilingFanOnHigh, stereoOnWithCd };
            Command[]    partyOff     = { livingRoomLightOff, ceilingFanOff, stereoOff };
            MacroCommand partyOnMacro = new MacroCommand(partyOn);
            MacroCommand partOffMacro = new MacroCommand(partyOff);

            Command[]    testPartyFanOn       = { ceilingFanOnHigh, ceilingFanOnMedium, ceilingFanOnLow };
            Command[]    testPartyFanOff      = { ceilingFanOff };
            MacroCommand testPartyFanOnMacro  = new MacroCommand(testPartyFanOn);
            MacroCommand testPartyFanOffMacro = new MacroCommand(testPartyFanOff);

            //remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            //remote.SetCommand(1, kitchenLightOn, kitchenLightOff);
            //remote.SetCommand(2, ceilingFanOnHigh, ceilingFanOff);
            //remote.SetCommand(3, garageOpen, garageClose);
            //remote.SetCommand(4, stereoOnWithCd, stereoOff);
            remote.SetCommand(0, ceilingFanOnHigh, ceilingFanOff);
            remote.SetCommand(1, ceilingFanOnMedium, ceilingFanOff);
            remote.SetCommand(2, ceilingFanOnLow, ceilingFanOff);
            remote.SetCommand(3, partyOnMacro, partOffMacro);
            remote.SetCommand(4, testPartyFanOnMacro, testPartyFanOffMacro);

            Console.WriteLine(remote);

            Console.WriteLine("\n Changing fan settings several times");
            remote.OnButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OnButtonWasPushed(2);
            Console.WriteLine("\n Undoing fan settings several times");
            remote.UndoButtonWasPushed();
            remote.UndoButtonWasPushed();
            remote.UndoButtonWasPushed();
            remote.UndoButtonWasPushed();
            remote.UndoButtonWasPushed();

            Console.WriteLine("\nTurning on macro");
            remote.OnButtonWasPushed(3);
            //Console.WriteLine("\nTurning off macro");
            //remote.OffButtonWasPushed(3);
            Console.WriteLine("\nUndoing previous macro button push");
            //Though this eventually calls 3 Undo()'s (one for each of the 3 classes in the MacroCommand's Command[]), the stack in
            //remote control class actually only has 1 object in it, the MacroCommand object
            remote.UndoButtonWasPushed();
            //This won't get called because stack size is not > 0
            remote.UndoButtonWasPushed();

            Console.WriteLine("\nTesting out how fan's handle the macro class");
            remote.OnButtonWasPushed(4);
            Console.WriteLine("\nUndoing the fan macro class");
            remote.UndoButtonWasPushed();

            //remote.OnButtonWasPushed(1);
            //remote.UndoButtonWasPushed();
            //remote.OnButtonWasPushed(1);
            //remote.OffButtonWasPushed(1);
            //remote.OnButtonWasPushed(2);
            //remote.OffButtonWasPushed(2);
            //remote.OnButtonWasPushed(3);
            //remote.OffButtonWasPushed(3);
            //remote.OnButtonWasPushed(4);
            //remote.OffButtonWasPushed(4);

            Console.ReadLine();
        }
Esempio n. 23
0
        public static void Run()
        {
            // Invoker
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

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

            CeilingFanLowCommand    ceilingFanLow    = new CeilingFanLowCommand(ceilingFan);
            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanHighCommand   ceilingFanHigh   = new CeilingFanHighCommand(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, ceilingFanLow, ceilingFanOff);
            remoteControl.SetCommand(3, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(4, ceilingFanHigh, ceilingFanOff);
            remoteControl.SetCommand(5, garageDoorUp, garageDoorDown);
            remoteControl.SetCommand(6, stereoOnWithCD, stereoOff);

            // Invoke Commands
            Console.WriteLine("==================================================");
            Console.WriteLine("============= Testing Remote Loader  =============");
            Console.WriteLine("==================================================");
            Console.WriteLine();
            Console.WriteLine(remoteControl);
            Console.WriteLine();
            for (int i = 0; i < remoteControl.numberOfSlots; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                remoteControl.OffButtonWasPushed(i);

                if (!(remoteControl.onCommands[i] is NoCommand))
                {
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
            Console.WriteLine("----- Undo -----");
            remoteControl.UndoButtonWasPushed();
        }