public static IServiceCollection AddStorageProvider(this HealthChecksUIBuilder builder, IConfiguration configuration)
        {
            string configuredStorage = configuration[UIKeys.STORAGE_PROVIDER];
            string connectionString  = configuration[UIKeys.STORAGE_CONNECTION];

            if (string.IsNullOrEmpty(configuredStorage))
            {
                configuredStorage = StorageProviderEnum.InMemory.ToString();
            }

            if (Enum.TryParse(configuredStorage, out StorageProviderEnum storageEnum))
            {
                var providers = Storage.GetProviders();

                var targetProvider = providers[storageEnum];

                if (targetProvider.RequiresConnectionString && string.IsNullOrEmpty(connectionString))
                {
                    throw new ArgumentNullException($"{UIKeys.STORAGE_CONNECTION} value has not been configured and it's required for {storageEnum.ToString()}");
                }

                Console.WriteLine($"Configuring image to work with {storageEnum} provider");

                targetProvider.SetupProvider(builder, connectionString);
            }
            else
            {
                throw new ArgumentException($"Variable {UIKeys.STORAGE_PROVIDER} has an invalid value: {configuredStorage}." +
                                            $" Available providers are {string.Join(" , ", Enum.GetNames(typeof(StorageProviderEnum)))}");
            }

            return(builder.Services);
        }
        public static HealthChecksUIBuilder AddSqliteStorage(this HealthChecksUIBuilder builder, string connectionString, Action <DbContextOptionsBuilder>?configureOptions = null)
        {
            builder.Services.AddDbContext <HealthChecksDb>(options =>
            {
                configureOptions?.Invoke(options);
                options.UseSqlite(connectionString, s => s.MigrationsAssembly("HealthChecks.UI.SQLite.Storage"));
            });

            return(builder);
        }
        public static HealthChecksUIBuilder AddPostgreSqlStorage(this HealthChecksUIBuilder builder, string connectionString, Action <DbContextOptionsBuilder> configureOptions = null)
        {
            builder.Services.AddDbContext <HealthChecksDb>(options =>
            {
                configureOptions?.Invoke(options);
                options.UseNpgsql(connectionString, o => o.MigrationsAssembly("HealthChecks.UI.PostgreSQL.Storage"));
            });

            return(builder);
        }
        public static HealthChecksUIBuilder AddMySqlStorage(this HealthChecksUIBuilder builder, string connectionString, Action <DbContextOptionsBuilder>?configureOptions = null)
        {
            builder.Services.AddDbContext <HealthChecksDb>(options =>
            {
                configureOptions?.Invoke(options);
                options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), s => s.MigrationsAssembly("HealthChecks.UI.MySql.Storage"));
            });

            return(builder);
        }
        public static HealthChecksUIBuilder AddInMemoryStorage(this HealthChecksUIBuilder builder, Action <DbContextOptionsBuilder> configureOptions = null, string databaseName = "HealthChecksUI")
        {
            builder.Services.AddDbContext <HealthChecksDb>(options =>
            {
                configureOptions?.Invoke(options);
                options.UseInMemoryDatabase(databaseName);
            });

            return(builder);
        }
Beispiel #6
0
 public static void ConfigureSqlServer(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI)
 {
     services.AddEntityFrameworkSqlServer();
     services.AddSingleton <IDataBaseModelBuilderOptions>(c => new MsSqlModelBuilderOptions());
     services.AddDbContextPool <ApplicationDbContext>(builder =>
     {
         builder.UseSqlServer(connectionString, s => s.MigrationsAssembly("IoTSharp.Data.SqlServer"));
         builder.UseInternalServiceProvider(services.BuildServiceProvider());
     }
                                                      , poolSize);
     checksBuilder.AddSqlServer(connectionString, name: "IoTSharp.Data.SqlServer");
     healthChecksUI.AddSqlServerStorage(connectionString);
 }
        public static void  ConfigureMySql(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI)
        {
            services.AddEntityFrameworkMySql();
            services.AddSingleton <IDataBaseModelBuilderOptions>(c => new MySqlModelBuilderOptions());
            ServerVersion serverVersion = null;

            try
            {
                serverVersion = ServerVersion.AutoDetect(connectionString);
            }
            catch (Exception ex)
            {
                throw new Exception($"Can't detect MySql server's version ,  {ex.Message} ", ex);
            }
            services.AddSingleton(serverVersion);
            services.AddDbContextPool <ApplicationDbContext>(builder =>
            {
                builder.UseInternalServiceProvider(services.BuildServiceProvider());
                builder.UseMySql(connectionString, serverVersion, s => s.MigrationsAssembly("IoTSharp.Data.MySQL"));
            }
                                                             , poolSize);

            checksBuilder.AddMySql(connectionString, "IoTSharp.Data.MySQL");
            healthChecksUI.AddMySqlStorage(connectionString);
        }
Beispiel #8
0
 public static void ConfigureInMemory(this IServiceCollection services, int poolSize, HealthChecksUIBuilder healthChecksUI)
 {
     services.AddEntityFrameworkInMemoryDatabase();
     services.AddSingleton <IDataBaseModelBuilderOptions>(c => new InMemoryModelBuilderOptions());
     services.AddDbContextPool <ApplicationDbContext>(builder =>
     {
         builder.UseInMemoryDatabase("IoTSharp");
         builder.UseInternalServiceProvider(services.BuildServiceProvider());
     }, poolSize);
     healthChecksUI.AddInMemoryStorage();
 }
        public static void  ConfigureMySql(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI)
        {
            services.AddEntityFrameworkMySql();
            services.AddSingleton <IDataBaseModelBuilderOptions>(c => new MySqlModelBuilderOptions());
            var sv = ServerVersion.AutoDetect(connectionString);

            services.AddSingleton(sv);
            services.AddDbContextPool <ApplicationDbContext>(builder =>
            {
                builder.UseInternalServiceProvider(services.BuildServiceProvider());
                builder.UseMySql(connectionString, sv, s => s.MigrationsAssembly("IoTSharp.Data.MySQL"));
            }
                                                             , poolSize);

            checksBuilder.AddMySql(connectionString, "IoTSharp.Data.MySQL");
            healthChecksUI.AddMySqlStorage(connectionString);
        }