상속: ICommand
        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);
        }
예제 #2
0
        public void Load()
        {
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

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

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

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

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

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

            LightOnCommand  lightOn  = new LightOnCommand(light);
            StereoOnCommand stereoOn = new StereoOnCommand(stereo);
            TVOnCommand     tvOn     = new TVOnCommand(tv);
            HottubOnCommand hottubOn = new HottubOnCommand(hottub);

            LightOffCommand  lightOff  = new LightOffCommand(light);
            TVOffCommand     tvOff     = new TVOffCommand(tv);
            HottubOffCommand hottubOff = new HottubOffCommand(hottub);

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

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

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);
            remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff);
            remoteControl.SetCommand(3, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(4, stereoOnWithCd, stereoOff);
            remoteControl.SetCommand(5, garageDoorUp, garageDoorDown);
            remoteControl.SetCommand(6, partyOnMacro, partyOffMacro);

            Console.WriteLine(remoteControl);

            for (int i = 0; i <= 6; i++)
            {
                remoteControl.OnButtonWasPushed(i);
                remoteControl.OffButtonWasPushed(i);
                remoteControl.UndoButtonWasPushed();
            }
        }
예제 #3
0
        private void bOk_Click(object sender, RoutedEventArgs e)
        {
            MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(controller);

            command.Description = CommandDescription.UPDATE_PACKAGE_MACRO;

            if (tbName.Text != oldName)
            {
                RenameElementCommand <Package> renameElementCommand = (RenameElementCommand <Package>) RenameElementCommandFactory <Package> .Factory().Create(controller);

                renameElementCommand.NewName              = tbName.Text;
                renameElementCommand.RenamedElement       = package;
                renameElementCommand.ContainingCollection = package.NestingPackage.NestedPackages;
                command.Commands.Add(renameElementCommand);
            }

            if (cbPackages.SelectedItem != package.NestingPackage)
            {
                MovePackageCommand movePackageCommand = (MovePackageCommand)MovePackageCommandFactory.Factory().Create(controller);
                movePackageCommand.OldPackage   = package.NestingPackage;
                movePackageCommand.NewPackage   = (Package)cbPackages.SelectedItem;
                movePackageCommand.MovedPackage = package;
                command.Commands.Add(movePackageCommand);
            }

            if (command.Commands.Count > 0)
            {
                command.Execute();
            }

            DialogResult = true;

            Close();
        }
예제 #4
0
        static void Main(string[] args)
        {
            var    remote = new RemoteControl();
            string userInput;

            remote.SetCommandForButton(1, new LightsCommand(new Light()));
            remote.SetCommandForButton(2, new TvCommand(new Tv()));
            remote.SetCommandForButton(3, new MusicCommand(new Music()));
            remote.SetCommandForButton(4, new TeapotCommand(new Teapot()));

            var teapotCommand = new TeapotCommand(new Teapot());
            var tvCommand     = new TvCommand(new Tv());
            var macroCommand  = new MacroCommand(new List <ICommand> {
                teapotCommand, tvCommand
            });

            remote.SetCommandForButton(5, macroCommand);

            do
            {
                Console.WriteLine("Выберите вариант ниже:");
                Console.WriteLine(remote);

                Console.Write("\nВаш выбор: ");
                var input = Console.ReadLine();
                int buttonId;
                int.TryParse(input, out buttonId);

                remote.PushButton(buttonId);
                remote.UndoButton(buttonId);

                Console.Write("\nВы хотите продолжить (y/n): ");
                userInput = Console.ReadLine();
            } while (userInput == "y");
        }
