Exemplo n.º 1
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");
            }
        }
Exemplo n.º 2
0
        internal static (string Database, string Server) GetDatabaseAndServerFromConnectionString(string factoryName, string connectionString)
        {
            string database;
            string server;

            switch (SqlProviderParser.GetSupportedProvider(factoryName))
            {
            case SqlProvider.SqlClient:
                database = GetConnectionStringValue(connectionString, new[] { "Initial Catalog", "Database" }, throwIfNotFound: false);

                if (database == null)
                {
                    database = "master";
                }

                server = GetConnectionStringValue(connectionString, new[] { "Data Source", "Server" });
                break;

            case SqlProvider.Npgsql:
                database = GetConnectionStringValue(connectionString, new[] { "Database" });
                server   = GetConnectionStringValue(connectionString, new[] { "Host", "Data Source", "Server" });

                var port = GetConnectionStringValue(connectionString, new[] { "Port" }, throwIfNotFound: false);

                if (string.IsNullOrEmpty(port))
                {
                    server += $":{port}";
                }
                break;

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

            return(database, server);
        }
Exemplo 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");
            }
        }
Exemplo n.º 4
0
        internal static (string Database, string Server) GetDatabaseAndServerFromConnectionString(string factoryName, string connectionString)
        {
            string database;
            string server;

            switch (SqlProviderParser.GetSupportedProvider(factoryName))
            {
            case SqlProvider.SqlClient:
                database = GetConnectionStringValue(connectionString, new[] { "Initial Catalog", "Database" });

                if (database == null)
                {
                    database = "master";
                }

                server = GetConnectionStringValue(connectionString, new[] { "Data Source", "Server", "Address", "Addr", "Network Address" });
                break;

            case SqlProvider.Npgsql:
                database = GetConnectionStringValue(connectionString, new[] { "Database" });
                server   = GetConnectionStringValue(connectionString, new[] { "Host", "Data Source", "Server" });

                var postgrePort = GetConnectionStringValue(connectionString, new[] { "Port" });

                if (string.IsNullOrEmpty(postgrePort))
                {
                    server += $":{postgrePort}";
                }
                break;

            case SqlProvider.MySqlClient:
                database = GetConnectionStringValue(connectionString, new[] { "Database", "Initial Catalog" });

                if (database == null)
                {
                    database = "mysql";
                }

                server = GetConnectionStringValue(connectionString, new[] { "Host", "Server", "Data Source", "DataSource", "Address", "Addr", "Network Address" });

                if (server == null)
                {
                    server = "localhost";
                }

                var mysqlPort = GetConnectionStringValue(connectionString, new[] { "Port" });

                if (string.IsNullOrEmpty(mysqlPort) == false)
                {
                    server += $":{mysqlPort}";
                }
                break;

            case SqlProvider.OracleClient:

                server   = null;
                database = null;

                var dataSource = GetConnectionStringValue(connectionString, new[] { "Data Source" });

                if (string.IsNullOrEmpty(dataSource) == false)
                {
                    server = GetOracleDataSourceSubValue(dataSource, "HOST");

                    if (server != null)
                    {
                        var port = GetOracleDataSourceSubValue(dataSource, "PORT");

                        if (port != null)
                        {
                            server += $":{port}";
                        }
                    }

                    database = GetOracleDataSourceSubValue(dataSource, "SERVICE_NAME") ?? GetOracleDataSourceSubValue(dataSource, "SID");

                    if (server == null)
                    {
                        var parts = dataSource.Split(new [] { '@' }, 2);

                        if (parts.Length == 2)
                        {
                            // Data Source=username/password@myserver//instancename;
                            // Data Source=username/password@myserver/myservice:dedicated/instancename;

                            server = parts[1];
                        }
                        else
                        {
                            // Data Source=myOracleDB;
                            server = dataSource;
                        }
                    }
                }

                break;


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

            return(database, server);
        }