Пример #1
0
        public IIntegrationDatabaseConfiguration Deserialize(string serialized, Func <string, string> valueDecrypter)
        {
            try {
                TextReader reader          = new StringReader(serialized);
                string     providerKeyLine = reader.ReadLine();

                if (providerKeyLine == null)
                {
                    throw new InvalidOperationException("Missing provider key in configuration");
                }

                var    providerKey     = DatabaseProviderKey.Deserialize(providerKeyLine.Replace(DatabaseConfigurations.ProviderKeyName + "=", ""));
                var    config          = createConf(providerKey);
                string encryptedConfig = reader.ReadLine();

                if (!String.IsNullOrEmpty(encryptedConfig))
                {
                    dalDeserializer.Deserialize(valueDecrypter(encryptedConfig), config);
                }

                return(config);
            } catch (Exception e) {
                throw new DatabaseSettingsSerialization.ConfigurationUnWrapException(e);
            }
        }
Пример #2
0
        internal static IPlatformDatabaseServices GetDatabaseServices(DBKind dbKind, ConnectionString connectionString, string schema)
        {
            var pluginProvider = new DatabasePluginProvider <IPlatformDatabaseProvider>(GetDatabasePluginsPath());
            var provider       = pluginProvider.GetImplementation(DatabaseProviderKey.Deserialize(dbKind.ToString()));

            var databaseConfiguration = CreateDatabaseConfiguration(provider, connectionString.GetConnectionString(),
                                                                    connectionString.GetOnsConfig(), String.Empty, schema);

            return(provider.GetPlatformDatabaseServices(databaseConfiguration));
        }
Пример #3
0
        public TConfiguration Deserialize(XElement xml)
        {
            try {
                var key = xml.Attribute(ProviderKeyAttribute);
                if (key == null)
                {
                    throw new ConfigurationSerializationException("No attribute " + ProviderKeyAttribute + " section " + xml.Name.LocalName);
                }

                var conf = createConf(DatabaseProviderKey.Deserialize(key.Value));
                dalDeserializer.Deserialize(xml, conf);
                return(conf);
            } catch (Exception e) {
                throw new ConfigurationSerializationException(e);
            }
        }
Пример #4
0
        public static IRuntimeDatabaseConfiguration For(DatabasePluginProvider <IPlatformDatabaseProvider> provider, DatabaseSettingsSerialization.Source source, DatabaseSettingsSerialization.User user)
        {
            var @params = Read(source, user);

            if (@params.Count == 0)
            {
                return(null);
            }

            var providerKey = DatabaseProviderKey.Deserialize(@params[DatabaseConfigurations.ProviderKeyName].ToString());
            var conf        = provider.GetImplementation(providerKey).CreateEmptyRuntimeDatabaseConfiguration();

            RuntimeDatabaseConfigurations.Fill(conf, @params);

            return(conf);
        }
