Пример #1
0
        internal static IRuntimeDatabaseConfiguration CreateDatabaseConfiguration(IPlatformDatabaseProvider databaseProvider, string connectionString,
                                                                                  string onsClusterConfig, string connectionStringExtras, string schema, bool forConnectionState)
        {
            var config = databaseProvider.CreateEmptyRuntimeDatabaseConfiguration();


            connectionStringExtras = connectionStringExtras ?? "";
            var fullConnectionString   = RuntimePlatformUtils.connectionStringJoin(connectionString, connectionStringExtras);
            var databaseIdentifier     = schema;
            var databaseUnicodeSupport = Settings.GetBool(Settings.Configs.Compiler_DatabaseUnicodeSupport);

            var wrapper = new MetaDatabaseConfiguration(config);

            wrapper.GetParameter("ConnectionString").Set(fullConnectionString);
            var sch = wrapper.GetParameter("Schema");

            if (sch != null)
            {
                sch.Set(databaseIdentifier);
            }

            var unicode = wrapper.GetParameter("DatabaseUnicodeSupport");

            if (unicode != null)
            {
                unicode.Set(databaseUnicodeSupport + "");
            }

            return(config);
        }
        public void Deserialize(XElement xmlConf, TConfiguration conf)
        {
            if (xmlConf == null)
            {
                throw new ConfigurationSerializationException("No root");
            }

            if (xmlConf.Name != Tag)
            {
                throw new ConfigurationSerializationException("Expected element tagged " + Tag + " got " + xmlConf.Name);
            }

            var meta = new MetaDatabaseConfiguration(conf);

            foreach (var elem in xmlConf.Elements())
            {
                var param = meta.GetParameter(elem.Name.LocalName);
                if (param != null)
                {
                    bool decryptValue = ValueDecrypter != null &&
                                        elem.Attribute("encrypted") != null &&
                                        elem.Attribute("encrypted").Value.Equals("true");

                    param.Set(decryptValue ? ValueDecrypter(elem.Value) : elem.Value);
                }
            }
        }
Пример #3
0
        public static ConnectionString GetConnectionString(IRuntimeDatabaseConfiguration config)
        {
            var wrapper = new MetaDatabaseConfiguration(config);

            var cs  = wrapper.GetParameter("ConnectionString");
            var ons = wrapper.GetParameter("OnsConfig");

            if (ons != null)
            {
                return(new ConnectionString(cs.Get(), ons.Get()));
            }
            else
            {
                return(new ConnectionString(cs.Get()));
            }
        }
Пример #4
0
        internal static string GetParameter(object conf, string name)
        {
            var meta  = new MetaDatabaseConfiguration(conf);
            var param = meta.GetParameter(name);

            return((param == null)? "": param.Get());
        }
Пример #5
0
 public void TestGetAdvancedConnectionStringField()
 {
     config = new MockDatabaseConfiguration();
     config.AdvancedConfiguration.AdvancedConnectionStringField = "nonnull";
     wrapper = new MetaDatabaseConfiguration(config);
     Assert.AreEqual("nonnull", wrapper.GetParameter("AdvancedConnectionStringField").Get());
 }
        public void GetParameterReturnsNullWhenNoParameterFound()
        {
            var config  = new MockDatabaseConfiguration();
            var wrapper = new MetaDatabaseConfiguration(config);

            var retrived = wrapper.GetParameter("IDontExist");

            Assert.IsNull(retrived, "Found non existing parameter " + "IDontExist");
        }
        public void GetParameterFindsOnExtraParameters()
        {
            var config  = new MockDatabaseConfiguration();
            var wrapper = new MetaDatabaseConfiguration(config);

            var retrived = wrapper.GetParameter("ConnectionStringOverride");

            Assert.AreEqual("ConnectionStringOverride", retrived.Name);
        }
        public void GetParameterFindsOnAnnotatedParameters()
        {
            var config  = new MockDatabaseConfiguration();
            var wrapper = new MetaDatabaseConfiguration(config);

            var retrieved = wrapper.GetParameter("MockText");

            Assert.AreEqual("MockText", retrieved.Name);
        }
Пример #9
0
        internal static void Fill(object conf, Dictionary <string, object> @params)
        {
            var meta = new MetaDatabaseConfiguration(conf);

            foreach (var p in @params)
            {
                var setter = meta.GetParameter(p.Key);
                if (setter != null)
                {
                    object value    = p.Value;
                    string strValue = (value == null)? null: value.ToString();
                    setter.Set(setter.Encrypt ? SecureConfidentialInformationEncryption.TryDecryptString(strValue) : strValue);
                }
            }
        }
Пример #10
0
        public static void Fill(IRuntimeDatabaseConfiguration conf, Dictionary <string, object> @params)
        {
            var meta = new MetaDatabaseConfiguration(conf);

            foreach (var p in @params)
            {
                var setter = meta.GetParameter(p.Key);
                if (setter != null && setter.Persist)
                {
                    object value    = p.Value;
                    string strValue = value == null ? null : value.ToString();
                    setter.Set(setter.Encrypt ? Settings.DecryptString(strValue) : strValue);
                }
            }
        }
        public void Deserialize(string serializedForm, IIntegrationDatabaseConfiguration config)
        {
            try {
                var wrapper    = new MetaDatabaseConfiguration(config);
                var properties = ReadPropertiesFromSerialization(serializedForm);
                foreach (var nameValue in properties)
                {
                    var param = wrapper.GetParameter(nameValue.Key);

                    if (param != null)
                    {
                        param.Set(nameValue.Value);
                    }
                }
            } catch (Exception e) {
                throw new ConfigurationSerializationException(e);
            }
        }
        /// <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);
        }
Пример #13
0
        public void TestEnumValueConvertion()
        {
            config.MockEnum = DirectionsEnum.Down;
            Assert.AreEqual("Down", wrapper.GetParameter("MockEnum").Get());

            wrapper.GetParameter("MockEnum").Set("Left");
            Assert.AreEqual(DirectionsEnum.Left, config.MockEnum);

            wrapper.GetParameter("MockEnum").Set("");
            Assert.AreEqual(Enum.GetValues(typeof(DirectionsEnum)).GetValue(0), config.MockEnum,
                            "Empty string should be converted to the first Enum value returned by Enum.GetValues in C# and getEnumConstants in Java");
        }