internal static void PopulateNewFunctionSchemaProcedures( Dictionary <EntityStoreSchemaFilterEntry, IDataSchemaProcedure> newFunctionSchemaProcedureMap, string designTimeProviderInvariantName, string designTimeProviderConnectionString, DoWorkEventArgs e = null, BackgroundWorker worker = null, int startingAmountOfProgressBar = 0, int amountOfProgressBarGiven = 100) { // set up database connection var dataConnectionManager = Services.ServiceProvider.GetService(typeof(IVsDataConnectionManager)) as IVsDataConnectionManager; Debug.Assert(dataConnectionManager != null, "Could not find IVsDataConnectionManager"); var dataProviderManager = Services.ServiceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; Debug.Assert(dataProviderManager != null, "Could not find IVsDataProviderManager"); IVsDataConnection dataConnection = null; if (null != dataConnectionManager && null != dataProviderManager) { dataConnection = DataConnectionUtils.GetDataConnection( dataConnectionManager, dataProviderManager, designTimeProviderInvariantName, designTimeProviderConnectionString); } if (null == dataConnection) { throw new ProgressDialogException( string.Format( CultureInfo.CurrentCulture, Design.Resources.RetrievingSprocReturnTypeErrorMessage, "null IVsDataConnection")); } // open the database connection and collect info for each Function try { dataConnection.Open(); var dataSchemaServer = new DataSchemaServer(dataConnection); // now loop over all entries adding return type information var numFunctionFilterEntries = newFunctionSchemaProcedureMap.Count; var numFunctionFilterEntryCurrent = 0; foreach (var entry in newFunctionSchemaProcedureMap.Keys.ToList()) { numFunctionFilterEntryCurrent++; if (worker != null && e != null && worker.CancellationPending) { // user requested interrupt of this process e.Cancel = true; } else { if (worker != null && worker.WorkerReportsProgress) { // report progress so ProgressDialog can update its status var percentCompleted = startingAmountOfProgressBar + ((int) (((numFunctionFilterEntryCurrent - 1) / (float)numFunctionFilterEntries) * amountOfProgressBarGiven)); var userState = new ProgressDialogUserState(); userState.NumberIterations = numFunctionFilterEntries; userState.CurrentIteration = numFunctionFilterEntryCurrent; userState.CurrentStatusMessage = string.Format( CultureInfo.CurrentCulture, Design.Resources.RetrievingSprocReturnTypeInfoMessage, numFunctionFilterEntryCurrent, numFunctionFilterEntries, entry.Schema, entry.Name); worker.ReportProgress(percentCompleted, userState); } // now retrieve and store the return type information var schemaProcedure = dataSchemaServer.GetProcedureOrFunction(entry.Schema, entry.Name); Debug.Assert( null == newFunctionSchemaProcedureMap[entry], "This entry has already been processed, Schema = " + entry.Schema + ", Name = " + entry.Name); newFunctionSchemaProcedureMap[entry] = schemaProcedure; } } } finally { if (null != dataConnection) { dataConnection.Close(); } } }
internal override bool OnWizardFinish() { using (new VsUtils.HourglassHelper()) { UpdateSettingsFromGui(); } // // validate app config connection name // if (checkBoxSaveInAppConfig.Checked) { var id = textBoxAppConfigConnectionName.Text; if (!EscherAttributeContentValidator.IsValidCsdlEntityContainerName(id) || !_identifierUtil.IsValidIdentifier(id)) { VsUtils.ShowErrorDialog( string.Format(CultureInfo.CurrentCulture, Resources.ConnectionStringNonValidIdentifier, id)); textBoxAppConfigConnectionName.Focus(); _isFocusSet = true; return(false); } // only check that the connection string name is new if started in // 'PerformAllFunctionality' mode if (ModelBuilderWizardForm.WizardMode.PerformAllFunctionality == Wizard.Mode) { string connectionString; if (ConnectionManager.GetExistingConnectionStrings(_configFileUtils).TryGetValue(id, out connectionString) && !string.Equals(textBoxConnectionString.Text, connectionString, StringComparison.Ordinal)) { VsUtils.ShowErrorDialog( string.Format(CultureInfo.CurrentCulture, Resources.ConnectionStringDuplicateIdentifer, id)); textBoxAppConfigConnectionName.Focus(); _isFocusSet = true; return(false); } } } // the Model Namespace and the Entity Container name must differ if (ModelBuilderWizardForm.ModelNamespaceAndEntityContainerNameSame(Wizard.ModelBuilderSettings)) { var s = Resources.NamespaceAndEntityContainerSame; VsUtils.ShowErrorDialog( String.Format(CultureInfo.CurrentCulture, s, Wizard.ModelBuilderSettings.AppConfigConnectionPropertyName)); textBoxAppConfigConnectionName.Focus(); _isFocusSet = true; return(false); } try { // this might cause dataConnection to include some sensitive data into connectionString // the Open function also can cause DDEX to put up a prompt for the username/password for an existing connection // that does not have any saved password information. _dataConnection.Open(); if (!IsDataValid) { sensitiveInfoTextBox.Enabled = true; allowSensitiveInfoButton.Checked = false; allowSensitiveInfoButton.Enabled = true; disallowSensitiveInfoButton.Checked = false; disallowSensitiveInfoButton.Enabled = true; var result = VsUtils.ShowMessageBox( PackageManager.Package, Resources.SensitiveDataInfoText, OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_THIRD, OLEMSGICON.OLEMSGICON_QUERY); switch (result) { case DialogResult.Yes: allowSensitiveInfoButton.Checked = true; break; case DialogResult.No: disallowSensitiveInfoButton.Checked = true; break; default: Wizard.OnValidationStateChanged(this); return(false); } } } catch (DataConnectionOpenCanceledException) { return(false); } catch (Exception e) { // show error dialog ModelBuilderWizardForm.ShowDatabaseConnectionErrorDialog(e); return(false); } finally { if (_dataConnection.State != DataConnectionState.Closed) { _dataConnection.Close(); } } return(true); }
internal static void SetupSettingsAndModeForDbPages( IServiceProvider sp, Project project, EFArtifact artifact, bool checkDatabaseConnection, ModelBuilderWizardForm.WizardMode noConnectionMode, ModelBuilderWizardForm.WizardMode existingConnectionMode, out ModelBuilderWizardForm.WizardMode startMode, out ModelBuilderSettings settings) { var conceptualEntityModel = artifact.ConceptualModel(); Debug.Assert(conceptualEntityModel != null, "Null Conceptual Entity Model"); var entityContainer = conceptualEntityModel.FirstEntityContainer as ConceptualEntityContainer; Debug.Assert(entityContainer != null, "Null Conceptual Entity Container"); var entityContainerName = entityContainer.LocalName.Value; // set up ModelBuilderSettings for startMode=noConnectionMode startMode = noConnectionMode; settings = new ModelBuilderSettings(); var appType = VsUtils.GetApplicationType(sp, project); settings.VSApplicationType = appType; settings.AppConfigConnectionPropertyName = entityContainerName; settings.Artifact = artifact; settings.UseLegacyProvider = ModelHelper.GetDesignerPropertyValueFromArtifactAsBool( OptionsDesignerInfo.ElementName, OptionsDesignerInfo.AttributeUseLegacyProvider, OptionsDesignerInfo.UseLegacyProviderDefault, artifact); settings.TargetSchemaVersion = artifact.SchemaVersion; settings.Project = project; settings.ModelPath = artifact.Uri.LocalPath; // Get the provider manifest token from the existing SSDL. // We don't want to attempt to get it from provider services since this requires a connection // which will severely impact the performance of Model First in disconnected scenarios. settings.ProviderManifestToken = DatabaseGenerationEngine.GetProviderManifestTokenDisconnected(artifact); // Change startMode and settings appropriately depending on whether there is an existing connection string and whether we can/should connect // to the database var connectionString = ConnectionManager.GetConnectionStringObject(project, entityContainerName); if (connectionString != null) { var ecsb = connectionString.Builder; var runtimeProviderName = ecsb.Provider; var runtimeProviderConnectionString = ecsb.ProviderConnectionString; var designTimeProviderConnectionString = connectionString.GetDesignTimeProviderConnectionString(project); var initialCatalog = String.Empty; if (checkDatabaseConnection) { // This path will check to make sure that we can connect to an existing database before changing the start mode to 'existingConnection' IVsDataConnection dataConnection = null; try { var dataConnectionManager = sp.GetService(typeof(IVsDataConnectionManager)) as IVsDataConnectionManager; Debug.Assert(dataConnectionManager != null, "Could not find IVsDataConnectionManager"); var dataProviderManager = sp.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; Debug.Assert(dataProviderManager != null, "Could not find IVsDataProviderManager"); if (dataConnectionManager != null && dataProviderManager != null) { // this will either get an existing connection or attempt to create a new one dataConnection = DataConnectionUtils.GetDataConnection( dataConnectionManager, dataProviderManager, connectionString.DesignTimeProviderInvariantName, designTimeProviderConnectionString); Debug.Assert( dataConnection != null, "Could not find the IVsDataConnection; an exception should have been thrown if this was the case"); if (dataConnection != null) { VsUtils.EnsureProvider(runtimeProviderName, settings.UseLegacyProvider, project, sp); if (CanCreateAndOpenConnection( new StoreSchemaConnectionFactory(), runtimeProviderName, connectionString.DesignTimeProviderInvariantName, designTimeProviderConnectionString)) { startMode = existingConnectionMode; initialCatalog = DataConnectionUtils.GetInitialCatalog(dataProviderManager, dataConnection); } } } } catch { // do nothing - we will go to WizardPageDbConfig which is // what we want if the DB connection fails } finally { // Close the IVsDataConnection if (dataConnection != null) { try { dataConnection.Close(); } catch { } } } } else { // This path will just parse the existing connection string in order to change the start mode. This is ideal for features // that do not need a database connection -- the information in the connection string is enough. startMode = existingConnectionMode; initialCatalog = DataConnectionUtils.GetInitialCatalog( connectionString.DesignTimeProviderInvariantName, designTimeProviderConnectionString); } if (startMode == existingConnectionMode) { // the invariant name and connection string came from app.config, so they are "runtime" invariant names and not "design-time" // (Note: it is OK for InitialCatalog to be null at this stage e.g. from a provider who do not support the concept of Initial Catalog) settings.SetInvariantNamesAndConnectionStrings( project, runtimeProviderName, runtimeProviderConnectionString, runtimeProviderConnectionString, false); settings.InitialCatalog = initialCatalog; settings.AppConfigConnectionPropertyName = entityContainerName; settings.SaveConnectionStringInAppConfig = false; VsUtils.EnsureProvider(runtimeProviderName, settings.UseLegacyProvider, project, sp); } } }