Beispiel #1
0
        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));
        }
Beispiel #2
0
        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));
        }
        public void UpdateConfiguration(OracleServiceInfo si, OracleProviderConnectorOptions configuration)
        {
            if (si == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(si.Uri))
            {
                configuration.Port = si.Port;
                if (configuration.UrlEncodedCredentials)
                {
                    configuration.Username = WebUtility.UrlDecode(si.UserName);
                    configuration.Password = WebUtility.UrlDecode(si.Password);
                }
                else
                {
                    configuration.Username = si.UserName;
                    configuration.Password = si.Password;
                }

                configuration.Server      = si.Host;
                configuration.ServiceName = si.Path;
            }
        }
Beispiel #4
0
 public OracleDbContextConnectorFactory(OracleServiceInfo info, OracleProviderConnectorOptions config, Type dbContextType)
     : base(info, config, dbContextType)
 {
     if (dbContextType == null)
     {
         throw new ArgumentNullException(nameof(dbContextType));
     }
 }
Beispiel #5
0
        private static string BuildeOracleConnectionString(IConfiguration config, string serviceName = null)
        {
            OracleServiceInfo oracleServiceInfo = string.IsNullOrEmpty(serviceName)
                  ? config.GetSingletonServiceInfo <OracleServiceInfo>()
                  : config.GetRequiredServiceInfo <OracleServiceInfo>(serviceName);

            return(BuildOracleODPConnectionString(oracleServiceInfo.Host, oracleServiceInfo.Port, oracleServiceInfo.Path, oracleServiceInfo.UserName, oracleServiceInfo.Password, true, 10, 20));
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
        /// <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());
        }
Beispiel #10
0
        private static string GetConnection(IConfiguration config, string serviceName = null)
        {
            OracleServiceInfo info = string.IsNullOrEmpty(serviceName)
                ? config.GetSingletonServiceInfo <OracleServiceInfo>()
                : config.GetRequiredServiceInfo <OracleServiceInfo>(serviceName);

            OracleProviderConnectorOptions mySqlConfig = new OracleProviderConnectorOptions(config);

            OracleProviderConnectorFactory factory = new OracleProviderConnectorFactory(info, mySqlConfig, null);

            return(factory.CreateConnectionString());
        }
        public void Oracle_Is_Connected_Returns_Up_Status()
        {
            var implementationType = OracleTypeLocator.OracleConnection;
            var sqlConfig          = new OracleProviderConnectorOptions();
            var sInfo       = new OracleServiceInfo("MyId", "oracle://*****:*****@localhost:1521/orclpdb1");
            var logrFactory = new LoggerFactory();
            var connFactory = new OracleProviderConnectorFactory(sInfo, sqlConfig, implementationType);
            var h           = new RelationalDbHealthContributor((IDbConnection)connFactory.Create(null), logrFactory.CreateLogger <RelationalDbHealthContributor>());

            var status = h.Health();

            Assert.Equal(HealthStatus.UP, status.Status);
        }
        public TestController(IConfigurationRoot config, IOptions <CloudFoundryServicesOptions> opsServInfo)
        {
            config.Bind(_cfApp);
            var env = config.GetSection("ASPNETCORE_ENVIRONMENT").Value;

            logger.Debug($"Created TestController with {env}");
            logger.Debug($"CloudFoundryApplicationOptions {_cfApp.ApplicationId} {_cfApp.ApplicationName} {_cfApp.InstanceIndex}");
            _cfServices = opsServInfo.Value;

            OracleServiceInfo oracleConnOpts = config.GetServiceInfo <OracleServiceInfo>("oracle-db");

            this.info = new AppInfo(config["vcap:application:name"], oracleConnOpts);
        }
Beispiel #13
0
        public void Constructor_CreatesExpected()
        {
            var uri = "oracle://*****:*****@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355?reconnect=true";
            var r1  = new OracleServiceInfo("myId", uri);

            Assert.Equal("myId", r1.Id);
            Assert.Equal("oracle", r1.Scheme);
            Assert.Equal("192.168.0.90", r1.Host);
            Assert.Equal(3306, r1.Port);
            Assert.Equal("7E1LxXnlH2hhlPVt", r1.Password);
            Assert.Equal("Dd6O1BPXUHdrmzbP", r1.UserName);
            Assert.Equal("cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", r1.Path);
            Assert.Equal("reconnect=true", r1.Query);
        }
        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 RelationalHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService <ILogger <RelationalHealthContributor> >()), ServiceLifetime.Singleton));
            }
        }
