// 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); }
private void LoadDesignerInfoAndDescriptors(EditingContext editingContext, EFArtifact artifact) { if (artifact != null && artifact.DesignerInfo() != null) { DesignerInfo connectionDesignerInfo = null; DesignerInfo optionsDesignerInfo = null; var foundConnectionDesignerInfo = artifact.DesignerInfo() .TryGetDesignerInfo(ConnectionDesignerInfo.ElementName, out connectionDesignerInfo); if (foundConnectionDesignerInfo) { var connectionDesigner = connectionDesignerInfo as ConnectionDesignerInfo; Debug.Assert(connectionDesigner != null, "DesignerInfo with element name 'Connection' must be a ConnectionDesignerInfo"); if (connectionDesigner != null) { // if the owner of the edmx file is a website, then we can // only have one possible value (EmbedInOutputAssembly) for metadata artifact processing // however the item template just adds CopyToOutputDirectory, so we need to fix it var project = VSHelpers.GetProjectForDocument(artifact.Uri.LocalPath, PackageManager.Package); if (project != null) { var appType = VsUtils.GetApplicationType(Services.ServiceProvider, project); if (appType == VisualStudioProjectSystem.Website) { var mapDefault = ConnectionManager.GetMetadataArtifactProcessingDefault(); if (connectionDesigner.MetadataArtifactProcessingProperty != null && connectionDesigner.MetadataArtifactProcessingProperty.ValueAttr.Value != mapDefault) { var cpc = new CommandProcessorContext( editingContext, EfiTransactionOriginator.PropertyWindowOriginatorId, Resources.Tx_ChangeMetadataArtifactProcessing); var cmd = new UpdateDefaultableValueCommand <string>( connectionDesigner.MetadataArtifactProcessingProperty.ValueAttr, mapDefault); CommandProcessor.InvokeSingleCommand(cpc, cmd); } } } _EFConnectionDesignerInfoDescriptor = new EFConnectionDesignerInfoDescriptor(); _EFConnectionDesignerInfoDescriptor.Initialize(connectionDesigner, editingContext); } } var foundOptionsDesignerInfo = artifact.DesignerInfo() .TryGetDesignerInfo(OptionsDesignerInfo.ElementName, out optionsDesignerInfo); if (foundOptionsDesignerInfo) { _EFOptionsDesignerInfoDescriptor = new EFOptionsDesignerInfoDescriptor(); _EFOptionsDesignerInfoDescriptor.Initialize(optionsDesignerInfo as OptionsDesignerInfo, editingContext); } } }
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; } } } } }