public DataContextForm(IVsDataExplorerConnectionManager vsDataExplorerConnectionManager) { this.connectionManager = vsDataExplorerConnectionManager; InitializeComponent(); BindDataSources(); }
public static IDbConnection GetConnection(DSRefNavigator navigator, out string type) { type = null; try { if (navigator != null) { IVsDataExplorerConnectionManager dataConnectionsService = (IVsDataExplorerConnectionManager)Package.GetGlobalService(typeof(IVsDataExplorerConnectionManager)); string itemName = navigator.GetConnectionName(); if (itemName != null) { var connection = dataConnectionsService.Connections[itemName]; return((IDbConnection)connection.Connection.GetLockedProviderObject()); //int iConn; // = dataConnectionsService.GetConnectionIndex(itemName); //DataViewHierarchyAccessor dataViewHierarchy = null; //for(iConn = 0; iConn < dataConnectionsService.Connections.Count; iConn++) //{ // DataViewHierarchyAccessor hierarchyAccessor = // new DataViewHierarchyAccessor((IVsUIHierarchy) dataConnectionsService.GetConnectionHierarchy(iConn)); // try // { // if (hierarchyAccessor.Connection.DisplayConnectionString == itemName) // { // dataViewHierarchy = hierarchyAccessor; // break; // } // } // catch // { // } //} //if (dataViewHierarchy != null) //{ // DataConnection connection = dataViewHierarchy.Connection; // if (connection != null && connection.ConnectionSupport.ProviderObject != null) // { // type = connection.ConnectionSupport.ProviderObject.GetType().FullName; // return (IDbConnection) connection.ConnectionSupport.ProviderObject; // } //} } } } catch { } return(null); }
internal static BindingSource LoadMySqlConnectionsFromServerExplorer(DTE dte) { Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider((IOleServiceProvider)dte); IVsDataExplorerConnectionManager seConnectionsMgr = (IVsDataExplorerConnectionManager)sp.GetService(typeof(IVsDataExplorerConnectionManager).GUID); var mysqlDataExplorerConnections = new List <IVsDataExplorerConnection>(); if (seConnectionsMgr != null) { IDictionary <string, IVsDataExplorerConnection> serverExplorerconnections = seConnectionsMgr.Connections; foreach (var connection in serverExplorerconnections) { if (GuidList.Provider.Equals(connection.Value.Provider)) { mysqlDataExplorerConnections.Add(connection.Value); } } } var connections = new BindingSource(); connections.DataSource = new List <MySqlServerExplorerConnection>(); foreach (IVsDataExplorerConnection con in mysqlDataExplorerConnections) { // get complete connections try { var activeConnection = (MySqlConnection)(con.Connection).GetLockedProviderObject(); if (activeConnection != null) { var csb = (MySqlConnectionStringBuilder)activeConnection.GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(activeConnection, null); if (csb != null) { connections.Add(new MySqlServerExplorerConnection { DisplayName = con.DisplayName, ConnectionString = csb.ConnectionString }); } } } catch { // ignored } finally { (con.Connection).UnlockProviderObject(); } } return(connections); }
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); } }
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 }
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 void ShowNewConnectionDialog(TextBox connectionStringTextBox, DTE dte, ComboBox cmbConnections, bool addSeConnection) { if (dte == null) { throw new ArgumentNullException("dte"); } try { var settings = connectionStringTextBox.Tag != null ? new MySqlConnectionStringBuilder(connectionStringTextBox.Tag.ToString()) : new MySqlConnectionStringBuilder(); var dlg = connectionStringTextBox.Tag == null ? new ConnectDialog() : new ConnectDialog(settings); DialogResult res = dlg.ShowDialog(); if (res != DialogResult.OK) { return; } if ((MySqlConnection)dlg.Connection == null) { return; } var csb = (MySqlConnectionStringBuilder)((MySqlConnection)dlg.Connection).GetType().GetProperty("Settings", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(((MySqlConnection)dlg.Connection), null); if (csb == null) { return; } //make sure we don't have already the same connection if (cmbConnections.FindString(string.Format("{0}({1})", csb.Server, csb.Database)) < 0) { connectionStringTextBox.Tag = csb.ConnectionString; if (!string.IsNullOrEmpty(connectionStringTextBox.Tag.ToString()) && addSeConnection) { // adding connection to server explorer connections Microsoft.VisualStudio.Shell.ServiceProvider sp = new Microsoft.VisualStudio.Shell.ServiceProvider((IOleServiceProvider)dte); IVsDataExplorerConnectionManager seConnectionsMgr = (IVsDataExplorerConnectionManager)sp.GetService(typeof(IVsDataExplorerConnectionManager).GUID); seConnectionsMgr.AddConnection(string.Format("{0}({1})", csb.Server, csb.Database), GuidList.Provider, connectionStringTextBox.Tag.ToString(), false); var connections = (List <MySqlServerExplorerConnection>)cmbConnections.DataSource; connections.Add(new MySqlServerExplorerConnection { DisplayName = string.Format("{0}({1})", csb.Server, csb.Database), ConnectionString = csb.ConnectionString }); cmbConnections.DataSource = null; cmbConnections.DataSource = connections; cmbConnections.ValueMember = "ConnectionString"; cmbConnections.DisplayMember = "DisplayName"; } } cmbConnections.Text = string.Format("{0}({1})", csb.Server, csb.Database); connectionStringTextBox.Text = MaskPassword(csb.ConnectionString); connectionStringTextBox.Tag = csb.ConnectionString; } catch (Exception ex) { MySqlSourceTrace.WriteAppErrorToLog(ex, null, "The connection string is not valid.", true); } }