| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using DirectSight.Common; |
| | | 5 | | |
| | | 6 | | namespace DirectSight; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Provides all parameters that are required for report generation. |
| | | 10 | | /// </summary> |
| | | 11 | | public class ReportConfiguration |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// The report files. |
| | | 15 | | /// </summary> |
| | 11 | 16 | | private readonly List<string> reportFiles = []; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// The report file pattern that could not be parsed. |
| | | 20 | | /// </summary> |
| | 11 | 21 | | private readonly List<string> invalidReportFilePatterns = []; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes a new instance of the <see cref="ReportConfiguration" /> class. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="reportFilePatterns">The report file patterns.</param> |
| | | 27 | | /// <param name="targetDirectory">The target directory.</param> |
| | | 28 | | /// <param name="debugMode">The indicator for debug mode.</param> |
| | 11 | 29 | | public ReportConfiguration( |
| | 11 | 30 | | IEnumerable<string> reportFilePatterns, |
| | 11 | 31 | | string targetDirectory, |
| | 11 | 32 | | string debugMode) |
| | 11 | 33 | | { |
| | 11 | 34 | | ArgumentNullException.ThrowIfNull(reportFilePatterns); |
| | | 35 | | |
| | 11 | 36 | | var seen = new HashSet<string>(); |
| | | 37 | | |
| | 57 | 38 | | foreach (var reportFilePattern in reportFilePatterns) |
| | 12 | 39 | | { |
| | | 40 | | try |
| | 12 | 41 | | { |
| | 12 | 42 | | var files = GlobbingFileSearch.GetFiles(reportFilePattern); |
| | | 43 | | |
| | 12 | 44 | | if (files.Any()) |
| | 9 | 45 | | { |
| | 45 | 46 | | foreach (var file in files) |
| | 9 | 47 | | { |
| | 9 | 48 | | if (seen.Add(file)) |
| | 9 | 49 | | { |
| | 9 | 50 | | this.reportFiles.Add(file); |
| | 9 | 51 | | } |
| | 9 | 52 | | } |
| | 9 | 53 | | } |
| | | 54 | | else |
| | 3 | 55 | | { |
| | 3 | 56 | | this.invalidReportFilePatterns.Add(reportFilePattern); |
| | 3 | 57 | | } |
| | 12 | 58 | | } |
| | 0 | 59 | | catch (Exception) |
| | 0 | 60 | | { |
| | 0 | 61 | | this.invalidReportFilePatterns.Add(reportFilePattern); |
| | 0 | 62 | | } |
| | 12 | 63 | | } |
| | | 64 | | |
| | 11 | 65 | | this.TargetDirectory = targetDirectory ?? throw new ArgumentNullException(nameof(targetDirectory)); |
| | | 66 | | |
| | 11 | 67 | | if (debugMode != null) |
| | 11 | 68 | | { |
| | 11 | 69 | | this.DebugModeValid = bool.TryParse(debugMode, out bool parsedDebugMode); |
| | | 70 | | |
| | 11 | 71 | | if (this.DebugModeValid) |
| | 10 | 72 | | { |
| | 10 | 73 | | if (parsedDebugMode == true) |
| | 1 | 74 | | { |
| | 1 | 75 | | this.DebugMode = true; |
| | 1 | 76 | | } |
| | 10 | 77 | | } |
| | 11 | 78 | | } |
| | | 79 | | else |
| | 0 | 80 | | { |
| | 0 | 81 | | this.DebugModeValid = true; |
| | 0 | 82 | | } |
| | 11 | 83 | | } |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// Gets the report files. |
| | | 87 | | /// </summary> |
| | 22 | 88 | | public IReadOnlyCollection<string> ReportFiles => this.reportFiles; |
| | | 89 | | |
| | | 90 | | /// <summary> |
| | | 91 | | /// Gets the target directory. |
| | | 92 | | /// </summary> |
| | 101 | 93 | | public string TargetDirectory { get; } |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// Gets the plugins. |
| | | 97 | | /// </summary> |
| | 18 | 98 | | public IReadOnlyCollection<string> Plugins { get; } = []; |
| | | 99 | | |
| | | 100 | | /// <summary> |
| | | 101 | | /// Gets whether to run the generator in debug mode (more verbose). |
| | | 102 | | /// </summary> |
| | 5 | 103 | | public bool DebugMode { get; } |
| | | 104 | | |
| | | 105 | | /// <summary> |
| | | 106 | | /// Gets the invalid file patters supplied by the user. |
| | | 107 | | /// </summary> |
| | | 108 | | public IReadOnlyCollection<string> InvalidReportFilePatterns |
| | | 109 | | { |
| | | 110 | | get |
| | 11 | 111 | | { |
| | 11 | 112 | | return this.invalidReportFilePatterns; |
| | 11 | 113 | | } |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | /// <summary> |
| | | 117 | | /// Gets a value indicating whether the debug mode was successfully parsed during initialization. |
| | | 118 | | /// </summary> |
| | 32 | 119 | | public bool DebugModeValid { get; private set; } |
| | | 120 | | } |