예제 #5
0
 private StackedCommand GetNormalizationCommand(PSMSchema schema)
 {
     // (d) Content model association normalization
     if (!modelVerifier.TestSchemaClassChildrenAreClasses(schema))
     {
         PSMContentModel         cm      = (PSMContentModel)modelVerifier.LastViolatingComponent;
         cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller);
         command.Set(cm.ParentAssociation.ID);
         return(command);
     } // (c) Empty name association
     else if (!modelVerifier.TestSchemaClassChildrenNames(schema))
     {
         PSMAssociation          a       = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller);
         command.Set(a.ID);
         return(command);
     } // (e) Root content model normalization
     else if (!modelVerifier.TestRootsAreNotContentModels(schema))
     {
         PSMContentModel cm = (PSMContentModel)modelVerifier.LastViolatingComponent;
         MacroCommand    m  = new MacroCommand(Controller);
         foreach (PSMAssociation childPsmAssociation in cm.ChildPSMAssociations)
         {
             cmdDeletePSMAssociation delA = new cmdDeletePSMAssociation(Controller);
             delA.Set(childPsmAssociation.ID);
             m.Commands.Add(delA);
         }
         cmdDeletePSMContentModel delCM = new cmdDeletePSMContentModel(Controller);
         delCM.Set(cm.ID);
         m.Commands.Add(delCM);
         return(m);
     } // (f) Root class normalization
     else if (!modelVerifier.TestRootsAreReferenced(schema))
     {
         PSMClass c = (PSMClass)modelVerifier.LastViolatingComponent;
         cmdDeleteRootPSMClass command = new cmdDeleteRootPSMClass(Controller);
         command.Set(c.ID);
         return(command);
     } // (a) Cardinality normalization
     else if (!modelVerifier.TestSchemaClassChildrenCardinality(schema))
     {
         PSMAssociation a = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdUpdatePSMAssociationCardinality command = new cmdUpdatePSMAssociationCardinality(Controller);
         command.Set(a.ID, 1, 1);
         return(command);
     } // (b) Name normalization
     else if (!modelVerifier.TestContentModelsAssociationNames(schema))
     {
         PSMAssociation     a       = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdRenameComponent command = new cmdRenameComponent(Controller)
         {
             ComponentGuid = a.ID, NewName = String.Empty
         };
         return(command);
     }
     else
     {
         throw new InvalidOperationException("Schema is already normalized. ");
     }
 }
예제 #6
0
        public override void Execute(object parameter)
        {
            IEnumerable <PSMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents()
                                                                .Where(c => c is PSMAssociation).Cast <PSMAssociation>();
            MacroCommand macro = new MacroCommand(Current.Controller);

            foreach (PSMAssociation a in
                     Left
                ? selectedAssociations.OrderBy(a => a.Parent.ChildPSMAssociations.IndexOf(a))
                : selectedAssociations.OrderByDescending(a => a.Parent.ChildPSMAssociations.IndexOf(a)))
            {
                macro.Commands.Add(new cmdShiftPSMAssociation(Current.Controller)
                {
                    AssociationGuid = a, Left = Left
                });
            }
            IEnumerable <PSMAssociationMember> selectedRoots = Current.ActiveDiagramView.GetSelectedComponents()
                                                               .Where(c => c is PSMAssociationMember).Cast <PSMAssociationMember>().Where(am => am.ParentAssociation == null);

            foreach (PSMAssociationMember am in selectedRoots)
            {
                macro.Commands.Add(new cmdShiftPSMRoot(Current.Controller)
                {
                    RootGuid = am, Left = Left
                });
            }

            macro.Execute();
        }
예제 #7
0
        protected override void Context()
        {
            base.Context();
            var macroCommand = new MacroCommand <MyContext>();

            sut.Add(macroCommand);
        }
예제 #8
0
        private void OrnamentButton_Click(object sender, EventArgs e)
        {
            DecoratorForm decoratorForm = new DecoratorForm();
            Shape         selectedShape = shapeList.FirstOrDefault(s => s.selected);

            if (selectedShape == null)
            {
                return;
            }

            decoratorForm.ShowDialog();

            if (decoratorForm.DialogResult == DialogResult.OK)
            {
                string ornamentText = decoratorForm.Ornament;

                ShapeDecorator ornament = new ShapeDecorator(selectedShape.x + 50, selectedShape.y, 50, 50, selectedShape, ornamentText, decoratorForm.position);

                MacroCommand macroCommand = new MacroCommand();
                macroCommand.Add(new CustomCommand(
                                     () => shapeList.Remove(selectedShape),
                                     () => shapeList.Add(selectedShape)));
                macroCommand.Add(new AddShapeCommand(shapeList, ornament));

                history.Add(macroCommand);

                Invalidate();
            }
        }
