Implement configuration system with embedded TOML resources for agent and provider definitions, custom IConfigurationSource/Provider for agent and provider options, and DI extension methods. Includes config models for agents, providers, sessions, and Telegram integration.
33 lines
995 B
C#
33 lines
995 B
C#
using System.Reflection;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Luna.Configuration.Services.Providers;
|
|
|
|
internal class ProviderOptionsConfigurationProvider(IEnumerable<(string Name, ProviderOptions Options)> providerOptions)
|
|
: ConfigurationProvider
|
|
{
|
|
public override void Load()
|
|
{
|
|
foreach (var (name, options) in providerOptions)
|
|
{
|
|
var keyPrefix = $"Providers:{name}";
|
|
|
|
foreach (var property in options.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
|
|
{
|
|
var value = property.GetValue(options);
|
|
|
|
if (value is string[] array)
|
|
{
|
|
for (var i = 0; i < array.Length; i++)
|
|
Data[$"{keyPrefix}:{property.Name}:{i}"] = array[i];
|
|
}
|
|
else
|
|
{
|
|
Data[$"{keyPrefix}:{property.Name}"] = value?.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|