src/Misc/EFTools/EntityDesign/VisualStudio/Package/ConnectionManager.cs
// <summary>
//     Translate a connection string from design-time to runtime or vice versa.
// </summary>
Translate a connection string from design-time to runtime or vice versa.
Translate a connection string from design - time to runtime or vice versa .
internal static string TranslateConnectionString(IServiceProvider serviceProvider, Project project, string invariantName, string connectionString, bool isDesignTime)
        {
            Debug.Assert(serviceProvider != null, "serviceProvider must not be null");
            Debug.Assert(project != null, "project must not be null");
            Debug.Assert(!string.IsNullOrWhiteSpace(invariantName), "invalid invariantName");
            if (string.IsNullOrEmpty(connectionString))
            {
                return connectionString;
            }
            var converter = (IConnectionStringConverterService)serviceProvider.GetService(typeof(IConnectionStringConverterService));
            if (converter == null)
            {
                return connectionString;
            }
            try
            {
                return isDesignTime
                    ? converter.ToRunTime(project, connectionString, invariantName)
                    : converter.ToDesignTime(
                        project, connectionString, TranslateInvariantName(serviceProvider, invariantName, connectionString, false));
            }
            catch (ConnectionStringConverterServiceException)
            {
                var ddexNotInstalledMsg = 
                    !DDEXProviderInstalled(serviceProvider, invariantName) ? 
                    string.Format(CultureInfo.CurrentCulture, Resources.DDEXNotInstalled, invariantName) :
                    string.Empty;
                var errMsg = isDesignTime
                                 ? string.Format(
                                     CultureInfo.CurrentCulture,
                                     Resources.CannotTranslateDesignTimeConnectionString,
                                     ddexNotInstalledMsg,
                                     connectionString)
                                 : string.Format(
                                     CultureInfo.CurrentCulture,
                                     Resources.CannotTranslateRuntimeConnectionString,
                                     ddexNotInstalledMsg,
                                     connectionString);
                throw new ArgumentException(errMsg);
            }
        }
internal static string TranslateConnectionString ( IServiceProvider serviceProvider , Project project , string invariantName , string connectionString , bool isDesignTime ) { Debug . Assert ( serviceProvider != null , " " ) ; Debug . Assert ( project != null , " " ) ; Debug . Assert ( ! string . IsNullOrWhiteSpace ( invariantName ) , " " ) ; if ( string . IsNullOrEmpty ( connectionString ) ) { return connectionString ; } var converter = ( IConnectionStringConverterService ) serviceProvider . GetService ( typeof ( IConnectionStringConverterService ) ) ; if ( converter == null ) { return connectionString ; } try { return isDesignTime ? converter . ToRunTime ( project , connectionString , invariantName ) : converter . ToDesignTime ( project , connectionString , TranslateInvariantName ( serviceProvider , invariantName , connectionString , false ) ) ; } catch ( ConnectionStringConverterServiceException ) { var ddexNotInstalledMsg = ! DDEXProviderInstalled ( serviceProvider , invariantName ) ? string . Format ( CultureInfo . CurrentCulture , Resources . DDEXNotInstalled , invariantName ) : string . Empty ; var errMsg = isDesignTime ? string . Format ( CultureInfo . CurrentCulture , Resources . CannotTranslateDesignTimeConnectionString , ddexNotInstalledMsg , connectionString ) : string . Format ( CultureInfo . CurrentCulture , Resources . CannotTranslateRuntimeConnectionString , ddexNotInstalledMsg , connectionString ) ; throw new ArgumentException ( errMsg ) ; } }
Translate a connection string from design-time to runtime or vice versa.
Translate a connection string from design - time to runtime or vice versa .
// ConnectionStringConverterServiceException has no Message - convert to a more descriptive exception
serviceProvider
IServiceProvider
project
Project
invariantName
string
connectionString
string
isDesignTime
bool