예제 #9
0
        public void AddNewAttribute(string attributeName, string newSimpleDataType, uint?lower, UnlimitedNatural?upper, string @default)
        {
            MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(DiagramController.ModelController);

            AddSimpleTypeCommand     simpleTypeCommand = (AddSimpleTypeCommand)AddSimpleTypeCommandFactory.Factory().Create(DiagramController.ModelController);
            ElementHolder <DataType> type = new ElementHolder <DataType>();

            simpleTypeCommand.CreatedSimpleType = type;
            command.Commands.Add(simpleTypeCommand);
            NewAttributeCommand attributeCommand = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController);

            if (!String.IsNullOrEmpty(attributeName))
            {
                attributeCommand.Name = attributeName;
            }
            else
            {
                attributeCommand.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name);
            }
            attributeCommand.Type    = type;
            attributeCommand.Lower   = lower;
            attributeCommand.Upper   = upper;
            attributeCommand.Default = @default;
            attributeCommand.Owner   = Class;
            command.Commands.Add(attributeCommand);
            command.Execute();
        }
예제 #10
0
    void Start()
    {
        // назначение ключу свою "команду" через методы в InputControll скрипте
        //run
        //inputCtrl.SetCommandForButton(_fire, new FireCommand());
        inputCtrl.SetCommandForButton(_fire, GameObject.FindObjectOfType <FireCommand>() as FireCommand);

        inputCtrl.SetCommandForButton(_jump, new JumpCommand());
        inputCtrl.SetCommandForButton(_sound, new SoundCommand());
        inputCtrl.SetCommandForButton(_ball, new BallCommand());
        //run switch
        inputCtrl.SetCommandForButton(_light, new SwitchLightsCommand(new Light()));
        inputCtrl.SetCommandForButton(_button, new SwitchButtonCommand(new Button()));

        //macrocommand
        //creating macrocommand
        var ballCommand  = new BallCommand();
        var soundCommand = new SoundCommand();
        //merging
        var macroCommand = new MacroCommand(new List <ICommand> {
            ballCommand, soundCommand
        });

        //run macrocommand
        inputCtrl.SetCommandForButton(_macro, macroCommand);

        // hold
        inputCtrl.SetCommandForButton(_hold, GameObject.FindObjectOfType <Hold>() as Hold);
    }
예제 #11
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();
        }
예제 #12
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);
        }
예제 #13
0
        private void bOk_Click(object sender, RoutedEventArgs e)
        {
            MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(controller);

            command.Description = CommandDescription.UPDATE_OPERATION_MACRO;

            if (tbName.Text != oldName)
            {
                RenameElementCommand <Operation> renameElementCommand = (RenameElementCommand <Operation>) RenameElementCommandFactory <Operation> .Factory().Create(controller);

                renameElementCommand.NewName              = tbName.Text;
                renameElementCommand.RenamedElement       = operation;
                renameElementCommand.ContainingCollection = operation.Class.Operations;
                command.Commands.Add(renameElementCommand);
            }

            if (command.Commands.Count > 0)
            {
                command.Execute();
            }

            DialogResult = true;

            Close();
        }
예제 #14
0
        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);
        }
