internal override bool ParseSingleElement(ICollection <XName> unprocessedElements, XElement element) { if (element.Name.LocalName == "Connection") { DesignerInfo connectionDesignerInfo = new ConnectionDesignerInfo(this, element); connectionDesignerInfo.Parse(unprocessedElements); _designerInfos.Add(element.Name.LocalName, connectionDesignerInfo); } else if (element.Name.LocalName == OptionsDesignerInfo.ElementName) { DesignerInfo optionsDesignerInfo = new OptionsDesignerInfo(this, element); optionsDesignerInfo.Parse(unprocessedElements); _designerInfos.Add(element.Name.LocalName, optionsDesignerInfo); } else if (_diagramArtifact == null && element.Name.LocalName == Diagrams.ElementName) // only parse Diagrams element if DiagramArtifact is not available. { _diagrams = new Diagrams(this, element); _diagrams.Parse(unprocessedElements); } else { return(base.ParseSingleElement(unprocessedElements, element)); } return(true); }
private DesignerInfo SetupOptionsDesignerInfo(string designerPropertyName, string designerPropertyValue) { var designerInfo = new OptionsDesignerInfo( null, XElement.Parse( "<Options xmlns='http://schemas.microsoft.com/ado/2009/11/edmx' />")); var designerInfoPropertySet = new DesignerInfoPropertySet( designerInfo, XElement.Parse( "<DesignerInfoPropertySet xmlns='http://schemas.microsoft.com/ado/2009/11/edmx' />")); if (designerPropertyName != null) { var designerProperty = new DesignerProperty( designerInfoPropertySet, XElement.Parse( "<DesignerProperty Name='" + designerPropertyName + "' Value='" + designerPropertyValue + "' xmlns='http://schemas.microsoft.com/ado/2009/11/edmx' />")); designerInfoPropertySet.AddDesignerProperty(designerPropertyName, designerProperty); } designerInfo.PropertySet = designerInfoPropertySet; return(designerInfo); }
// <summary> // Returns a Command to update a value of a designer property // </summary> private static void AddUpdateDesignerPropertyCommand( DesignerProperty property, string propertyName, bool checkBoxValue, OptionsDesignerInfo optionsDesignerInfo, List <Command> commands) { if (property == null || property.ValueAttr == null || checkBoxValue != bool.Parse(property.ValueAttr.Value)) { var value = checkBoxValue ? Boolean.TrueString : Boolean.FalseString; var cmd = new ChangeDesignerPropertyCommand(propertyName, value, optionsDesignerInfo); commands.Add(cmd); } }
protected override void InvokeInternal(CommandProcessorContext cpc) { var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; Debug.Assert(artifact != null, "Null Artifact"); if (null == artifact) { return; } // construct a mapping of the existing model's C-side objects // and their S-side identities before anything is updated var existingModel = new ExistingModelSummary(artifact); // replace the old SSDL with the new and fixup any references // in the MSL that broke because of the replacement of the SSDL // (i.e. the S-side Alias and S-side EntityContainer name) var replaceSsdlCommand = new ReplaceSsdlCommand(_newArtifactFromDB.StorageModel()); CommandProcessor.InvokeSingleCommand(cpc, replaceSsdlCommand); // remove any mappings with references which no longer work // with the new SSDL var deleteUnboundMappingsCommand = new DeleteUnboundMappingsCommand(); CommandProcessor.InvokeSingleCommand(cpc, deleteUnboundMappingsCommand); // remove any mappings which should no longer be mapped with the new SSDL // but actually are because a new S-side object with identical name // but different identity has been added var deleteChangedIdentityMappingsCommand = new DeleteChangedIdentityMappingsCommand(existingModel); CommandProcessor.InvokeSingleCommand(cpc, deleteChangedIdentityMappingsCommand); // from the temp model for the updated database determine which // C-side objects need to be added/updated and then update the // C- and M- side models appropriately var modelFromUpdatedDatabase = new UpdatedModelSummary(_newArtifactFromDB); var updateCsdlAndMslCommand = new UpdateConceptualAndMappingModelsCommand(existingModel, modelFromUpdatedDatabase); CommandProcessor.InvokeSingleCommand(cpc, updateCsdlAndMslCommand); // fix up Function Import parameters and add integrity checks if (artifact.MappingModel() != null && artifact.MappingModel().FirstEntityContainerMapping != null) { // Function Import parameters are now out-of-date compared to the updated Function ones. // We need to update them as otherwise there is no way to do so using Escher. foreach (var fim in artifact.MappingModel().FirstEntityContainerMapping.FunctionImportMappings()) { if (null != fim.FunctionImportName && null != fim.FunctionImportName.Target && null != fim.FunctionName && null != fim.FunctionName.Target) { CreateFunctionImportCommand.UpdateFunctionImportParameters( cpc, fim.FunctionImportName.Target, fim.FunctionName.Target); } } // Add integrity checks to enforce mapping rules foreach (var esm in artifact.MappingModel().FirstEntityContainerMapping.EntitySetMappings()) { EnforceEntitySetMappingRules.AddRule(cpc, esm); } // add the integrity check to propagate all appropriate StoreGeneratedPattern values to the S-side // Note: should not propagate "None"/defaulted values to prevent those C-side values overwriting // correctly updated S-side StoreGeneratedPattern values which were just received from the runtime PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, artifact, false); // Add integrity check to enforce synchronizing C-side Property facets to S-side values var shouldSynchronizePropertyFacets = ModelHelper.GetDesignerPropertyValueFromArtifactAsBool( OptionsDesignerInfo.ElementName, OptionsDesignerInfo.AttributeSynchronizePropertyFacets, OptionsDesignerInfo.SynchronizePropertyFacetsDefault(artifact), artifact); if (shouldSynchronizePropertyFacets) { PropagateStoragePropertyFacetsToConceptualModel.AddRule(cpc, artifact); } } }
internal WizardPageUpdateFromDatabase(ModelBuilderWizardForm wizard, IServiceProvider serviceProvider) : base(wizard, serviceProvider) { InitializeComponent(); Logo = Resources.PageIcon; Headline = Resources.SelectTablesPage_Title; Id = "WizardPageUpdateFromDatabaseId"; ShowInfoPanel = false; _bgWorkerPopulateTree = new BackgroundWorker(); _bgWorkerPopulateTree.WorkerSupportsCancellation = true; _bgWorkerPopulateTree.RunWorkerCompleted += bgWorkerPopulateTree_RunWorkerCompleted; _bgWorkerPopulateTree.DoWork += bgWorkerPopulateTree_DoWork; AddTabPage.Select(); HelpKeyword = null; Debug.Assert( Wizard.Mode == ModelBuilderWizardForm.WizardMode.PerformDatabaseConfigAndSelectTables || Wizard.Mode == ModelBuilderWizardForm.WizardMode.PerformSelectTablesOnly, "Unexpected wizard mode " + Wizard.Mode); // // Get the optionsDesignerInfo from the artifact // OptionsDesignerInfo optionsDesignerInfo = null; var artifact = Wizard.ModelBuilderSettings.Artifact; Debug.Assert(artifact != null, "Expected non-null artifact"); if (artifact != null) { DesignerInfo designerInfo; if (artifact.DesignerInfo().TryGetDesignerInfo(OptionsDesignerInfo.ElementName, out designerInfo)) { Debug.Assert(designerInfo != null, "expected non-null designerInfo"); optionsDesignerInfo = designerInfo as OptionsDesignerInfo; Debug.Assert(optionsDesignerInfo != null, "expected non-null optionsDesignerInfo"); } } // // set up pluralization checkbox. We only support english pluralization for this release, so default this checked in this case // if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "en") { // default to checked. toolTip.SetToolTip(chkPluralize, Resources.PluralizeCheckBoxToolTipText); chkPluralize.Enabled = true; chkPluralize.Checked = true; // read value from designer properties if (optionsDesignerInfo != null) { chkPluralize.Checked = TryReadDesignerProperty(optionsDesignerInfo.CheckPluralizationInWizard, true); } } else { // even if non-english, we still want the option available, just not checked by default chkPluralize.Enabled = true; chkPluralize.Checked = false; // read value from designer properties if (optionsDesignerInfo != null) { chkPluralize.Checked = TryReadDesignerProperty(optionsDesignerInfo.CheckPluralizationInWizard, false); } toolTip.SetToolTip(chkPluralize, Resources.PluralizeCheckBoxDisabledToolTipText); } // foreign keys are supported by any version of EF that runs on .NET Framework 4 or newer if (NetFrameworkVersioningHelper.TargetNetFrameworkVersion(Wizard.Project, Wizard.ServiceProvider) >= NetFrameworkVersioningHelper.NetFrameworkVersion4) { chkIncludeForeignKeys.Checked = true; chkIncludeForeignKeys.Enabled = true; toolTip.SetToolTip( chkIncludeForeignKeys, Resources.SelectTablesPage_IncludeForeignKeysToolTip); // try to read value from designer properties if (optionsDesignerInfo != null) { chkIncludeForeignKeys.Checked = TryReadDesignerProperty(optionsDesignerInfo.CheckIncludeForeignKeysInModel, true); } } else { toolTip.SetToolTip(chkIncludeForeignKeys, Design.Resources.DisabledFeatureTooltip); chkIncludeForeignKeys.Parent.MouseMove += IncludeForeignKeysArea_OnMouseMove; chkIncludeForeignKeys.Parent.MouseLeave += IncludeForeignKeysArea_OnMouseLeave; chkIncludeForeignKeys.Enabled = false; chkIncludeForeignKeys.Checked = false; } // assume we have no Stored Procs and so default the Create Function Imports checkbox to unchecked and not enabled chkCreateFunctionImports.Enabled = false; chkCreateFunctionImports.Checked = false; _stopwatch = new Stopwatch(); }