Exemple #1
0
        public void CommandExampleMacros()
        {
            RemoteControl remote = new RemoteControl(); // this is the invoker

            Light  livingRoomLight = new Light("Living Room");
            Stereo stereo          = new Stereo("Living Room");

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

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

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

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

            remote.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remote);
            Console.WriteLine("--- Pushing Macro On ---\n");
            remote.OnButtonWasPushed(0);
            Console.WriteLine("--- Pushing Macro Off ---\n");
            remote.OffButtonWasPushed(0);
            Console.WriteLine("--- Pushing Macro Undo ---\n"); // not working for every scenario
            remote.UndoButtonWasPushed();

            Console.ReadLine();
        }
Exemple #2
0
        public static void MacroCommandTests()
        {
            var light  = new Light("Living Room");
            var tv     = new TV("Living Room");
            var stereo = new Stereo("Living Room");
            var hottub = new Hottub();

            var lightOn  = new LightOnCommand(light);
            var stereoOn = new StereoOnWithCdCommand(stereo);
            var tvOn     = new TvOnCommand(tv);
            var hottubOn = new HottubOnCommand(hottub);

            var lightOff  = new LightOffCommand(light);
            var stereoOff = new StereoOffCommand(stereo);
            var tvOff     = new TvOffCommand(tv);
            var hottubOff = new HottubOffCommand(hottub);

            IUndoableCommand[] partyOn       = { lightOn, stereoOn, tvOn, hottubOn };
            IUndoableCommand[] partyOff      = { lightOff, stereoOff, tvOff, hottubOff };
            MacroCommand       partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand       partyOffMacro = new MacroCommand(partyOff);

            var remoteControl = new RemoteControl();

            remoteControl.SetCommand(1, partyOnMacro, partyOffMacro);

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

            Console.ReadKey();
        }
        public static void Start()
        {
            var remoteControl = new RemoteControl();

            var light               = new Light();
            var lightOn             = new LightOnCommand(light);
            var lightOff            = new LightOffCommand(light);
            var stereo              = new Stereo();
            var stereoOn            = new StereoOnCommand(stereo);
            var stereoOff           = new StereoOffCommand(stereo);
            var ceililngFan         = new CeilingFan("Kitchen room");
            var ceililngFanLowOn    = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Low);
            var ceililngFanMediumOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Medium);
            var ceililngFanHighOn   = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.High);
            var ceililngFanOff      = new CeilingFanOffCommand(ceililngFan);
            var partyOn             = new MacroCommand(new ICommand[] { lightOn, stereoOn });
            var partyOff            = new MacroCommand(new ICommand[] { lightOff, stereoOff });

            remoteControl.SetCommand(2, lightOn, lightOff);
            remoteControl.SetCommand(3, stereoOn, stereoOff);
            remoteControl.SetCommand(4, ceililngFanLowOn, ceililngFanOff);
            remoteControl.SetCommand(5, ceililngFanMediumOn, ceililngFanOff);
            remoteControl.SetCommand(6, ceililngFanHighOn, ceililngFanOff);
            remoteControl.SetCommand(1, partyOn, partyOff);
            remoteControl.P();
            RemoteControlPressButtons(remoteControl);
        }
Exemple #4
0
        public static void MacroCommandExample()
        {
            Light  light  = new Light("Living Room");
            TV     tv     = new TV("Living Room");
            Stereo stereo = new Stereo("Living Room");
            Hottub hottub = new Hottub();

            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);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            TVOffCommand     tvOff     = new TVOffCommand(tv);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

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

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

            RemoteControl remoteControl = new RemoteControl();

            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl.ToString());
            Console.WriteLine("\n--- Pushing Macro On---");
            remoteControl.OnButtonPushed(0);
            Console.WriteLine("\n--- Pushing Macro Off---");
            remoteControl.OffButtonPushed(0);
        }
