Beispiel #1
0
        public static DbProviderFactory GetFactory(string factoryName)
        {
            switch (SqlProviderParser.GetSupportedProvider(factoryName))
            {
            case SqlProvider.SqlClient:
                return(SqlClientFactory.Instance);

            case SqlProvider.Npgsql:
                return(NpgsqlFactory.Instance);

            default:
                throw new NotSupportedException($"Factory '{factoryName}' is not supported");
            }
        }
        public override bool UsingEncryptedCommunicationChannel()
        {
            switch (SqlProviderParser.GetSupportedProvider(FactoryName))
            {
            case SqlProvider.SqlClient:
                var encrypt = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "Encrypt" }, throwIfNotFound: false);

                if (string.IsNullOrEmpty(encrypt))
                {
                    return(false);
                }

                if (bool.TryParse(encrypt, out var encryptBool) == false)
                {
                    return(false);
                }

                return(encryptBool);

            case SqlProvider.Npgsql:
                var sslMode = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "SslMode" }, throwIfNotFound: false);

                if (string.IsNullOrEmpty(sslMode))
                {
                    return(false);
                }

                switch (sslMode.ToLower())
                {
                case "require":
                case "verify-ca":
                case "verify-full":
                    return(true);
                }

                return(false);

            default:
                throw new NotSupportedException($"Factory '{FactoryName}' is not supported");
            }
        }