src/Misc/EFTools/EntityDesignPackage/CustomCode/MicrosoftDataEntityDesignCommandSet.cs
/// <summary>
///     Event handler to create the related entity-types of the selected entity-type to a diagram.
/// </summary>
Event handler to create the related entity-types of the selected entity-type to a diagram.
Event handler to create the related entity - types of the selected entity - type to a diagram .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        internal void OnMenuIncludeRelatedEntityType(object sender, EventArgs e)
        {
            var diagram = GetDiagram();
            Debug.Assert(diagram != null, "There is no diagram selected");
            if (diagram != null)
            {
                var entityTypeShape = SingleSelection as EntityTypeShape;
                Debug.Assert(entityTypeShape != null, "EntityTypeShape is null.");
                if (entityTypeShape != null)
                {
                    var modelDiagram = diagram.ModelElement.ModelXRef.GetExisting(diagram) as Diagram;
                    Debug.Assert(modelDiagram != null, "Could not get the model diagram for diagram with title:" + diagram.Title);
                    var entityType = diagram.ModelElement.ModelXRef.GetExisting(entityTypeShape.ModelElement) as ModelEntity.EntityType;
                    Debug.Assert(entityType != null, "EntityType is null");
                    if (modelDiagram != null
                        && entityType != null)
                    {
                        var uri = Utils.FileName2Uri(CurrentDocData.FileName);
                        var editingContext = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(uri);
                        var cpc = new CommandProcessorContext(
                            editingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, Resources.Tx_IncludeRelatedEntityTypeShape);
                        var relatedEntityTypes = ModelHelper.GetRelatedEntityTypes(entityType);
                        IList<ModelEntity.EntityType> relatedEntityTypesNotInDiagram =
                            relatedEntityTypes.Except(modelDiagram.EntityTypeShapes.Select(ets => ets.EntityType.SafeTarget)).ToList();
                        if (relatedEntityTypesNotInDiagram.Count == 0)
                        {
                            return;
                        }
                        try
                        {
                            diagram.Arranger.Start(PointD.Empty);
                            var delegateCommand = new DelegateCommand(
                                () =>
                                    {
                                        foreach (var et in relatedEntityTypesNotInDiagram)
                                        {
                                            CreateEntityTypeShapeCommand.CreateEntityTypeShapeAndConnectorsInDiagram(
                                                cpc, modelDiagram, et as ModelEntity.ConceptualEntityType, entityTypeShape.FillColor, false);
                                        }
                                    });
                            CommandProcessor.InvokeSingleCommand(cpc, delegateCommand);
                        }
                        finally
                        {
                            diagram.Arranger.End();
                            diagram.EnsureSelectionVisible();
                        }
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] internal void OnMenuIncludeRelatedEntityType ( object sender , EventArgs e ) { var diagram = GetDiagram ( ) ; Debug . Assert ( diagram != null , " " ) ; if ( diagram != null ) { var entityTypeShape = SingleSelection as EntityTypeShape ; Debug . Assert ( entityTypeShape != null , " " ) ; if ( entityTypeShape != null ) { var modelDiagram = diagram . ModelElement . ModelXRef . GetExisting ( diagram ) as Diagram ; Debug . Assert ( modelDiagram != null , " " + diagram . Title ) ; var entityType = diagram . ModelElement . ModelXRef . GetExisting ( entityTypeShape . ModelElement ) as ModelEntity . EntityType ; Debug . Assert ( entityType != null , " " ) ; if ( modelDiagram != null && entityType != null ) { var uri = Utils . FileName2Uri ( CurrentDocData . FileName ) ; var editingContext = PackageManager . Package . DocumentFrameMgr . EditingContextManager . GetNewOrExistingContext ( uri ) ; var cpc = new CommandProcessorContext ( editingContext , EfiTransactionOriginator . EntityDesignerOriginatorId , Resources . Tx_IncludeRelatedEntityTypeShape ) ; var relatedEntityTypes = ModelHelper . GetRelatedEntityTypes ( entityType ) ; IList < ModelEntity . EntityType > relatedEntityTypesNotInDiagram = relatedEntityTypes . Except ( modelDiagram . EntityTypeShapes . Select ( ets => ets . EntityType . SafeTarget ) ) . ToList ( ) ; if ( relatedEntityTypesNotInDiagram . Count == 0 ) { return ; } try { diagram . Arranger . Start ( PointD . Empty ) ; var delegateCommand = new DelegateCommand ( ( ) => { foreach ( var et in relatedEntityTypesNotInDiagram ) { CreateEntityTypeShapeCommand . CreateEntityTypeShapeAndConnectorsInDiagram ( cpc , modelDiagram , et as ModelEntity . ConceptualEntityType , entityTypeShape . FillColor , false ) ; } } ) ; CommandProcessor . InvokeSingleCommand ( cpc , delegateCommand ) ; } finally { diagram . Arranger . End ( ) ; diagram . EnsureSelectionVisible ( ) ; } } } } }
Event handler to create the related entity-types of the selected entity-type to a diagram.
Event handler to create the related entity - types of the selected entity - type to a diagram .
// Find all related entity types. // Get all related entity types not in the diagram. // if there is no related EntityTypes just return.
sender
object
e
EventArgs