internal static void StaticInvoke(CommandProcessorContext cpc, AssociationConnector associationConnector) { var viewModel = associationConnector.GetRootViewModel(); Debug.Assert( viewModel != null, "Unable to find root view model from association connector: " + associationConnector.AccessibleName); if (viewModel != null) { var modelAssociation = viewModel.ModelXRef.GetExisting(associationConnector.ModelElement) as Association; var modelDiagram = viewModel.ModelXRef.GetExisting(associationConnector.Diagram) as Diagram; Debug.Assert(modelAssociation != null && modelDiagram != null); if (modelAssociation != null && modelDiagram != null) { var cmd = new CreateAssociationConnectorCommand(modelDiagram, modelAssociation); CommandProcessor.InvokeSingleCommand(cpc, cmd); var modelAssociationConnector = cmd.AssociationConnector; Debug.Assert(modelAssociationConnector != null); viewModel.ModelXRef.Add(modelAssociationConnector, associationConnector, viewModel.EditingContext); } } }
private static void InjectAssociationConnectorCommand( CommandProcessorContext commandProcessorContext, HashSet<ShapeChangeInformation> shapeChangeInfoSet, Diagram diagram, Association association, XObjectChange changeAction) { // First check to see if there is already a change in the original transaction // for the AssociationConnector that matches the one that we're getting var shapeChangeInfoToQuery = new ShapeChangeInformation { ChangeType = changeAction, ModelEFObject = association, DiagramId = diagram.Id.Value }; var shapeChangeInfoExists = shapeChangeInfoSet.Contains(shapeChangeInfoToQuery); // We only want to create model diagram if the transaction is originated from this diagram. if (changeAction == XObjectChange.Add && shapeChangeInfoExists == false) { // The association connector is added if // - the participating entities are in the diagram. // or // - the participating entities will be added in the current transaction. foreach (var end in association.AssociationEnds()) { if (end.Type != null && end.Type.Target != null) { if (diagram.EntityTypeShapes.Where(ets => ets.EntityType.Target == end.Type.Target).Any() || shapeChangeInfoSet.Where( sc => sc.DiagramId == diagram.Id.Value && sc.ModelEFObject == end.Type.Target && sc.ChangeType == XObjectChange.Add).Any()) { continue; } } // If it reach this point, that means that we should not add association connector in the diagram. return; } var cmd = new CreateAssociationConnectorCommand(diagram, association); CommandProcessor.InvokeSingleCommand(commandProcessorContext, cmd); } else if (changeAction == XObjectChange.Remove && shapeChangeInfoExists == false) { // this is happening before the transaction is taking place so we are free to look up anti-dependencies on this delete foreach ( var associationConnector in association.GetAntiDependenciesOfType<AssociationConnector>() .Where(ac => ac.Diagram != null && ac.Diagram.Id == diagram.Id.Value)) { if (associationConnector != null) { var deleteAssociationConnectorCommand = associationConnector.GetDeleteCommand(); CommandProcessor.InvokeSingleCommand(commandProcessorContext, deleteAssociationConnectorCommand); } } } }