static void Main(string[] args)
        {
            Application application = new Application();
            ICommand    openCommand = new OpenCommand(application);
            ICommand    pasteCommand;

            openCommand.Execute();
            pasteCommand = new PasteCommand(application.GetActiveDocument());
            pasteCommand.Execute();

            // will remember the sequence, could also reverse
            MacroCommand macroCommand = new MacroCommand();

            // open three documents and send them, later in macroCommand.Execute();
            for (int i = 0; i < 3; i++)
            {
                macroCommand.Add(new OpenCommand(application));
                macroCommand.Add(new SendCommand(application));
            }

            Console.WriteLine("\r\nCalling macroCommand.Execute()");
            macroCommand.Execute();

            Console.WriteLine("\r\n*****Done*****");

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            RemoteControl RemoteControl = new RemoteControl();

            Light          light   = new Light("Living Room");
            LightOnCommand lightOn = new LightOnCommand(light);
            LightOfCommand lightOf = new LightOfCommand(light);

            CeilingFan ceiling = new CeilingFan("Living Room");

            CeilingFanLowcommand  fanLowcommand = new CeilingFanLowcommand(ceiling);
            CeilingFanHighCommand chigh         = new CeilingFanHighCommand(ceiling);

            CeilingFanOfcommand fanOfcommand = new CeilingFanOfcommand(ceiling);

            GarrageDoor            gd     = new GarrageDoor("Garrage");
            GarageDoorOpenCommand  gopen  = new GarageDoorOpenCommand(gd);
            GarageDoorCloseCommand gclose = new GarageDoorCloseCommand(gd);



            ICommand[] partyOn  = { lightOn, gopen, chigh };
            ICommand[] partyOff = { lightOf, gclose, fanLowcommand };

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

            RemoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(RemoteControl);
            Console.WriteLine("-----Pushing Macro On----");
            RemoteControl.OnButtonWasPressed(0);
            Console.WriteLine("--------- Pushing Macro Of------");
            RemoteControl.OffButtonWasPressed(0);
        }
示例#3
0
        //A recursive function for handling the creation of the macro commands

        public static Command CreateMacro(MacroCommand macroCommand, StreamReader sr)
        {
            var line = sr.ReadLine();

            //base case, macro section is complete
            if (line.ElementAt(0) == 'E')
            {
                return(macroCommand);
            }

            //nested macro case
            else if (line.ElementAt(0) == 'B')
            {
                macroCommand.commands.Add(CreateMacro(new MacroCommand(), sr));
            }

            //add line to macro and run function again
            else
            {
                ArgStruct args = Parser.ParseLine(line);
                macroCommand.commands.Add(Factory.MakeCommand(args));
                CreateMacro(macroCommand, sr);
            }

            return(macroCommand);
        }
示例#4
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);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("1 ON | 1 OFF Remote example");
            RemoteControl remoteControl = new RemoteControl(1);

            // Creating objects to control
            Light garageLight = new Light("Garage Light");

            // Creating commands for objects to control
            LightOnCommand  garageLightOnCommand  = new LightOnCommand(garageLight);
            LightOffCommand garageLightOffCommand = new LightOffCommand(garageLight);

            // Loading commands into the remoteControl
            remoteControl.SetCommand(0, garageLightOnCommand, garageLightOffCommand);

            // Simulating button clicks
            remoteControl.OnPushed(0);
            remoteControl.OffPushed(0);
            Console.WriteLine("Undo test:");
            remoteControl.UndoPushed();

            /*
             * MACRO COMMAND EXAMPLE
             */
            Console.WriteLine("1 ON | 1 OFF Remote macro example");

            // Creating objects to control
            ICommand[] onCommandCollection  = new ICommand[5];
            ICommand[] offCommandCollection = new ICommand[5];
            for (int i = 0; i < 5; i++)
            {
                Light light = new Light("Light #" + (i + 1));
                onCommandCollection[i] = new LightOnCommand(light);
            }
            for (int i = 0; i < 5; i++)
            {
                Light light = new Light("Light #" + (i + 1));
                offCommandCollection[i] = new LightOffCommand(light);
            }

            // Inserting command collection into a Macro Command
            MacroCommand lightsOnMacro  = new MacroCommand(onCommandCollection);
            MacroCommand lightsOffMacro = new MacroCommand(offCommandCollection);

            // Loading macro commands into the remoteControl
            remoteControl.SetCommand(0, lightsOnMacro, lightsOffMacro);

            // Simulating button clicks
            remoteControl.OffPushed(0);
            remoteControl.OnPushed(0);
            Console.WriteLine("Undo macro test:");
            remoteControl.UndoPushed();
        }
