diff --git a/OmopTransformer/Documentation/DocumentationRenderer.cs b/OmopTransformer/Documentation/DocumentationRenderer.cs index 8b6d7f4..ba711c0 100644 --- a/OmopTransformer/Documentation/DocumentationRenderer.cs +++ b/OmopTransformer/Documentation/DocumentationRenderer.cs @@ -6,15 +6,15 @@ namespace OmopTransformer.Documentation; -public class DocumentationRenderer +internal class DocumentationRenderer { private readonly IReadOnlyCollection _types; - private readonly Dictionary _aggregateQueries; + private readonly IQueryLocator _queryLocator; - public DocumentationRenderer(IReadOnlyCollection types, Dictionary aggregateQueries) + public DocumentationRenderer(IReadOnlyCollection types, IQueryLocator queryLocator) { _types = types; - _aggregateQueries = aggregateQueries; + _queryLocator = queryLocator; } public string Render() @@ -79,7 +79,7 @@ public string Render() private void RenderAggregateTransform(string queryFileName, StringBuilder stringBuilder) { - var query = _aggregateQueries[queryFileName]; + var query = _queryLocator.GetQuery(queryFileName); if (query.Explanation?.Explanations == null) { diff --git a/OmopTransformer/Documentation/DocumentationWriter.cs b/OmopTransformer/Documentation/DocumentationWriter.cs index 12af3ae..4ff1526 100644 --- a/OmopTransformer/Documentation/DocumentationWriter.cs +++ b/OmopTransformer/Documentation/DocumentationWriter.cs @@ -1,6 +1,5 @@ using System.Reflection; using Microsoft.Extensions.Logging; -using OmopTransformer.Transformation; namespace OmopTransformer.Documentation; @@ -8,11 +7,13 @@ internal class DocumentationWriter : IDocumentationWriter { private readonly DocumentationOptions _documentationOption; private readonly ILogger _logger; + private readonly IQueryLocator _queryLocator; - public DocumentationWriter(DocumentationOptions documentationOption, ILogger logger) + public DocumentationWriter(DocumentationOptions documentationOption, ILogger logger, IQueryLocator queryLocator) { _documentationOption = documentationOption; _logger = logger; + _queryLocator = queryLocator; } public async Task WriteToPath(CancellationToken cancellationToken) @@ -25,31 +26,9 @@ public async Task WriteToPath(CancellationToken cancellationToken) return; } - string runningDirectory = AppDomain.CurrentDomain.BaseDirectory; - - string[] queryFilePaths = Directory.GetFiles(runningDirectory, "*.xml", SearchOption.AllDirectories); - - var queryFiles = - queryFilePaths - .Select(async path => - new - { - Path = path, - Text = await File.ReadAllTextAsync(path, cancellationToken) - }) - .ToList(); - - await Task.WhenAll(queryFiles); - - var aggregateQueries = - queryFiles - .ToDictionary( - keySelector: query => Path.GetFileName(query.Result.Path), - elementSelector: query => AggregateQueryParser.ParseAggregateQuery(query.Result.Text)); - Assembly currentAssembly = Assembly.GetExecutingAssembly(); - string documentation = new DocumentationRenderer(currentAssembly.GetTypes(), aggregateQueries).Render(); + string documentation = new DocumentationRenderer(currentAssembly.GetTypes(), _queryLocator).Render(); await File.WriteAllTextAsync(_documentationOption.FilePath, documentation, cancellationToken); }