예제 #15
0
        static void Main(string[] args)
        {
            Light      light              = new Light();
            GarageDoor garage             = new GarageDoor();
            ICommand   lightOnCommand     = new LivingLightOnCommand(light);
            ICommand   lightOffCommand    = new LivingLightOffCommand(light);
            ICommand   garageOpenCommand  = new GarageDoorOpenCommand(garage);
            ICommand   garageCloseCommand = new GarageDoorCloseCommand(garage);

            ICommand[] macroOnCommands  = { lightOnCommand, garageOpenCommand };
            ICommand[] macroOffCommands = { lightOffCommand, garageCloseCommand };
            var        macroOn          = new MacroCommand(macroOnCommands);
            var        macroOff         = new MacroCommand(macroOffCommands);

            IList <ICommand> onCommands = new List <ICommand> {
                lightOnCommand, garageOpenCommand, macroOn
            };
            IList <ICommand> offCommands = new List <ICommand> {
                lightOffCommand, garageCloseCommand, macroOff
            };
            var remoteControl = new RemoteControl(onCommands, offCommands);

            remoteControl.ButtonOnPressed(1);
            remoteControl.ButtonOnPressed(3);
        }
예제 #16
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());
        }
예제 #17
0
        private void button1_Click(object sender, EventArgs e)//edit to data struct
        {
            if (nodeSelected == null)
            {
                return;
            }
            var macro = new MacroCommand();

            if (nodeSelected is ScalarNode)
            {
                ScalarNode tempScalar = (ScalarNode)nodeSelected;
                TreeNode   node       = searchTreeEdit(root, tempScalar.id);

                var key   = dataGridView1.Rows[0].Cells[0].EditedFormattedValue.ToString();
                var value = dataGridView1.Rows[0].Cells[1].EditedFormattedValue.ToString();
                vl = new ValueCommand(mapNode, node, tempScalar, key, this, value);
                macro.Add(vl);
                Manager.Execute(macro);
            }
            else
            {
                vl = new ValueCommand(this, dataGridView1, nodeSelected);
                macro.Add(vl);
                Manager.Execute(macro);

                RefreshAll();

                expandAllNodes(nodeSelected);
            }
        }
예제 #18
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);
        }
예제 #19
0
        private void btnRemove_Click(object sender, EventArgs e)//button remove
        {
            if (root == null)
            {
                return;
            }
            if (nodeSelected == null)
            {
                return;
            }
            if (nodeSelected.getID() == 0)
            {
                return;
            }
            TreeNode[] nodeTreeviewEdit = root.Nodes.Find(nodeSelected.getID().ToString(), true);
            var        macro            = new MacroCommand();

            remove = new RemoveCommand(ref mapNode, nodeSelected, ref root, nodeTreeviewEdit[0], this);
            macro.Add(remove);
            Manager.Execute(macro);



            mainTreeView.Nodes.Clear();
            mainTreeView.Nodes.Add(root);
            root.Expand();

            mainTreeView.SelectedNode = root;
        }
예제 #20
0
        public override void Execute(object parameter)
        {
            IEnumerable <PSMContentModel> selectedContentModels = Current.ActiveDiagramView.GetSelectedComponents()
                                                                  .Where(c => c is PSMContentModel).Cast <PSMContentModel>();

            if (selectedContentModels.Count() > 0)
            {
                MacroCommand macro = new MacroCommand(Current.Controller);
                foreach (PSMContentModel cm in selectedContentModels)
                {
                    Guid newClassGuid = new Guid();
                    macro.Commands.Add(new cmdContentToPSMClass(Current.Controller)
                    {
                        Associations = cm.ChildPSMAssociations.Select(assoc => assoc.ID).ToList(),
                        ParentAssociationMemberGuid = cm,
                        ClassGuid = newClassGuid
                    });
                    macro.Commands.Add(new cmdLeaveOutUninterpretedAssociationMember(Current.Controller)
                    {
                        AssociationMemberGuid = cm
                    });
                }
                macro.Execute();
            }
            else
            {
                IEnumerable <PSMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents()
                                                                    .Where(c => c is PSMAssociation).Cast <PSMAssociation>();
                PSMAssociationMember parent  = selectedAssociations.First().Parent;
                cmdContentToPSMClass command = new cmdContentToPSMClass(Current.Controller);
                command.Set(parent, selectedAssociations.Select(a => a.ID), Guid.NewGuid(), Guid.NewGuid());
                command.Execute();
            }
        }
