| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Linq; |
| | | 3 | | using DirectSight.Logging; |
| | | 4 | | using DirectSight.Reporting.Builders; |
| | | 5 | | |
| | | 6 | | namespace DirectSight.Reporting; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Factory that creates instances of <see cref="IReportBuilder"/>. |
| | | 10 | | /// </summary> |
| | | 11 | | internal static class ReportBuilderFactory |
| | | 12 | | { |
| | | 13 | | public static List<IReportBuilder> GetReportBuilderInstances() |
| | 3 | 14 | | { |
| | 3 | 15 | | return [ new HtmlReportBuilder(), new JsonSummaryReportBuilder() ]; |
| | 3 | 16 | | } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets the available report types. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <returns> |
| | | 22 | | /// The available report types. |
| | | 23 | | /// </returns> |
| | | 24 | | public static IEnumerable<string> GetAvailableReportTypes() |
| | 1 | 25 | | { |
| | 1 | 26 | | var reportBuilders = GetReportBuilderInstances(); |
| | | 27 | | |
| | 3 | 28 | | return [.. reportBuilders.Select(r => r.ReportType)]; |
| | 1 | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets the report builders that correspond to the given <paramref name="reportContext" />. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="reportContext">The report context.</param> |
| | | 35 | | /// <returns> |
| | | 36 | | /// The report builders. |
| | | 37 | | /// </returns> |
| | | 38 | | public static IEnumerable<IReportBuilder> GetReportBuilders(ReportContext reportContext) |
| | 2 | 39 | | { |
| | 2 | 40 | | ConsoleLogger.Debug("Initializing report builders for all report types."); |
| | | 41 | | |
| | 2 | 42 | | var result = GetReportBuilderInstances(); |
| | | 43 | | |
| | 14 | 44 | | foreach (var reportBuilder in result) |
| | 4 | 45 | | { |
| | 4 | 46 | | reportBuilder.ReportContext = reportContext; |
| | 4 | 47 | | } |
| | | 48 | | |
| | 2 | 49 | | return result; |
| | 2 | 50 | | } |
| | | 51 | | } |