Exemplo n.º 1
0
        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 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;
        }
Exemplo n.º 3
0
            public IVsDataConnection GetDataConnection(IVsDataConnectionManager dataConnectionManager)
            {
                if (null == _dataConnection)
                {
                    Debug.Assert(null != dataConnectionManager, "dataConnectionManager should not be null");

                    _dataConnection = dataConnectionManager.GetConnection(_provider, _connectionString, _isConnectionStringEncrypted);
                }

                return(_dataConnection);
            }
Exemplo n.º 4
0
        // <summary>
        //     Changes connection string to point to new file path
        // </summary>
        // <param name="newFilePath">New file path</param>
        // <returns>whether successful</returns>
        private bool RetargetConnectionString(string newFilePath)
        {
            // compute the Design and Runtime Connection String values based on the new file path
            // Note: newAppConfigConnectionString should use the |DataDirectory| macro because
            // that is what's displayed on screen and interpreted at runtime, but newConnectionString
            // should not use the macro as it will be used by the wizard at the next step to create
            // a working DB connection
            var filePathKey = LocalDataUtil.GetFilePathKey(
                Wizard.ModelBuilderSettings.DesignTimeProviderInvariantName,
                Wizard.ModelBuilderSettings.DesignTimeConnectionString);
            var newConnectionString = ConvertConnectionStringToNewPath(
                Wizard.ModelBuilderSettings.DesignTimeProviderInvariantName, filePathKey,
                Wizard.ModelBuilderSettings.DesignTimeConnectionString, newFilePath, false);
            var newAppConfigConnectionString = ConvertConnectionStringToNewPath(
                Wizard.ModelBuilderSettings.DesignTimeProviderInvariantName, filePathKey,
                Wizard.ModelBuilderSettings.AppConfigConnectionString, newFilePath, true);

            // update the DataConnection itself with the new path
            var oldProvider = DataConnectionUtils.GetVsProvider(_dataProviderManager, _dataConnection);

            if (null == oldProvider)
            {
                Debug.Fail("Could not find VS Provider for DataConnection " + _dataConnection.DisplayConnectionString);
                return(false);
            }

            if (null == _dataConnectionManager)
            {
                Debug.Fail("this._dataConnectionManager is null - cannot construct new DataConnection");
                return(false);
            }

            var dataConnection = _dataConnectionManager.GetConnection(oldProvider.Guid, newConnectionString, false);

            if (null == dataConnection)
            {
                Debug.Fail(
                    "DataConnectionManager could not get a connection for provider " + oldProvider.Guid + ", newConnectionString "
                    + newConnectionString);
                return(false);
            }

            // update this WizardPage's DataConnection and also set the DataSourceComboBoxItem's
            // dataConnection to this so that this connection is used if the user re-selects this
            // item from the drop-down
            SetDataConnection(dataConnection);
            var currentDataSourceComboBoxItem = dataSourceComboBox.SelectedItem as DataSourceComboBoxItem;

            Debug.Assert(null != currentDataSourceComboBoxItem, "Currently selected should not be null");
            if (null != currentDataSourceComboBoxItem)
            {
                currentDataSourceComboBoxItem.ResetDataConnection(dataConnection);
            }

            // update the Design and Runtime Connection String values stored in ModelBuilderSettings
            // these connection strings & invariant names are coming from the ddex provider, so these are "design-time"
            Wizard.ModelBuilderSettings.SetInvariantNamesAndConnectionStrings(ServiceProvider,
                                                                              Wizard.Project, Wizard.ModelBuilderSettings.DesignTimeProviderInvariantName, newConnectionString,
                                                                              newAppConfigConnectionString, true);
            return(true);
        }
Exemplo n.º 5
0
            public IVsDataConnection GetDataConnection(IVsDataConnectionManager dataConnectionManager)
            {
                if (null == _dataConnection)
                {
                    Debug.Assert(null != dataConnectionManager, "dataConnectionManager should not be null");

                    _dataConnection = dataConnectionManager.GetConnection(_provider, _connectionString, _isConnectionStringEncrypted);
                }

                return _dataConnection;
            }