コード例 #1
0
        static void Main(string[] args)
        {
            //sample 2
            //IElectronicDevice newDevice = new Television();
            //ICommand onCommand = new TurnTVUp(newDevice);

            //DeviceButton onPressed= new DeviceButton(onCommand);
            //onPressed.Press();
            //onPressed.Press();
            //Console.WriteLine("---------------");
            ////--------------------------------------------------
            //IElectronicDevice theTv = new Television();
            //IElectronicDevice theRadio = new Radio();

            //IList<IElectronicDevice> allDevices= new List<IElectronicDevice>();
            //allDevices.Add(theTv);
            //allDevices.Add(theRadio);

            //ICommand onCommandTurnItOff = new TurnItAllOff(allDevices);

            //DeviceButton turnThemOff = new DeviceButton(onCommandTurnItOff);
            //turnThemOff.Press();
            //Console.WriteLine("--------------- Undo");
            ////undo
            //turnThemOff.Undo();

            //sample 1
            ShutDownCommand shutDownCommand = new ShutDownCommand(new EuropeServer());

            ServerCommandInvoker serverCommandInvoker = new ServerCommandInvoker(shutDownCommand);

            serverCommandInvoker.run();

            Console.ReadKey();
        }
コード例 #2
0
        public TestCommands()
        {
            Invoker     invoker     = new Invoker();
            InvokerPlus invokerplus = new InvokerPlus();
            //create the receivers
            AsiaServer asiaServer = new AsiaServer();
            EuroServer euroServer = new EuroServer();
            USServer   usServer   = new USServer();
            //Create the commands
            ShutDownCommand      shutDownAsia       = new ShutDownCommand(asiaServer);
            RunDiagnosticCommand runDiagnosticsAsia = new RunDiagnosticCommand(asiaServer);
            RebootCommand        rebootAsia         = new RebootCommand(asiaServer);
            ShutDownCommand      shutDownEuro       = new ShutDownCommand(euroServer);
            RunDiagnosticCommand runDiagnosticsEuro = new RunDiagnosticCommand(euroServer);
            RebootCommand        rebootEuro         = new RebootCommand(euroServer);
            ShutDownCommand      shutDownUS         = new ShutDownCommand(usServer);
            RunDiagnosticCommand runDiagnosticsUS   = new RunDiagnosticCommand(usServer);
            RebootCommand        rebootUS           = new RebootCommand(usServer);

            //Create the invokers to run methods
            invoker.setCommand(shutDownAsia);
            invoker.run();
            invoker.setCommand(rebootAsia);
            invoker.run();
            invoker.setCommand(runDiagnosticsAsia);
            invoker.run();
            invoker.setCommand(shutDownEuro);
            invoker.run();
            invoker.setCommand(runDiagnosticsEuro);
            invoker.run();
            invoker.setCommand(rebootUS);
            invoker.run();
            invokerplus.setCommand(shutDownAsia);
            invokerplus.run();
            invokerplus.setCommand(rebootAsia);
            invokerplus.run();
            invokerplus.setCommand(runDiagnosticsAsia);
            invokerplus.run();
            invokerplus.undo();
            invokerplus.undo();
            invokerplus.undo();
        }