示例#6
0
        private static void CommandsExamples()
        {
            // creating receivers
            var livingRoomLight      = new Light("Living Room");
            var kitchenLight         = new Light("Kitchen");
            var livingRoomCeilingFan = new CeilingFan("Living Room");
            var stereo = new Stereo("");

            // creating commands
            var livingRoomLightOnCommand  = new LightOnCommand(livingRoomLight);
            var livingRoomLightOffCommand = new LightOffCommand(livingRoomLight);
            var kitchenLightOnCommand     = new LightOnCommand(kitchenLight);
            var kitchenLightOffCommand    = new LightOffCommand(kitchenLight);
            var stereoOnCommand           = new StereoOnCommand(stereo);
            var stereoOffCommand          = new StereoOffCommand(stereo);

            // Macro Command
            var myCommand = new MacroCommand(new ICommand[]
            {
                kitchenLightOnCommand,
                stereoOnCommand,
                livingRoomLightOffCommand
            });

            // create remove control & assign commands
            var remoteControl = new RemoteControl();

            remoteControl.SetCommand(0, livingRoomLightOnCommand);
            remoteControl.SetCommand(1, livingRoomLightOffCommand);
            remoteControl.SetCommand(2, kitchenLightOnCommand);
            remoteControl.SetCommand(3, kitchenLightOffCommand);
            remoteControl.SetCommand(4, stereoOnCommand);
            remoteControl.SetCommand(5, stereoOffCommand);

            // run commands
            //for (int i = 0; i < 6; i++)
            //    remoteControl.Run(i);

            //remoteControl.Run(0);
            //remoteControl.Run(0);
            //remoteControl.Run(0);
            //remoteControl.Undo();
            //remoteControl.Undo();
            //remoteControl.Undo();
            //remoteControl.Undo();
            myCommand.Execute();
            Console.WriteLine("------------------");
            myCommand.Undo();

            //Console.WriteLine(remoteControl);
        }
示例#7
0
        public MainWindow()
        {
            InitializeComponent();
            remoteContorl = new InvokerRemoteControl();
            CommandFactoryMethod factoryMethod = new CommandFactoryMethod(this);

            Code.ICommand on, off;

            factoryMethod.GetCommand(CommandsType.MacroCommand, out on, out off);
            MacroCommand partyOn  = (MacroCommand)on;
            MacroCommand partyOff = (MacroCommand)off;

            remoteContorl.SettCommand(8, partyOn, partyOff);

            factoryMethod.GetCommand(CommandsType.MacroCommand, out on, out off);
            MacroCommand allLightsOn  = (MacroCommand)on;
            MacroCommand allLightsOff = (MacroCommand)off;

            partyOn.SetCommand(allLightsOn);
            partyOff.SetCommand(allLightsOff);
            remoteContorl.SettCommand(7, on, off);

            factoryMethod.GetCommand(CommandsType.Light, out on, out off);
            remoteContorl.SettCommand(1, on, off);
            allLightsOn.SetCommand(on);
            allLightsOff.SetCommand(off);

            factoryMethod.GetCommand(CommandsType.Light, out on, out off);
            remoteContorl.SettCommand(2, on, off);
            allLightsOn.SetCommand(on);
            allLightsOff.SetCommand(off);

            factoryMethod.GetCommand(CommandsType.Garage, out on, out off);
            remoteContorl.SettCommand(4, on, off);
            partyOn.SetCommand(on);
            partyOff.SetCommand(off);

            factoryMethod.GetCommand(CommandsType.Stereo, out on, out off);
            remoteContorl.SettCommand(6, on, off);
            partyOn.SetCommand(on);
            partyOff.SetCommand(off);
        }