예제 #21
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();
        }
예제 #22
0
        static void Main(string[] args)
        {
            var remote = new RemoteControl();
            var light = new Light();
            var lightOn = new LightOnCommand(light);
            var lightOff = new LightOffCommand(light);
            var stereo = new Stereo();
            var stereoOn = new StereoOnWithCDCommand(stereo);
            var stereoOff = new StereoOffWithCDCommand(stereo);
            var ceilingFan = new CeilingFan("Living Room");
            var ceilingFanHighOn = new CeilingFanHighCommand(ceilingFan);

            var macro = new MacroCommand(new ICommand[] {lightOn, stereoOn});

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(2, stereoOn, stereoOff);
            remote.SetCommand(3, ceilingFanHighOn, new NoComand());
            remote.SetCommand(4, macro, new NoComand());
            remote.OnButtonWasPushed(0);
            remote.OnButtonWasPushed(1);
            remote.OnButtonWasPushed(2);

            remote.OffButtonWasPushed(0);
            remote.OffButtonWasPushed(1);
            remote.OffButtonWasPushed(2);

            remote.UndoButtonWasPushed();

            remote.OnButtonWasPushed(3);
            remote.UndoButtonWasPushed();
            remote.OnButtonWasPushed(4);
            remote.UndoButtonWasPushed();

            Console.ReadKey();
        }
예제 #23
0
        public async Task AsyncronousMacroCommand()
        {
            var cmdNoop = new DelegateCommand(() =>
            {
                System.Threading.Thread.Sleep(20);
                return(true);
            });
            var cmdAddNumbers = new DelegateCommand((s, c) =>
            {
                var v1  = PropertyResolver.GetPropertyValue <int>(c, "Val1");
                var v2  = PropertyResolver.GetPropertyValue <int>(c, "Val2");
                var sum = v1 + v2;
                return(new BoolCommandResult(true, string.Format("Sum of {0} + {1} = {2}", v1, v2, sum)));
            });
            var cmdMacro = new MacroCommand();

            cmdMacro.Commands.Add(cmdNoop);
            cmdMacro.Commands.Add(cmdAddNumbers);
            cmdMacro.Commands.Add(cmdNoop);
            cmdMacro.Commands.Add(cmdAddNumbers);
            cmdMacro.AllowAsyncExecution = true;
            var contextObj = new
            {
                Val1   = 2,
                Val2   = 5,
                Result = -1
            };
            var cmdRes = await cmdMacro.ExecuteAsync(this.svcProvider, contextObj);

            Assert.IsTrue(cmdRes.IsSuccess);
            Assert.AreEqual(cmdRes.Description, "4 commands executed - 4 successful and 0 failed");
        }
        public override void Execute(object parameter)
        {
            IEnumerable <PSMContentModel> selectedContentModels = Current.ActiveDiagramView.GetSelectedComponents()
                                                                  .Where(c => c is PSMContentModel).Cast <PSMContentModel>();

            if (selectedContentModels.Count() > 0)
            {
                MacroCommand macro = new MacroCommand(Current.Controller);
                foreach (PSMContentModel cm in selectedContentModels)
                {
                    macro.Commands.Add(new cmdUpdatePSMContentModel(Current.Controller)
                    {
                        CmodelGuid = cm, Type = Type
                    });
                }
                macro.Execute();
            }
            else
            {
                IEnumerable <PSMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents()
                                                                    .Where(c => c is PSMAssociation).Cast <PSMAssociation>();
                PSMAssociationMember     parent  = selectedAssociations.First().Parent;
                cmdContentToContentModel command = new cmdContentToContentModel(Current.Controller);
                command.Set(parent, selectedAssociations.Select(a => a.ID), Type, Guid.NewGuid(), Guid.NewGuid());
                command.Execute();
            }
        }