Beispiel #15
0
        public void Create_ReturnsMySqlConnection()
        {
            OracleProviderConnectorOptions config = new OracleProviderConnectorOptions()
            {
                Server      = "localhost",
                Port        = 3306,
                Password    = "******",
                Username    = "******",
                ServiceName = "database"
            };
            OracleServiceInfo si = new OracleServiceInfo("MyId", "oracle://*****:*****@localhost:1521/orclpdb1");
            var factory          = new OracleProviderConnectorFactory(si, config, typeof(OracleConnection));
            var connection       = factory.Create(null);

            Assert.NotNull(connection);
        }
        public void UpdateConfiguration(OracleServiceInfo si, OracleProviderConnectorOptions configuration)
        {
            if (si == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(si.Uri))
            {
                configuration.Port        = si.Port;
                configuration.Username    = si.UserName;
                configuration.Password    = si.Password;
                configuration.Server      = si.Host;
                configuration.ServiceName = si.Path;
            }
        }
Beispiel #17
0
        /// <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>
        /// <param name="logFactory">logger factory</param>
        /// <returns>IServiceCollection for chaining</returns>
        public static IServiceCollection AddOracleHealthContributor(this IServiceCollection services, IConfiguration config, ServiceLifetime contextLifetime = ServiceLifetime.Singleton, ILoggerFactory logFactory = 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);
            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="contextLifetime">Lifetime of the service to inject</param>
        /// <param name="logFactory">logging factory</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, ILoggerFactory logFactory = null, bool addSteeltoeHealthChecks = false)
        {
            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, addSteeltoeHealthChecks);
            return(services);
        }
Beispiel #19
0
        public void Oracle_Not_Connected_Returns_Down_Status()
        {
            // arrange
            var implementationType = OracleTypeLocator.OracleConnection;
            var sqlConfig          = new OracleProviderConnectorOptions();
            var sInfo       = new OracleServiceInfo("MyId", "oracle://*****:*****@localhost:1521/someService");
            var logrFactory = new LoggerFactory();
            var connFactory = new OracleProviderConnectorFactory(sInfo, sqlConfig, implementationType);
            var h           = new RelationalHealthContributor((IDbConnection)connFactory.Create(null), logrFactory.CreateLogger <RelationalHealthContributor>());

            // act
            var status = h.Health();

            // assert
            Assert.Equal(HealthStatus.DOWN, status.Status);
            Assert.Contains(status.Details.Keys, k => k == "error");
        }
        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());
            }
        }
