src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/Diagram/DSLDesignerNavigationHelper.cs
/// <summary>
///     Given an EFObject, return collection of DiagramItems for it.
/// </summary>
Given an EFObject, return collection of DiagramItems for it.
Given an EFObject return collection of DiagramItems for it .
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
        [SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        private static void RetrieveDiagramItemCollectionForEFObject(
            EntityDesignerDiagram diagram, EFObject efobject, DiagramItemCollection diagramItemCollection)
        {
            if (efobject == null)
            {
                return;
            }
            var cModel = efobject.RuntimeModelRoot() as ConceptualEntityModel;
            if (cModel == null)
            {
                return;
            }
            if (!(efobject is Association))
            {
                var association = efobject.GetParentOfType(typeof(Association)) as Association;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }
            if (efobject is Association)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is NavigationProperty)
            {
                var np = efobject as NavigationProperty;
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, np.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;
                if (entityTypeShape != null)
                {
                    var vmNavProp = diagram.ModelElement.ModelXRef.GetExisting(np) as ViewModel.NavigationProperty;
                    if (vmNavProp != null)
                    {
                        var index = entityTypeShape.NavigationCompartment.Items.IndexOf(vmNavProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.NavigationCompartment, entityTypeShape.NavigationCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is Property)
            {
                var prop = efobject as Property;
                if (prop.IsComplexTypeProperty)
                {
                    return;
                }
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, prop.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;
                if (entityTypeShape != null)
                {
                    var vmProp = diagram.ModelElement.ModelXRef.GetExisting(prop) as ViewModel.Property;
                    if (vmProp != null)
                    {
                        var index = entityTypeShape.PropertiesCompartment.Items.IndexOf(vmProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.PropertiesCompartment, entityTypeShape.PropertiesCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is EntityType)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is EntitySet)
            {
                var es = efobject as EntitySet;
                foreach (var entityType in es.GetEntityTypesInTheSet())
                {
                    if (entityType != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, entityType, diagramItemCollection);
                    }
                }
                return;
            }
            else if (efobject is AssociationSet)
            {
                var associationSet = efobject as AssociationSet;
                var association = associationSet.Association.Target;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is AssociationSetEnd)
            {
                var associationSetEnd = efobject as AssociationSetEnd;
                var end = associationSetEnd.Role.Target;
                if (end != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, end, diagramItemCollection);
                    return;
                }
                else
                {
                    var es = associationSetEnd.EntitySet.Target;
                    if (es != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, es, diagramItemCollection);
                        return;
                    }
                }
            }
            else if (efobject is PropertyRef)
            {
                var pref = efobject as PropertyRef;
                if (pref.Name.Target != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref.Name.Target, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is PropertyRefContainer)
            {
                var prefContainer = efobject as PropertyRefContainer;
                foreach (var pref in prefContainer.PropertyRefs)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is EFAttribute)
            {
                RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                return;
            }
            else if (efobject is ConceptualEntityModel)
            {
                return;
            }
            else if (efobject is ConceptualEntityContainer)
            {
                return;
            }
            else if (efobject is FunctionImport)
            {
                return;
            }
            else
            {
                Debug.Fail("unexpected type of efobject.  type = " + efobject.GetType());
                if (efobject.Parent != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] [ SuppressMessage ( " " , " " ) ] [ SuppressMessage ( " " , " " ) ] private static void RetrieveDiagramItemCollectionForEFObject ( EntityDesignerDiagram diagram , EFObject efobject , DiagramItemCollection diagramItemCollection ) { if ( efobject == null ) { return ; } var cModel = efobject . RuntimeModelRoot ( ) as ConceptualEntityModel ; if ( cModel == null ) { return ; } if ( ! ( efobject is Association ) ) { var association = efobject . GetParentOfType ( typeof ( Association ) ) as Association ; if ( association != null ) { RetrieveDiagramItemCollectionForEFObject ( diagram , association , diagramItemCollection ) ; return ; } } if ( efobject is Association ) { var shapeElement = GetDesignerShapeElementForEFObject ( diagram , efobject ) ; if ( shapeElement != null ) { diagramItemCollection . Add ( new DiagramItem ( shapeElement ) ) ; return ; } } else if ( efobject is NavigationProperty ) { var np = efobject as NavigationProperty ; var shapeElement = GetDesignerShapeElementForEFObject ( diagram , np . Parent ) ; var entityTypeShape = shapeElement as EntityTypeShape ; if ( entityTypeShape != null ) { var vmNavProp = diagram . ModelElement . ModelXRef . GetExisting ( np ) as ViewModel . NavigationProperty ; if ( vmNavProp != null ) { var index = entityTypeShape . NavigationCompartment . Items . IndexOf ( vmNavProp ) ; if ( index >= 0 ) { diagramItemCollection . Add ( new DiagramItem ( entityTypeShape . NavigationCompartment , entityTypeShape . NavigationCompartment . ListField , new ListItemSubField ( index ) ) ) ; return ; } } } } else if ( efobject is Property ) { var prop = efobject as Property ; if ( prop . IsComplexTypeProperty ) { return ; } var shapeElement = GetDesignerShapeElementForEFObject ( diagram , prop . Parent ) ; var entityTypeShape = shapeElement as EntityTypeShape ; if ( entityTypeShape != null ) { var vmProp = diagram . ModelElement . ModelXRef . GetExisting ( prop ) as ViewModel . Property ; if ( vmProp != null ) { var index = entityTypeShape . PropertiesCompartment . Items . IndexOf ( vmProp ) ; if ( index >= 0 ) { diagramItemCollection . Add ( new DiagramItem ( entityTypeShape . PropertiesCompartment , entityTypeShape . PropertiesCompartment . ListField , new ListItemSubField ( index ) ) ) ; return ; } } } } else if ( efobject is EntityType ) { var shapeElement = GetDesignerShapeElementForEFObject ( diagram , efobject ) ; if ( shapeElement != null ) { diagramItemCollection . Add ( new DiagramItem ( shapeElement ) ) ; return ; } } else if ( efobject is EntitySet ) { var es = efobject as EntitySet ; foreach ( var entityType in es . GetEntityTypesInTheSet ( ) ) { if ( entityType != null ) { RetrieveDiagramItemCollectionForEFObject ( diagram , entityType , diagramItemCollection ) ; } } return ; } else if ( efobject is AssociationSet ) { var associationSet = efobject as AssociationSet ; var association = associationSet . Association . Target ; if ( association != null ) { RetrieveDiagramItemCollectionForEFObject ( diagram , association , diagramItemCollection ) ; return ; } } else if ( efobject is AssociationSetEnd ) { var associationSetEnd = efobject as AssociationSetEnd ; var end = associationSetEnd . Role . Target ; if ( end != null ) { RetrieveDiagramItemCollectionForEFObject ( diagram , end , diagramItemCollection ) ; return ; } else { var es = associationSetEnd . EntitySet . Target ; if ( es != null ) { RetrieveDiagramItemCollectionForEFObject ( diagram , es , diagramItemCollection ) ; return ; } } } else if ( efobject is PropertyRef ) { var pref = efobject as PropertyRef ; if ( pref . Name . Target != null ) { RetrieveDiagramItemCollectionForEFObject ( diagram , pref . Name . Target , diagramItemCollection ) ; return ; } } else if ( efobject is PropertyRefContainer ) { var prefContainer = efobject as PropertyRefContainer ; foreach ( var pref in prefContainer . PropertyRefs ) { RetrieveDiagramItemCollectionForEFObject ( diagram , pref , diagramItemCollection ) ; return ; } } else if ( efobject is EFAttribute ) { RetrieveDiagramItemCollectionForEFObject ( diagram , efobject . Parent , diagramItemCollection ) ; return ; } else if ( efobject is ConceptualEntityModel ) { return ; } else if ( efobject is ConceptualEntityContainer ) { return ; } else if ( efobject is FunctionImport ) { return ; } else { Debug . Fail ( " " + efobject . GetType ( ) ) ; if ( efobject . Parent != null ) { RetrieveDiagramItemCollectionForEFObject ( diagram , efobject . Parent , diagramItemCollection ) ; } } }
Given an EFObject, return collection of DiagramItems for it.
Given an EFObject return collection of DiagramItems for it .
// this either isn't a c-space object, or it is the ConceptualEntityModel node, so just return null // if this is a child element of the association, return the diagram item for the association // get the view model navigation property // try to create the DiagramItem from this // complex type properties are not supported in the designer // get the view model  property // return a diagram item for the association // just use the first entry in the list. // this is an EFAttribute node, so get the DiagramItem for the parent // nothing in the DSL surface to map to, so return null // nothing in the DSL surface to map to, so return null // nothing in the DSL surface to map to, so return null
diagram
EntityDesignerDiagram
efobject
EFObject
diagramItemCollection
DiagramItemCollection