Exemple #5
0
        private static string ProcessMacroCommand()
        {
            StringBuilder sb = new StringBuilder();

            RemoteControl remoteControl = new RemoteControl();

            Light  light  = new Light("Living Room");
            Stereo stereo = new Stereo();

            LightOnCommand        lightOn  = new LightOnCommand(light);
            StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo);

            LightOffCommand  lightOff  = new LightOffCommand(light);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);

            ICommand[] partyOn  = { lightOn, stereoOn };
            ICommand[] partyOff = { lightOff, stereoOff };

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

            remoteControl.OnCommands[0]  = partyOnMacro;
            remoteControl.OffCommands[0] = partyOffMacro;

            sb.AppendLine(remoteControl.ToString());
            sb.AppendLine("--- Pushing Macro On ---");
            sb.AppendLine(remoteControl.OnButtonWasPushed(0));
            sb.AppendLine("--- Pushing Macro Off ---");
            sb.AppendLine(remoteControl.OffButtonWasPushed(0));

            return(sb.ToString());
        }
Exemple #6
0
        public static void RunRemoteControl()
        {
            var remote          = new RemoteControl();
            var light           = new Light();
            var lightOn         = new LightOnCommand(light);
            var lightOff        = new LightOffCommand(light);
            var garageDoor      = new GarageDoor();
            var garageDoorOpen  = new GarageDoorOpenCommand(garageDoor);
            var garageDoorClose = new GarageDoorCloseCommand(garageDoor);
            var stereo          = new Stereo();
            var stereoOnWithCD  = new StereoOnWithCDCommand(stereo);
            var stereoOff       = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, garageDoorOpen, garageDoorClose);
            remote.SetCommand(2, stereoOnWithCD, stereoOff);

            System.Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
            remote.OnButtonWasPressed(2);
            remote.OffButtonWasPressed(2);
        }
Exemple #7
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);
        }
Exemple #8
0
        public static void CommandTest()
        {
            // 实例化遥控器
            RemoteControl remoteControl = new RemoteControl();
            // 实例化需要控制对象,并传入房子位置
            Stereo stereo = new Stereo("客厅");
            Light  light  = new Light("客厅");
            TV     tv     = new TV("卧室");
            // 调用设备开关方法
            StereoOnWithCDCommand stereoOnWichCD  = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOffWithCD = new StereoOffCommand(stereo);
            LightOnCommand        lightOn         = new LightOnCommand(light);
            LightOffCommand       lightOff        = new LightOffCommand(light);
            TVOnCommand           tvOn            = new TVOnCommand(tv);
            TVOffCommand          tvOff           = new TVOffCommand(tv);

            // 设置插槽位置(遥控器的哪个按钮对应哪个设备开关)
            remoteControl.SetCommand(0, lightOn, lightOff);
            remoteControl.SetCommand(3, stereoOnWichCD, stereoOffWithCD);
            remoteControl.SetCommand(5, tvOn, tvOff);
            // 输出插槽位置
            Console.WriteLine(remoteControl);
            // 按下开关
            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(3);
            remoteControl.OffButtonWasPushed(3);
            remoteControl.OnButtonWasPushed(5);
            remoteControl.OffButtonWasPushed(5);
        }
Exemple #9
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();
            }
        }
        private static void CommandPattern()
        {
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            Light  light  = new Light("Living Room");
            TV     tv     = new TV("Living Room");
            Stereo stereo = new Stereo("Living Room");
            Hottub hottub = new Hottub();

            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);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            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, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);
            Console.WriteLine("--- Pushing Macro On ---");
            remoteControl.onButtonWasPushed(0);
            Console.WriteLine("--- Pushing Macro Off ---");
            remoteControl.offButtonWasPushed(0);
        }
