| | | 1 | | using System; |
| | | 2 | | using System.IO; |
| | | 3 | | using DirectSight.Common; |
| | | 4 | | using DirectSight.Logging; |
| | | 5 | | |
| | | 6 | | namespace DirectSight; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Validates an <see cref="ReportConfiguration"/> to verify all user input is applicable and correct. |
| | | 10 | | /// </summary> |
| | | 11 | | internal class ReportConfigurationValidator |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Validates all parameters. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="reportConfiguration">The report configuration.</param> |
| | | 17 | | /// <returns> |
| | | 18 | | /// <c>true</c> if all parameters are in a valid state; otherwise <c>false</c>. |
| | | 19 | | /// </returns> |
| | | 20 | | internal static bool Validate(ReportConfiguration reportConfiguration) |
| | 7 | 21 | | { |
| | 7 | 22 | | if (reportConfiguration.InvalidReportFilePatterns.Count > 0) |
| | 1 | 23 | | { |
| | 5 | 24 | | foreach (var failedReportFilePattern in reportConfiguration.InvalidReportFilePatterns) |
| | 1 | 25 | | { |
| | 1 | 26 | | if (failedReportFilePattern.Contains('*')) |
| | 0 | 27 | | { |
| | 0 | 28 | | ConsoleLogger.Warn("The report file pattern '{0}' found no matching files.", failedReportFilePattern |
| | 0 | 29 | | } |
| | | 30 | | else |
| | 1 | 31 | | { |
| | 1 | 32 | | ConsoleLogger.Warn( |
| | 1 | 33 | | "The report file '{0}' is invalid. File does not exist (Full path: '{1}').", |
| | 1 | 34 | | failedReportFilePattern, |
| | 1 | 35 | | new FileInfo(failedReportFilePattern).FullName); |
| | 1 | 36 | | } |
| | 1 | 37 | | } |
| | 1 | 38 | | } |
| | | 39 | | |
| | 7 | 40 | | bool result = true; |
| | | 41 | | |
| | 21 | 42 | | foreach (var file in reportConfiguration.Plugins) |
| | 0 | 43 | | { |
| | 0 | 44 | | if (!File.Exists(file)) |
| | 0 | 45 | | { |
| | 0 | 46 | | ConsoleLogger.Error("The plugin '{0}' does not exist.", file); |
| | 0 | 47 | | result &= false; |
| | 0 | 48 | | } |
| | 0 | 49 | | } |
| | | 50 | | |
| | 7 | 51 | | if (reportConfiguration.ReportFiles.Count == 0) |
| | 2 | 52 | | { |
| | 2 | 53 | | ConsoleLogger.Error("No report files specified."); |
| | 2 | 54 | | result &= false; |
| | 2 | 55 | | } |
| | | 56 | | else |
| | 5 | 57 | | { |
| | 25 | 58 | | foreach (var file in reportConfiguration.ReportFiles) |
| | 5 | 59 | | { |
| | 5 | 60 | | if (!File.Exists(file)) |
| | 0 | 61 | | { |
| | 0 | 62 | | ConsoleLogger.Error("The report file '{0}' does not exist.", file); |
| | 0 | 63 | | result &= false; |
| | 0 | 64 | | } |
| | 5 | 65 | | } |
| | 5 | 66 | | } |
| | | 67 | | |
| | 7 | 68 | | if (string.IsNullOrEmpty(reportConfiguration.TargetDirectory)) |
| | 1 | 69 | | { |
| | 1 | 70 | | ConsoleLogger.Error("No target directory specified."); |
| | 1 | 71 | | result &= false; |
| | 1 | 72 | | } |
| | 6 | 73 | | else if (!Directory.Exists(reportConfiguration.TargetDirectory)) |
| | 3 | 74 | | { |
| | | 75 | | try |
| | 3 | 76 | | { |
| | 3 | 77 | | Directory.CreateDirectory(reportConfiguration.TargetDirectory); |
| | 2 | 78 | | } |
| | 1 | 79 | | catch (Exception ex) |
| | 1 | 80 | | { |
| | 1 | 81 | | ConsoleLogger.Error( |
| | 1 | 82 | | "The target directory '{0}' could not be created: {1}", |
| | 1 | 83 | | reportConfiguration.TargetDirectory, |
| | 1 | 84 | | ex.GetExceptionMessageForDisplay()); |
| | 1 | 85 | | result &= false; |
| | 1 | 86 | | } |
| | 3 | 87 | | } |
| | | 88 | | |
| | 7 | 89 | | if (!reportConfiguration.DebugModeValid) |
| | 0 | 90 | | { |
| | 0 | 91 | | ConsoleLogger.Error("Unknown debug mode value (should be true/false)"); |
| | 0 | 92 | | result &= false; |
| | 0 | 93 | | } |
| | | 94 | | |
| | 7 | 95 | | return result; |
| | 7 | 96 | | } |
| | | 97 | | } |