private static void InjectInheritanceConnectorCommand( CommandProcessorContext commandProcessorContext, HashSet <ShapeChangeInformation> shapeChangeInfoSet, Diagram diagram, EntityTypeBaseType baseType, XObjectChange changeAction) { // First check to see if there is already a change in the original transaction // for the InheritanceConnector that matches the one that we're getting var shapeChangeInfoToQuery = new ShapeChangeInformation { ChangeType = changeAction, ModelEFObject = baseType.OwnerEntityType, DiagramId = diagram.Id.Value }; var shapeChangeInfoExists = shapeChangeInfoSet.Contains(shapeChangeInfoToQuery); if (changeAction == XObjectChange.Add && shapeChangeInfoExists == false) { var participatingEntityTypes = new List <EntityType>(); var derivedEntityType = baseType.Parent as EntityType; Debug.Assert(derivedEntityType != null, "Where is the parent EntityType of this BaseType attribute?"); if (derivedEntityType != null) { // The inheritance connector is added if // - the participating entities exists in the diagram. // or // - the participating entities will be added in the current transaction. participatingEntityTypes.Add(derivedEntityType); participatingEntityTypes.Add(((ConceptualEntityType)derivedEntityType).BaseType.Target); foreach (var entityType in participatingEntityTypes) { if (diagram.EntityTypeShapes.Where(ets => ets.EntityType.Target == entityType).Any() || shapeChangeInfoSet.Where( sc => sc.DiagramId == diagram.Id.Value && sc.ModelEFObject == entityType && sc.ChangeType == XObjectChange.Add) .Any()) { continue; } // If it reach this point, that means that we should not add inheritance connector in the diagram. return; } var cmd = new CreateInheritanceConnectorCommand(diagram, derivedEntityType); 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 var owningEntityType = baseType.Parent as EntityType; if (owningEntityType != null) { foreach ( var inheritanceConnector in owningEntityType.GetAntiDependenciesOfType <InheritanceConnector>() .Where(ic => ic.Diagram != null && ic.Diagram.Id == diagram.Id.Value)) { if (inheritanceConnector != null) { var deleteInheritanceConnectorCommand = inheritanceConnector.GetDeleteCommand(); CommandProcessor.InvokeSingleCommand(commandProcessorContext, deleteInheritanceConnectorCommand); } } } } }
private static void InjectInheritanceConnectorCommand( CommandProcessorContext commandProcessorContext, HashSet<ShapeChangeInformation> shapeChangeInfoSet, Diagram diagram, EntityTypeBaseType baseType, XObjectChange changeAction) { // First check to see if there is already a change in the original transaction // for the InheritanceConnector that matches the one that we're getting var shapeChangeInfoToQuery = new ShapeChangeInformation { ChangeType = changeAction, ModelEFObject = baseType.OwnerEntityType, DiagramId = diagram.Id.Value }; var shapeChangeInfoExists = shapeChangeInfoSet.Contains(shapeChangeInfoToQuery); if (changeAction == XObjectChange.Add && shapeChangeInfoExists == false) { var participatingEntityTypes = new List<EntityType>(); var derivedEntityType = baseType.Parent as EntityType; Debug.Assert(derivedEntityType != null, "Where is the parent EntityType of this BaseType attribute?"); if (derivedEntityType != null) { // The inheritance connector is added if // - the participating entities exists in the diagram. // or // - the participating entities will be added in the current transaction. participatingEntityTypes.Add(derivedEntityType); participatingEntityTypes.Add(((ConceptualEntityType)derivedEntityType).BaseType.Target); foreach (var entityType in participatingEntityTypes) { if (diagram.EntityTypeShapes.Where(ets => ets.EntityType.Target == entityType).Any() || shapeChangeInfoSet.Where( sc => sc.DiagramId == diagram.Id.Value && sc.ModelEFObject == entityType && sc.ChangeType == XObjectChange.Add) .Any()) { continue; } // If it reach this point, that means that we should not add inheritance connector in the diagram. return; } var cmd = new CreateInheritanceConnectorCommand(diagram, derivedEntityType); 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 var owningEntityType = baseType.Parent as EntityType; if (owningEntityType != null) { foreach ( var inheritanceConnector in owningEntityType.GetAntiDependenciesOfType<InheritanceConnector>() .Where(ic => ic.Diagram != null && ic.Diagram.Id == diagram.Id.Value)) { if (inheritanceConnector != null) { var deleteInheritanceConnectorCommand = inheritanceConnector.GetDeleteCommand(); CommandProcessor.InvokeSingleCommand(commandProcessorContext, deleteInheritanceConnectorCommand); } } } } }