示例#8
0
        static void Main(string[] args)
        {
            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //Light light = new Light();
            //GarageDoor garageDoor = new GarageDoor();

            //LightOnCommand lightOn = new LightOnCommand(light);
            //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

            //remote.setCommand(lightOn);
            //remote.buttonWasPressed();

            //remote.setCommand(garageOpen);
            //remote.buttonWasPressed();
            RemoteControl remoteControl = new RemoteControl();

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

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

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

            StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo);

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

            remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.setCommand(2, garageOpen, garageClose);
            remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD);

            remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff);
            remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff);
            remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff);

            Console.WriteLine(remoteControl.toString());

            remoteControl.onButtonWasPushed(0);
            remoteControl.offButtonWasPushed(0);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(1);
            remoteControl.offButtonWasPushed(1);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(2);
            remoteControl.offButtonWasPushed(2);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(3);
            remoteControl.offButtonWasPushed(3);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(5);
            remoteControl.offButtonWasPushed(5);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(4);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            #region marco command
            Command[] partyOn = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD };
            Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD };

            MacroCommand partyOnCommand = new MacroCommand(partyOn);
            MacroCommand partyOffCommand = new MacroCommand(partyOff);

            remoteControl.setCommand(6, partyOnCommand, partyOffCommand);

            remoteControl.onButtonWasPushed(6);
            remoteControl.offButtonWasPushed(6);
            remoteControl.undoButtonWasPushed();
            #endregion
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // Setup

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

            // Command initialization

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

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

            var garageDoorUp   = new GarageDoorOpenCommand(garageDoor);
            var garageDoorDown = new GarageDoorDownCommand(garageDoor);

            var stereoWithCd = new StereoWithCdCommand(stereo);
            var stereoOff    = new StereoOffCommand(stereo);

            // Remote setup

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(3, ceilingFanHigh, ceilingFanOff);
            remoteControl.SetCommand(4, stereoWithCd, stereoOff);

            // Remote with undo

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

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

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

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

            // Macro commands
            ICommand[] partyOn  = { kitchenLightOn, livingRoomLightOn, stereoWithCd, ceilingFanMedium };
            ICommand[] partyOff = { kitchenLightOff, livingRoomLightOff, stereoOff, ceilingFanOff };

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

            remoteControl.SetCommand(5, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);
            Console.WriteLine("--- Pushing Macro On---");
            remoteControl.OnButtonWasPushed(5);
            Console.WriteLine("--- Pushing Macro Off---");
            remoteControl.OffButtonWasPushed(5);
            Console.WriteLine("--- Pushing Macro Undo---");
            remoteControl.UndoButtonWasPushed();

            // Ceiling fan multiple undo
            remoteControl.OnButtonWasPushed(2);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            remoteControl.UndoButtonWasPushed();
            remoteControl.UndoButtonWasPushed();

            // Setting remote using lambdas instead of small classes
        }
示例#10
0
        static void Main(string[] args)
        {
            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //Light light = new Light();
            //GarageDoor garageDoor = new GarageDoor();

            //LightOnCommand lightOn = new LightOnCommand(light);
            //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

            //remote.setCommand(lightOn);
            //remote.buttonWasPressed();

            //remote.setCommand(garageOpen);
            //remote.buttonWasPressed();
            RemoteControl remoteControl = new RemoteControl();


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

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

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

            StereoOnWithCDCommand  stereoOnWithCD  = new StereoOnWithCDCommand(stereo);
            StereoOffWithCDCommand stereoOffWithCD = new StereoOffWithCDCommand(stereo);

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

            remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.setCommand(2, garageOpen, garageClose);
            remoteControl.setCommand(3, stereoOnWithCD, stereoOffWithCD);

            remoteControl.setCommand(4, ceilingFanHigh, ceilingFanOff);
            remoteControl.setCommand(5, ceilingFanMedium, ceilingFanOff);
            remoteControl.setCommand(6, ceilingFanLow, ceilingFanOff);

            Console.WriteLine(remoteControl.toString());

            remoteControl.onButtonWasPushed(0);
            remoteControl.offButtonWasPushed(0);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(1);
            remoteControl.offButtonWasPushed(1);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(2);
            remoteControl.offButtonWasPushed(2);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(3);
            remoteControl.offButtonWasPushed(3);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(5);
            remoteControl.offButtonWasPushed(5);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();

            remoteControl.onButtonWasPushed(4);
            Console.WriteLine(remoteControl);
            remoteControl.undoButtonWasPushed();


            #region marco command
            Command[] partyOn  = { kitchenLightOn, livingRoomLightOn, garageOpen, stereoOnWithCD };
            Command[] partyOff = { kitchenLightOff, livingRoomLightOff, garageClose, stereoOffWithCD };

            MacroCommand partyOnCommand  = new MacroCommand(partyOn);
            MacroCommand partyOffCommand = new MacroCommand(partyOff);

            remoteControl.setCommand(6, partyOnCommand, partyOffCommand);

            remoteControl.onButtonWasPushed(6);
            remoteControl.offButtonWasPushed(6);
            remoteControl.undoButtonWasPushed();
            #endregion
            Console.ReadLine();
        }
