Example #1
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 RelationalHealthContributor((IDbConnection)factory.Create(ctx), ctx.GetService <ILogger <RelationalHealthContributor> >()), 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());
        }
Example #3
0
        private static string GetConnection(IConfiguration config, string serviceName = null)
        {
            var info = string.IsNullOrEmpty(serviceName)
                ? config.GetSingletonServiceInfo <OracleServiceInfo>()
                : config.GetRequiredServiceInfo <OracleServiceInfo>(serviceName);

            var oracleConfig = new OracleProviderConnectorOptions(config);

            var factory = new OracleProviderConnectorFactory(info, oracleConfig, 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);
        }
        private static void DoAdd(IServiceCollection services, OracleServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks)
        {
            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 (!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));
            }
        }
        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));
        }
Example #7
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);
        }
Example #8
0
        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");
            }
        }
Example #9
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");
        }
        /// <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>());
        }
        /// <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));
        }