From b67e0a629e798c0abcde8af4ee2afa7d295c9dbd Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 13 Aug 2021 12:01:07 +0200 Subject: [PATCH] Plugins: Adding an enabled property --- Kyoo.CommonAPI/Extensions.cs | 14 ++++++++++++-- Kyoo.Postgresql/PostgresModule.cs | 3 +++ Kyoo.SqLite/SqLiteModule.cs | 3 +++ Kyoo/Controllers/PluginManager.cs | 1 + Kyoo/PluginsStartup.cs | 2 +- Kyoo/settings.json | 29 ++++++++++++++++------------- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/Kyoo.CommonAPI/Extensions.cs b/Kyoo.CommonAPI/Extensions.cs index dfb2d4d8..43031638 100644 --- a/Kyoo.CommonAPI/Extensions.cs +++ b/Kyoo.CommonAPI/Extensions.cs @@ -11,16 +11,26 @@ namespace Kyoo /// /// Get a connection string from the Configuration's section "Database" /// - /// The IConfiguration instance to load. + /// The IConfiguration instance to use. /// The database's name. /// A parsed connection string public static string GetDatabaseConnection(this IConfiguration config, string database) { DbConnectionStringBuilder builder = new(); - IConfigurationSection section = config.GetSection("Database").GetSection(database); + IConfigurationSection section = config.GetSection("database:configurations").GetSection(database); foreach (IConfigurationSection child in section.GetChildren()) builder[child.Key] = child.Value; return builder.ConnectionString; } + + /// + /// Get the name of the selected database. + /// + /// The IConfiguration instance to use. + /// The name of the selected database. + public static string GetSelectedDatabase(this IConfiguration config) + { + return config.GetValue("database:enabled"); + } } } \ No newline at end of file diff --git a/Kyoo.Postgresql/PostgresModule.cs b/Kyoo.Postgresql/PostgresModule.cs index b05c1ab7..bbebf946 100644 --- a/Kyoo.Postgresql/PostgresModule.cs +++ b/Kyoo.Postgresql/PostgresModule.cs @@ -23,6 +23,9 @@ namespace Kyoo.Postgresql /// public string Description => "A database context for postgresql."; + /// + public bool Enabled => _configuration.GetSelectedDatabase() == "postgres"; + /// /// The configuration to use. The database connection string is pulled from it. /// diff --git a/Kyoo.SqLite/SqLiteModule.cs b/Kyoo.SqLite/SqLiteModule.cs index 0aa378d7..45dca0f2 100644 --- a/Kyoo.SqLite/SqLiteModule.cs +++ b/Kyoo.SqLite/SqLiteModule.cs @@ -21,6 +21,9 @@ namespace Kyoo.SqLite /// public string Description => "A database context for sqlite."; + + /// + public bool Enabled => _configuration.GetSelectedDatabase() == "sqlite"; /// diff --git a/Kyoo/Controllers/PluginManager.cs b/Kyoo/Controllers/PluginManager.cs index 4812883d..f4d91b81 100644 --- a/Kyoo/Controllers/PluginManager.cs +++ b/Kyoo/Controllers/PluginManager.cs @@ -116,6 +116,7 @@ namespace Kyoo.Controllers .Concat(pluginsPaths.SelectMany(LoadPlugin)) .GroupBy(x => x.Name) .Select(x => x.First()) + .Where(x => x.Enabled) ); if (!_plugins.Any()) diff --git a/Kyoo/PluginsStartup.cs b/Kyoo/PluginsStartup.cs index a28d118c..e279cb57 100644 --- a/Kyoo/PluginsStartup.cs +++ b/Kyoo/PluginsStartup.cs @@ -43,7 +43,7 @@ namespace Kyoo typeof(CoreModule), typeof(AuthenticationModule), typeof(PostgresModule), - // typeof(SqLiteModule), + typeof(SqLiteModule), typeof(PluginTvdb), typeof(PluginTmdb) ); diff --git a/Kyoo/settings.json b/Kyoo/settings.json index 1ddc8cf1..a3d90396 100644 --- a/Kyoo/settings.json +++ b/Kyoo/settings.json @@ -10,19 +10,22 @@ }, "database": { - "sqlite": { - "data Source": "kyoo.db", - "cache": "Shared" - }, - "postgres": { - "server": "127.0.0.1", - "port": "5432", - "database": "kyooDB", - "user ID": "kyoo", - "password": "kyooPassword", - "pooling": "true", - "maxPoolSize": "95", - "timeout": "30" + "enabled": "sqlite", + "configurations": { + "sqlite": { + "data Source": "kyoo.db", + "cache": "Shared" + }, + "postgres": { + "server": "127.0.0.1", + "port": "5432", + "database": "kyooDB", + "user ID": "kyoo", + "password": "kyooPassword", + "pooling": "true", + "maxPoolSize": "95", + "timeout": "30" + } } },