Esempio n. 1
0
 public NpgsqlDatabaseInfoCacheKey(NpgsqlConnectionStringBuilder connectionString)
 {
     Port              = connectionString.Port;
     Host              = connectionString.Host;
     Database          = connectionString.Database;
     CompatibilityMode = connectionString.ServerCompatibilityMode;
 }
 public VersionManagerDbContext(string host, int port, string database, string username, string password, SslMode?sslMode = null) : base()
 {
     Host         = host;
     Port         = port;
     DatabaseName = database;
     Username     = username;
     Password     = password;
     SslMode      = sslMode;
     // TODO: This can be made configurable if targeting Postgres?
     // Requires testing.
     CompatibilityMode = ServerCompatibilityMode.Redshift;
 }
Esempio n. 3
0
        /// <summary>
        /// The function will modify private member only, not base[key].
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="value"></param>
        /// <returns>value, coerced as needed to the stored type.</returns>
        private object SetValue(Keywords keyword, object value)
        {
            try
            {
                switch (keyword)
                {
                case Keywords.Host:
                    return(this._host = Convert.ToString(value));

                case Keywords.Port:
                    return(this._port = Convert.ToInt32(value));

                case Keywords.Database:
                    return(this._database = Convert.ToString(value));

                case Keywords.UserName:
                    return(this._username = Convert.ToString(value));

                case Keywords.Password:
                    return(this._password = value as string);

                case Keywords.Krbsrvname:
                    return(this._krbsrvname = Convert.ToString(value));

                case Keywords.SSL:
                    return(this._ssl = ToBoolean(value));

                case Keywords.SslMode:
                    return(this._sslmode = ToSslMode(value));

                case Keywords.Timeout:
                    return(this._timeout = ToInt32(value, 0, TIMEOUT_LIMIT, keyword));

                case Keywords.SearchPath:
                    return(this._searchpath = Convert.ToString(value));

                case Keywords.BufferSize:
                    return(this._bufferSize = Convert.ToInt32(value));

                case Keywords.Pooling:
                    return(this._pooling = ToBoolean(value));

                case Keywords.ConnectionLifeTime:
                    return(this._connection_life_time = Convert.ToInt32(value));

                case Keywords.MinPoolSize:
                    return(this._min_pool_size = ToInt32(value, 0, POOL_SIZE_LIMIT, keyword));

                case Keywords.MaxPoolSize:
                    return(this._max_pool_size = ToInt32(value, 0, POOL_SIZE_LIMIT, keyword));

                case Keywords.SyncNotification:
                    return(this._sync_notification = ToBoolean(value));

                case Keywords.CommandTimeout:
                    return(this._command_timeout = Convert.ToInt32(value));

                case Keywords.Enlist:
                    return(this._enlist = ToBoolean(value));

                case Keywords.IntegratedSecurity:
                    bool iS = ToIntegratedSecurity(value);
                    if (iS == true)
                    {
                        CheckIntegratedSecuritySupport();
                    }

                    return(this._integrated_security = ToIntegratedSecurity(iS));

                case Keywords.IncludeRealm:
                    return(this._includeRealm = ToBoolean(value));

                case Keywords.ApplicationName:
                    return(this._application_name = Convert.ToString(value));

                case Keywords.ServerCompatibility:
                    var strValue = (string)value;
                    if (String.IsNullOrWhiteSpace(strValue))
                    {
                        ServerCompatibilityMode = ServerCompatibilityMode.None;
                    }
                    else if (!Enum.TryParse(strValue, true, out ServerCompatibilityMode))
                    {
                        throw new Exception("Invalid server compatibility value: " + strValue);
                    }
                    return(strValue);

                // No longer supported
                case Keywords.PreloadReader:
                    if (ToBoolean(value))
                    {
                        throw new NotSupportedException("The PreloadReader parameter is no longer supported. Please see https://github.com/npgsql/Npgsql/wiki/PreloadReader-Removal");
                    }
                    return(false);

                case Keywords.UseExtendedTypes:
                    if (ToBoolean(value))
                    {
                        throw new NotSupportedException("The UseExtendedTypes parameter is no longer supported. Please see https://github.com/npgsql/Npgsql/wiki/UseExtendedTypes-Removal");
                    }
                    return(false);

                case Keywords.Compatible:
                    if (!String.IsNullOrWhiteSpace(Convert.ToString(value)))
                    {
                        throw new NotSupportedException("The Compatible parameter is no longer supported.");
                    }
                    return(value);
                }
            }
            catch (InvalidCastException exception)
            {
                string exception_template = string.Empty;

                switch (keyword)
                {
                case Keywords.Port:
                case Keywords.Timeout:
                case Keywords.ConnectionLifeTime:
                case Keywords.MinPoolSize:
                case Keywords.MaxPoolSize:
                case Keywords.CommandTimeout:
                    exception_template = "expecting {0}=[Numeric] value in ConnectionString";
                    break;

                case Keywords.SSL:
                case Keywords.Pooling:
                case Keywords.SyncNotification:
                    exception_template = "expecting {0}=[True/False] value in ConnectionString";
                    break;
                }

                if (!string.IsNullOrEmpty(exception_template))
                {
                    string key_name = GetKeyName(keyword);

                    throw new ArgumentException(string.Format(exception_template, key_name), key_name, exception);
                }

                throw;
            }

            return(null);
        }