static void Main(string[] args)
        {
            var remote = new SimpleRemoteControl();
            var light = new Light();
            var lightOn = new LightOnCommand(light);
            var lightOff = new LightOffCommand(light);

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

            var stereo = new Stereo();
            var stereoOnWithCD = new StereoOnWithCdCommand(stereo);
            var stereoOn = new StereoOnCommand(stereo);
            var stereoOff = new StereoOffCommand(stereo);

            remote.SetCommand(lightOn);
            remote.ButtonWasPressed();
            remote.SetCommand(garageDoorOpen);
            remote.ButtonWasPressed();

            Console.WriteLine("\n-----Newer Universal Remote-----\n");

            var universalRemote = new RemoteControl();

            universalRemote.AddCommand("Light", lightOn, lightOff);
            universalRemote.AddCommand("GarageDoor", garageDoorOpen, garageDoorClose);
            universalRemote.AddCommand("Stereo", stereoOn, stereoOff);
            universalRemote.AddCommand("StereoWithCD", stereoOnWithCD, stereoOff);

            Console.WriteLine(universalRemote.ToString());

            Input(universalRemote);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var remote   = new SimpleRemoteControl();
            var light    = new Light();
            var lightOn  = new LightOnCommand(light);
            var lightOff = new LightOffCommand(light);

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

            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCdCommand(stereo);
            var stereoOn       = new StereoOnCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);


            remote.SetCommand(lightOn);
            remote.ButtonWasPressed();
            remote.SetCommand(garageDoorOpen);
            remote.ButtonWasPressed();

            Console.WriteLine("\n-----Newer Universal Remote-----\n");

            var universalRemote = new RemoteControl();

            universalRemote.AddCommand("Light", lightOn, lightOff);
            universalRemote.AddCommand("GarageDoor", garageDoorOpen, garageDoorClose);
            universalRemote.AddCommand("Stereo", stereoOn, stereoOff);
            universalRemote.AddCommand("StereoWithCD", stereoOnWithCD, stereoOff);

            Console.WriteLine(universalRemote.ToString());

            Input(universalRemote);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl();
            Light         light1        = new Light("Living Room");
            Light         light2        = new Light("Kitchen");
            Stereo        stereo1       = new Stereo("Living Room");
            Stereo        stereo2       = new Stereo("Kitchen");

            LightOnCommand  lightOnCommand1  = new LightOnCommand(light1);
            LightOffCommand lightOffCommand1 = new LightOffCommand(light1);

            LightOnCommand  lightOnCommand2  = new LightOnCommand(light2);
            LightOffCommand lightOffCommand2 = new LightOffCommand(light2);

            StereoOnCommand  stereoOnCommand1  = new StereoOnCommand(stereo1);
            StereoOffCommand stereoOffCommand1 = new StereoOffCommand(stereo1);

            StereoOnCommand  stereoOnCommand2  = new StereoOnCommand(stereo2);
            StereoOffCommand stereoOffCommand2 = new StereoOffCommand(stereo2);

            remoteControl.SetCommand(0, lightOnCommand1, lightOffCommand1);
            remoteControl.SetCommand(1, lightOnCommand2, lightOffCommand2);
            remoteControl.SetCommand(2, stereoOnCommand1, stereoOffCommand1);
            remoteControl.SetCommand(3, stereoOnCommand2, stereoOffCommand2);

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

            Console.ReadKey();
        }
Beispiel #4
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);
        }
Beispiel #5
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();
        }