private void DispatchInternal() { Debug.Assert( WizardKind == WizardKind.UpdateModel || WizardKind == WizardKind.Generate, "Unexpected value for WizardKind = " + WizardKind); var modelGenerationExtensions = EscherExtensionPointManager.LoadModelGenerationExtensions(); if (modelGenerationExtensions.Length > 0) // don't create context if not needed { var modelGenerationExtensionContext = CreateContext(); foreach (var exportInfo in modelGenerationExtensions) { var extension = exportInfo.Value; try { DispatchToSingleExtension(extension, modelGenerationExtensionContext); } catch (Exception e) { VsUtils.ShowErrorDialog( string.Format( CultureInfo.CurrentCulture, Resources.Extensibility_ErrorOccurredDuringCallToExtension, extension.GetType().FullName, VsUtils.ConstructInnerExceptionErrorMessage(e))); } } } }
// <summary> // Helper method to raise a dialog to display the encountered database connection errors // </summary> // <returns>the error message</returns> internal static string ShowDatabaseConnectionErrorDialog(Exception e) { if (null == e) { Debug.Fail("exception should not be null"); return(null); } // show the error dialog var errMsgWithInnerExceptions = VsUtils.ConstructInnerExceptionErrorMessage(e); var errMsg = string.Format( CultureInfo.CurrentCulture, Resources.DbConnectionErrorText, e.GetType().FullName, errMsgWithInnerExceptions); VsUtils.ShowErrorDialog(errMsg); return(errMsg); }
// <summary> // Prompts the user to copy the database file into the project if appropriate // </summary> // <returns>whether wizard should continue to next page</returns> private bool PromptConvertLocalConnection() { // first check whether connection is Local if (!LocalDataUtil.IsLocalDbFileConnectionString( Wizard.ModelBuilderSettings.DesignTimeProviderInvariantName, Wizard.ModelBuilderSettings.DesignTimeConnectionString)) { return(true); } // if connection is Local but has already been copied into the project should not prompt var filePath = LocalDataUtil.GetLocalDbFilePath( Wizard.ModelBuilderSettings.DesignTimeProviderInvariantName, Wizard.ModelBuilderSettings.DesignTimeConnectionString); if (!string.IsNullOrEmpty(filePath)) { var projectItemCollection = LocalDataUtil.GetDefaultCollectionForLocalDataFile(Wizard.ServiceProvider, Wizard.Project); var targetPath = VsUtils.ConstructTargetPathForDatabaseFile( Wizard.Project, projectItemCollection, Path.GetFileName(filePath)); if (File.Exists(targetPath)) { return(true); } } // Special case -- Check if this is a SQL Mobile Device if (LocalDataUtil.IsSqlMobileDeviceConnectionString( Wizard.ModelBuilderSettings.DesignTimeProviderInvariantName, Wizard.ModelBuilderSettings.DesignTimeConnectionString)) { // For mobile devices, if the connection starts with 'Mobile Device' it means that the connection // refers to a location on the device itself. Do not perform conversion. return(true); } // ask user if they want to copy var result = VsUtils.ShowMessageBox( Wizard.ServiceProvider, Resources.LocalDataConvertConnectionText, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_QUERY); if (DialogResult.Yes != result) { return(true); } try { return(CopyFileIntoProjectAndConvertConnectionString(filePath)); } catch (FileCopyException e) { var errMsgWithInnerExceptions = VsUtils.ConstructInnerExceptionErrorMessage(e); var errMsg = string.Format( CultureInfo.CurrentCulture, Resources.LocalDataExceptionCopyingFile, e.GetType().FullName, filePath, errMsgWithInnerExceptions); VsUtils.ShowErrorDialog(errMsg); return(false); } }
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { var baseProperties = base.GetProperties(attributes); // clear out dictionary, as we will rebuild it in this method _propertyDescriptorToOwner.Clear(); if (RunningInVS) { // we only dispatch to extensions when we are running in VS. This is because there is a dep on vS things like ProjectItem var el = WrappedItem as EFElement; Debug.Assert(el != null, "wrapped item is null"); if (el != null) { var currentSelectionOrNull = EscherExtensionPointManager.DetermineEntityDesignerSelection(el); if (currentSelectionOrNull != null) { var currentSelection = (EntityDesignerSelection)currentSelectionOrNull; Debug.Assert((int)currentSelection != 0, "unexpected value for current selection"); var extensions = EscherExtensionPointManager.LoadPropertyDescriptorExtensions(); if (extensions.Length > 0) { // Note that if the user adds an EDMX file to their project and chooses not to save the project file, // the project item below can be null; it won't even exist in the miscellaneous files project. var projectItem = VsUtils.GetProjectItemForDocument(el.Artifact.Uri.LocalPath, PackageManager.Package); if (projectItem != null && VsUtils.EntityFrameworkSupportedInProject( projectItem.ContainingProject, PackageManager.Package, allowMiscProject: false)) { var targetSchemaVersion = EdmUtils.GetEntityFrameworkVersion(projectItem.ContainingProject, PackageManager.Package); // Use MEF extensions to create "owner" objects that define new property descriptors to add into the property sheet. // TODO: We track 'visited factories' since have to load the App-DB contracts as well as the standard contracts, but // MEF also loads the standard contracts in addition to the App-DB contracts. Need to see if MEF can support // otherwise. var propDescriptorOwners = new List <Object>(); var visitedFactories = new HashSet <IEntityDesignerExtendedProperty>(); foreach (var ex in extensions) { if (((int)ex.Metadata.EntityDesignerSelection & (int)currentSelection) == (int)currentSelection) { // Continue processing this extension var factory = ex.Value; if (factory != null && !visitedFactories.Contains(factory)) { visitedFactories.Add(factory); try { var extensionContext = new PropertyExtensionContextImpl( EditingContext, projectItem, targetSchemaVersion, factory.GetType().Assembly.GetName().GetPublicKeyToken()); var xelem = el.XElement; var sem = el as StorageEntityModel; if (currentSelection == EntityDesignerSelection.StorageModelEntityContainer && sem != null) { xelem = sem.FirstEntityContainer.XElement; } var o = factory.CreateProperty(xelem, extensionContext); if (o != null) { propDescriptorOwners.Add(o); } } catch (Exception e) { var exceptionMessage = VsUtils.ConstructInnerExceptionErrorMessage(e); var errorMessage = String.Format( CultureInfo.CurrentCulture, Resources.Extensibility_ErrorOccurredDuringCallToExtension, factory.GetType().FullName, exceptionMessage); VsUtils.ShowErrorDialog(errorMessage); } } } } // // Create PropertyDescriptors over the new "owner" // foreach (var o in propDescriptorOwners) { var props = TypeDescriptor.GetProperties(o, attributes, false); foreach (PropertyDescriptor pd in props) { var reflectedPropertyDescriptor = new ReflectedPropertyDescriptor(EditingContext, pd, o); if (reflectedPropertyDescriptor.IsBrowsable) { if (_propertyDescriptorToOwner.ContainsKey(reflectedPropertyDescriptor)) { // handle degenerate error case where dictionary already contains key. This shouldn't happen, but this is here just to be safe. Debug.Fail("_propertyDescriptor2Owner table already contains entry"); _propertyDescriptorToOwner.Remove(reflectedPropertyDescriptor); } _propertyDescriptorToOwner.Add(reflectedPropertyDescriptor, o); baseProperties.Add(reflectedPropertyDescriptor); } } } } } } } } return(baseProperties); }
protected override void OnEnteredPage(EventArgs e) { // Set the AcceptButton to be a disabled Finish Button WizardForm.AcceptButton = WizardForm.FinishButton; WizardForm.FinishButton.Enabled = false; var wizardData = WizardForm.WizardData as EdmDataSourceWizardData; Debug.Assert(wizardData != null, "Instance of EdmDataSourceWizardData is not passed in to LaunchModelGenWizardPage."); _isPageClosing = false; _dismissDSWizard = false; if (wizardData != null) { try { Message = Resources.LaunchingEntityDataModelWizardMessage; // Hide Data-Source Wizard asynchronously. This is a workaround so our wizard can be displayed in the correct position. _hideDataSourceWizardFormTimer.Start(); _dismissDSWizard = LaunchEntityDesignerWizard(wizardData); } catch (WizardCancelledException) { wizardData.IsCancelled = true; } catch (Exception ex) { try { var errMessageWithInnerExceptions = VsUtils.ConstructInnerExceptionErrorMessage(ex); var message = string.Format( CultureInfo.CurrentCulture, Resources.LaunchEntityDesignerWizardErrorMessage, ex.GetType().FullName, errMessageWithInnerExceptions); VsUtils.ShowErrorDialog(message); } catch (Exception) { // exception trying to show error dialog - do nothing } } finally { // Don't need to make the form visible if we are about to dismiss the wizard. if (!_dismissDSWizard) { WizardForm.Visible = true; } } } // Just return to the previous DS Wizard page if we should not dismiss the DS Wizard. if (!_dismissDSWizard) { WizardForm.BackPage(); } else { // Call Finish method to dismiss the wizard. WizardForm.FinishButton.Enabled = true; WizardForm.Finish(); } }