internal static IVsDataConnection GetDataConnection( IVsDataConnectionManager dataConnectionManager, IVsDataProviderManager dataProviderManager, string providerInvariantName, string providerConnectionString) { IVsDataConnection connection = null; var dataProviderGuid = Guid.Empty; foreach (var dataProvider in dataProviderManager.Providers.Values) { var invariantName = dataProvider.GetProperty("InvariantName") as string; if (!string.IsNullOrEmpty(invariantName) && invariantName == providerInvariantName) { dataProviderGuid = dataProvider.Guid; break; } } Debug.Assert(dataProviderGuid != Guid.Empty, "The IVsDataProvider could not be found among the list of providers"); if (dataProviderGuid != Guid.Empty) { connection = dataConnectionManager.GetConnection(dataProviderGuid, providerConnectionString, false); } return connection; }
internal static IVsDataConnectionProperties GetConnectionProperties( IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataConnectionProperties properties = null; var provider = GetVsProvider(dataProviderManager, dataConnection); Debug.Assert(provider != null, "null provider value for dataConnection"); if (provider != null) { var dataSource = GetVsDataSource(dataProviderManager, dataConnection); properties = provider.TryCreateObject <IVsDataConnectionProperties>(dataSource); Debug.Assert(properties != null, "Could not get connection properties service"); if (properties != null) { var connectionString = DecryptConnectionString(dataConnection) ?? string.Empty; properties.Parse(connectionString); } } return(properties); }
// internal for testing internal string GetTextBoxConnectionStringValue(IVsDataProviderManager dataProviderManager, Guid providerGuid, string maskedConnectionString) { // providerGuid will be the design-time provider guid from DDEX, so we need to translate to the runtime provider invariant name var designTimeProviderInvariantName = DataConnectionUtils.GetProviderInvariantName(dataProviderManager, providerGuid); var runtimeProviderInvariantName = ConnectionManager.TranslateInvariantName( ServiceProvider, designTimeProviderInvariantName, maskedConnectionString, true); var runtimeConnectionString = ConnectionManager.TranslateConnectionString(ServiceProvider, Wizard.Project, designTimeProviderInvariantName, maskedConnectionString, true); if (Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.GenerateFromDatabase || Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.GenerateDatabaseScript) { var metadataFiles = ConnectionManager.GetMetadataFileNamesFromArtifactFileName( Wizard.Project, Wizard.ModelBuilderSettings.ModelPath, ServiceProvider); return(ConnectionManager.CreateEntityConnectionString( Wizard.Project, Wizard.ModelBuilderSettings.VSApplicationType, metadataFiles, runtimeConnectionString, runtimeProviderInvariantName).Text); } else { Debug.Assert( Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.CodeFirstFromDatabase, "Unexpected model generation option"); return(ConnectionManager.InjectEFAttributesIntoConnectionString( runtimeConnectionString, runtimeProviderInvariantName)); } }
public static string GetSourceDisplayName( IServiceProvider serviceProvider, IVsDataSource dataSource) { string displayName = null; string resourceId = null; Guid provider = dataSource.DefaultProvider; if (provider != Guid.Empty) { resourceId = dataSource.GetProperty(provider, "DisplayName") as string; } if (resourceId == null) { foreach (Guid providerId in dataSource.GetProviders()) { resourceId = dataSource.GetProperty( providerId, "DisplayName") as string; if (resourceId != null) { provider = providerId; break; } } } if (provider != Guid.Empty && resourceId != null) { IVsDataProviderManager providerManager = serviceProvider.GetService( typeof(IVsDataProviderManager)) as IVsDataProviderManager; IVsDataProvider dataProvider = providerManager.Providers[provider]; displayName = dataProvider.GetString(resourceId); } return(displayName); }
internal static IVsDataConnection GetDataConnection( IVsDataConnectionManager dataConnectionManager, IVsDataProviderManager dataProviderManager, string providerInvariantName, string providerConnectionString) { IVsDataConnection connection = null; var dataProviderGuid = Guid.Empty; foreach (var dataProvider in dataProviderManager.Providers.Values) { var invariantName = dataProvider.GetProperty("InvariantName") as string; if (!string.IsNullOrEmpty(invariantName) && invariantName == providerInvariantName) { dataProviderGuid = dataProvider.Guid; break; } } Debug.Assert(dataProviderGuid != Guid.Empty, "The IVsDataProvider could not be found among the list of providers"); if (dataProviderGuid != Guid.Empty) { connection = dataConnectionManager.GetConnection(dataProviderGuid, providerConnectionString, false); } return(connection); }
internal static string GetInitialCatalog(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { string initialCatalog = null; var invariantName = GetProviderInvariantName(dataProviderManager, dataConnection.Provider); var props = GetConnectionProperties(dataProviderManager, dataConnection); if (props != null) { if (props.ContainsKey(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME) && !string.IsNullOrEmpty(props[LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME] as string)) { //sql client with "AttachDbFileName" parameter in the connection string. object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else if (LocalDataUtil.IsSqlMobileConnectionString(invariantName)) { // sql CE object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_DATA_SOURCE, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else { object o = null; props.TryGetValue("Database", out o); initialCatalog = o as String; } } // save the default catalog if (string.IsNullOrEmpty(initialCatalog)) { var sourceInformation = dataConnection.GetService(typeof(IVsDataSourceInformation)) as IVsDataSourceInformation; Debug.Assert( sourceInformation != null, "Could not find the IVsDataSourceInformation for this IVsDataConnection to determine the default catalog"); if (sourceInformation != null) { initialCatalog = sourceInformation["DefaultCatalog"] as string; // Note: it is valid for initialCatalog to be null for certain providers which do not support that concept } } return(initialCatalog); }
private static bool HasLegacyEntityFrameworkProvider(IVsDataProviderManager dataProviderManager, Guid provider) { Debug.Assert(dataProviderManager != null, "dataProviderManager is null."); var providerFactory = GetProviderFactoryForProviderGuid(dataProviderManager, provider); var serviceProvider = providerFactory as IServiceProvider; return(serviceProvider != null && LegacyDbProviderServicesUtils.CanGetDbProviderServices(serviceProvider)); }
private static bool HasLegacyEntityFrameworkProvider(IVsDataProviderManager dataProviderManager, Guid provider) { Debug.Assert(dataProviderManager != null, "dataProviderManager is null."); var providerFactory = GetProviderFactoryForProviderGuid(dataProviderManager, provider); var serviceProvider = providerFactory as IServiceProvider; return serviceProvider != null && LegacyDbProviderServicesUtils.CanGetDbProviderServices(serviceProvider); }
public static void EnumerateProviders(IServiceProvider serviceProvider) { IVsDataProviderManager providerManager = serviceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; foreach (IVsDataProvider provider in providerManager.Providers.Values) { Trace.WriteLine(provider.Name); } }
internal static bool HasEntityFrameworkProvider( IVsDataProviderManager dataProviderManager, Guid provider, Project project, IServiceProvider serviceProvider) { Debug.Assert(dataProviderManager != null, "dataProviderManager is null."); Debug.Assert(project != null, "project is null."); Debug.Assert(serviceProvider != null, "serviceProvider is null."); return(HasLegacyEntityFrameworkProvider(dataProviderManager, provider) || HasModernEntityFrameworkProvider(dataProviderManager, provider, project, serviceProvider)); }
internal static bool HasEntityFrameworkProvider( IVsDataProviderManager dataProviderManager, Guid provider, Project project, IServiceProvider serviceProvider) { Debug.Assert(dataProviderManager != null, "dataProviderManager is null."); Debug.Assert(project != null, "project is null."); Debug.Assert(serviceProvider != null, "serviceProvider is null."); return HasLegacyEntityFrameworkProvider(dataProviderManager, provider) || HasModernEntityFrameworkProvider(dataProviderManager, provider, project, serviceProvider); }
private static Guid GetVsDataSource(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } var guid = Guid.Empty; var provider = GetVsProvider(dataProviderManager, dataConnection); guid = provider.DeriveSource(DataProtection.DecryptString(dataConnection.EncryptedConnectionString)); return(guid); }
public static void OutputSupportingProviders( IServiceProvider serviceProvider, IVsDataSource dataSource) { IVsDataProviderManager providerManager = serviceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; foreach (Guid providerGuid in dataSource.GetProviders()) { IVsDataProvider provider = providerManager.Providers[providerGuid]; Trace.WriteLine(provider.Name); } }
internal static IVsDataProvider GetVsProvider(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataProvider vsDataProvider = null; dataProviderManager.Providers.TryGetValue(dataConnection.Provider, out vsDataProvider); Debug.Assert( vsDataProvider != null, "Data provider identified by guid '{0}' could not be loaded" + dataConnection.Provider.ToString()); return(vsDataProvider); }
public static void UseDataProvider( IServiceProvider serviceProvider, Guid providerGuid) { IVsDataProviderManager providerManager = serviceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; IVsDataProvider provider = providerManager.Providers[providerGuid]; Trace.WriteLine(provider.DisplayName); Trace.WriteLine(provider.Description); IVsDataConnectionProperties connectionProperties = provider.CreateObject <IVsDataConnectionProperties>(); connectionProperties.Parse("Test connection string"); }
private static bool HasModernEntityFrameworkProvider( IVsDataProviderManager dataProviderManager, Guid provider, Project project, IServiceProvider serviceProvider) { Debug.Assert(dataProviderManager != null, "dataProviderManager is null."); Debug.Assert(project != null, "project is null."); Debug.Assert(serviceProvider != null, "serviceProvider is null."); var invariantName = GetProviderInvariantName(dataProviderManager, provider); if (string.IsNullOrWhiteSpace(invariantName)) { return(false); } return(VsUtils.IsModernProviderAvailable(invariantName, project, serviceProvider)); }
public static void OutputDataSource( IServiceProvider serviceProvider, Guid dataSourceGuid) { IVsDataSourceManager sourceManager = serviceProvider.GetService(typeof(IVsDataSourceManager)) as IVsDataSourceManager; IVsDataSource source = sourceManager.Sources[dataSourceGuid]; Trace.WriteLine(source.DisplayName); Trace.WriteLine(source.Description); IVsDataProviderManager providerManager = serviceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; foreach (Guid providerGuid in source.GetProviders()) { IVsDataProvider provider = providerManager.Providers[providerGuid]; Trace.WriteLine(provider.Name); } }
internal static string GetProviderInvariantName(IVsDataProviderManager dataProviderManager, Guid provider) { var invariantName = String.Empty; IVsDataProvider dataProvider = null; Debug.Assert(dataProviderManager != null, "_dataProviderManager is not initialized!"); if (dataProviderManager != null) { dataProviderManager.Providers.TryGetValue(provider, out dataProvider); Debug.Assert(dataProvider != null, "Invalid provider Guid"); if (dataProvider != null) { invariantName = (string)dataProvider.GetProperty("InvariantName"); } } Debug.Assert( !String.IsNullOrEmpty(invariantName), "provider " + dataProvider != null ? dataProvider.DisplayName : "(null)" + " has a null InvariantName"); return(invariantName); }
private static DbProviderFactory GetProviderFactoryForProviderGuid(IVsDataProviderManager dataProviderManager, Guid provider) { var invariantName = GetProviderInvariantName(dataProviderManager, provider); DbProviderFactory pf = null; if (!String.IsNullOrEmpty(invariantName)) { try { pf = DbProviderFactories.GetFactory(invariantName); } catch (ConfigurationException) { // do nothing. we were tracing here before } catch (ArgumentException) { // do nothing. we were tracing here before } } return pf; }
private static DbProviderFactory GetProviderFactoryForProviderGuid(IVsDataProviderManager dataProviderManager, Guid provider) { var invariantName = GetProviderInvariantName(dataProviderManager, provider); DbProviderFactory pf = null; if (!String.IsNullOrEmpty(invariantName)) { try { pf = DbProviderFactories.GetFactory(invariantName); } catch (ConfigurationException) { // do nothing. we were tracing here before } catch (ArgumentException) { // do nothing. we were tracing here before } } return(pf); }
internal EntityDataConnectionDialog(Project appProject) { _appProject = appProject; _dialogFactory = Package.GetGlobalService(typeof(IVsDataConnectionDialogFactory)) as IVsDataConnectionDialogFactory; if (_dialogFactory == null) { throw new InvalidOperationException(Resources.EntityDataConnectionDialog_NoDataConnectionDialogFactory); } _dataProviderManager = Package.GetGlobalService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; if (_dataProviderManager == null) { throw new InvalidOperationException(Resources.EntityDataConnectionDialog_NoDataProviderManager); } _dataExplorerConnectionManager = Package.GetGlobalService(typeof(IVsDataExplorerConnectionManager)) as IVsDataExplorerConnectionManager; if (_dataExplorerConnectionManager == null) { throw new InvalidOperationException(Resources.EntityDataConnectionDialog_NoDataExplorerConnectionManager); } }
private void Init() { if (_isInitialized) { // need to reset settings on the dialog to avoid displaying stale information // especially showing EntityConnectionString for CodeFirst from Database NewDataSourceSelected(); return; } using (new VsUtils.HourglassHelper()) { // // look up the DDEX Service Providers we use in this wizard // _dataConnectionManager = ServiceProvider.GetService(typeof(IVsDataConnectionManager)) as IVsDataConnectionManager; _dataExplorerConnectionManager = ServiceProvider.GetService(typeof(IVsDataExplorerConnectionManager)) as IVsDataExplorerConnectionManager; _dataProviderManager = ServiceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; var providerMapper = ServiceProvider.GetService(typeof(IDTAdoDotNetProviderMapper)) as IDTAdoDotNetProviderMapper; Debug.Assert(providerMapper != null, "providerMapper == null"); // populate the combo box with project connections first var globalConnectionService = ServiceProvider.GetService(typeof(IGlobalConnectionService)) as IGlobalConnectionService; var dataConnections = new Dictionary <string, DataConnection>(); if (null != globalConnectionService) { try { var connections = globalConnectionService.GetConnections(ServiceProvider, Wizard.Project); foreach (var connection in connections) { if (connection.Location == ConnectionLocation.SettingsFile || connection.Location == ConnectionLocation.Both) { var providerGuid = providerMapper.MapInvariantNameToGuid( connection.ProviderName, connection.DesignTimeConnectionString, false); if (DataConnectionUtils.HasEntityFrameworkProvider( _dataProviderManager, providerGuid, Wizard.Project, ServiceProvider) && DataProviderProjectControl.IsProjectSupported(providerGuid, Wizard.Project)) { dataSourceComboBox.Items.Add( new DataSourceComboBoxItem( connection.Name + " (Settings)", providerGuid, connection.DesignTimeConnectionString, false)); dataConnections.Add(connection.DesignTimeConnectionString, connection); } } } } catch { // there is a bug in the VSDesigner; it throws an exception when attempting to call GetConnections if there is a bad connection // if there is a problem, the only thing we can do is just add all connections, and the project connections won't be sorted in order. } } // populate the combo box with connection names from server explorer foreach (var connection in _dataExplorerConnectionManager.Connections.Values) { if (DataConnectionUtils.HasEntityFrameworkProvider( _dataProviderManager, connection.Provider, Wizard.Project, ServiceProvider) && DataProviderProjectControl.IsProjectSupported(connection.Provider, Wizard.Project) && !dataConnections.ContainsKey(DataConnectionUtils.DecryptConnectionString(connection.Connection))) { dataSourceComboBox.Items.Add(new DataSourceComboBoxItem(connection.DisplayName, connection.Connection)); } } // highlight the first one in the list if (dataSourceComboBox.Items.Count > 0) { dataSourceComboBox.SelectedIndex = 0; } // set a minimum height for the connection string text box if (textBoxConnectionString.Height < textBoxConnectionString.Font.Height) { textBoxConnectionString.Height = textBoxConnectionString.Font.Height; } // mark as initialized _isInitialized = true; } // restore cursor }
internal static string GetInitialCatalog(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { string initialCatalog = null; var invariantName = GetProviderInvariantName(dataProviderManager, dataConnection.Provider); var props = GetConnectionProperties(dataProviderManager, dataConnection); if (props != null) { if (props.ContainsKey(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME) && !string.IsNullOrEmpty(props[LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME] as string)) { //sql client with "AttachDbFileName" parameter in the connection string. object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_ATTACH_DB_FILENAME, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else if (LocalDataUtil.IsSqlMobileConnectionString(invariantName)) { // sql CE object o = null; props.TryGetValue(LocalDataUtil.CONNECTION_PROPERTY_DATA_SOURCE, out o); initialCatalog = o as String; if (initialCatalog != null) { initialCatalog = Path.GetFileNameWithoutExtension(initialCatalog); } } else { object o = null; props.TryGetValue("Database", out o); initialCatalog = o as String; } } // save the default catalog if (string.IsNullOrEmpty(initialCatalog)) { var sourceInformation = dataConnection.GetService(typeof(IVsDataSourceInformation)) as IVsDataSourceInformation; Debug.Assert( sourceInformation != null, "Could not find the IVsDataSourceInformation for this IVsDataConnection to determine the default catalog"); if (sourceInformation != null) { initialCatalog = sourceInformation["DefaultCatalog"] as string; // Note: it is valid for initialCatalog to be null for certain providers which do not support that concept } } return initialCatalog; }
private void Init() { if (_isInitialized) { // need to reset settings on the dialog to avoid displaying stale information // especially showing EntityConnectionString for CodeFirst from Database NewDataSourceSelected(); return; } using (new VsUtils.HourglassHelper()) { // // look up the DDEX Service Providers we use in this wizard // _dataConnectionManager = ServiceProvider.GetService(typeof(IVsDataConnectionManager)) as IVsDataConnectionManager; _dataExplorerConnectionManager = ServiceProvider.GetService(typeof(IVsDataExplorerConnectionManager)) as IVsDataExplorerConnectionManager; _dataProviderManager = ServiceProvider.GetService(typeof(IVsDataProviderManager)) as IVsDataProviderManager; var providerMapper = ServiceProvider.GetService(typeof(IDTAdoDotNetProviderMapper)) as IDTAdoDotNetProviderMapper; Debug.Assert(providerMapper != null, "providerMapper == null"); // populate the combo box with project connections first var globalConnectionService = ServiceProvider.GetService(typeof(IGlobalConnectionService)) as IGlobalConnectionService; var dataConnections = new Dictionary<string, DataConnection>(); if (null != globalConnectionService) { try { var connections = globalConnectionService.GetConnections(ServiceProvider, Wizard.Project); foreach (var connection in connections) { if (connection.Location == ConnectionLocation.SettingsFile || connection.Location == ConnectionLocation.Both) { var providerGuid = providerMapper.MapInvariantNameToGuid( connection.ProviderName, connection.DesignTimeConnectionString, false); if (DataConnectionUtils.HasEntityFrameworkProvider( _dataProviderManager, providerGuid, Wizard.Project, ServiceProvider) && DataProviderProjectControl.IsProjectSupported(providerGuid, Wizard.Project)) { dataSourceComboBox.Items.Add( new DataSourceComboBoxItem( connection.Name + " (Settings)", providerGuid, connection.DesignTimeConnectionString, false)); dataConnections.Add(connection.DesignTimeConnectionString, connection); } } } } catch { // there is a bug in the VSDesigner; it throws an exception when attempting to call GetConnections if there is a bad connection // if there is a problem, the only thing we can do is just add all connections, and the project connections won't be sorted in order. } } // populate the combo box with connection names from server explorer foreach (var connection in _dataExplorerConnectionManager.Connections.Values) { if (DataConnectionUtils.HasEntityFrameworkProvider( _dataProviderManager, connection.Provider, Wizard.Project, ServiceProvider) && DataProviderProjectControl.IsProjectSupported(connection.Provider, Wizard.Project) && !dataConnections.ContainsKey(DataConnectionUtils.DecryptConnectionString(connection.Connection))) { dataSourceComboBox.Items.Add(new DataSourceComboBoxItem(connection.DisplayName, connection.Connection)); } } // highlight the first one in the list if (dataSourceComboBox.Items.Count > 0) { dataSourceComboBox.SelectedIndex = 0; } // set a minimum height for the connection string text box if (textBoxConnectionString.Height < textBoxConnectionString.Font.Height) { textBoxConnectionString.Height = textBoxConnectionString.Font.Height; } // mark as initialized _isInitialized = true; } // restore cursor }
internal static string GetProviderInvariantName(IVsDataProviderManager dataProviderManager, Guid provider) { var invariantName = String.Empty; IVsDataProvider dataProvider = null; Debug.Assert(dataProviderManager != null, "_dataProviderManager is not initialized!"); if (dataProviderManager != null) { dataProviderManager.Providers.TryGetValue(provider, out dataProvider); Debug.Assert(dataProvider != null, "Invalid provider Guid"); if (dataProvider != null) { invariantName = (string)dataProvider.GetProperty("InvariantName"); } } Debug.Assert( !String.IsNullOrEmpty(invariantName), "provider " + dataProvider != null ? dataProvider.DisplayName : "(null)" + " has a null InvariantName"); return invariantName; }
// internal for testing internal string GetTextBoxConnectionStringValue(IVsDataProviderManager dataProviderManager, Guid providerGuid, string maskedConnectionString) { // providerGuid will be the design-time provider guid from DDEX, so we need to translate to the runtime provider invariant name var designTimeProviderInvariantName = DataConnectionUtils.GetProviderInvariantName(dataProviderManager, providerGuid); var runtimeProviderInvariantName = ConnectionManager.TranslateInvariantName( ServiceProvider, designTimeProviderInvariantName, maskedConnectionString, true); var runtimeConnectionString = ConnectionManager.TranslateConnectionString(ServiceProvider, Wizard.Project, designTimeProviderInvariantName, maskedConnectionString, true); if (Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.GenerateFromDatabase) { var metadataFiles = ConnectionManager.GetMetadataFileNamesFromArtifactFileName( Wizard.Project, Wizard.ModelBuilderSettings.ModelPath, ServiceProvider); return ConnectionManager.CreateEntityConnectionString( Wizard.Project, Wizard.ModelBuilderSettings.VSApplicationType, metadataFiles, runtimeConnectionString, runtimeProviderInvariantName).Text; } else { Debug.Assert( Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.CodeFirstFromDatabase, "Unexpected model generation option"); return ConnectionManager.InjectEFAttributesIntoConnectionString( runtimeConnectionString, runtimeProviderInvariantName); } }
internal static IVsDataConnectionProperties GetConnectionProperties( IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataConnectionProperties properties = null; var provider = GetVsProvider(dataProviderManager, dataConnection); Debug.Assert(provider != null, "null provider value for dataConnection"); if (provider != null) { var dataSource = GetVsDataSource(dataProviderManager, dataConnection); properties = provider.TryCreateObject<IVsDataConnectionProperties>(dataSource); Debug.Assert(properties != null, "Could not get connection properties service"); if (properties != null) { var connectionString = DecryptConnectionString(dataConnection) ?? string.Empty; properties.Parse(connectionString); } } return properties; }
private static Guid GetVsDataSource(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } var guid = Guid.Empty; var provider = GetVsProvider(dataProviderManager, dataConnection); guid = provider.DeriveSource(DataProtection.DecryptString(dataConnection.EncryptedConnectionString)); return guid; }
internal static IVsDataProvider GetVsProvider(IVsDataProviderManager dataProviderManager, IVsDataConnection dataConnection) { if (dataConnection == null) { throw new ArgumentNullException("dataConnection"); } IVsDataProvider vsDataProvider = null; dataProviderManager.Providers.TryGetValue(dataConnection.Provider, out vsDataProvider); Debug.Assert( vsDataProvider != null, "Data provider identified by guid '{0}' could not be loaded" + dataConnection.Provider.ToString()); return vsDataProvider; }
private static bool HasModernEntityFrameworkProvider( IVsDataProviderManager dataProviderManager, Guid provider, Project project, IServiceProvider serviceProvider) { Debug.Assert(dataProviderManager != null, "dataProviderManager is null."); Debug.Assert(project != null, "project is null."); Debug.Assert(serviceProvider != null, "serviceProvider is null."); var invariantName = GetProviderInvariantName(dataProviderManager, provider); if (string.IsNullOrWhiteSpace(invariantName)) { return false; } return VsUtils.IsModernProviderAvailable(invariantName, project, serviceProvider); }