internal static DesignerProperty GetMetadataPropertyFromArtifact(EFArtifact artifact)
        {
            var designerRoot = artifact.DesignerInfo();
            DesignerProperty mapProperty = null;
            if (designerRoot != null)
            {
                DesignerInfo designerInfo;
                if (designerRoot.TryGetDesignerInfo(ConnectionDesignerInfo.ElementName, out designerInfo))
                {
                    var connectionDesignerInfo = designerInfo as ConnectionDesignerInfo;
                    Debug.Assert(
                        connectionDesignerInfo != null,
                        "We should have associated the ConnectionDesignerInfo with " + ConnectionDesignerInfo.ElementName);

                    if (connectionDesignerInfo != null)
                    {
                        mapProperty = connectionDesignerInfo.MetadataArtifactProcessingProperty;
                    }
                }
            }
            return mapProperty;
        }
        // internal for testing
        internal static bool ShouldValidateArtifactDuringBuild(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "artifact != null");

            if (artifact.DesignerInfo() != null)
            {
                DesignerInfo designerInfo;
                if (artifact.DesignerInfo().TryGetDesignerInfo(OptionsDesignerInfo.ElementName, out designerInfo))
                {
                    var optionsDesignerInfo = (OptionsDesignerInfo)designerInfo;

                    if (optionsDesignerInfo.ValidateOnBuild != null
                        && optionsDesignerInfo.ValidateOnBuild.ValueAttr != null)
                    {
                        bool validateOnBuild;
                        if (bool.TryParse(optionsDesignerInfo.ValidateOnBuild.ValueAttr.Value, out validateOnBuild))
                        {
                            return validateOnBuild;
                        }
                    }
                }
            }

            return true;
        }
        public void EnsureDiagramIsCreated(EFArtifact artifact)
        {
            if (RootElement != null)
            {
                var modelRoot = RootElement as EntityDesignerViewModel;
                if (modelRoot != null)
                {
                    var diagram = modelRoot.GetDiagram();
                    Debug.Assert(diagram != null, "DSL Diagram should have been created by now");

                    if (diagram != null)
                    {
                        Debug.Assert(artifact.DesignerInfo() != null, "artifact.DesignerInfo should not be null");
                        Debug.Assert(artifact.DesignerInfo().Diagrams != null, "artifact.DesignerInfo.Diagrams should not be null");

                        if (artifact.DesignerInfo() != null
                            && artifact.DesignerInfo().Diagrams != null)
                        {
                            var saveDiagramDocument = false;

                            if (artifact.DesignerInfo().Diagrams.FirstDiagram == null)
                            {
                                // layout is very slow.  Only auto-layout if less than a max number of types
                                if (diagram.ModelElement.EntityTypes.Count < EntityDesignerDiagram.IMPLICIT_AUTO_LAYOUT_CEILING)
                                {
                                    diagram.AutoLayoutDiagram();
                                }

                                try
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = false;
                                    EntityModelToDslModelTranslatorStrategy.CreateDefaultDiagram(modelRoot.EditingContext, diagram);

                                    // Ensure that DSL Diagram and Model Diagram are in sync:
                                    // - Update xref between 2 diagrams
                                    // - Propagetes model diagram info to DSL Diagram.
                                    var modelDiagram = artifact.DesignerInfo().Diagrams.FirstDiagram;
                                    Debug.Assert(modelDiagram != null, "modelDiagram should not be null");
                                    if (modelDiagram != null)
                                    {
                                        ModelTranslatorContextItem.GetEntityModelTranslator(EditingContext)
                                            .SynchronizeSingleDslModelElement(modelRoot, modelDiagram);
                                    }
                                }
                                finally
                                {
                                    EntityDesignerViewModel.RespondToModelChanges = true;
                                }

                                // save the file after adding Diagram element so it won't open as a dirty document
                                saveDiagramDocument = true;
                            }

                            if (saveDiagramDocument)
                            {
                                var rdt = new RunningDocumentTable(ServiceProvider);
                                rdt.SaveFileIfDirty(FileName);
                            }

                            _isDiagramLoaded = true;
                        }
                    }
                }
            }
        }