예제 #25
0
        static void Main(string[] args)
        {
            RemoteControl remote           = new RemoteControl();
            Light         kitchenRoomlight = new Light("Kitchen");
            Light         livingRoomLight  = new Light("Living Room");
            GarageDoor    garageDoor       = new GarageDoor("");
            Stereo        stereo           = new Stereo("Living Room");

            LightOnCommand  livingRoomLightOn   = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff  = new LightOffCommand(livingRoomLight);
            LightOnCommand  kitchenRoomLightOn  = new LightOnCommand(kitchenRoomlight);
            LightOffCommand kitchenRoomLightOff = new LightOffCommand(kitchenRoomlight);

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

            StereoOnWidthCDCommand  stereoOnWidthCDCommand  = new StereoOnWidthCDCommand(stereo);
            StereoOffWidthCDCommand stereoOffWidthCDCommand = new StereoOffWidthCDCommand(stereo);

            ICommand[] partyOn  = { livingRoomLightOn, garageDoorUp, stereoOnWidthCDCommand, kitchenRoomLightOn };
            ICommand[] partyOff = { livingRoomLightOff, garageDoorDown, stereoOffWidthCDCommand, kitchenRoomLightOff };

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

            remote.SetCommand(0, partyOnMacro, partyOffMacro);

            Console.WriteLine(remote);
            Console.WriteLine("--- Pushing Macro On ---");
            remote.onButtonWasPressed(0);
            Console.WriteLine("--- Pushing Macro Off ---");
            remote.offButtonWasPressed(0);

            Console.ReadKey();
        }
예제 #26
0
        public void MacroCommandtest()
        {
            Remote remote = new Remote();

            Light light = new Light();
            Stero stero = new Stero();
            Fan   fan   = new Fan();

            LightOnCommand       lightOn = new LightOnCommand(light);
            SteroOnWithCDCommand steroOn = new SteroOnWithCDCommand(stero);
            FanHighCommand       fanOn   = new FanHighCommand(fan);

            LightOffCommand lightOff = new LightOffCommand(light);
            SteroOffCommand steroOff = new SteroOffCommand(stero);
            FanOffCommand   fanOff   = new FanOffCommand(fan);

            MacroCommand macroCommandOn  = new MacroCommand(new ICommand[] { lightOn, steroOn, fanOn });
            MacroCommand macroCommandOff = new MacroCommand(new ICommand[] { lightOff, steroOff, fanOff });

            remote.SetCommnd(0, macroCommandOn, macroCommandOff);
            remote.OnButtonPressed(0);

            Assert.AreEqual(Light.States.On, light.CurrentState);
            Assert.AreEqual(Stero.State.CD, stero.CurrentState);
            Assert.AreEqual((int)11, stero.Volume);
            Assert.AreEqual(Fan.Speed.High, fan.CurrentSpeed);

            remote.OffButtonPressed(0);
            Assert.AreEqual(Light.States.Off, light.CurrentState);
            Assert.AreEqual(Stero.State.Off, stero.CurrentState);
            Assert.AreEqual((int)0, stero.Volume);
            Assert.AreEqual(Fan.Speed.Off, fan.CurrentSpeed);
        }
        public override void Execute(object parameter = null)
        {
            IList <DiagramView> topDiagramViews = Current.MainWindow.DiagramTabManager.GetTopDiagramViews();

            /* there must be two diagrams, each with one selected component, both components must be of the
             * same type and they must not be linked already */
            DiagramView diagramView1 = topDiagramViews[0];
            DiagramView diagramView2 = topDiagramViews[1];

            cmdRemoveVersionLink cmdCreateVersionLinkS = new cmdRemoveVersionLink(Current.Controller);

            cmdCreateVersionLinkS.Set(diagramView1.Diagram.Schema, diagramView2.Diagram.Schema);
            cmdRemoveVersionLink cmdCreateVersionLinkD = new cmdRemoveVersionLink(Current.Controller);

            cmdCreateVersionLinkD.Set(diagramView1.Diagram, diagramView2.Diagram);
            MacroCommand m = new MacroCommand(Current.Controller);

            m.Commands.Add(cmdCreateVersionLinkS);
            m.Commands.Add(cmdCreateVersionLinkD);
            m.CheckFirstOnlyInCanExecute = true;
            m.Execute();


            Current.InvokeSelectionChanged();
        }