Beispiel #21
0
        public void Create_ReturnsDbContext()
        {
            OracleProviderConnectorOptions config = new OracleProviderConnectorOptions()
            {
                Server      = "localhost",
                Port        = 1521,
                Password    = "******",
                Username    = "******",
                ServiceName = "ORCLCDB"
            };
            OracleServiceInfo si = new OracleServiceInfo("MyId", "Oracle://*****:*****@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355");
            var factory          = new OracleDbContextConnectorFactory(si, config, typeof(GoodOracleDbContext));
            var context          = factory.Create(null);

            Assert.NotNull(context);
            GoodOracleDbContext gcontext = context as GoodOracleDbContext;

            Assert.NotNull(gcontext);
        }
        public void ConnectionTypeLocatorFindsTypeFromServiceInfo()
        {
            var cosmosInfo   = new CosmosDbServiceInfo("id");
            var mongoInfo    = new MongoDbServiceInfo("id", "mongodb://host");
            var mysqlInfo    = new MySqlServiceInfo("id", "mysql://host");
            var oracleInfo   = new OracleServiceInfo("id", "oracle://host");
            var postgresInfo = new PostgresServiceInfo("id", "postgres://host");
            var rabbitMqInfo = new RabbitMQServiceInfo("id", "rabbitmq://host");
            var redisInfo    = new RedisServiceInfo("id", "redis://host");
            var sqlInfo      = new SqlServerServiceInfo("id", "sqlserver://host");
            var manager      = new ConnectionStringManager(new ConfigurationBuilder().Build());

            Assert.StartsWith("CosmosDb", manager.GetFromServiceInfo(cosmosInfo).Name);
            Assert.StartsWith("MongoDb", manager.GetFromServiceInfo(mongoInfo).Name);
            Assert.StartsWith("MySql", manager.GetFromServiceInfo(mysqlInfo).Name);
            Assert.StartsWith("Oracle", manager.GetFromServiceInfo(oracleInfo).Name);
            Assert.StartsWith("Postgres", manager.GetFromServiceInfo(postgresInfo).Name);
            Assert.StartsWith("RabbitMQ", manager.GetFromServiceInfo(rabbitMqInfo).Name);
            Assert.StartsWith("Redis", manager.GetFromServiceInfo(redisInfo).Name);
            Assert.StartsWith("SqlServer", manager.GetFromServiceInfo(sqlInfo).Name);
        }
        /// <summary>
        /// Add your Oracle-based DbContext to the ContainerBuilder
        /// </summary>
        /// <typeparam name="TContext">Your DbContext</typeparam>
        /// <param name="container">Autofac <see cref="ContainerBuilder" /></param>
        /// <param name="config">Your app config</param>
        /// <param name="serviceName">Name of service instance</param>
        /// <returns><see cref="IRegistrationBuilder{TLimit, TActivatorData, TRegistrationStyle}"/></returns>
        public static IRegistrationBuilder <object, SimpleActivatorData, SingleRegistrationStyle> RegisterDbContext <TContext>(this ContainerBuilder container, IConfiguration config, string serviceName = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

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

            OracleServiceInfo info = serviceName == null
                ? config.GetSingletonServiceInfo <OracleServiceInfo>()
                : config.GetRequiredServiceInfo <OracleServiceInfo>(serviceName);

            var oracleConfig = new OracleProviderConnectorOptions(config);
            var factory      = new OracleProviderConnectorFactory(info, oracleConfig, typeof(TContext));

            return(container.Register(c => factory.Create(null)).As <TContext>());
        }
        public void UpdateConfiguration_WithOracleServiceInfo_ReturnsExpected()
        {
            var configurer = new OracleProviderConfigurer();
            var config     = new OracleProviderConnectorOptions()
            {
                Server      = "localhost",
                Port        = 1234,
                Username    = "******",
                Password    = "******",
                ServiceName = "orcl"
            };
            var si = new OracleServiceInfo("MyId", "oracle://*****:*****@localhost:1521/orclpdb1");

            configurer.UpdateConfiguration(si, config);

            Assert.Equal("localhost", config.Server);
            Assert.Equal(1521, config.Port);
            Assert.Equal("user", config.Username);
            Assert.Equal("pwd", config.Password);
            Assert.Equal("orclpdb1", config.ServiceName);
        }
        public void Configure_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            OracleProviderConnectorOptions config = new OracleProviderConnectorOptions()
            {
                Server      = "localhost",
                Port        = 1234,
                Username    = "******",
                Password    = "******",
                ServiceName = "orcl"
            };

            OracleProviderConfigurer configurer = new OracleProviderConfigurer();
            OracleServiceInfo        si         = new OracleServiceInfo("MyId", "oracle://*****:*****@localhost:1521/orclpdb1");

            _ = configurer.Configure(si, config);

            Assert.Equal("localhost", config.Server);
            Assert.Equal(1521, config.Port);
            Assert.Equal("user", config.Username);
            Assert.Equal("pwd", config.Password);
            Assert.Equal("orclpdb1", config.ServiceName);
        }
        /// <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);
        }
        /// <summary>
        /// Adds a OracleConnection (as IDbConnection and OracleConnection) to your Autofac Container
        /// </summary>
        /// <param name="container">Your Autofac Container Builder</param>
        /// <param name="config">Application configuration</param>
        /// <param name="serviceName">Cloud Foundry service name binding</param>
        /// <returns>the RegistrationBuilder for (optional) additional configuration</returns>
        public static IRegistrationBuilder <object, SimpleActivatorData, SingleRegistrationStyle> RegisterOracleConnection(this ContainerBuilder container, IConfiguration config, string serviceName = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

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

            OracleServiceInfo info = serviceName == null
                ? config.GetSingletonServiceInfo <OracleServiceInfo>()
                : config.GetRequiredServiceInfo <OracleServiceInfo>(serviceName);

            Type oracleConnection = OracleTypeLocator.OracleConnection;
            var  oracleConfig     = new OracleProviderConnectorOptions(config);
            var  factory          = new OracleProviderConnectorFactory(info, oracleConfig, oracleConnection);

            container.RegisterType <RelationalHealthContributor>().As <IHealthContributor>();
            return(container.Register(c => factory.Create(null)).As(typeof(IDbConnection), oracleConnection));
        }
        private static void DoAdd(IServiceCollection services, IConfiguration config, OracleServiceInfo info, Type dbContextType, ServiceLifetime contextLifetime)
        {
            var oracleConfig = new OracleProviderConnectorOptions(config);

            var factory = new OracleDbContextConnectorFactory(info, oracleConfig, dbContextType);

            services.Add(new ServiceDescriptor(dbContextType, factory.Create, contextLifetime));
        }
Beispiel #29
0
 public FaultyController(OracleServiceInfo oracleDbInfo)
 {
 }
 public string Configure(OracleServiceInfo si, OracleProviderConnectorOptions configuration)
 {
     UpdateConfiguration(si, configuration);
     return(configuration.ToString());
 }