示例#11
0
        static void Main(string[] args)
        {
            Light light = new Light("Any");
            Light kitchenLight = new Light("Kitchen");
            Light livingRoomLight = new Light("Living room");
            Light bedroomLight = new Light("Bedroom");

            Command lightONBtn = new LightONCommand(light);
            Command lightOffBtn = new LightOFFCommand(light);

            Command kitchenLightON = new LightONCommand(kitchenLight);
            Command kitchenLightOFF = new LightOFFCommand(kitchenLight);

            Command livingRoomON = new LightONCommand(livingRoomLight);
            Command livingRoomOFF = new LightOFFCommand(livingRoomLight);

            SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl();

            simpRemoteCntrl.SetCommand(0,lightONBtn,lightOffBtn);
            simpRemoteCntrl.SetCommand(1, kitchenLightON, kitchenLightOFF);
            simpRemoteCntrl.SetCommand(2, livingRoomON, livingRoomOFF);

            simpRemoteCntrl.OnButtonPushed(0);
            simpRemoteCntrl.OffButtonPushed(0);

            simpRemoteCntrl.OnButtonPushed(1);
            simpRemoteCntrl.OffButtonPushed(1);

            simpRemoteCntrl.OnButtonPushed(2);
            simpRemoteCntrl.OffButtonPushed(2);

            CeilingFan ceilingFanLivingRoom = new CeilingFan("Living Room");
            Command ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFanLivingRoom);
            Command ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFanLivingRoom);
            simpRemoteCntrl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand);

            simpRemoteCntrl.OnButtonPushed(3);

            Console.WriteLine("\n Start of macro \n");

            Command[] partyCommandsOn = new Command[] { lightONBtn,kitchenLightON,livingRoomON};
            Command[] partyCommandsOff = new Command[] {lightOffBtn,kitchenLightOFF,livingRoomOFF };

            MacroCommand macroCommandON = new MacroCommand(partyCommandsOn);
            MacroCommand macroCommandOff = new MacroCommand(partyCommandsOff);

            simpRemoteCntrl.SetCommand(0, macroCommandON, macroCommandOff);

            simpRemoteCntrl.OnButtonPushed();
            simpRemoteCntrl.OffButtonPushed();

            Console.WriteLine(simpRemoteCntrl.ToString());
        }
示例#12
0
 public void SetCommand(int slot, MacroCommand onCommands, MacroCommand offCommands)
 {
     this.onCommandsMacro = onCommands;
     this.offCommandsMacro = offCommands;
 }