Exemple #11
0
        private static string ProcessRemoteControl()
        {
            RemoteControl remoteControl = new RemoteControl();

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

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

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

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

            StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOffCommand      = new StereoOffCommand(stereo);

            remoteControl.OnCommands[0] = livingRoomLightOn;
            remoteControl.OnCommands[1] = kitchenLightOn;
            remoteControl.OnCommands[2] = ceilingFanOnCommand;
            remoteControl.OnCommands[3] = stereoOnWithCDCommand;

            remoteControl.OffCommands[0] = livingRoomLightOff;
            remoteControl.OffCommands[1] = kitchenLightOff;
            remoteControl.OffCommands[2] = ceilingFanOffCommand;
            remoteControl.OffCommands[3] = stereoOffCommand;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(remoteControl.ToString());

            sb.AppendLine(remoteControl.OnButtonWasPushed(0));
            sb.AppendLine(remoteControl.OffButtonWasPushed(0));
            sb.AppendLine(remoteControl.OnButtonWasPushed(1));
            sb.AppendLine(remoteControl.OffButtonWasPushed(1));
            sb.AppendLine(remoteControl.OnButtonWasPushed(2));
            sb.AppendLine(remoteControl.OffButtonWasPushed(2));
            sb.AppendLine(remoteControl.OnButtonWasPushed(3));
            sb.AppendLine(remoteControl.OffButtonWasPushed(3));

            return(sb.ToString());
        }
Exemple #12
0
        static void Main(string[] args)
        {
            var remoteControl = new RemoteControl();

            var light      = new Light("Living Roon");
            var tv         = new TV("Living Room");
            var stereo     = new Stereo("Living Room");
            var hottub     = new Hottub();
            var garageDoor = new GarageDoor(string.Empty);

            var lightOnCommand   = new LightOnCommand(light);
            var lightOffCommand  = new LightOffCommand(light);
            var stereoOnCommand  = new StereoOnCommand(stereo);
            var stereoOffCommand = new StereoOffCommand(stereo);
            var tvOnCommand      = new TVOnCommand(tv);
            var tvOffCommand     = new TVOffCommand(tv);
            var hottubOnCommand  = new HottubOnCommand(hottub);
            var hottubOffCommand = new HottubOffCommand(hottub);

            var partyOn  = new ICommand[] { lightOnCommand, stereoOnCommand, tvOnCommand, hottubOnCommand };
            var partyOff = new ICommand[] { lightOffCommand, stereoOffCommand, tvOffCommand, hottubOffCommand };

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

            //remoteControl.SetCommand(0, lightOnCommand, lightOffCommand);
            //remoteControl.SetCommand(1, tvOnCommand, tvOffCommand);
            //remoteControl.SetCommand(2, stereoOnCommand, stereoOffCommand);
            //remoteControl.SetCommand(3, hottubOnCommand, hottubOffCommand);
            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);
            remoteControl.SetCommand(6, new GarageDoorUpCommand(garageDoor), new GarageDoorDownCommand(garageDoor));

            Console.WriteLine(remoteControl);

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

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

            remoteControl.OnButtonPressed(6);
            remoteControl.UndoButtonPressed();

            Console.Read();
        }
Exemple #13
0
        public static void Run()
        {
            var remoteControl = new RemoteControl();

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

            var livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            var livingRoomLightOff = new LightOffCommand(livingRoomLight);

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

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

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

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

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

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

            remoteControl.OnButtonWasPushed(0);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(0);
            Console.WriteLine();
            remoteControl.OnButtonWasPushed(1);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(1);
            Console.WriteLine();
            remoteControl.OnButtonWasPushed(2);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(2);
            Console.WriteLine();
            remoteControl.OnButtonWasPushed(3);
            Console.WriteLine();
            remoteControl.OffButtonWasPushed(3);
        }
Exemple #14
0
        static void Main(string[] args)
        {
            #region SimpleRemoteControl
            //var remote = new SimpleRemoteControl();

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

            //remote.Slot = lightOn;
            //remote.ButtonWasPressed();

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

            //var doorOpen = new DoorOpenCommand(new Door());

            //remote.Slot = doorOpen;
            //remote.ButtonWasPressed();
            #endregion

            #region RemoteControl
            var remote         = new RemoteControl();
            var light          = new Light();
            var lightOn        = new LightOnCommand(light);
            var lightOff       = new LightOffCommand(light);
            var door           = new Door();
            var doorOpen       = new DoorOpenCommand(door);
            var doorClose      = new DoorCloseCommand(door);
            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, doorOpen, doorClose);
            remote.SetCommand(2, stereoOnWithCD, stereoOff);

            Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
            remote.OnButtonWasPressed(2);
            remote.OffButtonWasPressed(2);
            remote.UndoButtonWasPressed();
            #endregion

            Console.ReadKey();
        }
