src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/CustomSerializer/EntityModelToDslModelTranslatorStrategy.cs
/// <summary>
///     This method assumes that the ShapeElement as well as the Designer EFObject already exist but they haven't been pushed
///     into the view model's XRef yet.
/// </summary>
This method assumes that the ShapeElement as well as the Designer EFObject already exist but they haven't been pushed
into the view model's XRef yet.
This method assumes that the ShapeElement as well as the Designer EFObject already exist but they haven ' t been pushed into the view model ' s XRef yet .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        internal static void TranslateDiagramObject(
            EntityDesignerViewModel viewModel, ModelDiagram.BaseDiagramObject modelDiagramObject,
            bool updateShapeElements, IList<ViewModelDiagram.ShapeElement> shapesToAutoLayout)
        {
            Debug.Assert(modelDiagramObject is EFObject, "Why did you define a DiagramEFObject that is not an EFObject?");
            var modelEntityTypeShape = modelDiagramObject as DesignerModel.EntityTypeShape;
            if (modelEntityTypeShape != null
                && modelEntityTypeShape.IsDisposed != true
                && modelEntityTypeShape.EntityType.Target != null
                && modelEntityTypeShape.EntityType.Target.IsDisposed != true)
            {
                TranslateDiagramObjectHelper(
                    viewModel, modelDiagramObject, modelEntityTypeShape.EntityType.Target, updateShapeElements,
                    shapeElement =>
                        {
                            var viewEntityTypeShape = shapeElement as EntityTypeShape;
                            var rectangle = new ViewModelDiagram.RectangleD(
                                modelEntityTypeShape.PointX.Value
                                , modelEntityTypeShape.PointY.Value, modelEntityTypeShape.Width.Value, 0.0);
                            viewEntityTypeShape.AbsoluteBounds = rectangle;
                            viewEntityTypeShape.IsExpanded = modelEntityTypeShape.IsExpanded.Value;
                            if (!shapesToAutoLayout.Contains(viewEntityTypeShape))
                            {
                                shapesToAutoLayout.Add(viewEntityTypeShape);
                            }
                            foreach (var linkShape in viewEntityTypeShape.Link)
                            {
                                if (linkShape.ManuallyRouted == false
                                    && shapesToAutoLayout.Contains(linkShape) == false)
                                {
                                    shapesToAutoLayout.Add(linkShape);
                                }
                            }
                        });
                var dslEntityTypeShape = viewModel.ModelXRef.GetExisting(modelEntityTypeShape) as EntityTypeShape;
                if (dslEntityTypeShape != null)
                {
                    dslEntityTypeShape.FillColor = modelEntityTypeShape.FillColor.Value;
                }
            }
            var modelAssociationConnectorShape = modelDiagramObject as DesignerModel.AssociationConnector;
            if (modelAssociationConnectorShape != null
                && modelAssociationConnectorShape.IsDisposed != true
                && modelAssociationConnectorShape.Association.Target != null
                && modelAssociationConnectorShape.Association.Target.IsDisposed != true)
            {
                TranslateDiagramObjectHelper(
                    viewModel, modelDiagramObject, modelAssociationConnectorShape.Association.Target, true,
                    shapeElement => TranslateAssociationConnectors(
                        shapeElement as AssociationConnector, modelAssociationConnectorShape, shapesToAutoLayout));
            }
            var modelInheritanceConnectorShape = modelDiagramObject as DesignerModel.InheritanceConnector;
            if (modelInheritanceConnectorShape != null
                && modelInheritanceConnectorShape.IsDisposed != true
                && modelInheritanceConnectorShape.EntityType.Target != null
                && modelInheritanceConnectorShape.EntityType.Target.IsDisposed != true)
            {
                var cet = modelInheritanceConnectorShape.EntityType.Target as ConceptualEntityType;
                if (cet != null
                    && cet.BaseType != null
                    && cet.BaseType.RefName != null)
                {
                    TranslateDiagramObjectHelper(
                        viewModel, modelDiagramObject, cet.BaseType, true,
                        shapeElement => TranslateInheritanceConnectors(
                            shapeElement as InheritanceConnector, modelInheritanceConnectorShape, shapesToAutoLayout));
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] [ SuppressMessage ( " " , " " ) ] internal static void TranslateDiagramObject ( EntityDesignerViewModel viewModel , ModelDiagram . BaseDiagramObject modelDiagramObject , bool updateShapeElements , IList < ViewModelDiagram . ShapeElement > shapesToAutoLayout ) { Debug . Assert ( modelDiagramObject is EFObject , " " ) ; var modelEntityTypeShape = modelDiagramObject as DesignerModel . EntityTypeShape ; if ( modelEntityTypeShape != null && modelEntityTypeShape . IsDisposed != true && modelEntityTypeShape . EntityType . Target != null && modelEntityTypeShape . EntityType . Target . IsDisposed != true ) { TranslateDiagramObjectHelper ( viewModel , modelDiagramObject , modelEntityTypeShape . EntityType . Target , updateShapeElements , shapeElement => { var viewEntityTypeShape = shapeElement as EntityTypeShape ; var rectangle = new ViewModelDiagram . RectangleD ( modelEntityTypeShape . PointX . Value , modelEntityTypeShape . PointY . Value , modelEntityTypeShape . Width . Value , 0.0 ) ; viewEntityTypeShape . AbsoluteBounds = rectangle ; viewEntityTypeShape . IsExpanded = modelEntityTypeShape . IsExpanded . Value ; if ( ! shapesToAutoLayout . Contains ( viewEntityTypeShape ) ) { shapesToAutoLayout . Add ( viewEntityTypeShape ) ; } foreach ( var linkShape in viewEntityTypeShape . Link ) { if ( linkShape . ManuallyRouted == false && shapesToAutoLayout . Contains ( linkShape ) == false ) { shapesToAutoLayout . Add ( linkShape ) ; } } } ) ; var dslEntityTypeShape = viewModel . ModelXRef . GetExisting ( modelEntityTypeShape ) as EntityTypeShape ; if ( dslEntityTypeShape != null ) { dslEntityTypeShape . FillColor = modelEntityTypeShape . FillColor . Value ; } } var modelAssociationConnectorShape = modelDiagramObject as DesignerModel . AssociationConnector ; if ( modelAssociationConnectorShape != null && modelAssociationConnectorShape . IsDisposed != true && modelAssociationConnectorShape . Association . Target != null && modelAssociationConnectorShape . Association . Target . IsDisposed != true ) { TranslateDiagramObjectHelper ( viewModel , modelDiagramObject , modelAssociationConnectorShape . Association . Target , true , shapeElement => TranslateAssociationConnectors ( shapeElement as AssociationConnector , modelAssociationConnectorShape , shapesToAutoLayout ) ) ; } var modelInheritanceConnectorShape = modelDiagramObject as DesignerModel . InheritanceConnector ; if ( modelInheritanceConnectorShape != null && modelInheritanceConnectorShape . IsDisposed != true && modelInheritanceConnectorShape . EntityType . Target != null && modelInheritanceConnectorShape . EntityType . Target . IsDisposed != true ) { var cet = modelInheritanceConnectorShape . EntityType . Target as ConceptualEntityType ; if ( cet != null && cet . BaseType != null && cet . BaseType . RefName != null ) { TranslateDiagramObjectHelper ( viewModel , modelDiagramObject , cet . BaseType , true , shapeElement => TranslateInheritanceConnectors ( shapeElement as InheritanceConnector , modelInheritanceConnectorShape , shapesToAutoLayout ) ) ; } } }
This method assumes that the ShapeElement as well as the Designer EFObject already exist but they haven't been pushed
into the view model's XRef yet.
This method assumes that the ShapeElement as well as the Designer EFObject already exist but they haven ' t been pushed into the view model ' s XRef yet .
// the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject. // Loop through all the shape's connectors and add the connector to list to be autolayout if the connector is not manually routed. // dslEntityTypeShape is null if the entity-type is deleted, in that case skip sync FillColor property. // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject. // the view model could have gotten deleted as a result of OnEFObjectDeleted() so don't attempt to translate the diagram EFObject.
viewModel
EntityDesignerViewModel
modelDiagramObject
ModelDiagram.BaseDiagramObject
updateShapeElements
bool
shapesToAutoLayout
IList<ViewModelDiagram.ShapeElement>