diff --git a/Px.Utils.TestingApp/Commands/PxFileValidationBenchmark.cs b/Px.Utils.TestingApp/Commands/PxFileValidationBenchmark.cs index 49ce752..492d8bc 100644 --- a/Px.Utils.TestingApp/Commands/PxFileValidationBenchmark.cs +++ b/Px.Utils.TestingApp/Commands/PxFileValidationBenchmark.cs @@ -1,4 +1,5 @@ -using Px.Utils.PxFile.Metadata; +using Px.Utils.Exceptions; +using Px.Utils.PxFile.Metadata; using Px.Utils.Validation; using System.Text; @@ -30,10 +31,10 @@ protected override void OneTimeBenchmarkSetup() { encoding = reader.GetEncoding(stream); } - catch (Exception e) + catch (InvalidPxFileMetadataException) { - Console.WriteLine($"Error while reading the encoding of the file: {e.Message}"); encoding = Encoding.Default; + throw; } } diff --git a/Px.Utils/Validation/ContentValidation/ContentValidator.UtilityMethods.cs b/Px.Utils/Validation/ContentValidation/ContentValidator.UtilityMethods.cs index 38c7151..1d77178 100644 --- a/Px.Utils/Validation/ContentValidation/ContentValidator.UtilityMethods.cs +++ b/Px.Utils/Validation/ContentValidation/ContentValidator.UtilityMethods.cs @@ -56,7 +56,7 @@ private static Dictionary, string[]> FindDimensionV KeyValuePair feedback = new( new(ValidationFeedbackLevel.Error, ValidationFeedbackRule.VariableValuesMissing), - new(filename, 0, 0, $"{dimension}, {language}") + new(filename, additionalInfo: $"{dimension}, {language}") ); feedbackItems.Add(feedback); @@ -98,7 +98,7 @@ private static Dictionary, string[]> FindDimensionV return new KeyValuePair ( new(recommended ? ValidationFeedbackLevel.Warning : ValidationFeedbackLevel.Error, recommended ? ValidationFeedbackRule.RecommendedKeyMissing : ValidationFeedbackRule.RequiredKeyMissing), - new(validator._filename, 0, 0, $"{keyword}, {language}, {dimensionName}, {dimensionValueName}") + new(validator._filename, additionalInfo: $"{keyword}, {language}, {dimensionName}, {dimensionValueName}") ); } else if (entry.Key.FirstSpecifier is null || entry.Key.SecondSpecifier is null) @@ -143,7 +143,7 @@ private static Dictionary, string[]> FindDimensionV return new( new(ValidationFeedbackLevel.Warning, ValidationFeedbackRule.RecommendedKeyMissing), - new(validator._filename, 0, 0, $"{keyword}, {language}, {dimensionName}") + new(validator._filename, additionalInfo: $"{keyword}, {language}, {dimensionName}") ); } diff --git a/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs b/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs index 3ab7e6a..9b31682 100644 --- a/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs +++ b/Px.Utils/Validation/ContentValidation/ContentValidator.ValidationFunctions.cs @@ -425,7 +425,7 @@ validator._headingDimensionNames is not null && feedbackItems.Add(new( new(ValidationFeedbackLevel.Warning, ValidationFeedbackRule.DuplicateEntry), - new(validator._filename, 0, 0, $"{item.Key.Key}, {item.Key.Value}") + new(validator._filename, additionalInfo: $"{item.Key.Key}, {item.Key.Value}") )); } } diff --git a/Px.Utils/Validation/DatabaseValidation/DatabaseValidator.cs b/Px.Utils/Validation/DatabaseValidation/DatabaseValidator.cs index a14ceea..e603f19 100644 --- a/Px.Utils/Validation/DatabaseValidation/DatabaseValidator.cs +++ b/Px.Utils/Validation/DatabaseValidation/DatabaseValidator.cs @@ -237,7 +237,7 @@ private DatabaseFileInfo GetPxFileInfo(string filename, Stream stream) feedbacks.Add(new( new(ValidationFeedbackLevel.Error, ValidationFeedbackRule.NoEncoding), - new(filename, 0, 0, $"Error while reading the encoding of the file {filename}: {e.Message}")) + new(filename, additionalInfo: $"Error while reading the encoding of the file {filename}: {e.Message}")) ); } stream.Position = 0; @@ -299,7 +299,7 @@ private async Task GetPxFileInfoAsync(string filename, Stream feedbacks.Add(new( new(ValidationFeedbackLevel.Error, ValidationFeedbackRule.NoEncoding), - new(filename, 0, 0, $"Error while reading the encoding of the file {filename}: {e.Message}")) + new(filename, additionalInfo: $"Error while reading the encoding of the file {filename}: {e.Message}")) ); } stream.Position = 0; diff --git a/Px.Utils/Validation/DatabaseValidation/DatabaseValidatorFunctions.cs b/Px.Utils/Validation/DatabaseValidation/DatabaseValidatorFunctions.cs index e466f4d..c6b1fc1 100644 --- a/Px.Utils/Validation/DatabaseValidation/DatabaseValidatorFunctions.cs +++ b/Px.Utils/Validation/DatabaseValidation/DatabaseValidatorFunctions.cs @@ -24,7 +24,7 @@ public class DuplicatePxFileName(List pxFiles) : IDatabaseVali return new( new(ValidationFeedbackLevel.Warning, ValidationFeedbackRule.DuplicateFileNames), - new(fileInfo.Name, 0, 0, $"Duplicate file name: {fileInfo.Name}") + new(fileInfo.Name) ); } else @@ -55,7 +55,7 @@ public class MissingPxFileLanguages(IEnumerable allLanguages) : IDatabas return new( new(ValidationFeedbackLevel.Warning, ValidationFeedbackRule.FileLanguageDiffersFromDatabase), - new(fileInfo.Name, 0, 0, $"Missing languages in file {fileInfo.Name}: {string.Join(", ", _allLanguages.Except(fileInfo.Languages))}") + new(fileInfo.Name, additionalInfo: $"Missing languages: {string.Join(", ", _allLanguages.Except(fileInfo.Languages))}") ); } else @@ -86,7 +86,7 @@ public class MismatchingEncoding(Encoding mostCommonEncoding) : IDatabaseValidat return new ( new(ValidationFeedbackLevel.Warning, ValidationFeedbackRule.FileEncodingDiffersFromDatabase), - new(fileInfo.Name, 0, 0, $"Inconsistent encoding in file {fileInfo.Name}: {fileInfo.Encoding.EncodingName}. " + + new(fileInfo.Name, additionalInfo: $"Inconsistent encoding: {fileInfo.Encoding.EncodingName}. " + $"Most commonly used encoding is {_mostCommonEncoding.EncodingName}")); } else @@ -120,7 +120,7 @@ public class MissingAliasFiles(List aliasFiles, IEnumerable /// Stores information about a specific instance of a validation feedback rule violation. /// - public readonly struct ValidationFeedbackValue(string filename, int line = 0, int character = 0, string? additionalInfo = null) + public readonly struct ValidationFeedbackValue(string filename, int? line = null, int? character = null, string? additionalInfo = null) { /// /// Name of the file where the violation occurred. @@ -73,11 +73,11 @@ public readonly struct ValidationFeedbackValue(string filename, int line = 0, in /// /// Line number where the violation occurred. /// - public int Line { get; } = line; + public int? Line { get; } = line; /// /// Character position where the violation occurred. /// - public int Character { get; } = character; + public int? Character { get; } = character; /// /// Additional information about the violation. ///