src/Misc/EFTools/EntityDesignModel/Commands/CreateEntityTypeShapeCommand.cs
/// <summary>
///     The method do the following:
///     - Create the shape for the entity-type in diagram.
///     - Create association and inheritance connectors for the entity type shape and all entity type shapes in the diagram.
///     - If createRelatedEntityTypeShapes flag is set to true, it will also create all directly related entity-type-shapes not in the diagram.
/// </summary>
The method do the following:
Create the shape for the entity-type in diagram.
Create association and inheritance connectors for the entity type shape and all entity type shapes in the diagram.
If createRelatedEntityTypeShapes flag is set to true, it will also create all directly related entity-type-shapes not in the diagram.
The method do the following : Create the shape for the entity - type in diagram . Create association and inheritance connectors for the entity type shape and all entity type shapes in the diagram . If createRelatedEntityTypeShapes flag is set to true it will also create all directly related entity - type - shapes not in the diagram .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        internal static void CreateEntityTypeShapeAndConnectorsInDiagram(
            CommandProcessorContext cpc, Diagram diagram, ConceptualEntityType entity, Color entityTypeShapeFillColor,
            bool createRelatedEntityTypeShapes)
        {
            if (entity == null
                || entity.GetAntiDependenciesOfType<EntityTypeShape>().Count(ets => ets.Diagram.Id == diagram.Id.Value) > 0)
            {
                return;
            }
            var createEntityTypeShapecommand = new CreateEntityTypeShapeCommand(diagram, entity, entityTypeShapeFillColor);
            createEntityTypeShapecommand.PostInvokeEvent += (o, eventsArgs) =>
                {
                    if (createEntityTypeShapecommand.EntityTypeShape != null)
                    {
                        var relatedEntityTypesNotInDiagram = new List<EntityType>();
                        var entityTypesInDiagram = new HashSet<EntityType>(diagram.EntityTypeShapes.Select(ets => ets.EntityType.Target));
                        if (entity.SafeBaseType != null)
                        {
                            if (entityTypesInDiagram.Contains(entity.SafeBaseType))
                            {
                                CommandProcessor.InvokeSingleCommand(cpc, new CreateInheritanceConnectorCommand(diagram, entity));
                            }
                            else
                            {
                                relatedEntityTypesNotInDiagram.Add(entity.SafeBaseType);
                            }
                        }
                        foreach (var derivedEntityType in entity.ResolvableDirectDerivedTypes)
                        {
                            if (entityTypesInDiagram.Contains(derivedEntityType))
                            {
                                CommandProcessor.InvokeSingleCommand(cpc, new CreateInheritanceConnectorCommand(diagram, derivedEntityType));
                            }
                            else
                            {
                                relatedEntityTypesNotInDiagram.Add(derivedEntityType);
                            }
                        }
                        var participatingAssociations = Association.GetAssociationsForEntityType(entity);
                        foreach (var association in participatingAssociations)
                        {
                            var entityTypesInAssociation = association.AssociationEnds().Select(ae => ae.Type.Target).ToList();
                            var entityTypesNotInDiagram = entityTypesInAssociation.Except(entityTypesInDiagram).ToList();
                            if (entityTypesNotInDiagram.Count == 0)
                            {
                                CommandProcessor.InvokeSingleCommand(cpc, new CreateAssociationConnectorCommand(diagram, association));
                            }
                            relatedEntityTypesNotInDiagram.AddRange(entityTypesNotInDiagram);
                        }
                        if (createRelatedEntityTypeShapes)
                        {
                            foreach (var entityType in relatedEntityTypesNotInDiagram)
                            {
                                CreateEntityTypeShapeAndConnectorsInDiagram(
                                    cpc, diagram, entityType as ConceptualEntityType, entityTypeShapeFillColor, false);
                            }
                        }
                    }
                };
            CommandProcessor.InvokeSingleCommand(cpc, createEntityTypeShapecommand);
        }
[ SuppressMessage ( " " , " " ) ] internal static void CreateEntityTypeShapeAndConnectorsInDiagram ( CommandProcessorContext cpc , Diagram diagram , ConceptualEntityType entity , Color entityTypeShapeFillColor , bool createRelatedEntityTypeShapes ) { if ( entity == null || entity . GetAntiDependenciesOfType < EntityTypeShape > ( ) . Count ( ets => ets . Diagram . Id == diagram . Id . Value ) > 0 ) { return ; } var createEntityTypeShapecommand = new CreateEntityTypeShapeCommand ( diagram , entity , entityTypeShapeFillColor ) ; createEntityTypeShapecommand . PostInvokeEvent += ( o , eventsArgs ) => { if ( createEntityTypeShapecommand . EntityTypeShape != null ) { var relatedEntityTypesNotInDiagram = new List < EntityType > ( ) ; var entityTypesInDiagram = new HashSet < EntityType > ( diagram . EntityTypeShapes . Select ( ets => ets . EntityType . Target ) ) ; if ( entity . SafeBaseType != null ) { if ( entityTypesInDiagram . Contains ( entity . SafeBaseType ) ) { CommandProcessor . InvokeSingleCommand ( cpc , new CreateInheritanceConnectorCommand ( diagram , entity ) ) ; } else { relatedEntityTypesNotInDiagram . Add ( entity . SafeBaseType ) ; } } foreach ( var derivedEntityType in entity . ResolvableDirectDerivedTypes ) { if ( entityTypesInDiagram . Contains ( derivedEntityType ) ) { CommandProcessor . InvokeSingleCommand ( cpc , new CreateInheritanceConnectorCommand ( diagram , derivedEntityType ) ) ; } else { relatedEntityTypesNotInDiagram . Add ( derivedEntityType ) ; } } var participatingAssociations = Association . GetAssociationsForEntityType ( entity ) ; foreach ( var association in participatingAssociations ) { var entityTypesInAssociation = association . AssociationEnds ( ) . Select ( ae => ae . Type . Target ) . ToList ( ) ; var entityTypesNotInDiagram = entityTypesInAssociation . Except ( entityTypesInDiagram ) . ToList ( ) ; if ( entityTypesNotInDiagram . Count == 0 ) { CommandProcessor . InvokeSingleCommand ( cpc , new CreateAssociationConnectorCommand ( diagram , association ) ) ; } relatedEntityTypesNotInDiagram . AddRange ( entityTypesNotInDiagram ) ; } if ( createRelatedEntityTypeShapes ) { foreach ( var entityType in relatedEntityTypesNotInDiagram ) { CreateEntityTypeShapeAndConnectorsInDiagram ( cpc , diagram , entityType as ConceptualEntityType , entityTypeShapeFillColor , false ) ; } } } } ; CommandProcessor . InvokeSingleCommand ( cpc , createEntityTypeShapecommand ) ; }
The method do the following:
 Create the shape for the entity-type in diagram.
The method do the following : Create the shape for the entity - type in diagram .
// if the entity type shape has been created, return immediately. // add inheritance connector if the base type exists in the diagram. // add the inheritance connector if the derived type exist in the diagram. // Find all associations which the entity type participates. // we only want to bring entity-type directly related to the entity-type, so set createRelatedEntityTypeShapes flag to false.
cpc
CommandProcessorContext
diagram
Diagram
entity
ConceptualEntityType
entityTypeShapeFillColor
Color
createRelatedEntityTypeShapes
bool