Exemple #15
0
        public void CommandExample()
        {
            RemoteControl remote = new RemoteControl(); // this is the invoker

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

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

            CeilingFanOnHighCommand   ceilingFanOnHigh   = new CeilingFanOnHighCommand(ceilingFan);
            CeilingFanOnMediumCommand ceilingFanOnMedium = new CeilingFanOnMediumCommand(ceilingFan);
            CeilingFanOffCommand      ceilingFanOff      = new CeilingFanOffCommand(ceilingFan);

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

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

            remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remote.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remote.SetCommand(2, ceilingFanOnHigh, ceilingFanOnMedium);
            remote.SetCommand(3, stereoOnWithCd, stereoOff);

            Console.WriteLine(remote);

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

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

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

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

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

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

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

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



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

            Console.WriteLine(remoteControl);

            // Invoke Commands
            for (int i = 0; i < remoteControl.numberOfSlots; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                remoteControl.OffButtonWasPushed(i);
            }
        }
Exemple #17
0
        public static void UseCommandPattern(IView view)
        {
            RemoteControl remote = new RemoteControl(view);

            Light livingRoomLight = new Light(view, "Living Room");
            Light kitchenLight    = new Light(view, "Kitchen");

            //CeilingFan ceilingFan = new CeilingFan(view, "Kitchen");

            Garage garage = new Garage(view);
            Stereo stereo = new Stereo(view);

            ICommand livigRommLightOn  = new LightOnCommand(livingRoomLight);
            ICommand livigRommLightOff = new LightsOffCommand(livingRoomLight);
            ICommand KitchenLightOn    = new LightOnCommand(kitchenLight);
            ICommand KitchenightOff    = new LightsOffCommand(kitchenLight);

            ICommand garageDoorOpen  = new GarageOpenCommand(garage);
            ICommand garageDoorClose = new GarageCloseCommand(garage);

            ICommand stereoWithCd = new StereoWithCDCommand(stereo);
            ICommand stereoOff    = new StereoOffCommand(stereo);

            remote.SetCommand(0, livigRommLightOn, livigRommLightOff);
            remote.SetCommand(1, KitchenLightOn, KitchenightOff);
            remote.SetCommand(2, garageDoorOpen, garageDoorClose);
            remote.SetCommand(3, stereoWithCd, stereoOff);

            remote.DisplayButtons();

            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OffButtonWasPushed(1);
            remote.OnButtonWasPushed(2);
            remote.OffButtonWasPushed(2);
            remote.OnButtonWasPushed(3);
            remote.OffButtonWasPushed(3);
        }
Exemple #18
0
        public static void RunRemoteControlWithUndo()
        {
            var remote         = new RemoteControlWithUndo();
            var light          = new Light();
            var lightOn        = new LightOnCommand(light);
            var lightOff       = new LightOffCommand(light);
            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, stereoOnWithCD, stereoOff);
            System.Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.UndoButtonWasPressed();

            remote.OnButtonWasPressed(1);
            remote.UndoButtonWasPressed();
            remote.OffButtonWasPressed(1);
        }
        public IControlebel GetCommand(CommandsType commandType, out ICommand onCommand, out ICommand offCommand)
        {
            IControlebel controlebel;

            switch (commandType)
            {
            case CommandsType.Light:
                controlebel = new Light(win);
                onCommand   = new LightOnCommand(controlebel);
                offCommand  = new LightOffCommand(controlebel);
                break;

            case CommandsType.Garage:
                controlebel = new Garage(win);
                onCommand   = new GarageDoorOpenCommand(controlebel);
                offCommand  = new GarageDoorCloseCommand(controlebel);
                break;

            case CommandsType.Stereo:
                controlebel = new Stereo(win);
                onCommand   = new StereoOnWithCDCommand(controlebel);
                offCommand  = new StereoOffCommand(controlebel);
                break;

            case CommandsType.MacroCommand:
                controlebel = default(IControlebel);
                onCommand   = new MacroCommand();
                offCommand  = new MacroCommand();
                break;

            default:
                controlebel = default(IControlebel);
                onCommand   = default(ICommand);
                offCommand  = default(ICommand);
                break;
            }

            return(controlebel);
        }
