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>
/// Get a connection string from the Configuration's section "Database"
/// </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>
/// <returns>A parsed connection string</returns>
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;
}
/// <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 />
public string Description => "A database context for postgresql.";
/// <inheritdoc />
public bool Enabled => _configuration.GetSelectedDatabase() == "postgres";
/// <summary>
/// The configuration to use. The database connection string is pulled from it.
/// </summary>

View File

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

View File

@ -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())

View File

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

View File

@ -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"
}
}
},