示例#13
0
        static void Main(string[] args)
        {
            #region Simple remote control test
            //Light light = new Light();
            //Command lightOn = new LightOnCommand(light);

            //SimpleRemoteControl remote = new SimpleRemoteControl();
            //remote.SetCommand(lightOn);
            //remote.ButtonPressed();

            //GarageDoor door = new GarageDoor();
            //GaraDoorOpenCommand garageOpen = new GaraDoorOpenCommand(door);
            //remote.SetCommand(garageOpen);
            //remote.ButtonPressed();
            #endregion

            #region remote control
            //Light kitchenLight = new Light("kichen");
            //Light bedroomLight = new Light("bedroom");
            //Stereo parlorStereo = new Stereo("parlor");
            //Stereo washRommStereo = new Stereo("washroom");
            //GarageDoor garageDoor = new GarageDoor(string.Empty);

            //LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight);
            //LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);
            //StereoOnWithCDCommand parlorStereoOn = new StereoOnWithCDCommand(parlorStereo);
            //StereoOffCommand parloStereoOff = new StereoOffCommand(parlorStereo);
            //GaraDoorOpenCommand garageDoorOpen = new GaraDoorOpenCommand(garageDoor);
            //GaraDoorCloseCommand garageDoorClose = new GaraDoorCloseCommand(garageDoor);

            //RemoteControl remoteControl = new RemoteControl();
            //remoteControl.SetCommand(0, kitchenLightOn, kitchenLightOff);
            //remoteControl.SetCommand(1, parlorStereoOn, parloStereoOff);
            //remoteControl.SetCommand(2, garageDoorOpen, garageDoorClose);

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

            //remoteControl.OnButtonWasPushed(3);
            //remoteControl.OffButtonWasPushed(4);

            #endregion

            #region remote control with undo
            //Light livintRoomLight = new Light("livingroom");
            //LightOnCommand livingRoomOn = new LightOnCommand(livintRoomLight);
            //LightOffCommand livingRommOff = new LightOffCommand(livintRoomLight);
            //RemoteControlWithUndo remoteUndo = new RemoteControlWithUndo();
            //remoteUndo.SetCommand(0, livingRoomOn, livingRommOff);
            //remoteUndo.OnButtonWasPushed(0);
            //remoteUndo.OffButtonWasPushed(0);
            //Console.WriteLine(remoteUndo.ToString());
            //remoteUndo.UndoButtonWasPushed();
            //remoteUndo.OffButtonWasPushed(0);
            //remoteUndo.OnButtonWasPushed(0);
            //Console.WriteLine(remoteUndo.ToString());
            //remoteUndo.UndoButtonWasPushed();

            #endregion

            #region remote control with multiple undo states
            //RemoteControlWithUndo remote = new RemoteControlWithUndo();
            //CeilingFan fan = new CeilingFan("livingroom");
            //CeilingFanHighSpeedCommand ceilingFanHigh = new CeilingFanHighSpeedCommand(fan);
            //CeilingFanLowSpeedCommand ceilingFanLow = new CeilingFanLowSpeedCommand(fan);
            //CeilingFanOffSpeedCommand ceilingFanOff = new CeilingFanOffSpeedCommand(fan);
            //remote.SetCommand(0, ceilingFanHigh, ceilingFanOff);
            //remote.SetCommand(1, ceilingFanLow, ceilingFanOff);

            //remote.OnButtonWasPushed(0);
            //remote.OffButtonWasPushed(0);
            //Console.WriteLine(remote.ToString());
            //remote.UndoButtonWasPushed();

            //remote.OnButtonWasPushed(1);
            //Console.WriteLine(remote.ToString());
            //remote.UndoButtonWasPushed();
            #endregion

            #region remote control with macro commands
            RemoteControlWithUndo remote                     = new RemoteControlWithUndo();
            Light                        light               = new Light("livingroom");
            Stereo                       stero               = new Stereo("livingroom");
            CeilingFan                   fan                 = new CeilingFan("livingroom");
            LightOnCommand               livingLightOn       = new LightOnCommand(light);
            StereoOnWithCDCommand        livingStereoOn      = new StereoOnWithCDCommand(stero);
            CeilingFanMediumSpeedCommand livingCeilingMedium = new CeilingFanMediumSpeedCommand(fan);
            LightOffCommand              livingLightOff      = new LightOffCommand(light);
            StereoOffCommand             livingStereoOff     = new StereoOffCommand(stero);
            CeilingFanOffSpeedCommand    livingCeilingOff    = new CeilingFanOffSpeedCommand(fan);

            Command[]    macroOnCmd  = { livingLightOn, livingStereoOn, livingCeilingMedium };
            Command[]    macroOffCmd = { livingLightOff, livingStereoOff, livingCeilingOff };
            MacroCommand macroOn     = new MacroCommand(macroOnCmd);
            MacroCommand macroOff    = new MacroCommand(macroOffCmd);

            remote.SetCommand(0, macroOn, macroOff);

            Console.WriteLine(remote.ToString());
            remote.OnButtonWasPushed(0);
            Console.WriteLine("------push macro on-----");
            remote.OffButtonWasPushed(0);
            Console.WriteLine("------push macro off----");


            #endregion

            Console.Read();
        }
示例#14
0
        static void Main(string[] args)
        {
            /*var remote = new SimpleRemoteControl();
             *
             * var light = new Light();
             * var garageDoor = new GarageDoor();
             *
             * var lightOnCommand = new LigthOnCommand(light);
             * var garageOpenCommand = new GarageDoorOpenCommand(garageDoor);
             *
             * remote.SetCommand(lightOnCommand);
             * remote.ButtonWasPressed();
             * remote.SetCommand(garageOpenCommand);
             * remote.ButtonWasPressed();*/

            var remoteControl = new RemoteControl();

            var livigRoomLight = 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(livigRoomLight);
            var livingRoomLightOff = new LightOffCommand(livigRoomLight);

            var kitchenRoomLightOn  = new LightOnCommand(kitchenLight);
            var kitchenRoomLightOff = new LightOffCommand(kitchenLight);

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

            var garageDoorUp   = new GarageDoorOpenCommand(garageDoor);
            var garageDoorDown = new GarageDoorDownCommand(garageDoor);

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

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenRoomLightOn, kitchenRoomLightOff);
            remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);

            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("-----------------------------------------------------");

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

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

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

            Console.WriteLine("-----------------------------------------------------");

            Console.WriteLine(remoteControl);

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

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

            Console.WriteLine("-----------------------------------------------------");

            var tv     = new TV("Living room");
            var hottub = new Hottub();

            var stereoOn = new StereoOnCommand(stereo);
            var tvOn     = new TVOnCommand(tv);
            var hottubOn = new HottubOnCommand(hottub);

            var tvOff     = new TVOffCommand(tv);
            var hottubOff = new HottubOffCommand(hottub);

            ICommand[] partyOn  = { livingRoomLightOn, stereoOn, tvOn, hottubOn };
            ICommand[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff };

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

            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);
            Console.WriteLine("---Pushing Macro On---");
            remoteControl.OnButtonWasPushed(0);
            Console.WriteLine("---Pushing Macro Off---");
            remoteControl.OffButtonWasPushed(0);

            remoteControl.UndoButtonWasPushed();
        }