예제 #28
0
        private static void UseUpgradedStore()
        {
            var store = new UpgradedStore();
            store.SetAC(85);

            var coffeeGrinder = new CoffeeGrinder();
            var coffeeMaker = new CoffeeMaker();

            store.AddOpenCommand(new LightsCommand(store));
            store.AddOpenCommand(new ToggleAcCommand(store, 75d));

            var macro = new MacroCommand();
            macro.AddCommand(new TurnOnOffCommand(coffeeGrinder));
            macro.AddCommand(new TurnOnOffCommand(coffeeMaker));

            store.AddOpenCommand(macro);

            store.OpenStore();

            Console.ReadLine();

            store.CloseStore();

            Console.ReadLine();
        }
예제 #29
0
        private void XTimeClip_Thumb_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            _beingDragged = false;

            var vm = DataContext as TimeClipViewModel;

            if (vm == null)
            {
                return;
            }

            var dragDistance = (float)(Mouse.GetPosition(_visualParent) - _mousePositionAtDragStart).Length;

            // Select only
            if (dragDistance < SystemParameters.MinimumVerticalDragDistance)
            {
                var newSelection = new List <ISelectable> {
                    vm.OperatorWidget
                };
                App.Current.MainWindow.CompositionView.CompositionGraphView.SelectedElements = newSelection;
                _updateValueGroupMacroCommand.Undo();
            }
            else
            {
                App.Current.UndoRedoStack.Add(_updateValueGroupMacroCommand);
                _updateValueGroupMacroCommand = null;
            }
        }
예제 #30
0
        private void Button3_Click(object sender, EventArgs e)
        {
            RemoteControl remoteControl = new RemoteControl(3);

            Light light = new Light();
            Fan   fan   = new Fan();

            LightOnCommand  lightOnCommand  = new LightOnCommand(light);
            LightOffCommand lightOffCommand = new LightOffCommand(light);
            FanOnCommand    fanOnCommand    = new FanOnCommand(fan);
            FanOffCommand   fanOffCommand   = new FanOffCommand(fan);

            Command[] onCommands  = { lightOnCommand, fanOnCommand };
            Command[] offCommands = { lightOffCommand, fanOffCommand };

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

            remoteControl.setCommand(0, onMacro, offMacro);

            salida.Text = remoteControl.toString() + " ";

            salida.Text += "\n" + remoteControl.onButtonWasPushed(0);
            salida.Text += "\n" + remoteControl.offButtonWasPushed(0);
        }
예제 #31
0
        static void TryRemoteControlWithMacroCommand()
        {
            Console.WriteLine("\n----- Remote control with party! -----\n");

            var remoteControl = new RemoteControl();

            var light  = new Light("Living room");
            var stereo = new Stereo("Living room");

            var lightOn   = new LightsOnCommand(light);
            var lightOff  = new LightsOffCommand(light);
            var stereoOn  = new StereoOnWithCDCommand(stereo);
            var stereoOff = new StereoOffWithCDCommand(stereo);

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

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

            remoteControl.SetCommand(0, partyOnCommand, partyOffCommand);
            Console.WriteLine(remoteControl);

            Console.WriteLine("\n-- Party on --\n");
            remoteControl.PressOnButton(0);
            Console.WriteLine("\n-- Party off --\n");
            remoteControl.PressOffButton(0);
        }
