OracleProviderConnectorOptions

We found 10 examples in language CSharp for this search. You will see 27 fragments of code.
        public string Configure(OracleServiceInfo si, OracleProviderConnectorOptions configuration)
        {
            UpdateConfiguration(si, configuration);
            return configuration.ToString();
        }

        [Fact]
        public void Constructor_ThrowsIfConfigNull()
        {
            IConfiguration config = null;

            var ex = Assert.Throws<ArgumentNullException>(() => new OracleProviderConnectorOptions(config));
            Assert.Contains(nameof(config), ex.Message);
        }

        [Fact]
        public void Constructor_ThrowsIfTypeNull()
        {
            var config = new OracleProviderConnectorOptions();
            OracleServiceInfo si = null;
            Type dbContextType = null;

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

        [Fact]
        public void Create_ThrowsIfNoValidConstructorFound()
        {
            var config = new OracleProviderConnectorOptions();
            OracleServiceInfo si = null;
            var dbContextType = typeof(BadOracleDbContext);

            var ex = Assert.Throws<ConnectorException>(() => new OracleDbContextConnectorFactory(si, config, dbContextType).Create(null));
            Assert.Contains("BadOracleDbContext", ex.Message);
        }

        public string Configure(OracleServiceInfo si, OracleProviderConnectorOptions configuration)
        {
            UpdateConfiguration(si, configuration);
            return configuration.ToString();
        }

        [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>
        /// 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
                };

            }
        }


        public override object Create(IServiceProvider arg)
        {
            var connectionString = CreateConnectionString();
            object result = null;
            if (connectionString != null)
            {
                result = ReflectionHelpers.CreateInstance(ConnectorType, new object[] { connectionString });
            }

            if (result == null)
            {
                throw new ConnectorException(string.Format("Unable to create instance of '{0}', are you missing 'public {0}(string connectionString)' constructor", ConnectorType));
            }

            return result;
        }

        public Connection Get(IConfiguration configuration, string serviceName)
        {
            var info = string.IsNullOrEmpty(serviceName)
                ? configuration.GetSingletonServiceInfo<OracleServiceInfo>()
                : configuration.GetRequiredServiceInfo<OracleServiceInfo>(serviceName);
            return GetConnection(info, configuration);
        }

        public Connection Get(IConfiguration configuration, IServiceInfo serviceInfo)
            => GetConnection((OracleServiceInfo)serviceInfo, configuration);

        public bool IsSameType(string serviceType) =>
            serviceType.Equals("oracle", StringComparison.InvariantCultureIgnoreCase) ||
            serviceType.Equals("oracledb", StringComparison.InvariantCultureIgnoreCase);

        public bool IsSameType(IServiceInfo serviceInfo) => serviceInfo is OracleServiceInfo;

        private Connection GetConnection(OracleServiceInfo info, IConfiguration configuration)
        {
            var oracleConfig = new OracleProviderConnectorOptions(configuration);
            var configurer = new OracleProviderConfigurer();
            return new Connection(configurer.Configure(info, oracleConfig), "Oracle", info);
        }



        /// <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="logFactory">logging factory</param>
        /// <param name="builder">Microsoft HealthChecksBuilder</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, ILoggerFactory logFactory = null, IHealthChecksBuilder builder = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

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

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

            DoAdd(services, info, config, contextLifetime, builder);
            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="logFactory">logging factory</param>
        /// <param name="builder">Microsoft HealthChecksBuilder</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, ILoggerFactory logFactory = null, IHealthChecksBuilder builder = 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));
            }

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

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

        private static void DoAdd(IServiceCollection services, OracleServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, IHealthChecksBuilder builder)
        {
            Type OracleConnection = ConnectorHelpers.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 (builder == null)
            {
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new SkynetCloudRelationalHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService<ILogger<SkynetCloudRelationalHealthContributor>>()), ServiceLifetime.Singleton));
            }
            else
            {
                builder.AddOracle(factory.CreateConnectionString());
            }
        }

        [Fact]
        public void GetMySqlContributor_ReturnsContributor()
        {
            var appsettings = new Dictionary<string, string>()
            {
                ["mysql:client:server"] = "localhost",
                ["mysql:client:port"] = "1234",
                ["mysql:client:PersistSecurityInfo"] = "true",
                ["mysql:client:password"] = "password",
                ["mysql:client:username"] = "username",
                ["mysql:client:ConnectionTimeout"] = "1"
            };

            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddInMemoryCollection(appsettings);
            var config = configurationBuilder.Build();
            var contrib = RelationalDbHealthContributor.GetMySqlContributor(config);
            Assert.NotNull(contrib);
            var status = contrib.Health();
            Assert.Equal(HealthStatus.DOWN, status.Status);
        }

        [Fact]
        public void GetPostgreSqlContributor_ReturnsContributor()
        {
            var appsettings = new Dictionary<string, string>()
            {
                ["postgres:client:host"] = "localhost",
                ["postgres:client:port"] = "1234",
                ["postgres:client:password"] = "password",
                ["postgres:client:username"] = "username",
                ["postgres:client:timeout"] = "1"
            };

            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddInMemoryCollection(appsettings);
            var config = configurationBuilder.Build();
            var contrib = RelationalDbHealthContributor.GetPostgreSqlContributor(config);
            Assert.NotNull(contrib);
            var status = contrib.Health();
            Assert.Equal(HealthStatus.DOWN, status.Status);
        }

        [Fact]
        public void GetSqlServerContributor_ReturnsContributor()
        {
            var appsettings = new Dictionary<string, string>()
            {
                ["sqlserver:credentials:timeout"] = "1",
                ["sqlserver:credentials:uid"] = "username",
                ["sqlserver:credentials:uri"] = "jdbc:sqlserver://servername:1433;databaseName=de5aa3a747c134b3d8780f8cc80be519e",
                ["sqlserver:credentials:db"] = "de5aa3a747c134b3d8780f8cc80be519e",
                ["sqlserver:credentials:pw"] = "password"
            };

            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddInMemoryCollection(appsettings);
            var config = configurationBuilder.Build();
            var contrib = RelationalDbHealthContributor.GetSqlServerContributor(config);
            Assert.NotNull(contrib);
            var status = contrib.Health();
            Assert.Equal(HealthStatus.DOWN, status.Status);
        }

        [Fact]
        public void GetOracleContributor_ReturnsContributor()
        {
            var appsettings = new Dictionary<string, string>()
            {
                ["oracle:client:server"] = "localhost",
                ["oracle:client:port"] = "1234",
                ["oracle:client:PersistSecurityInfo"] = "true",
                ["oracle:client:password"] = "password",
                ["oracle:client:username"] = "username",
                ["oracle:client:connectiontimeout"] = "1"
            };

            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddInMemoryCollection(appsettings);
            var config = configurationBuilder.Build();
            var contrib = RelationalDbHealthContributor.GetOracleContributor(config);
            Assert.NotNull(contrib);
            var status = contrib.Health();
            Assert.Equal(HealthStatus.DOWN, status.Status);
        }

        [Fact]
        public void Sql_Not_Connected_Returns_Down_Status()
        {
            var implementationType = SqlServerTypeLocator.SqlConnection;
            var sqlConfig = new SqlServerProviderConnectorOptions() { Timeout = 1 };
            var sInfo = new SqlServerServiceInfo("MyId", "jdbc:sqlserver://localhost:1433/databaseName=invalidDatabaseName", "Dd6O1BPXUHdrmzbP", "7E1LxXnlH2hhlPVt");
            var logrFactory = new LoggerFactory();
            var connFactory = new SqlServerProviderConnectorFactory(sInfo, sqlConfig, implementationType);
            var h = new RelationalDbHealthContributor((IDbConnection)connFactory.Create(null), logrFactory.CreateLogger<RelationalDbHealthContributor>());

            var status = h.Health();

            Assert.Equal(HealthStatus.DOWN, status.Status);
            Assert.Contains(status.Details.Keys, k => k == "error");
        }

        [Fact(Skip = "Integration test - requires local db server")]
        public void Sql_Is_Connected_Returns_Up_Status()
        {
            var implementationType = SqlServerTypeLocator.SqlConnection;
            var sqlConfig = new SqlServerProviderConnectorOptions() { Timeout = 1, ConnectionString = "Server=(localdb)\\MSSQLLocalDB;Integrated Security=true" };
            var sInfo = new SqlServerServiceInfo("MyId", string.Empty);
            var logrFactory = new LoggerFactory();
            var connFactory = new SqlServerProviderConnectorFactory(sInfo, sqlConfig, implementationType);
            var h = new RelationalDbHealthContributor((IDbConnection)connFactory.Create(null), logrFactory.CreateLogger<RelationalDbHealthContributor>());

            var status = h.Health();

            Assert.Equal(HealthStatus.UP, status.Status);
        }

Steeltoe.CloudFoundry.Connector.Oracle.OracleProviderConnectorOptions : AbstractServiceConnectorOptions

Fields :

public static String Default_Server
public static Int32 Default_Port

Constructors :

public OracleProviderConnectorOptions()
public OracleProviderConnectorOptions(IConfiguration config = )

Methods :

public String get_ConnectionString()
public Void set_ConnectionString(String value = )
public String get_Server()
public Void set_Server(String value = )
public Int32 get_Port()
public Void set_Port(Int32 value = )
public String get_Username()
public Void set_Username(String value = )
public String get_Password()
public Void set_Password(String value = )
public String get_ServiceName()
public Void set_ServiceName(String value = )
public Int32 get_ConnectionTimeout()
public Void set_ConnectionTimeout(Int32 value = )
public String ToString()
public Type GetType()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()