示例#15
0
        static void Main(string[] args)
        {
            ////////SimpleRemoteControl remote = new SimpleRemoteControl();
            ////////ligth ligth = new ligth();
            ////////GarageDoor garageDoor = new GarageDoor();
            ////////LightOnCommand ligthon = new LightOnCommand(ligth);
            ////////GarageDoorOpenCommand garageOpen= new GarageDoorOpenCommand(garageDoor);
            ////////remote.setCommand(ligthon);
            ////////remote.buttonWasPressed();

            ////////remote.setCommand(garageOpen);
            ////////remote.buttonWasPressed();

            //////RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();
            //////ligth livingRoomLigth = new ligth("Living Room");
            //////ligth kitchenLight = new ligth("kitchen");
            //////GarageDoor garageDoor = new GarageDoor();
            //////stereo stereo = new stereo("Living Room");

            //////LightOnCommand livingRoomLigthOn = new LightOnCommand(livingRoomLigth);
            //////LightOffCommand livingRoomLigthOff = new LightOffCommand(livingRoomLigth);
            //////LightOnCommand KitchenLigthOn = new LightOnCommand(kitchenLight);
            //////LightOffCommand KitchenLigthOff = new LightOffCommand(kitchenLight);

            //////GarageDoorOpenCommand garageDoorUp = new GarageDoorOpenCommand(garageDoor);
            //////GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

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

            //////remoteControl.setCommand(0, livingRoomLigthOn, livingRoomLigthOff);
            //////remoteControl.setCommand(1, KitchenLigthOn, KitchenLigthOff);
            //////remoteControl.setCommand(2, stereoOnWithCD, stereoOff);

            //////Console.WriteLine(remoteControl.toString());

            //////remoteControl.onButtonWasPushed(0);
            //////remoteControl.offButtonWasPushed(0);
            //////remoteControl.onButtonWasPushed(1);
            //////remoteControl.offButtonWasPushed(1);
            //////remoteControl.onButtonWasPushed(2);
            //////remoteControl.offButtonWasPushed(2);
            //////Console.ReadLine();

            ////RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();
            ////ligth livingRoomLigth = new ligth("Living Room");

            ////LightOnCommand livingRoomLigthOn = new LightOnCommand(livingRoomLigth);
            ////LightOffCommand livingRoomLigthOff = new LightOffCommand(livingRoomLigth);

            ////remoteControl.setCommand(0, livingRoomLigthOn, livingRoomLigthOff);
            ////remoteControl.onButtonWasPushed(0);
            ////remoteControl.offButtonWasPushed(0);
            ////Console.WriteLine(remoteControl.toString());
            ////remoteControl.undoButtonWasPushed();
            ////remoteControl.offButtonWasPushed(0);
            ////remoteControl.onButtonWasPushed(0);
            ////Console.WriteLine(remoteControl.toString());
            ////remoteControl.undoButtonWasPushed();
            ////Console.ReadLine();
            //RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            //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.toString());
            //remoteControl.undoButtonWasPushed();

            //remoteControl.onButtonWasPushed(1);
            //Console.WriteLine(remoteControl.toString());
            //remoteControl.undoButtonWasPushed();
            //Console.ReadLine();

            ligth light = new ligth("Living Room");
            stereo stereo = new stereo("Living Room");
            CeilingFan ceilingfan = new CeilingFan("living room");

            LightOnCommand ligthOn = new LightOnCommand(light);
            StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo);
            CeilingFanHighCommand CeilingfanOn = new CeilingFanHighCommand(ceilingfan);
            LightOffCommand ligthOff = new LightOffCommand(light);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            CeilingFanOffCommand CeilingfanOff = new CeilingFanOffCommand(ceilingfan);

            command[] partyOn ={ligthOn,stereoOn,CeilingfanOn};
            command[] partyOff = { ligthOff, stereoOff, CeilingfanOff };

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

            RemoteControlWithUndo remotecontrol = new RemoteControlWithUndo();

            remotecontrol.setCommand(0, partyOnMacro, PartyOffMacro);
            Console.WriteLine(remotecontrol.toString());
            Console.WriteLine("===Pushing Macro On ===");
            remotecontrol.onButtonWasPushed(0);
            Console.WriteLine("===Pushing Macro Off ===");
            remotecontrol.offButtonWasPushed(0);
            Console.WriteLine("===Pushing Macro undo ===");
            remotecontrol.undoButtonWasPushed();
            Console.ReadLine();
        }
示例#16
0
 public Form1()
 {
     history = new MacroCommand();
     canvas  = new DrawCanvas(400, 400, history);
     InitializeComponent();
 }
        static void Main(string[] args)
        {
            var simpleRemoteControl = new SimpleRemoteControl();
            var light          = new Light("Bedroom");
            var lightOnCommand = new LightOnCommand(light);

            simpleRemoteControl.SetCommand(lightOnCommand);
            simpleRemoteControl.ButtonWasPressed();

            var door = new GarageDoor("");
            var garageDoorOpenCommand = new GarageDoorOpenCommand(door);

            simpleRemoteControl.SetCommand(garageDoorOpenCommand);
            simpleRemoteControl.ButtonWasPressed();

            Console.WriteLine();

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

            var livingRoomLightOnCommand  = new LightOnCommand(livingRoomLight);
            var livingRoomLightOffCommand = new LightOffCommand(livingRoomLight);
            var kitchenLightOnCommand     = new LightOnCommand(kitchenLight);
            var kitchenLightOffCommand    = new LightOffCommand(kitchenLight);

            var ceilingFanOnCommand  = new CeilingFanOnCommand(ceilingFan);
            var ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);

            var garageDoorUpCommand   = new GarageDoorOpenCommand(garageDoor);
            var garageDoorDownCommand = new GarageDoorCloseCommand(garageDoor);

            var stereoOnWithCdCommand = new StereoOnWithCdCommand(stereo);
            var stereoOffCommand      = new StereoOffCommand(stereo);

            var remote = new RemoteControl();

            remote.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand);
            remote.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand);
            remote.SetCommand(2, ceilingFanOnCommand, ceilingFanOffCommand);
            remote.SetCommand(3, stereoOnWithCdCommand, stereoOffCommand);

            Console.WriteLine(remote.ToString());
            Console.WriteLine();
            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OffButtonWasPushed(1);
            remote.OnButtonWasPushed(2);
            remote.OffButtonWasPushed(2);
            remote.OnButtonWasPushed(3);
            remote.OffButtonWasPushed(3);

            Console.WriteLine();
            Console.WriteLine("------------ Remote with Undo ------------");

            var remoteWithUndo         = new RemoteControlWithUndo();
            var sunRoomLight           = new Light("Sun Room");
            var sunRoomLightOnCommand  = new LightOnCommand(sunRoomLight);
            var sunRoomLightOffCommand = new LightOffCommand(sunRoomLight);

            remoteWithUndo.SetCommand(0, sunRoomLightOnCommand, sunRoomLightOffCommand);

            remoteWithUndo.OnButtonWasPushed(0);
            remoteWithUndo.OffButtonWasPushed(0);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();
            remoteWithUndo.OffButtonWasPushed(0);
            remoteWithUndo.OnButtonWasPushed(0);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();

            Console.WriteLine();
            Console.WriteLine("------------ Ceiling Fan with Undo ------------");

            remoteWithUndo = new RemoteControlWithUndo();
            var ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan);
            var ceilingFanHighCommand   = new CeilingFanHighCommand(ceilingFan);

            ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan);
            remoteWithUndo.SetCommand(0, ceilingFanMediumCommand, ceilingFanOffCommand);
            remoteWithUndo.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand);

            remoteWithUndo.OnButtonWasPushed(0);
            remoteWithUndo.OffButtonWasPushed(0);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();

            remoteWithUndo.OnButtonWasPushed(1);
            Console.WriteLine(remoteWithUndo.ToString());
            remoteWithUndo.UndoButtonWasPushed();

            Console.WriteLine();
            Console.WriteLine("------------ Party Mode (Macro Commands) ------------");
            remoteWithUndo = new RemoteControlWithUndo();
            ICommand[] partyOn       = { livingRoomLightOnCommand, stereoOnWithCdCommand, ceilingFanMediumCommand };
            ICommand[] partyOff      = { livingRoomLightOffCommand, stereoOffCommand, ceilingFanOffCommand };
            var        partyOnMacro  = new MacroCommand(partyOn);
            var        partyOffMacro = new MacroCommand(partyOff);

            remoteWithUndo.SetCommand(0, partyOnMacro, partyOffMacro);
            remoteWithUndo.OnButtonWasPushed(0);
            Console.WriteLine();
            remoteWithUndo.OffButtonWasPushed(0);

            Console.ReadLine();
        }