예제 #32
0
        private void XTimeClip_Thumb_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
        {
            var vm = DataContext as TimeClipViewModel;

            if (vm == null)
            {
                return;
            }

            _mousePositionAtDragStart = Mouse.GetPosition(_visualParent);
            _startTimeBeforeDrag      = vm.StartTime;
            _endTimeBeforeDrag        = vm.EndTime;
            _sourceInTimeBeforeDrag   = vm.SourceStartTime;
            _sourceOutTimeBeforeDrag  = vm.SourceEndTime;
            _layerBeforeDrag          = vm.Layer;
            _exceededDragThreshold    = false;
            _beingDragged             = true;

            _commandsForInputs = new Dictionary <OperatorPart, ICommand>();
            var commandList = new List <ICommand>();

            commandList.Add(BuildManipulationCommand(vm.OperatorWidget.Operator.Inputs[HACK_TIMECLIP_STARTTIME_PARAM_INDEX], (float)vm.StartTime));
            commandList.Add(BuildManipulationCommand(vm.OperatorWidget.Operator.Inputs[HACK_TIMECLIP_ENDTIME_PARAM_INDEX], (float)vm.EndTime));
            commandList.Add(BuildManipulationCommand(vm.OperatorWidget.Operator.Inputs[HACK_TIMECLIP_SOURCEIN_PARAM_INDEX], (float)vm.SourceStartTime));
            commandList.Add(BuildManipulationCommand(vm.OperatorWidget.Operator.Inputs[HACK_TIMECLIP_SOURCEOUT_PARAM_INDEX], (float)vm.SourceEndTime));
            commandList.Add(BuildManipulationCommand(vm.OperatorWidget.Operator.Inputs[HACK_TIMECLIP_SOURCEOUT_LAYER_ID], (float)vm.Layer));
            _updateValueGroupMacroCommand = new MacroCommand("Update timeclip parameters", commandList);
            _updateValueGroupMacroCommand.Do();
        }
예제 #33
0
        public void Execute_CommndRaisedException()
        {
            string result = string.Empty;
            Exception exception = new Exception();

            var command1 = Substitute.For<ICommand>();
            command1.When(command => command.Execute()).Do((info) => result += "1");

            var command2 = Substitute.For<ICommand>();
            command2.When(command => command.Execute()).Do((info) =>
            {
                throw new CommandExecutionException(command2, exception);
            });

            var command3 = Substitute.For<ICommand>();
            command3.When(command => command.Execute()).Do((info) => result += "3");

            ICommand macro = new MacroCommand()
            {
                command1,
                command2,
                command3
            };

            Assert.Throws<CommandExecutionException>(() => macro.Execute());
            Assert.AreEqual(result, "1");
        }
예제 #34
0
        public void Add_ItemsAdded()
        {
            MacroCommand macro = new MacroCommand();
            ICommand command1 = Substitute.For<ICommand>();

            macro.Add(command1);
            Assert.AreEqual(macro.Commands.Count, 1);
            Assert.AreSame(command1, macro.Commands[0]);

            ICommand command2 = Substitute.For<ICommand>();
            macro.Add(command2);
            Assert.AreEqual(macro.Commands.Count, 2);
            Assert.AreSame(command2, macro.Commands[1]);
        }
예제 #35
0
        public void Execute_ProperExecutionSequence()
        {
            string result = string.Empty;

            var command1 = Substitute.For<ICommand>();
            command1.When(command => command.Execute()).Do((info) => result += "1");

            var command2 = Substitute.For<ICommand>();
            command2.When(command => command.Execute()).Do((info) => result += "2");

            var command3 = Substitute.For<ICommand>();
            command3.When(command => command.Execute()).Do((info) => result += "3");

            IMacroCommand macroCommand = new MacroCommand()
            {
                command1,
                command2,
                command3
            };

            macroCommand.Execute();
            Assert.AreEqual(result, "123");
        }
예제 #36
0
 public void Commands_EmptyWhenCreated()
 {
     MacroCommand command = new MacroCommand();
     Assert.IsNotNull(command.Commands);
     Assert.IsEmpty(command.Commands);
 }
예제 #37
0
 public void Add_NullCommand_Exception()
 {
     MacroCommand macro = new MacroCommand();
     Assert.Catch<ArgumentException>(() => macro.Add(null));
 }