Files
meeting-assistant/MeetingAssistant/Workflow/FileMeetingWorkflowRulesProvider.cs
T
2026-05-27 12:55:18 +02:00

61 lines
1.9 KiB
C#

using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace MeetingAssistant.Workflow;
public interface IMeetingWorkflowRulesProvider
{
Task<IReadOnlyList<MeetingWorkflowRule>> GetRulesAsync(
MeetingAssistantOptions options,
CancellationToken cancellationToken);
}
public sealed class FileMeetingWorkflowRulesProvider : IMeetingWorkflowRulesProvider
{
private readonly ILogger<FileMeetingWorkflowRulesProvider> logger;
private readonly IDeserializer yamlDeserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.Build();
public FileMeetingWorkflowRulesProvider(ILogger<FileMeetingWorkflowRulesProvider> logger)
{
this.logger = logger;
}
public async Task<IReadOnlyList<MeetingWorkflowRule>> GetRulesAsync(
MeetingAssistantOptions options,
CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(options.Automation.RulesPath))
{
return [];
}
var path = ResolvePath(options.Automation.RulesPath);
if (!File.Exists(path))
{
logger.LogDebug("Meeting workflow rules file {RulesPath} does not exist", path);
return [];
}
var yaml = await File.ReadAllTextAsync(path, cancellationToken);
if (string.IsNullOrWhiteSpace(yaml))
{
return [];
}
var rulesFile = yamlDeserializer.Deserialize<MeetingWorkflowRulesFile>(yaml)
?? new MeetingWorkflowRulesFile();
return rulesFile.Rules;
}
private static string ResolvePath(string configuredPath)
{
var expanded = Environment.ExpandEnvironmentVariables(configuredPath);
return Path.IsPathRooted(expanded)
? Path.GetFullPath(expanded)
: Path.GetFullPath(expanded);
}
}