OracleProviderConnectorFactory

We found 8 examples in language CSharp for this search. You will see 34 fragments of code.
        [Fact]
        public void Constructor_ThrowsIfConfigNull()
        {
            OracleProviderConnectorOptions config = null;
            OracleServiceInfo si = null;

            var ex = Assert.Throws<ArgumentNullException>(() => new OracleProviderConnectorFactory(si, config, typeof(OracleConnection)));
            Assert.Contains(nameof(config), ex.Message);
        }

        /// <summary>
        /// Add an IHealthContributor to a ServiceCollection for Oracle
        /// </summary>
        /// <param name="services">Service collection to add to</param>
        /// <param name="config">App configuration</param>
        /// <param name="contextLifetime">Lifetime of the service to inject</param>
        /// <returns>IServiceCollection for chaining</returns>
        public static IServiceCollection AddOracleHealthContributor(this IServiceCollection services, IConfiguration config, ServiceLifetime contextLifetime = ServiceLifetime.Singleton)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var info = config.GetSingletonServiceInfo<OracleServiceInfo>();

            DoAdd(services, info, config, contextLifetime);
            return services;
        }

        /// <summary>
        /// Add an IHealthContributor to a ServiceCollection for Oracle
        /// </summary>
        /// <param name="services">Service collection to add to</param>
        /// <param name="config">App configuration</param>
        /// <param name="serviceName">cloud foundry service name binding</param>
        /// <param name="contextLifetime">Lifetime of the service to inject</param>
        /// <returns>IServiceCollection for chaining</returns>
        public static IServiceCollection AddOracleHealthContributor(this IServiceCollection services, IConfiguration config, string serviceName, ServiceLifetime contextLifetime = ServiceLifetime.Singleton)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException(nameof(serviceName));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var info = config.GetRequiredServiceInfo<OracleServiceInfo>(serviceName);

            DoAdd(services, info, config, contextLifetime);
            return services;
        }

        private static void DoAdd(IServiceCollection services, OracleServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
        {
            var oracleConfig = new OracleProviderConnectorOptions(config);
            var factory = new OracleProviderConnectorFactory(info, oracleConfig, OracleTypeLocator.OracleConnection);
            services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalDbHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService<ILogger<RelationalDbHealthContributor>>()), contextLifetime));
        }

        /// <summary>
        /// Oracle连接字符串构建
        /// </summary>
        /// <param name="config"></param>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public static string BuildeOracleConnectionString(this IConfiguration config, string serviceName = null)
        {
            OracleServiceInfo info = string.IsNullOrEmpty(serviceName)
                  ? config.GetSingletonServiceInfo<OracleServiceInfo>()
                  : config.GetRequiredServiceInfo<OracleServiceInfo>(serviceName);
            OracleProviderConnectorOptions oracleProviderConnectorOptions = new OracleProviderConnectorOptions(config);
            OracleProviderConnectorFactory factory = new OracleProviderConnectorFactory(info, oracleProviderConnectorOptions, null);
            return factory.CreateConnectionString();
        }


        /// <summary>
        /// Mysql连接字符串构建
        /// </summary>
        /// <param name="config"></param>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public static string BuildeMysqlConnectionString(this IConfiguration config, string serviceName = null)
        {
            MySqlServiceInfo info = string.IsNullOrEmpty(serviceName)
                    ? config.GetSingletonServiceInfo<MySqlServiceInfo>()
                    : config.GetRequiredServiceInfo<MySqlServiceInfo>(serviceName);
            MySqlProviderConnectorOptions mySqlConfig = new MySqlProviderConnectorOptions(config);
            MySqlProviderConnectorFactory factory = new MySqlProviderConnectorFactory(info, mySqlConfig, null);
            return factory.CreateConnectionString();
        }

        /// <summary>
        /// Postgre连接字符串构建
        /// </summary>
        /// <param name="config"></param>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public static string BuildePostgreConnectionString(this IConfiguration config, string serviceName = null)
        {
            PostgresServiceInfo info = string.IsNullOrEmpty(serviceName)
                    ? config.GetSingletonServiceInfo<PostgresServiceInfo>()
                    : config.GetRequiredServiceInfo<PostgresServiceInfo>(serviceName);

            PostgresProviderConnectorOptions mySqlConfig = new PostgresProviderConnectorOptions(config);
            PostgresProviderConnectorFactory factory = new PostgresProviderConnectorFactory(info, mySqlConfig, null);
            return factory.CreateConnectionString();
        }

        /// <summary>
        /// MsSql连接字符串构建
        /// </summary>
        /// <param name="config"></param>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public static string BuildeSqlServerConnectionString(this IConfiguration config, string serviceName = null)
        {
            SqlServerServiceInfo info = string.IsNullOrEmpty(serviceName)
           ? config.GetSingletonServiceInfo<SqlServerServiceInfo>()
           : config.GetRequiredServiceInfo<SqlServerServiceInfo>(serviceName);

            SqlServerProviderConnectorOptions sqlServerConfig = new SqlServerProviderConnectorOptions(config);

            SqlServerProviderConnectorFactory factory = new SqlServerProviderConnectorFactory(info, sqlServerConfig, null);
            var dbConnectionString = factory.CreateConnectionString();
            return factory.CreateConnectionString();
        }

        /// <summary>
        /// 连接信息构建
        /// </summary>
        /// <param name="dbContextOption"></param>
        /// <param name="dbcs"></param>
        /// <returns></returns>
        public static IEnumerable<DbContextOption> DbContextOption(this DbContextOption dbContextOption, IDictionary<string, DbContextOption> dbcs)
        {
            if (dbcs.Count > 0)
            {
                using (var connContext = new ProtocolDbContext(dbContextOption))
                {
                    var conn = connContext.Set<ProtocolInfo>().Where(p => p.ProtocalType == ProtocalType.DB && dbcs.Keys.Contains(p.ContainerName)).ToList();
                    List<int> cfgIds = conn.Select(p => p.CfgID).ToList();
                    var details = connContext.Set<ProtocolCfgInfo>().Where(p => cfgIds.Contains(p.CfgID)).ToList();
                    if (conn != null && conn.Count > 0)
                    {
                        foreach (var item in conn)
                        {
                            if (details != null && details.Count > 0)
                            {
                                var connDetail = details.FirstOrDefault(p => p.CfgID == item.CfgID);
                                if (connDetail != null)
                                {

                                    if (connDetail.ProviderName == DbProviderNames.Oracle && !string.IsNullOrWhiteSpace(connDetail.ServerName))
                                    {
                                        connDetail.Driver = DbProviderNames.Oracle_Managed_ODP;
                                        item.DataBaseName = connDetail.ServerName;
                                    }
                                    var connectStrings = dbContextOption.ConnectionString;
                                    if (connDetail.ProviderName == DbProviderNames.Oracle)
                                        connectStrings = BuildOracleClientConnectionString(item.DataBaseName, connDetail.DesUserID, connDetail.DesPassword, item.IsConnPool, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                                    else if (connDetail.ProviderName == DbProviderNames.Oracle_Managed_ODP)
                                        connectStrings = BuildOracleManagedODPConnectionString(connDetail.Url, connDetail.Port, item.DataBaseName, connDetail.DesUserID, connDetail.DesPassword, item.IsConnPool, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                                    else if (connDetail.ProviderName == DbProviderNames.Oracle_ODP)
                                        connectStrings = BuildOracleODPConnectionString(connDetail.Url, connDetail.Port, item.DataBaseName, connDetail.DesUserID, connDetail.DesPassword, item.IsConnPool, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                                    else if (connDetail.ProviderName == DbProviderNames.SqlServer)
                                        connectStrings = BuildSqlServerConnectionString(connDetail.Url, connDetail.DesUserID, connDetail.DesPassword, item.DataBaseName, connDetail.Port);
                                    else if (connDetail.ProviderName == DbProviderNames.MySQL)
                                        connectStrings = BuildMySqlConnectionString(connDetail.Url, connDetail.DesUserID, connDetail.DesPassword, item.DataBaseName, connDetail.Port, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                                    if (dbcs.ContainsKey(item.ContainerName))
                                    {
                                        dbcs[item.ContainerName].ConnectionString = connectStrings;
                                        dbcs[item.ContainerName].Provider = connDetail.ProviderName;
                                    }
                                    else
                                    {
                                        var key = dbcs.Keys.FirstOrDefault(p => p.StartsWith(item.ContainerName));
                                        if (!string.IsNullOrEmpty(key))
                                        {
                                            dbcs[key].ConnectionString = connectStrings;
                                            dbcs[key].Provider = connDetail.ProviderName;
                                            dbcs[key].LogggerFactory = dbContextOption.LogggerFactory;
                                        }
                                    }


                                }
                            }
                        }


                    }
                }
            }


            return dbcs.Values;
        }

        /// <summary>
        /// 单一连接构建
        /// </summary>
        /// <param name="dbContextOption"></param>
        /// <param name="defaultContainer"></param>
        /// <returns></returns>
        public static DbContextOption SingleDbContextOption(this DbContextOption dbContextOption, string defaultContainer)
        {
            using (var connContext = new ProtocolDbContext(dbContextOption))
            {
                var conn = connContext.Set<ProtocolInfo>().Where(p => p.ProtocalType == ProtocalType.DB && p.ContainerName.Equals(defaultContainer)).ToList();

                if (conn != null && conn.Count > 0)
                {
                    var item = conn.FirstOrDefault();
                    var connDetail = connContext.Set<ProtocolCfgInfo>().Get(item.CfgID);
                    if (connDetail != null)
                    {

                        if (connDetail.ProviderName == DbProviderNames.Oracle && !string.IsNullOrWhiteSpace(connDetail.ServerName))
                        {
                            connDetail.Driver = DbProviderNames.Oracle_Managed_ODP;
                            item.DataBaseName = connDetail.ServerName;
                        }
                        var connectStrings = dbContextOption.ConnectionString;
                        if (connDetail.ProviderName == DbProviderNames.Oracle)
                            connectStrings = BuildOracleClientConnectionString(item.DataBaseName, connDetail.DesUserID, connDetail.DesPassword, item.IsConnPool, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                        else if (connDetail.ProviderName == DbProviderNames.Oracle_Managed_ODP)
                            connectStrings = BuildOracleManagedODPConnectionString(connDetail.Url, connDetail.Port, item.DataBaseName, connDetail.DesUserID, connDetail.DesPassword, item.IsConnPool, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                        else if (connDetail.ProviderName == DbProviderNames.Oracle_ODP)
                            connectStrings = BuildOracleODPConnectionString(connDetail.Url, connDetail.Port, item.DataBaseName, connDetail.DesUserID, connDetail.DesPassword, item.IsConnPool, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                        else if (connDetail.ProviderName == DbProviderNames.SqlServer)
                            connectStrings = BuildSqlServerConnectionString(connDetail.Url, connDetail.DesUserID, connDetail.DesPassword, item.DataBaseName, connDetail.Port);
                        else if (connDetail.ProviderName == DbProviderNames.MySQL)
                            connectStrings = BuildMySqlConnectionString(connDetail.Url, connDetail.DesUserID, connDetail.DesPassword, item.DataBaseName, connDetail.Port, connDetail.CONNET_POOL_MAXACTIVE, connDetail.CONNET_POOL_MAXIDLE);
                        return new DbContextOption()
                        {
                            Container = "upms",
                            Provider = connectStrings,
                            ConnectionString = connDetail.ProviderName,
                            ModuleAssemblyName = dbContextOption.ModuleAssemblyName,
                            MappingFile = dbContextOption.MappingFile,
                            LogggerFactory = dbContextOption.LogggerFactory
                        };

                    }
                }

                return new DbContextOption()
                {
                    Container = defaultContainer,
                    Provider = dbContextOption.Provider,
                    ConnectionString = dbContextOption.ConnectionString,
                    ModuleAssemblyName = dbContextOption.ModuleAssemblyName,
                    MappingFile = dbContextOption.MappingFile,
                    LogggerFactory = dbContextOption.LogggerFactory
                };

            }
        }

        /// <summary>
        /// Add a Oracle-backed DbContext and Oracle health contributor to the Service Collection
        /// </summary>
        /// <typeparam name="TContext">Type of DbContext to add</typeparam>
        /// <param name="services">Service Collection</param>
        /// <param name="config">Application Configuration</param>
        /// <param name="contextLifetime">Lifetime of the service to inject</param>
        /// <param name="logFactory">logging factory</param>
        /// <returns>IServiceCollection for chaining</returns>
        public static IServiceCollection AddDbContext<TContext>(this IServiceCollection services, IConfiguration config, ServiceLifetime contextLifetime = ServiceLifetime.Scoped, ILoggerFactory logFactory = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var info = config.GetSingletonServiceInfo<OracleServiceInfo>();
            DoAdd(services, config, info, typeof(TContext), contextLifetime, logFactory?.CreateLogger("OracleDbContextServiceCollectionExtensions"));

            return services;
        }

        /// <summary>
        /// Add a Oracle-backed DbContext and Oracle health contributor to the Service Collection
        /// </summary>
        /// <typeparam name="TContext">Type of DbContext to add</typeparam>
        /// <param name="services">Service Collection</param>
        /// <param name="config">Application Configuration</param>
        /// <param name="serviceName">Name of service binding in Cloud Foundry</param>
        /// <param name="contextLifetime">Lifetime of the service to inject</param>
        /// <param name="logFactory">logging factory</param>
        /// <returns>IServiceCollection for chaining</returns>
        public static IServiceCollection AddDbContext<TContext>(this IServiceCollection services, IConfiguration config, string serviceName, ServiceLifetime contextLifetime = ServiceLifetime.Scoped, ILoggerFactory logFactory = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException(nameof(serviceName));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var info = config.GetRequiredServiceInfo<OracleServiceInfo>(serviceName);
            DoAdd(services, config, info, typeof(TContext), contextLifetime, logFactory?.CreateLogger("OracleDbContextServiceCollectionExtensions"));

            return services;
        }

        private static void DoAdd(IServiceCollection services, IConfiguration config, OracleServiceInfo info, Type dbContextType, ServiceLifetime contextLifetime, ILogger logger = null)
        {
            var oracleConfig = new OracleProviderConnectorOptions(config);

            var factory = new OracleDbContextConnectorFactory(info, oracleConfig, dbContextType);
            services.Add(new ServiceDescriptor(dbContextType, factory.Create, contextLifetime));
            try
            {
                var healthFactory = new OracleProviderConnectorFactory(info, oracleConfig, OracleTypeLocator.OracleConnection);
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalDbHealthContributor((IDbConnection)healthFactory.Create(ctx), ctx.GetService<ILogger<RelationalDbHealthContributor>>()), contextLifetime));
            }
            catch (TypeLoadException)
            {
                logger?.LogWarning("Failed to add a HealthContributor for the Oracle DbContext");
            }
        }

        /// <summary>
        /// Add Oracle and its IHealthContributor to a ServiceCollection
        /// </summary>
        /// <param name="services">Service collection to add to</param>
        /// <param name="config">App configuration</param>
        /// <param name="contextLifetime">Lifetime of the service to inject</param>
        /// <param name="addSteeltoeHealthChecks">Add steeltoeHealth checks even if community health checks exist</param>
        /// <returns>IServiceCollection for chaining</returns>
        /// <remarks>OracleConnection is retrievable as both OracleConnection and IDbConnection</remarks>
        public static IServiceCollection AddOracleConnection(this IServiceCollection services, IConfiguration config, ServiceLifetime contextLifetime = ServiceLifetime.Scoped, bool addSteeltoeHealthChecks = false)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var info = config.GetSingletonServiceInfo<OracleServiceInfo>();

            DoAdd(services, info, config, contextLifetime, addSteeltoeHealthChecks);
            return services;
        }

        /// <summary>
        /// Add Oracle and its IHealthContributor to a ServiceCollection.
        /// </summary>
        /// <param name="services">Service collection to add to</param>
        /// <param name="config">App configuration</param>
        /// <param name="serviceName">cloud foundry service name binding</param>
        /// <param name="contextLifetime">Lifetime of the service to inject</param>
        /// <param name="addSteeltoeHealthChecks">Add steeltoeHealth checks even if community health checks exist</param>
        /// <returns>IServiceCollection for chaining</returns>
        /// <remarks>OracleConnection is retrievable as both OracleConnection and IDbConnection</remarks>
        public static IServiceCollection AddOracleConnection(this IServiceCollection services, IConfiguration config, string serviceName, ServiceLifetime contextLifetime = ServiceLifetime.Scoped, bool addSteeltoeHealthChecks = false)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException(nameof(serviceName));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var info = config.GetRequiredServiceInfo<OracleServiceInfo>(serviceName);

            DoAdd(services, info, config, contextLifetime, addSteeltoeHealthChecks);
            return services;
        }

        private static void DoAdd(IServiceCollection services, OracleServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks)
        {
            var oracleConnection = ReflectionHelpers.FindType(OracleTypeLocator.Assemblies, OracleTypeLocator.ConnectionTypeNames);
            var oracleConfig = new OracleProviderConnectorOptions(config);
            var factory = new OracleProviderConnectorFactory(info, oracleConfig, oracleConnection);
            services.Add(new ServiceDescriptor(typeof(IDbConnection), factory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(oracleConnection, factory.Create, contextLifetime));

            if (!services.Any(s => s.ServiceType == typeof(HealthCheckService)) || addSteeltoeHealthChecks)
            {
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RelationalDbHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService<ILogger<RelationalDbHealthContributor>>()), ServiceLifetime.Singleton));
            }
        }

        public static IHealthContributor GetMySqlContributor(IConfiguration configuration, ILogger<SkynetCloudRelationalHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<MySqlServiceInfo>();
            Type mySqlConnection = ConnectorHelpers.FindType(MySqlTypeLocator.Assemblies, MySqlTypeLocator.ConnectionTypeNames);
            var mySqlConfig = new MySqlProviderConnectorOptions(configuration);
            var factory = new MySqlProviderConnectorFactory(info, mySqlConfig, mySqlConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new SkynetCloudRelationalHealthContributor(connection, logger);
        }

        public static IHealthContributor GetOracleContributor(IConfiguration configuration, ILogger<SkynetCloudRelationalHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<OracleServiceInfo>();
            Type oracleConnection = ConnectorHelpers.FindType(OracleTypeLocator.Assemblies, OracleTypeLocator.ConnectionTypeNames);
            var oracleConfig = new OracleProviderConnectorOptions(configuration);
            var factory = new OracleProviderConnectorFactory(info, oracleConfig, oracleConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new SkynetCloudRelationalHealthContributor(connection, logger);
        }

        public static IHealthContributor GetPostgreSqlContributor(IConfiguration configuration, ILogger<SkynetCloudRelationalHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<PostgresServiceInfo>();
            Type postgresConnection = ConnectorHelpers.FindType(PostgreSqlTypeLocator.Assemblies, PostgreSqlTypeLocator.ConnectionTypeNames);
            var postgresConfig = new PostgresProviderConnectorOptions(configuration);
            var factory = new PostgresProviderConnectorFactory(info, postgresConfig, postgresConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new SkynetCloudRelationalHealthContributor(connection, logger);
        }

        public static IHealthContributor GetSqlServerContributor(IConfiguration configuration, ILogger<SkynetCloudRelationalHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<SqlServerServiceInfo>();
            Type sqlServerConnection = SqlServerTypeLocator.SqlConnection;
            var sqlServerConfig = new SqlServerProviderConnectorOptions(configuration);
            var factory = new SqlServerProviderConnectorFactory(info, sqlServerConfig, sqlServerConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new SkynetCloudRelationalHealthContributor(connection, logger);
        }

        public HealthCheckResult Health()
        {
            _logger?.LogTrace("Checking {DbConnection} health", Id);
            var result = new HealthCheckResult();
            result.Details.Add("database", Id);
            try
            {
                _connection.Open();
                var cmd = _connection.CreateCommand();
                cmd.CommandText = "SELECT 1;";
                var qresult = cmd.ExecuteScalar();
                result.Details.Add("status", HealthStatus.UP.ToString());
                result.Status = HealthStatus.UP;
                _logger?.LogTrace("{DbConnection} up!", Id);
            }
            catch (Exception e)
            {
                _logger?.LogError("{DbConnection} down! {HealthCheckException}", Id, e.Message);
                result.Details.Add("error", e.GetType().Name + ": " + e.Message);
                result.Details.Add("status", HealthStatus.DOWN.ToString());
                result.Status = HealthStatus.DOWN;
                result.Description = $"{Id} health check failed";
            }
            finally
            {
                _connection.Close();
            }

            return result;
        }

        private string GetDbName(IDbConnection connection)
        {
            var result = "db";
            switch (connection.GetType().Name)
            {
                case "NpgsqlConnection":
                    result = "PostgreSQL";
                    break;
                case "SqlConnection":
                    result = "SqlServer";
                    break;
                case "MySqlConnection":
                    result = "MySQL";
                    break;
                case "OracleConnection":
                    result = "Oracle";
                    break;
            }

            return string.Concat(result, "-", connection.Database);
        }

        public static DbContextOptionsBuilder UseOracle(this DbContextOptionsBuilder optionsBuilder, IConfiguration config, object oracleOptionsAction = null)
        {
            if (optionsBuilder == null)
            {
                throw new ArgumentNullException(nameof(optionsBuilder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var connection = GetConnection(config);

            return DoUseOracle(optionsBuilder, connection, oracleOptionsAction);
        }

        public static DbContextOptionsBuilder UseOracle(this DbContextOptionsBuilder optionsBuilder, IConfiguration config, string serviceName, object oracleOptionsAction = null)
        {
            if (optionsBuilder == null)
            {
                throw new ArgumentNullException(nameof(optionsBuilder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentException(nameof(serviceName));
            }

            var connection = GetConnection(config, serviceName);

            return DoUseOracle(optionsBuilder, connection, oracleOptionsAction);
        }

        public static DbContextOptionsBuilder<TContext> UseOracle<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, IConfiguration config, object oracleOptionsAction = null)
            where TContext : DbContext
        {
            if (optionsBuilder == null)
            {
                throw new ArgumentNullException(nameof(optionsBuilder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var connection = GetConnection(config);

            return DoUseOracle<TContext>(optionsBuilder, connection, oracleOptionsAction);
        }

        public static DbContextOptionsBuilder<TContext> UseOracle<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, IConfiguration config, string serviceName, object oracleOptionsAction = null)
            where TContext : DbContext
        {
            if (optionsBuilder == null)
            {
                throw new ArgumentNullException(nameof(optionsBuilder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentException(nameof(serviceName));
            }

            var connection = GetConnection(config, serviceName);

            return DoUseOracle<TContext>(optionsBuilder, connection, oracleOptionsAction);
        }

        private static DbContextOptionsBuilder DoUseOracle(DbContextOptionsBuilder optionsBuilder, object connection, object oracleOptionsAction)
        {
            var extensionType = EntityFrameworkCoreTypeLocator.OracleDbContextOptionsType;

            var useMethod = FindUseSqlMethod(extensionType, new Type[] { typeof(DbContextOptionsBuilder), typeof(string) });
            if (extensionType == null)
            {
                throw new ConnectorException("Unable to find UseOracle extension, are you missing Oracle EntityFramework Core assembly");
            }

            var result = ReflectionHelpers.Invoke(useMethod, null, new object[] { optionsBuilder, connection, oracleOptionsAction });
            if (result == null)
            {
                throw new ConnectorException(string.Format("Failed to invoke UseOracle extension, connection: {0}", connection));
            }

            return (DbContextOptionsBuilder)result;
        }

        private static DbContextOptionsBuilder<TContext> DoUseOracle<TContext>(DbContextOptionsBuilder<TContext> optionsBuilder, string connection, object oracleOptionsAction = null)
            where TContext : DbContext
        {
            return (DbContextOptionsBuilder<TContext>)DoUseOracle((DbContextOptionsBuilder)optionsBuilder, connection, oracleOptionsAction);
        }

        public static IHealthContributor GetMySqlContributor(IConfiguration configuration, ILogger<RelationalDbHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<MySqlServiceInfo>();
            var mySqlConnection = ReflectionHelpers.FindType(MySqlTypeLocator.Assemblies, MySqlTypeLocator.ConnectionTypeNames);
            var mySqlConfig = new MySqlProviderConnectorOptions(configuration);
            var factory = new MySqlProviderConnectorFactory(info, mySqlConfig, mySqlConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new RelationalDbHealthContributor(connection, logger);
        }

        public static IHealthContributor GetPostgreSqlContributor(IConfiguration configuration, ILogger<RelationalDbHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<PostgresServiceInfo>();
            var postgresConnection = ReflectionHelpers.FindType(PostgreSqlTypeLocator.Assemblies, PostgreSqlTypeLocator.ConnectionTypeNames);
            var postgresConfig = new PostgresProviderConnectorOptions(configuration);
            var factory = new PostgresProviderConnectorFactory(info, postgresConfig, postgresConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new RelationalDbHealthContributor(connection, logger);
        }

        public static IHealthContributor GetSqlServerContributor(IConfiguration configuration, ILogger<RelationalDbHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<SqlServerServiceInfo>();
            var sqlServerConnection = SqlServerTypeLocator.SqlConnection;
            var sqlServerConfig = new SqlServerProviderConnectorOptions(configuration);
            var factory = new SqlServerProviderConnectorFactory(info, sqlServerConfig, sqlServerConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new RelationalDbHealthContributor(connection, logger);
        }

        public static IHealthContributor GetOracleContributor(IConfiguration configuration, ILogger<RelationalDbHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var info = configuration.GetSingletonServiceInfo<OracleServiceInfo>();
            var oracleConnection = ReflectionHelpers.FindType(OracleTypeLocator.Assemblies, OracleTypeLocator.ConnectionTypeNames);
            var oracleConfig = new OracleProviderConnectorOptions(configuration);
            var factory = new OracleProviderConnectorFactory(info, oracleConfig, oracleConnection);
            var connection = factory.Create(null) as IDbConnection;
            return new RelationalDbHealthContributor(connection, logger);
        }

        public HealthCheckResult Health()
        {
            _logger?.LogTrace("Checking {DbConnection} health", Id);
            var result = new HealthCheckResult();
            result.Details.Add("database", Id);
            try
            {
                _connection.Open();
                var cmd = _connection.CreateCommand();
                cmd.CommandText = (Id.IndexOf("Oracle", StringComparison.OrdinalIgnoreCase) != -1) ? "SELECT 1 FROM dual" : "SELECT 1;";
                var qresult = cmd.ExecuteScalar();
                result.Details.Add("status", HealthStatus.UP.ToString());
                result.Status = HealthStatus.UP;
                _logger?.LogTrace("{DbConnection} up!", Id);
            }
            catch (Exception e)
            {
                _logger?.LogError("{DbConnection} down! {HealthCheckException}", Id, e.Message);
                result.Details.Add("error", e.GetType().Name + ": " + e.Message);
                result.Details.Add("status", HealthStatus.DOWN.ToString());
                result.Status = HealthStatus.DOWN;
                result.Description = $"{Id} health check failed";
            }
            finally
            {
                _connection.Close();
            }

            return result;
        }

        private string GetDbName(IDbConnection connection)
        {
            var result = "db";
            switch (connection.GetType().Name)
            {
                case "NpgsqlConnection":
                    result = "PostgreSQL";
                    break;
                case "SqlConnection":
                    result = "SqlServer";
                    break;
                case "MySqlConnection":
                    result = "MySQL";
                    break;
                case "OracleConnection":
                    result = "Oracle";
                    break;
            }

            return string.Concat(result, "-", connection.Database);
        }

Steeltoe.CloudFoundry.Connector.Oracle.OracleProviderConnectorFactory : Object

Constructors :

public OracleProviderConnectorFactory()
public OracleProviderConnectorFactory(OracleServiceInfo sinfo = , OracleProviderConnectorOptions config = , Type type = )

Methods :

public Object Create(IServiceProvider provider = )
public String CreateConnectionString()
public Object CreateConnection(String connectionString = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods