Plugins: Adding an enabled property

This commit is contained in:
Zoe Roux 2021-08-13 12:01:07 +02:00
parent 2e0c96b228
commit b67e0a629e
6 changed files with 36 additions and 16 deletions

View File

@ -11,16 +11,26 @@ namespace Kyoo
/// <summary> /// <summary>
/// Get a connection string from the Configuration's section "Database" /// Get a connection string from the Configuration's section "Database"
/// </summary> /// </summary>
/// <param name="config">The IConfiguration instance to load.</param> /// <param name="config">The IConfiguration instance to use.</param>
/// <param name="database">The database's name.</param> /// <param name="database">The database's name.</param>
/// <returns>A parsed connection string</returns> /// <returns>A parsed connection string</returns>
public static string GetDatabaseConnection(this IConfiguration config, string database) public static string GetDatabaseConnection(this IConfiguration config, string database)
{ {
DbConnectionStringBuilder builder = new(); DbConnectionStringBuilder builder = new();
IConfigurationSection section = config.GetSection("Database").GetSection(database); IConfigurationSection section = config.GetSection("database:configurations").GetSection(database);
foreach (IConfigurationSection child in section.GetChildren()) foreach (IConfigurationSection child in section.GetChildren())
builder[child.Key] = child.Value; builder[child.Key] = child.Value;
return builder.ConnectionString; return builder.ConnectionString;
} }
/// <summary>
/// Get the name of the selected database.
/// </summary>
/// <param name="config">The IConfiguration instance to use.</param>
/// <returns>The name of the selected database.</returns>
public static string GetSelectedDatabase(this IConfiguration config)
{
return config.GetValue<string>("database:enabled");
}
} }
} }

View File

@ -23,6 +23,9 @@ namespace Kyoo.Postgresql
/// <inheritdoc /> /// <inheritdoc />
public string Description => "A database context for postgresql."; public string Description => "A database context for postgresql.";
/// <inheritdoc />
public bool Enabled => _configuration.GetSelectedDatabase() == "postgres";
/// <summary> /// <summary>
/// The configuration to use. The database connection string is pulled from it. /// The configuration to use. The database connection string is pulled from it.
/// </summary> /// </summary>

View File

@ -21,6 +21,9 @@ namespace Kyoo.SqLite
/// <inheritdoc /> /// <inheritdoc />
public string Description => "A database context for sqlite."; public string Description => "A database context for sqlite.";
/// <inheritdoc />
public bool Enabled => _configuration.GetSelectedDatabase() == "sqlite";
/// <summary> /// <summary>

View File

@ -116,6 +116,7 @@ namespace Kyoo.Controllers
.Concat(pluginsPaths.SelectMany(LoadPlugin)) .Concat(pluginsPaths.SelectMany(LoadPlugin))
.GroupBy(x => x.Name) .GroupBy(x => x.Name)
.Select(x => x.First()) .Select(x => x.First())
.Where(x => x.Enabled)
); );
if (!_plugins.Any()) if (!_plugins.Any())

View File

@ -43,7 +43,7 @@ namespace Kyoo
typeof(CoreModule), typeof(CoreModule),
typeof(AuthenticationModule), typeof(AuthenticationModule),
typeof(PostgresModule), typeof(PostgresModule),
// typeof(SqLiteModule), typeof(SqLiteModule),
typeof(PluginTvdb), typeof(PluginTvdb),
typeof(PluginTmdb) typeof(PluginTmdb)
); );

View File

@ -10,19 +10,22 @@
}, },
"database": { "database": {
"sqlite": { "enabled": "sqlite",
"data Source": "kyoo.db", "configurations": {
"cache": "Shared" "sqlite": {
}, "data Source": "kyoo.db",
"postgres": { "cache": "Shared"
"server": "127.0.0.1", },
"port": "5432", "postgres": {
"database": "kyooDB", "server": "127.0.0.1",
"user ID": "kyoo", "port": "5432",
"password": "kyooPassword", "database": "kyooDB",
"pooling": "true", "user ID": "kyoo",
"maxPoolSize": "95", "password": "kyooPassword",
"timeout": "30" "pooling": "true",
"maxPoolSize": "95",
"timeout": "30"
}
} }
}, },