Пример #5
0
        public static IRuntimeDatabaseConfiguration For(
            DatabasePluginProvider <IPlatformDatabaseProvider> provider,
            DatabaseSettingsSerialization.Source source,
            DatabaseSettingsSerialization.User user,
            DatabaseSettingsSerialization.DataSpace dataSpace,
            ISettingsProvider settingsProvider)
        {
            var providerKeySetting = new Setting <string>(BuildSettingName(source, user, dataSpace, DatabaseConfigurations.ProviderKeyName), string.Empty);
            var providerKeyString  = settingsProvider.Get(providerKeySetting);

            if (string.IsNullOrEmpty(providerKeyString))
            {
                return(null);
            }

            var providerKey = DatabaseProviderKey.Deserialize(providerKeyString);
            var conf        = provider.GetImplementation(providerKey).CreateEmptyRuntimeDatabaseConfiguration();

            RuntimeDatabaseConfigurations.Fill(conf, BuildSettingName(source, user, dataSpace, ""), settingsProvider);

            return(conf);
        }
        /// <summary>
        /// Upgrades the specified connection.
        /// </summary>
        /// <param name="dbmsName">Name of the DBMS.</param>
        /// <param name="connStr">The connection string.</param>
        /// <returns>The upgraded database configuration.</returns>
        /// <exception cref="ConnectionUpgradeException">Unable to upgrade database connection.</exception>
        public IIntegrationDatabaseConfiguration Upgrade(string dbmsName, string connStr)
        {
#pragma warning disable 618
            connStr = SettingsInternal.DecryptStringForUpgrade(connStr);
#pragma warning restore 618

            Dictionary <String, String> providerKeys = new Dictionary <string, string>();
            providerKeys.Add("sql server", "SqlServer");
            providerKeys.Add("oracle", "Oracle");
            bool isSqlServer = dbmsName.ToLower().Equals("sql server");

            IDatabaseProvider provider = pluginProvider.GetImplementation(DatabaseProviderKey.Deserialize(providerKeys[dbmsName.ToLower()]));
            IIntegrationDatabaseConfiguration dbConfig = provider.CreateEmptyIntegrationDatabaseConfiguration();
            MetaDatabaseConfiguration         meta     = new MetaDatabaseConfiguration(dbConfig);

            if (RuntimePlatformUtils.IsJava())
            {
                string connStringOverride_SID  = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(PORT={0})(HOST={1}))(CONNECT_DATA=(SID={2})))";
                Regex  _datasourceJavaSidRegex = new Regex(@"jdbc:oracle:thin:([^/]*)/([^@]*)@([^:]*):([^:]*):([^:]*)", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

                string connStringOverride_ServiceName  = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(PORT={0})(HOST={1}))(CONNECT_DATA=(SERVICE_NAME={2})))";
                Regex  _datasourceJavaServiceNameRegex = new Regex(@"jdbc:oracle:thin:([^/]*)/([^@]*)@([^:]*):([^:]*)/([^:]*)", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

                string username, password, tnsDescriptor;
                Match  _sidMatch, _snMatch;

                _sidMatch = _datasourceJavaSidRegex.Match(connStr);
                if (_sidMatch.Success)
                {
                    username      = _sidMatch.Groups[1].Value;
                    password      = _sidMatch.Groups[2].Value;
                    tnsDescriptor = String.Format(connStringOverride_SID, _sidMatch.Groups[4].Value, _sidMatch.Groups[3].Value, _sidMatch.Groups[5].Value);
                }
                else
                {
                    _snMatch = _datasourceJavaServiceNameRegex.Match(connStr);
                    if (!_snMatch.Success)
                    {
                        throw new ConnectionUpgradeException("Unable to upgrade database connection.");
                    }
                    username      = _snMatch.Groups[1].Value;
                    password      = _snMatch.Groups[2].Value;
                    tnsDescriptor = String.Format(connStringOverride_ServiceName, _snMatch.Groups[4].Value, _snMatch.Groups[3].Value, _snMatch.Groups[5].Value);
                }
                meta.GetParameter("Username").Set(username);
                meta.GetParameter("Password").Set(password);
                dbConfig.AdvancedConfiguration.AdvancedConnectionStringField = tnsDescriptor;
                dbConfig.ConnectionStringOverride = String.Empty;
            }
            else
            {
                Regex _datasourceRegex = new Regex(@"data source=\s*([^ ;]+)\s*;", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                Regex _portRegex       = new Regex(@"port=\s*([^ ;]+)\s*;", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                Regex _catalogRegex    = new Regex(@"initial catalog=\s*([^ ;]+)\s*;", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                Regex _userIdRegex     = new Regex(@"user id=\s*([^ ;]+)\s*;", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                Regex _passwordRegex   = new Regex(@"password=\s*([^ ;]+)\s*;", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);


                Match userIdMatch, passwordMatch;
                bool  isAdvanced = false;

                List <string> basicKeys = new List <string> {
                    "data source", "user id", "password"
                };
                if (isSqlServer)
                {
                    basicKeys.Add("initial catalog");
                }
                else
                {
                    basicKeys.Add("port");
                }

                List <string> keysInConnection = connStr.Split(';').ToList <string>();
                connStr += connStr.EndsWith(";") ? "" : ";";

                foreach (string key in keysInConnection)
                {
                    if (!basicKeys.Contains(key.Substring(0, key.IndexOf("=")).Trim().ToLower()))
                    {
                        isAdvanced = true;
                        break;
                    }
                }

                userIdMatch = _userIdRegex.Match(connStr);
                meta.GetParameter("Username").Set(userIdMatch.Groups[1].Value.Replace("\"", ""));

                passwordMatch = _passwordRegex.Match(connStr);
                meta.GetParameter("Password").Set(passwordMatch.Groups[1].Value.Replace("\"", ""));

                if (isAdvanced)
                {
                    // In advanced mode the connection string override will hold all keys and values except username and password
                    dbConfig.AdvancedConfiguration.AdvancedConnectionStringField = connStr;
                    if (userIdMatch.Success)
                    {
                        dbConfig.AdvancedConfiguration.AdvancedConnectionStringField = dbConfig.AdvancedConfiguration.AdvancedConnectionStringField.Replace(userIdMatch.Groups[0].Value, "");
                    }
                    if (passwordMatch.Success)
                    {
                        dbConfig.AdvancedConfiguration.AdvancedConnectionStringField = dbConfig.AdvancedConfiguration.AdvancedConnectionStringField.Replace(passwordMatch.Groups[0].Value, "");
                    }
                }
                else
                {
                    if (isSqlServer)
                    {
                        meta.GetParameter("Server").Set(_datasourceRegex.Match(connStr).Groups[1].Value.Replace("\"", ""));
                        meta.GetParameter("Catalog").Set(_catalogRegex.Match(connStr).Groups[1].Value.Replace("\"", ""));
                    }
                    else
                    {
                        var dataSrcValues = _datasourceRegex.Match(connStr).Groups[1].Value.Replace("\"", "").Split('/');
                        var portValue     = _portRegex.Match(connStr).Groups[1].Value.Replace("\"", "");
                        meta.GetParameter("Host").Set(dataSrcValues.IsEmpty() ? "" : dataSrcValues[0]);
                        meta.GetParameter("Port").Set(portValue.IsNullOrEmpty() || portValue.Equals("0") ? "1521" /*default*/ : portValue);
                        meta.GetParameter("ServiceName").Set(dataSrcValues.Length < 1 ? "" : dataSrcValues[1]);
                    }
                }
                dbConfig.ConnectionStringOverride = String.Empty;
            }
            return(dbConfig);
        }