private bool IsSupportedProvider(Guid source, Guid provider)
        {
            RaiseBeforeIsAdoNetProviderEvent();

            var result = DataConnectionUtils.HasEntityFrameworkProvider(
                _dataProviderManager, provider, _appProject, Services.ServiceProvider) &&
                         DataProviderProjectControl.IsProjectSupported(provider, _appProject);

            RaiseAfterIsAdoNetProviderEvent();

            return(result);
        }
Ejemplo n.º 2
0
        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
        }