-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCPluginJsonConfiguration.cs
More file actions
73 lines (66 loc) · 1.98 KB
/
CPluginJsonConfiguration.cs
File metadata and controls
73 lines (66 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Microsoft.Extensions.Configuration;
namespace CPlugin.Net;
/// <summary>
/// Represents a configuration to get the plugin files from a json.
/// </summary>
/// <remarks>
/// The section must be called <c>Plugins</c> and its value must be an array of strings.
/// <para>Example:</para>
/// <c>
/// { "Plugins": [ "MyPlugin1.dll", "MyPlugin2.dll" ] }
/// </c>
/// <para>if you have plugins with dependencies, you can do this:</para>
/// <c>
/// {
/// "Plugins": [
/// {
/// "Name": "TestProject.JsonPlugin",
/// "DependsOn": [
/// "TestProject.OldJsonPlugin"
/// ]
/// },
/// {
/// "Name": "TestProject.OldJsonPlugin",
/// "DependsOn": []
/// }
/// ]
/// }
/// </c>
/// </remarks>
public class CPluginJsonConfiguration : CPluginConfigurationBase
{
private readonly IConfiguration _configuration;
/// <summary>
/// Initializes a new instance of the <see cref="CPluginJsonConfiguration"/> class.
/// </summary>
/// <param name="configuration">
/// A set of key/value application configuration properties.
/// </param>
/// <exception cref="ArgumentNullException">
/// <c>configuration</c> is <c>null</c>.
/// </exception>
public CPluginJsonConfiguration(IConfiguration configuration)
{
ArgumentNullException.ThrowIfNull(configuration);
_configuration = configuration;
}
public override IEnumerable<PluginConfig> GetPluginConfigFiles()
{
var values = _configuration
.GetSection("Plugins")
.Get<PluginConfig[]>();
return values is null ? [] : values.Select(p => new PluginConfig
{
Name = GetPluginPath(p.Name),
DependsOn = p.DependsOn
});
}
/// <inheritdoc />
public override IEnumerable<string> GetPluginFiles()
{
var values = _configuration
.GetSection("Plugins")
.Get<string[]>();
return values is null ? [] : values.Select(GetPluginPath);
}
}