示例#18
0
        static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl();

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

            LightOnCommand  livingRoomLightOnCommand  = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOffCommand = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenLightOnCommand     = new LightOnCommand(kitchenLight);
            LightOffCommand kitchenLightOffCommand    = new LightOffCommand(kitchenLight);

            CeilingFanOnCommand  livingRoomCeilingFanOnCommand  = new CeilingFanOnCommand(livingRoomCeilingFan);
            CeilingFanOffCommand livingRoomCeilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan);

            GarageDoorUpCommand   garageDoorUpCommand   = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDownCommand = new GarageDoorDownCommand(garageDoor);

            StereoWithCDCommand livingRoomStereoWithCDCommand = new StereoWithCDCommand(livingRoomStereo);
            StereoOffCommand    livingRoomStereoOffCommand    = new StereoOffCommand(livingRoomStereo);

            // MAIN
            //remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand);
            //remoteControl.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand);
            //remoteControl.SetCommand(2, livingRoomCeilingFanOnCommand, livingRoomCeilingFanOffCommand);
            //remoteControl.SetCommand(3, livingRoomStereoWithCDCommand, livingRoomStereoOffCommand);

            //Console.WriteLine(remoteControl.ToString());

            //Console.ReadLine();

            //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.ReadLine();

            // UNDO
            //remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand);
            //remoteControl.OnButtonWasPushed(0);
            //remoteControl.OffButtonWasPushed(0);
            //Console.WriteLine(remoteControl.ToString());
            //remoteControl.UndoButtonWasPushed();
            //remoteControl.OffButtonWasPushed(0);
            //remoteControl.OnButtonWasPushed(0);
            //Console.WriteLine(remoteControl.ToString());
            //remoteControl.UndoButtonWasPushed();

            //CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(livingRoomCeilingFan);
            //CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(livingRoomCeilingFan);
            //CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(livingRoomCeilingFan);

            //remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff);
            //remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff);
            //remoteControl.OnButtonWasPushed(0);
            //remoteControl.OffButtonWasPushed(0);
            //remoteControl.UndoButtonWasPushed();
            //remoteControl.OnButtonWasPushed(1);
            //remoteControl.UndoButtonWasPushed();
            //Console.ReadLine();

            // MACRO COMMAND
            ICommand[] partyOn  = new ICommand[] { livingRoomLightOnCommand, garageDoorUpCommand };
            ICommand[] partyOff = new ICommand[] { livingRoomLightOffCommand, garageDoorDownCommand };

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

            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);
            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            remoteControl.UndoButtonWasPushed();

            Console.ReadLine();
        }
示例#19
0
        static void Main(string[] args)
        {
            Light light           = new Light("Any");
            Light kitchenLight    = new Light("Kitchen");
            Light livingRoomLight = new Light("Living room");
            Light bedroomLight    = new Light("Bedroom");

            Command lightONBtn  = new LightONCommand(light);
            Command lightOffBtn = new LightOFFCommand(light);

            Command kitchenLightON  = new LightONCommand(kitchenLight);
            Command kitchenLightOFF = new LightOFFCommand(kitchenLight);

            Command livingRoomON  = new LightONCommand(livingRoomLight);
            Command livingRoomOFF = new LightOFFCommand(livingRoomLight);


            SimpleRemoteControl simpRemoteCntrl = new SimpleRemoteControl();

            simpRemoteCntrl.SetCommand(0, lightONBtn, lightOffBtn);
            simpRemoteCntrl.SetCommand(1, kitchenLightON, kitchenLightOFF);
            simpRemoteCntrl.SetCommand(2, livingRoomON, livingRoomOFF);

            simpRemoteCntrl.OnButtonPushed(0);
            simpRemoteCntrl.OffButtonPushed(0);

            simpRemoteCntrl.OnButtonPushed(1);
            simpRemoteCntrl.OffButtonPushed(1);

            simpRemoteCntrl.OnButtonPushed(2);
            simpRemoteCntrl.OffButtonPushed(2);


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

            simpRemoteCntrl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand);

            simpRemoteCntrl.OnButtonPushed(3);


            Console.WriteLine("\n Start of macro \n");

            Command[] partyCommandsOn  = new Command[] { lightONBtn, kitchenLightON, livingRoomON };
            Command[] partyCommandsOff = new Command[] { lightOffBtn, kitchenLightOFF, livingRoomOFF };



            MacroCommand macroCommandON  = new MacroCommand(partyCommandsOn);
            MacroCommand macroCommandOff = new MacroCommand(partyCommandsOff);

            simpRemoteCntrl.SetCommand(0, macroCommandON, macroCommandOff);

            simpRemoteCntrl.OnButtonPushed();
            simpRemoteCntrl.OffButtonPushed();



            Console.WriteLine(simpRemoteCntrl.ToString());
        }
示例#20
0
 public void SetCommand(int slot, MacroCommand onCommands, MacroCommand offCommands)
 {
     this.onCommandsMacro  = onCommands;
     this.offCommandsMacro = offCommands;
 }