public void SingleCommand_Execute_NoError() { _macroCommand.AddCommand(_waitableCommand); _macroCommand.Execute(new object()); Assert.IsTrue(_waitableCommand.IsDoneWasRaised); }
public void SyncronousMacroCommand() { var cmdNoop = new DelegateCommand(() => 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 = false; var contextObj = new { Val1 = 2, Val2 = 5, Result = -1 }; var cmdRes = cmdMacro.Execute(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) { 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(); } }
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(); }
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(); }
// これが無いと、最小化から戻したときなどに、再描画されない。 private void DrawCanvas_Paint(object sender, PaintEventArgs e) { if (history != null) { history.Execute(); } }
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(); }
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(); }
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(); }
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(); } }
public override void Execute(object parameter) { IEnumerable <PSMComponent> components = Current.ActiveDiagramView.GetSelectedComponents().Where(c => !(c is PSMSchemaClass)).Cast <PSMComponent>(); bool found = true; IEnumerable <PSMComponent> current = components; while (found) { found = false; List <PSMComponent> next = new List <PSMComponent>(); foreach (PSMComponent c in current) { if (current.Any(co => co != c && c.IsDescendantFrom(co))) { found = true; } else { next.Add(c); } } current = next; } IEnumerable <PSMAssociation> associations = current.Where(c => c is PSMAssociation).Cast <PSMAssociation>(); IEnumerable <PSMAssociationMember> associationMembers = current.Where(c2 => (!(c2 is PSMSchemaClass) && (c2 is PSMAssociationMember))).Cast <PSMAssociationMember>(); IEnumerable <PSMAssociationMember> roots = associationMembers.Where(am => am.ParentAssociation == null); IEnumerable <PSMAssociation> nonrootAssociations = associationMembers.Where(am => am.ParentAssociation != null).Select(am2 => am2.ParentAssociation); IEnumerable <PSMAttribute> attributes = current.Where(c => c is PSMAttribute).Cast <PSMAttribute>(); MacroCommand macro = new MacroCommand(Current.Controller) { CheckFirstOnlyInCanExecute = true }; foreach (PSMAssociation a in associations.Union(nonrootAssociations)) { macro.Commands.Add(new cmdDeletePSMAssociationRecursive(Current.Controller) { AssociationGuid = a }); } foreach (PSMAssociationMember am in roots) { macro.Commands.Add(new cmdDeletePSMAssociationMemberRecursive(Current.Controller) { AssociationMemberGuid = am }); } foreach (PSMAttribute a in attributes) { macro.Commands.Add(new cmdDeletePSMAttribute(Current.Controller) { AttributeGuid = a }); } macro.Execute(); }
/// <summary> /// Executes all commands stored after the <see cref="BeginMacro"/> call /// </summary> public void CommitMacro() { MacroCommand tmp = CreatedMacro; CreatedMacro = null; if (tmp.Commands.Count > 0) { tmp.Execute(); } }
public override void Execute(object parameter) { IEnumerable <PSMComponent> components = Current.ActiveDiagramView.GetSelectedComponents().Where(c => !(c is PSMSchemaClass)).Cast <PSMComponent>(); IEnumerable <PSMAssociation> associations = components.Where(c => c is PSMAssociation).Cast <PSMAssociation>(); IEnumerable <PSMAssociationMember> associationMembers = components.Where(c2 => (!(c2 is PSMSchemaClass) && (c2 is PSMAssociationMember))).Cast <PSMAssociationMember>(); IEnumerable <PSMAssociation> nonrootAssociations = associationMembers.Where(am => am.ParentAssociation != null).Select(am2 => am2.ParentAssociation); IEnumerable <PSMAttribute> attributes = components.Where(c => c is PSMAttribute).Cast <PSMAttribute>(); IEnumerable <PSMGeneralization> generalizations = components.Where(c => c is PSMGeneralization).Cast <PSMGeneralization>(); MacroCommand macro = new MacroCommand(Current.Controller) { CheckFirstOnlyInCanExecute = true }; foreach (PSMGeneralization g in generalizations) { macro.Commands.Add(new Exolutio.Controller.Commands.Atomic.PSM.MacroWrappers.cmdDeletePSMGeneralization(Current.Controller) { GeneralizationGuid = g }); } foreach (PSMAssociation a in associations.Union(nonrootAssociations)) { macro.Commands.Add(new cmdDeletePSMAssociation(Current.Controller) { AssociationGuid = a }); } foreach (PSMAssociationMember am in associationMembers) { if (am is PSMContentModel) { macro.Commands.Add(new cmdDeleteRootPSMContentModel(Current.Controller) { ContentModelGuid = am }); } else { macro.Commands.Add(new cmdDeleteRootPSMClass(Current.Controller) { ClassGuid = am }); } } foreach (PSMAttribute a in attributes) { macro.Commands.Add(new cmdDeletePSMAttribute(Current.Controller) { AttributeGuid = a }); } macro.Execute(); }
public override void Execute(object parameter) { IEnumerable <PIMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMAssociation).Cast <PIMAssociation>(); MacroCommand macro = new MacroCommand(Current.Controller); foreach (PIMAssociation a in selectedAssociations) { macro.Commands.Add(new Exolutio.Controller.Commands.Complex.PIM.cmdDeletePIMAssociation(Current.Controller) { AssociationGuid = a }); } macro.Execute(); }
public override void Execute(object parameter) { IEnumerable <PSMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PSMAssociation).Cast <PSMAssociation>(); MacroCommand command = new MacroCommand(Current.Controller); foreach (PSMAssociation a in selectedAssociations) { command.Commands.Add(new cmdSplitPSMAssociation(Current.Controller) { PSMAssociationGuid = a, Count = Count }); } command.Execute(); }
public override void Execute(object parameter) { IEnumerable <PIMAttribute> selectedAttributes = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMAttribute).Cast <PIMAttribute>(); MacroCommand command = new MacroCommand(Current.Controller); foreach (PIMAttribute a in selectedAttributes) { command.Commands.Add(new cmdSplitPIMAttribute(Current.Controller) { PIMAttributeGuid = a, Count = Count }); } command.Execute(); }
public override void Execute(object parameter) { IEnumerable <PIMClass> selectedClasses = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMClass).Cast <PIMClass>(); MacroCommand macro = new MacroCommand(Current.Controller); foreach (PIMClass c in selectedClasses) { macro.Commands.Add(new Exolutio.Controller.Commands.Complex.PIM.cmdDeletePIMClass(Current.Controller) { ClassGuid = c }); } macro.Execute(); }
public override void Execute(object parameter) { IEnumerable <PIMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMAssociation).Cast <PIMAssociation>(); IEnumerable <PIMAttribute> selectedAttributes = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMAttribute).Cast <PIMAttribute>(); IEnumerable <PIMClass> selectedClasses = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMClass).Cast <PIMClass>(); IEnumerable <PIMGeneralization> selectedGeneralizations = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMGeneralization).Cast <PIMGeneralization>(); MacroCommand macro = new MacroCommand(Current.Controller) { CheckFirstOnlyInCanExecute = true }; foreach (PIMAssociation a in selectedAssociations) { macro.Commands.Add(new Exolutio.Controller.Commands.Complex.PIM.cmdDeletePIMAssociation(Current.Controller) { AssociationGuid = a }); } foreach (PIMAttribute a in selectedAttributes) { macro.Commands.Add(new Exolutio.Controller.Commands.Complex.PIM.cmdDeletePIMAttribute(Current.Controller) { AttributeGuid = a }); } foreach (PIMGeneralization g in selectedGeneralizations) { macro.Commands.Add(new Exolutio.Controller.Commands.Complex.PIM.cmdDeletePIMGeneralization(Current.Controller) { GeneralizationGuid = g }); } foreach (PIMClass c in selectedClasses) { macro.Commands.Add(new Exolutio.Controller.Commands.Complex.PIM.cmdDeletePIMClass(Current.Controller) { ClassGuid = c }); } macro.Execute(); }
public override void Execute(object parameter) { IEnumerable <PIMAttribute> selectedAttributes = Current.ActiveDiagramView.GetSelectedComponents() .Where(c => c is PIMAttribute).Cast <PIMAttribute>(); MacroCommand macro = new MacroCommand(Current.Controller); foreach (PIMAttribute a in Up ? selectedAttributes.OrderBy(a => a.PIMClass.PIMAttributes.IndexOf(a)) : selectedAttributes.OrderByDescending(a => a.PIMClass.PIMAttributes.IndexOf(a))) { macro.Commands.Add(new cmdShiftPIMAttribute(Current.Controller) { AttributeGuid = a, Up = Up }); } macro.Execute(); }
public override void Execute(object parameter) { Element element; MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller); command.Description = CommandDescription.ADD_OPERATION; foreach (ISelectable item in ActiveDiagramView.SelectedItems) { if (item is XCaseViewBase && (element = (item as XCaseViewBase).Controller.Element) is IHasOperations) { NewOperationCommand c = NewOperationCommandFactory.Factory().Create(ActiveDiagramView.Controller.ModelController) as NewOperationCommand; c.Owner = element as IHasOperations; c.Name = NameSuggestor <Operation> .SuggestUniqueName((element as IHasOperations).Operations, "Operation", property => property.Name); command.Commands.Add(c); } } if (command.Commands.Count > 0) { command.Execute(); } }
public override void Execute(object parameter) { Element element; MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller); command.Description = CommandDescription.ADD_PSM_ATTRIBUTE; foreach (ISelectable item in ActiveDiagramView.SelectedItems) { if (item is PSM_Class && (element = (item as PSM_Class).Controller.Element) is PSMClass) { AddPSMClassAttributeCommand c = AddPSMClassAttributeCommandFactory.Factory().Create(ActiveDiagramView.Controller) as AddPSMClassAttributeCommand; c.PSMClass = (PSMClass)element; c.Name = NameSuggestor <PSMAttribute> .SuggestUniqueName(((PSMClass)element).PSMAttributes, "FreeAttribute", property => property.AliasOrName); command.Commands.Add(c); } } if (command.Commands.Count > 0) { command.Execute(); } }
/// <summary> /// Finalizes the resizing process, issues the resize command (see <see cref="ResizeElementCommand"/>). /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Controls.Primitives.DragCompletedEventArgs"/> instance containing the event data.</param> void ResizeThumb_DragCompleted(object sender, DragCompletedEventArgs e) { Control designerItem = this.belongsTo; XCaseCanvas designer = VisualTreeHelper.GetParent(designerItem) as XCaseCanvas; if (designer != null) { MacroCommand <DiagramController> macroResize = MacroCommandFactory <DiagramController> .Factory().Create(designer.Controller); macroResize.Description = CommandDescription.RESIZE_MACRO; // generate move Commands for all resized elements and execute them as macro foreach (Control item in designer.SelectedItems.OfType <IResizable>()) { item.Width = startSizes[item].Width; item.Height = startSizes[item].Height; CommandBase command = ViewController.CreateResizeCommand(item.ActualWidth, item.ActualHeight, ((IResizable)item).ViewHelper, designer.Controller); macroResize.Commands.Add(command); } macroResize.Execute(); } }
public void paint(Graphics g) { history.Execute(); }
/// <summary> /// 重绘时 直接添加的所有命令 /// </summary> protected override void OnCreateControl() { //要持有之前的所有命令记录,才能执行历史命令 _history.Execute(); }
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"); }
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"); }
/// <summary> /// Drags the completed. /// </summary> /// <param name="finalPoint">The final point.</param> /// <param name="totalShift">The total shift.</param> protected virtual void DragCompleted(Point finalPoint, Vector totalShift) { if (visualAidsAdorner != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(XCaseCanvas); adornerLayer.Remove(visualAidsAdorner); visualAidsAdorner = null; } if (DragStartPoint != finalPoint) { DiagramController controller = XCaseCanvas.Controller; MacroCommand <DiagramController> moveMacroCommand = MacroCommandFactory <DiagramController> .Factory().Create(controller); moveMacroCommand.Description = CommandDescription.MOVE_MACRO; JunctionPointCommand.PointMoveDataDictionary pointMoveDataCollection = null; foreach (KeyValuePair <DragThumb, rPoint> pair in startPositions) { if (pair.Key is IAlignable) { IAlignable element = (IAlignable)pair.Key; DragThumb dragThumb = element as DragThumb; double _x; double _y; if (dragThumb != null && dragThumb.Placement == EPlacementKind.RelativeCanvas) { _x = dragThumb.Left - dragThumb.ReferentialElement.CanvasPosition.X; _y = dragThumb.Top - dragThumb.ReferentialElement.CanvasPosition.Y; } else { _x = element.Left; _y = element.Top; } CommandBase command = ViewController.CreateMoveCommand( _x, _y, element.ViewHelper, controller); moveMacroCommand.Commands.Add(command); } else if (pair.Key is JunctionPoint) { JunctionPoint junctionPoint = (JunctionPoint)pair.Key; JunctionPointCommand.PointMoveData data = new JunctionPointCommand.PointMoveData { Index = junctionPoint.OrderInJunction, OldPosition = pair.Value, NewPosition = new rPoint(junctionPoint.Position) { tag = junctionPoint.Placement }, }; if (pointMoveDataCollection == null) { pointMoveDataCollection = new JunctionPointCommand.PointMoveDataDictionary(); } if (!pointMoveDataCollection.ContainsKey(junctionPoint.Junction.viewHelperPointsCollection)) { pointMoveDataCollection[junctionPoint.Junction.viewHelperPointsCollection] = new List <JunctionPointCommand.PointMoveData>(); } pointMoveDataCollection[junctionPoint.Junction.viewHelperPointsCollection].Add(data); } } // add one command for each affected junction if (pointMoveDataCollection != null) { JunctionPointCommand junctionPointCommand = (JunctionPointCommand)JunctionPointCommandFactory.Factory().Create(controller); junctionPointCommand.Action = JunctionPointCommand.EJunctionPointAction.MovePoints; junctionPointCommand.PointMoveDataCollection = pointMoveDataCollection; junctionPointCommand.Description = CommandDescription.MOVE_JUNCTION_POINTS; moveMacroCommand.Commands.Add(junctionPointCommand); } moveMacroCommand.Execute(); if (Dropped != null) { Dropped(); } } }