Exemple #20
0
        public static void CommandExample()
        {
            Light      livingRoomLight = new Light("Living Room");
            Light      kitchenLight    = new Light("Kitchen");
            CeilingFan ceilingFan      = new CeilingFan("Living Room");
            GarageDoor garageDoor      = new GarageDoor("");
            Stereo     stereo          = new Stereo("Living Room");

            LightOnCommand        livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            LightOffCommand       livingRoomLightOff = new LightOffCommand(livingRoomLight);
            LightOnCommand        kitchenLightOn     = new LightOnCommand(kitchenLight);
            LightOffCommand       kitchenLightOff    = new LightOffCommand(kitchenLight);
            CeilingFanOnCommand   ceilingFanOn       = new CeilingFanOnCommand(ceilingFan);
            CeilingFanOffCommand  ceilingFanOff      = new CeilingFanOffCommand(ceilingFan);
            GarageDoorUpCommand   garageDoorUp       = new GarageDoorUpCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown     = new GarageDoorDownCommand(garageDoor);
            StereoOnWithCDCommand stereoOnWithCD     = new StereoOnWithCDCommand(stereo);
            StereoOffCommand      stereoOff          = new StereoOffCommand(stereo);

            RemoteControl remoteControl = new RemoteControl();

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

            Console.WriteLine(remoteControl.ToString());

            remoteControl.OnButtonPushed(0);
            remoteControl.OffButtonPushed(0);
            remoteControl.OnButtonPushed(1);
            remoteControl.OffButtonPushed(1);
            remoteControl.OnButtonPushed(2);
            remoteControl.OffButtonPushed(2);
            remoteControl.OnButtonPushed(3);
            remoteControl.OffButtonPushed(3);
        }
        static void Main(string[] args)
        {
            RemoteControl remoteControl = new RemoteControl();
            //GarageDoor
            GarageDoor             garageDoor             = new GarageDoor();
            GarageDoorCloseCommand garageDoorCloseCommand = new GarageDoorCloseCommand(garageDoor);
            GarageDoorOpenCommand  garageDoorOpenCommand  = new GarageDoorOpenCommand(garageDoor);

            Light           light           = new Light();
            LightOnCommand  lightOnCommand  = new LightOnCommand(light);
            LightOffCommand lightOffCommand = new LightOffCommand(light);

            TV           tv           = new TV();
            TvOnCommand  tvOnCommand  = new TvOnCommand(tv);
            TvOffCommand tvOffCommand = new TvOffCommand(tv);

            Stereo           stereo           = new Stereo();
            StereoOnCommand  stereoOnCommand  = new StereoOnCommand(stereo);
            StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo);


            remoteControl.SetCommand(0, garageDoorOpenCommand, garageDoorCloseCommand);
            remoteControl.SetCommand(1, lightOnCommand, lightOffCommand);
            remoteControl.SetCommand(2, tvOnCommand, tvOffCommand);
            remoteControl.SetCommand(3, stereoOnCommand, stereoOffCommand);


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

            Console.WriteLine(remoteControl);

            remoteControl.OffButtonWasPushed(0);
            Console.ReadKey();
        }
 public void Setup()
 {
     stereo           = new Stereo();
     stereoOffCommand = new StereoOffCommand(this.stereo);
     stereoOnCommand  = new StereoOnWithCDCommand(this.stereo);
 }
