Esempio n. 1
0
        public override string GetDestination()
        {
            if (_name != null)
            {
                return(_name);
            }

            var(database, server) = SqlConnectionStringParser.GetDatabaseAndServerFromConnectionString(FactoryName, Connection.ConnectionString);

            return(_name = $"{database}@{server}");
        }
Esempio n. 2
0
        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");
            }
        }
Esempio n. 3
0
        public override bool UsingEncryptedCommunicationChannel()
        {
            string encrypt;
            bool   encryptBool;

            string sslMode;

            switch (SqlProviderParser.GetSupportedProvider(GetFactoryName()))
            {
            case SqlProvider.SqlClient:
                encrypt = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "Encrypt" });

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

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

                return(encryptBool);

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

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

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

                return(false);

            case SqlProvider.MySqlClient:
                encrypt = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "Encrypt", "UseSSL" });

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

                    return(encryptBool);
                }
                else
                {
                    sslMode = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "SSL Mode", "SslMode", "Ssl-Mode" });

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

                    switch (sslMode.ToLower())
                    {
                    case "required":
                    case "verifyca":
                    case "verifyfull":
                        return(true);
                    }

                    return(false);
                }

            case SqlProvider.OracleClient:
                var dataSource = SqlConnectionStringParser.GetConnectionStringValue(Connection.ConnectionString, new[] { "Data Source" });

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

                var protocol = SqlConnectionStringParser.GetOracleDataSourceSubValue(dataSource, "PROTOCOL");

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

                switch (protocol.ToLower())
                {
                case "tcps":
                    return(true);
                }

                return(false);

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