Exemple #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();
        }
        public void TestTurningOn()//Command Pattern Client
        {
            //Command Pattern Invoker
            Remote remote = new Remote();

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

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

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

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

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

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

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

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

            //			Console.WriteLine(remote.toString());
        }
    static void RootMain()
    {
        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");


        ICommand livingRoomLightOn  = (ICommand) new LightOnCommand(livingRoomLight);
        ICommand livingRoomLightOff = (ICommand) new LightOffCommand(livingRoomLight);

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

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

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

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

        ICommand[] pseudoPartyOn       = new ICommand[] { garageDoorUp, ceilingFanHigh, kitchenLightOn, livingRoomLightOn };
        ICommand[] pseudoPartyOff      = new ICommand[] { garageDoorDown, ceilingFanOff, kitchenLightOff, livingRoomLightOff };
        ICommand   pseudoPartyOnMacro  = new MacroCommand(pseudoPartyOn) as ICommand;
        ICommand   pseudoPartyOffMacro = new MacroCommand(pseudoPartyOff) as ICommand;

        remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
        remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
        remoteControl.SetCommand(2, stereoOnWithCD, stereoOff);
        remoteControl.SetCommand(3, ceilingFanLow, ceilingFanOff);
        remoteControl.SetCommand(4, ceilingFanMedium, ceilingFanOff);
        remoteControl.SetCommand(5, ceilingFanHigh, ceilingFanOff);
        remoteControl.SetCommand(6, pseudoPartyOnMacro, pseudoPartyOffMacro);

        System.Console.WriteLine(remoteControl);

        remoteControl.OnButtonPushed(0);
        remoteControl.OffButtonPushed(0);
        remoteControl.OnButtonPushed(1);
        remoteControl.OffButtonPushed(1);
        remoteControl.OnButtonPushed(2);
        remoteControl.OffButtonPushed(2);
        remoteControl.UndoButtonPushed();

        remoteControl.OnButtonPushed(3);
        remoteControl.OnButtonPushed(4);
        remoteControl.OnButtonPushed(5);
        remoteControl.UndoButtonPushed();
        remoteControl.OffButtonPushed(4);

        remoteControl.OnButtonPushed(6);
        remoteControl.OffButtonPushed(6);
        remoteControl.UndoButtonPushed();
    }
        static void Main(string[] args)                                     // Client
        {
            // Example 1
            SimpleRemoteControl remote         = new SimpleRemoteControl(); // Invoker
            LightBulb           light          = new LightBulb();           // Receiver
            LightOnCommand      lightOnCommand = new LightOnCommand(light); // Command

            remote.SetCommand(lightOnCommand);
            remote.ButtonWasPressed();
            remote.UndoButtonWasPressed();

            // Example 2
            AdvancedRemote remote2 = new AdvancedRemote();

            GarageDoor garageDoor = new GarageDoor();
            Stereo     stereo     = new Stereo();

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

            StereoOnCommand  stereoOnCommand  = new StereoOnCommand(stereo);
            StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo);

            remote2.SetCommand(0, garageDoorUpCommand, garageDoorDownCommand);
            remote2.SetCommand(1, stereoOnCommand, stereoOffCommand);

            remote2.OnButtonWasPressed(0);
            remote2.OnButtonWasPressed(1);
            remote2.OffButtonWasPressed(0);
            remote2.OffButtonWasPressed(1);

            remote2.UndoButtonWasPressed();

            // Example 3

            AdvancedRemote remote3 = new AdvancedRemote();

            Fan fan = new Fan();

            FanHighCommand   fanHighCommand   = new FanHighCommand(fan);
            FanMeduimCommand fanMeduimCommand = new FanMeduimCommand(fan);
            FanLowCommand    fanLowCommand    = new FanLowCommand(fan);
            FanOffCommand    fanOffCommand    = new FanOffCommand(fan);

            // Remote from Example 2 Reused
            remote3.SetCommand(0, fanHighCommand, fanOffCommand);
            remote3.SetCommand(1, fanMeduimCommand, fanOffCommand);

            remote3.OnButtonWasPressed(0);              // High
            remote3.OffButtonWasPressed(0);             // Off
            remote3.UndoButtonWasPressed();             // Back To High

            // Example 4
            RoomTV          roomTV          = new RoomTV();
            HotTub          hotTub          = new HotTub();
            HotTubOnCommand hotTubOnCommand = new HotTubOnCommand(hotTub);

            TVOnCommand tvOnCommand = new TVOnCommand(roomTV);

            Command[] PartyCommands = new Command[2];
            PartyCommands[0] = hotTubOnCommand;
            PartyCommands[1] = tvOnCommand;


            MacroCommand macroCommand = new MacroCommand(PartyCommands);    // Put All Commands in this MacroCommand

            AdvancedRemote remote4 = new AdvancedRemote();

            remote4.SetCommand(0, macroCommand, new NoCommand());           // No Command for Off Button
            remote4.OnButtonWasPressed(0);
        }
Exemple #27
0
        static void Main(string[] args)
        {
            #region Strategy Pattern
            //Duck mallardDuck = new MallardDuck();
            //mallardDuck.PerformQuack();
            //mallardDuck.PerformFly();

            //Duck modelDuck = new ModeldDuck();
            //modelDuck.PerformFly();
            //modelDuck.PerformQuack();
            //modelDuck.setFlyBhavior(new FlyRocketPowered());// to change behavior at runtime just call setter method
            //modelDuck.PerformFly();

            //mallardDuck.Display();
            #endregion

            #region Observer Pattern
            //WeatherData weatherData = new WeatherData();

            //CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData);


            //weatherData.SetMeaserments(32.46f, 65, 30.4f);
            #endregion

            #region Decorator Pattern

            //Beverage beverage = new Espresso();
            //Console.WriteLine(beverage.GetDiscription() + " TK-" + beverage.cost());
            //Console.ReadLine();

            #endregion

            #region Factory Pattern

            //PizzaStore nyPizzaStore = new NYPizzaStore();
            //ProductPizza pizza = nyPizzaStore.Orderpizza("Cheese");

            #endregion

            #region Command Pattern

            RemoteControl remoteControl = new RemoteControl();// invoker, it will be passed a command object that can be used to make request
            #region
            #region Create all devices in their Proper Location
            Light      livingRoomLight  = new Light("Living Room");// receiver of the request
            Light      kitchenRoomLight = new Light("kitchen Room");
            CeilingFan ceilingFan       = new CeilingFan("Living Room");
            Stereo     stereo           = new Stereo("Living Room");
            GarageDoor garageDoor       = new GarageDoor();
            #endregion

            #region Create all the command object
            LightOnCommand  livingRoomLightOn  = new LightOnCommand(livingRoomLight);   // create a command & pass it to the receiver
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);  // create a command & pass it to the receiver
            LightOnCommand  KichenRoomLightOn  = new LightOnCommand(kitchenRoomLight);  // create a command & pass it to the receiver
            LightOffCommand KichenRoomLightOff = new LightOffCommand(kitchenRoomLight); // create a command & pass it to the receiver

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

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

            GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor);
            GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor);

            #endregion

            #region load all commands in the  remote slot
            //remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            //remoteControl.SetCommand(1, KichenRoomLightOn, KichenRoomLightOff);
            //remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff);
            //remoteControl.SetCommand(3, stereoOnWithCD, stereoOff);
            #endregion

            #region action
            //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);
            #endregion

            #endregion

            #region Undo Action in ceiling
            //CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan);
            //CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            //CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(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();
            //Console.WriteLine(remoteControl);
            #endregion


            #region Macro Command

            ICommand[] partyOn  = { livingRoomLightOn, stereoOnWithCD, ceilingFanOn, garageDoorOpen };
            ICommand[] partyOff = { livingRoomLightOff, stereoOff, ceilingFanOff, garageDoorDown };

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand 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);
            //Console.WriteLine("----Pushing Macro Undo----");
            //remoteControl.undoButtonWasPushed();
            #endregion


            #endregion

            #region Adapter Pattern
            //MallaDuck duck = new MallaDuck();

            //WildTurkey wildTurkey = new WildTurkey();

            //IDuck turkeyAdapter = new TurkeyAdapter(wildTurkey);

            //Console.WriteLine("The Turkey Says...");
            //wildTurkey.Gobble();
            //wildTurkey.Fly();

            //Console.WriteLine("\n The Duck Says...");
            //testDuck(duck);

            //Console.WriteLine("\n The TurkeyAdapter Says...");
            //testDuck(turkeyAdapter);
            #endregion

            #region Facade Pattern

            //Amplifier amp = new Amplifier();
            //var tuner = new Tuner();
            //DvdPlayer dvdPlayer = new DvdPlayer();
            //CdPlayer cdPlayer = new CdPlayer();
            //Projector projector = new Projector();
            //TheaterLights theaterLights = new TheaterLights();
            //Screen screen = new Screen();
            //PopcornPopper popper = new PopcornPopper();
            //TheaterLights light = new TheaterLights();


            //HomeTheaterFacade theaterFacade = new HomeTheaterFacade( tuner, amp, dvdPlayer, cdPlayer, projector, light, screen, popper);
            //theaterFacade.WatchMovies("BatMan");
            //Console.WriteLine("-------------------------");
            //theaterFacade.EndMovie();

            #endregion


            #region Template Method Pattern

            Tea tea = new Tea();
            tea.PrepareRecipe();

            #endregion

            #region
            #endregion

            #region
            #endregion

            #region
            #endregion

            #region
            #endregion

            Console.ReadLine();
        }
        public static void Test()
        {
            RemoteControl remoteControl = new RemoteControl();

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

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

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

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

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

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

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



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

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

            Console.WriteLine(remoteControl);

            remoteControl.onButtonWasPushed(0);
            remoteControl.offButtonWasPushed(0);
            remoteControl.onButtonWasPushed(1);
            remoteControl.offButtonWasPushed(1);
            remoteControl.onButtonWasPushed(2);
            remoteControl.offButtonWasPushed(2);
            remoteControl.onButtonWasPushed(3);
            remoteControl.offButtonWasPushed(3);

            Console.WriteLine("-------------------------------------------------------------- Party Mode On -----------------------------------------------");
            remoteControl.onButtonWasPushed(4);
            remoteControl.offButtonWasPushed(4);
            remoteControl.undoButtonPushed();
        }
        public static void Run()
        {
            // Invoker
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            // Receivers
            Light  livingRoomLight = new Light("Living Room");
            TV     tv     = new TV("Living Room");
            Stereo stereo = new Stereo("Living Room");
            Hottub hottub = new Hottub("Outside");

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

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

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

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

            // Set Macro
            ICommand[] partyOn  = { livingRoomLightOn, stereoOnWithCD, tvOn, hottubOn };
            ICommand[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff };

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

            // Set Commands
            remoteControl.SetCommand(0, partyOnMacro, partyOffMacro);

            // Invoke Commands
            Console.WriteLine("==================================================");
            Console.WriteLine("============= Pressing Macro Buttons =============");
            Console.WriteLine("==================================================");
            Console.WriteLine();
            Console.WriteLine(remoteControl);
            Console.WriteLine();
            for (int i = 0; i < remoteControl.numberOfSlots; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                if (!(remoteControl.onCommands[i] is NoCommand))
                {
                    Console.WriteLine();
                }
                remoteControl.OffButtonWasPushed(i);

                if (!(remoteControl.onCommands[i] is NoCommand))
                {
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
            Console.WriteLine("----- Undo -----");
            int undoSize = remoteControl.undoCommands.Count;

            for (int i = 0; i < undoSize; i++)
            {
                remoteControl.UndoButtonWasPushed();
            }
        }
Exemple #30
0
        public static void Start()
        {
            // SimpleRemoteControl example
            //SimpleRemoteControl remote = new SimpleRemoteControl();

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

            //GarageDoor garageDoor = new GarageDoor();
            //GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor);

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

            //remote.SetCommand(garageOpen);
            //remote.ButtonWasPressed();

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

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

            //GarageDoorOpenCommand garageDoorUp = new GarageDoorOpenCommand(garageDoor);
            //GarageDoorCloseCommand garageDoorDown = new GarageDoorCloseCommand(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);

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

            // MacroCommand Example
            RemoteControl remoteControl = new RemoteControl();

            Light  light  = new Light("Living Room");
            TV     tv     = new TV("Living Room");
            Stereo stereo = new Stereo("Living Room");
            Hottub hottub = new Hottub();

            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);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            TVOffCommand     tvOff     = new TVOffCommand(tv);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

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

            MacroCommand partyOnMacro  = new MacroCommand(partyOn);
            MacroCommand 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);
        }