From 26225e974bd77b0397d0473cb993b427cce938b7 Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:35:57 +0200 Subject: [PATCH 1/5] Update ApplicationOptions.cs --- AudioCuesheetEditor/Model/Options/ApplicationOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs b/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs index 47080595..51c0c1fb 100644 --- a/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs +++ b/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs @@ -51,8 +51,8 @@ public static IReadOnlyCollection AvailableCultures { var cultures = new List { - new CultureInfo("en-US"), - new CultureInfo("de-DE") + new("en-US"), + new("de-DE") }; return cultures.AsReadOnly(); } From eb0ba76b99ff8940e93398ce8abe0b66d151d6e6 Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:41:29 +0200 Subject: [PATCH 2/5] Make Exportfilegenerator validateable --- .../Model/Entity/IValidateable.cs | 2 +- .../Model/IO/Export/ExportfileGenerator.cs | 142 ++++++++++++------ 2 files changed, 99 insertions(+), 45 deletions(-) diff --git a/AudioCuesheetEditor/Model/Entity/IValidateable.cs b/AudioCuesheetEditor/Model/Entity/IValidateable.cs index 324e6e77..eb779b5c 100644 --- a/AudioCuesheetEditor/Model/Entity/IValidateable.cs +++ b/AudioCuesheetEditor/Model/Entity/IValidateable.cs @@ -53,7 +53,7 @@ public class ValidationResult { private List? validationMessages; - public static ValidationResult Create(ValidationStatus validationStatus, IReadOnlyCollection? validationMessages = null) + public static ValidationResult Create(ValidationStatus validationStatus, IEnumerable? validationMessages = null) { return new ValidationResult() { Status = validationStatus, ValidationMessages = validationMessages?.ToList() }; } diff --git a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs index 01db88a1..ca6b772e 100644 --- a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs +++ b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs @@ -30,62 +30,27 @@ public enum ExportType Exportprofile } - public class ExportfileGenerator + public class ExportfileGenerator : Validateable { public Cuesheet Cuesheet { get; } public Exportprofile? Exportprofile { get; set; } public ApplicationOptions? ApplicationOptions { get; set; } public IAudioConverterService? AudioConverterService { get; set; } + public ExportType ExportType { get; set; } - public ExportfileGenerator(Cuesheet cuesheet, Exportprofile? exportprofile = null, ApplicationOptions? applicationOptions = null, IAudioConverterService? audioConverterService = null) + public ExportfileGenerator(ExportType exportType, Cuesheet cuesheet, Exportprofile? exportprofile = null, ApplicationOptions? applicationOptions = null, IAudioConverterService? audioConverterService = null) { + ExportType = exportType; Cuesheet = cuesheet; Exportprofile = exportprofile; ApplicationOptions = applicationOptions; AudioConverterService = audioConverterService; } - /// - /// Is an export of the possible? - /// - /// Which type of export should be done? - /// Boolean indicating if export is possible or not - public Boolean CanWrite(ExportType exportType) - { - Boolean canWrite = false; - switch (exportType) - { - case ExportType.Cuesheet: - canWrite = (Cuesheet.Validate().Status != ValidationStatus.Error) - && (Cuesheet.Cataloguenumber.Validate().Status != ValidationStatus.Error) - && Cuesheet.Tracks.All(x => x.Validate().Status != ValidationStatus.Error) - && (ApplicationOptions?.Validate(x => x.CuesheetFilename).Status != ValidationStatus.Error); - break; - case ExportType.Exportprofile: - if (Exportprofile != null) - { - canWrite = (Cuesheet.Validate().Status != ValidationStatus.Error) - && (Cuesheet.Cataloguenumber.Validate().Status != ValidationStatus.Error) - && Cuesheet.Tracks.All(x => x.Validate().Status != ValidationStatus.Error) - && (ApplicationOptions?.Validate(x => x.CuesheetFilename).Status != ValidationStatus.Error) - && (Exportprofile.Validate().Status != ValidationStatus.Error); - } - break; - } - var hasSplitPoints = Cuesheet.SplitPoints.Any(); - if (hasSplitPoints) - { - canWrite = canWrite - && AudioConverterService != null - && Cuesheet.Audiofile != null; - } - return canWrite; - } - - public async Task> GenerateExportfilesAsync(ExportType exportType) + public async Task> GenerateExportfilesAsync() { List exportfiles = new(); - if (CanWrite(exportType)) + if (Validate().Status != ValidationStatus.Error) { if (Cuesheet.SplitPoints.Count != 0) { @@ -99,7 +64,7 @@ public async Task> GenerateExportfilesAsync(Expo audioFileName = String.Format("{0}({1}){2}", Path.GetFileNameWithoutExtension(Cuesheet.Audiofile?.Name), counter, Path.GetExtension(Cuesheet.Audiofile?.Name)); if (splitPoint.Validate().Status == ValidationStatus.Success) { - switch (exportType) + switch (ExportType) { case ExportType.Cuesheet: content = WriteCuesheet(audioFileName, previousSplitPointMoment, splitPoint); @@ -124,7 +89,7 @@ public async Task> GenerateExportfilesAsync(Expo } //After a split point attach the last part audioFileName = String.Format("{0}({1}){2}", Path.GetFileNameWithoutExtension(Cuesheet.Audiofile?.Name), counter, Path.GetExtension(Cuesheet.Audiofile?.Name)); - switch (exportType) + switch (ExportType) { case ExportType.Cuesheet: content = WriteCuesheet(audioFileName, previousSplitPointMoment); @@ -148,7 +113,7 @@ public async Task> GenerateExportfilesAsync(Expo { String filename = String.Empty; String? content = null; - switch (exportType) + switch (ExportType) { case ExportType.Cuesheet: var cuesheetfilename = ApplicationOptions?.CuesheetFilename; @@ -381,5 +346,94 @@ private String WriteExport(String audiofileName, TimeSpan? from = null, SplitPoi } return exportAudiofile; } + + protected override ValidationResult Validate(string property) + { + ValidationResult validationResult; + switch (property) + { + case nameof(Cuesheet): + var validationResults = new Dictionary + { + { Cuesheet, Cuesheet.Validate() }, + { Cuesheet.Cataloguenumber, Cuesheet.Cataloguenumber.Validate() } + }; + foreach (var track in Cuesheet.Tracks) + { + validationResults.Add(track, track.Validate()); + } + if (validationResults.Any(x => x.Value.Status == ValidationStatus.Error)) + { + //TODO: Für jedes Objekt eine Nachricht erstellen und den Objektnamen voranstellen! + var messages = validationResults.Values.Where(x => x.ValidationMessages != null).SelectMany(x => x.ValidationMessages!); + validationResult = ValidationResult.Create(ValidationStatus.Error, messages); + } + else + { + validationResult = ValidationResult.Create(ValidationStatus.Success); + } + break; + case nameof(ApplicationOptions): + if (ApplicationOptions == null) + { + var validationMessages = new List() + { + new("{0} has no value!", nameof(ApplicationOptions)) + }; + validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages); + } + else + { + validationResult = ValidationResult.Create(ValidationStatus.Success); + } + break; + case nameof(Exportprofile): + if (ExportType == ExportType.Exportprofile) + { + if (Exportprofile != null) + { + validationResult = Exportprofile.Validate(); + } + else + { + var validationMessages = new List() + { + new("{0} has no value!", nameof(Exportprofile)) + }; + validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages); + } + } + else + { + validationResult = ValidationResult.Create(ValidationStatus.NoValidation); + } + break; + case nameof(AudioConverterService): + if (Cuesheet.SplitPoints.Any()) + { + if (AudioConverterService == null) + { + var validationMessages = new List() + { + new("{0} has no value!", nameof(Exportprofile)) + }; + validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages); + } + else + { + validationResult = ValidationResult.Create(ValidationStatus.Success); + } + } + else + { + validationResult = ValidationResult.Create(ValidationStatus.NoValidation); + } + break; + default: + validationResult = ValidationResult.Create(ValidationStatus.NoValidation); + break; + } + return validationResult; + } } } From 32516c33c2720fa09f4eca44935ae66fa1a6011c Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:01:17 +0200 Subject: [PATCH 3/5] Display validation errors to user --- AudioCuesheetEditor/Shared/MainLayout.razor | 52 +++++++++++-------- .../Shared/ModalExportdialog.razor | 32 ++++++++++-- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/AudioCuesheetEditor/Shared/MainLayout.razor b/AudioCuesheetEditor/Shared/MainLayout.razor index f5d077ef..276999b9 100644 --- a/AudioCuesheetEditor/Shared/MainLayout.razor +++ b/AudioCuesheetEditor/Shared/MainLayout.razor @@ -98,7 +98,7 @@ along with Foobar. If not, see - + @@ -421,39 +421,49 @@ along with Foobar. If not, see { get { - String? text = null; - if (IsCuesheetExportable == false) + var generator = new ExportfileGenerator(ExportType.Cuesheet, _sessionStateContainer.Cuesheet, applicationOptions: applicationOptions, audioConverterService: _audioConverterService); + var validationResult = generator.Validate(); + if (validationResult.Status == Model.Entity.ValidationStatus.Error) { - text = _localizer["Please check processinghints for errors, otherwise the file is not exportable"]; + string? detailText = null; + if (validationResult.ValidationMessages != null) + { + foreach (var validationMessage in validationResult.ValidationMessages) + { + detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine); + } + } + return _localizer["Please check processinghints for errors, otherwise the file is not exportable: {0}", detailText]; } - return text; + return null; } } - Boolean IsCuesheetExportable + Boolean IsCuesheetExportable => IsCuesheetExportableTooltip == null; + + string? IsExportprofileExportableTooltip { get { - if (applicationOptions?.Validate(x => x.CuesheetFilename).Status != Model.Entity.ValidationStatus.Error) - { - var generator = new ExportfileGenerator(_sessionStateContainer.Cuesheet, applicationOptions: applicationOptions, audioConverterService: _audioConverterService); - return generator.CanWrite(ExportType.Cuesheet); - } - else + var generator = new ExportfileGenerator(ExportType.Exportprofile, _sessionStateContainer.Cuesheet, SelectedExportProfile, audioConverterService: _audioConverterService); + var validationResult = generator.Validate(); + if (validationResult.Status == Model.Entity.ValidationStatus.Error) { - return false; + string? detailText = null; + if (validationResult.ValidationMessages != null) + { + foreach (var validationMessage in validationResult.ValidationMessages) + { + detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine); + } + } + return _localizer["Please check processinghints for errors, otherwise the file is not exportable: {0}", detailText]; } + return null; } } - Boolean IsExportprofileExportable - { - get - { - var generator = new ExportfileGenerator(_sessionStateContainer.Cuesheet, SelectedExportProfile, audioConverterService: _audioConverterService); - return generator.CanWrite(ExportType.Exportprofile); - } - } + Boolean IsExportprofileExportable => IsExportprofileExportableTooltip == null; Boolean ModalExportdialogCuesheetLockUserInput { diff --git a/AudioCuesheetEditor/Shared/ModalExportdialog.razor b/AudioCuesheetEditor/Shared/ModalExportdialog.razor index 2de42131..f8f9b7c3 100644 --- a/AudioCuesheetEditor/Shared/ModalExportdialog.razor +++ b/AudioCuesheetEditor/Shared/ModalExportdialog.razor @@ -113,7 +113,7 @@ along with Foobar. If not, see { @if (selectedStep != "displayExportResult") { - + @@ -175,6 +175,27 @@ along with Foobar. If not, see } } + String? ExportPossibleTooltip + { + get + { + var validationResult = ExportfileGenerator?.Validate(); + if (validationResult?.Status == Model.Entity.ValidationStatus.Error) + { + string? detailText = null; + if (validationResult.ValidationMessages != null) + { + foreach (var validationMessage in validationResult.ValidationMessages) + { + detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine); + } + } + return _localizer["Export files can not be generated. Please check validationerrors and solve errors in order to download export: {0}", detailText]; + } + return null; + } + } + Boolean ExportPossible { get @@ -184,9 +205,10 @@ along with Foobar. If not, see { exportPossible = Validations.ValidateAll().GetAwaiter().GetResult(); } - if ((exportPossible == false) && (ExportfileGenerator != null)) + //TODO: Warum nur bei exportPossible == false? + if (exportPossible == false) { - exportPossible = ExportfileGenerator.CanWrite(ExportType); + exportPossible = ExportPossibleTooltip == null; } return exportPossible; } @@ -198,7 +220,7 @@ along with Foobar. If not, see .Add(Key.Enter, OnEnterKeyDown); _audioConverterService.ProgressChanged += IAudioConverterService_ProgressChanged; - ExportfileGenerator = new ExportfileGenerator(_sessionStateContainer.Cuesheet, audioConverterService: _audioConverterService); + ExportfileGenerator = new ExportfileGenerator(ExportType, _sessionStateContainer.Cuesheet, audioConverterService: _audioConverterService); await base.OnInitializedAsync(); } @@ -244,7 +266,7 @@ along with Foobar. If not, see exportProgress = 0; if (ExportfileGenerator != null) { - exportfiles = await ExportfileGenerator.GenerateExportfilesAsync(ExportType); + exportfiles = await ExportfileGenerator.GenerateExportfilesAsync(); selectedStep = "displayExportResult"; prepareExportCompleted = true; } From 1b196cf78d5fc8f82752ee3571d2be99f15606e4 Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:08:00 +0200 Subject: [PATCH 4/5] Fixed unit tests --- .../Model/IO/Export/ExportfileGenerator.cs | 19 ++++--- .../IO/Export/ExportfileGeneratorTests.cs | 50 +++++++++---------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs index ca6b772e..b7d3958f 100644 --- a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs +++ b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs @@ -374,17 +374,24 @@ protected override ValidationResult Validate(string property) } break; case nameof(ApplicationOptions): - if (ApplicationOptions == null) + if (ExportType == ExportType.Cuesheet) { - var validationMessages = new List() + if (ApplicationOptions == null) { - new("{0} has no value!", nameof(ApplicationOptions)) - }; - validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages); + var validationMessages = new List() + { + new("{0} has no value!", nameof(ApplicationOptions)) + }; + validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages); + } + else + { + validationResult = ValidationResult.Create(ValidationStatus.Success); + } } else { - validationResult = ValidationResult.Create(ValidationStatus.Success); + validationResult = ValidationResult.Create(ValidationStatus.NoValidation); } break; case nameof(Exportprofile): diff --git a/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs b/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs index 69a21f3d..a58f4c74 100644 --- a/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs +++ b/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs @@ -56,8 +56,8 @@ public async Task GenerateCuesheetFilesTestAsync() track.End = begin; cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(Exportfile.DefaultCuesheetFilename, generatedFiles.First().Name); var content = generatedFiles.First().Content; @@ -83,7 +83,7 @@ public async Task GenerateCuesheetFilesTestAsync() File.Delete(fileName); cuesheet.CDTextfile = new CDTextfile("Testfile.cdt"); cuesheet.Cataloguenumber.Value = "0123456789123"; - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -95,8 +95,8 @@ public async Task GenerateCuesheetFilesTestAsync() File.Delete(fileName); cuesheet.CDTextfile = new CDTextfile("Testfile.cdt"); cuesheet.Cataloguenumber.Value = "Testvalue"; - Assert.IsFalse(generator.CanWrite(ExportType.Cuesheet)); - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + Assert.AreEqual(ValidationStatus.Error, generator.Validate().Status); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(0, generatedFiles.Count); } @@ -131,8 +131,8 @@ public async Task GenerateCuesheetFilesWithPreGapAndPostGapTestAsync() track.PreGap = new TimeSpan(0, 0, 3); cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); var content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -193,8 +193,8 @@ public async Task GenerateCuesheetFilesWithTrackFlagsTestAsync() } cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); var content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -245,16 +245,16 @@ public async Task GenerateCuesheetFilesWithIncorrectTrackPositionsTestAsync() track.End = begin; cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - Assert.IsFalse(generator.CanWrite(ExportType.Cuesheet)); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + Assert.AreEqual(ValidationStatus.Error, generator.Validate().Status); //Rearrange positions cuesheet.Tracks.ElementAt(0).Position = 1; cuesheet.Tracks.ElementAt(1).Position = 2; cuesheet.Tracks.ElementAt(2).Position = 3; cuesheet.Tracks.ElementAt(3).Position = 4; cuesheet.Tracks.ElementAt(4).Position = 5; - Assert.IsTrue(generator.CanWrite(ExportType.Cuesheet)); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + Assert.AreEqual(ValidationStatus.Success, generator.Validate().Status); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); var content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -315,9 +315,9 @@ public async Task GenerateCuesheetFilesWithSplitPointsTestAsync() splitPoint.Title = "Title 3"; splitPoint.Moment = new TimeSpan(1, 30, 0); testHelper.ApplicationOptions.CuesheetFilename = "Unit test.cue"; - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions, audioConverterService:testHelper.AudioConverterService); - Assert.IsTrue(generator.CanWrite(ExportType.Cuesheet)); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions, audioConverterService:testHelper.AudioConverterService); + Assert.AreEqual(ValidationStatus.Success, generator.Validate().Status); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(5, generatedFiles.Count); var position = 1; var counter = 1; @@ -427,8 +427,8 @@ public async Task GenerateExportfilesTestAsync() SchemeFooter = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor" }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); - var generator = new ExportfileGenerator(cuesheet, exportprofile: exportProfile); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + var generator = new ExportfileGenerator(ExportType.Exportprofile, cuesheet, exportprofile: exportProfile); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); var fileContent = generatedFiles.First().Content; @@ -461,7 +461,7 @@ public async Task GenerateExportfilesTestAsync() }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); generator.Exportprofile = exportProfile; - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); fileContent = generatedFiles.First().Content; @@ -495,7 +495,7 @@ public async Task GenerateExportfilesTestAsync() }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); generator.Exportprofile = exportProfile; - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); fileContent = generatedFiles.First().Content; @@ -565,8 +565,8 @@ public async Task GenerateExportfilesWithPregapAndPostgapTestAsync() SchemeFooter = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor at %Date%" }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); - var generator = new ExportfileGenerator(cuesheet, exportprofile: exportProfile); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + var generator = new ExportfileGenerator(ExportType.Exportprofile, cuesheet, exportprofile: exportProfile); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); var fileContent = generatedFiles.First().Content; @@ -641,9 +641,9 @@ public async Task GenerateExportfilesWithSplitPointsTestAsync() SchemeTracks = "%Track.Position%;%Track.Artist%;%Track.Title%;%Track.Begin%;%Track.End%;%Track.Length%", SchemeFooter = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor" }; - var generator = new ExportfileGenerator(cuesheet, exportProfile, audioConverterService: testHelper.AudioConverterService); - Assert.IsTrue(generator.CanWrite(ExportType.Exportprofile)); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + var generator = new ExportfileGenerator(ExportType.Exportprofile, cuesheet, exportProfile, audioConverterService: testHelper.AudioConverterService); + Assert.AreEqual(ValidationStatus.Success, generator.Validate().Status); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(5, generatedFiles.Count); //Check split according to split points From 44260cac0aef4f439bc62229e17e4d6e9654d92d Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:55:56 +0200 Subject: [PATCH 5/5] Fix for localizing messages --- .../Model/IO/Export/ExportfileGenerator.cs | 1 - .../Resources/Localization/MainLayout/de.json | 2 +- .../Resources/Localization/MainLayout/en.json | 2 +- .../Localization/ModalExportdialog/de.json | 2 +- .../Localization/ModalExportdialog/en.json | 2 +- .../Localization/ValidationMessage/de.json | 5 ++-- .../Localization/ValidationMessage/en.json | 5 ++-- AudioCuesheetEditor/Shared/MainLayout.razor | 30 ++----------------- .../Shared/ModalExportdialog.razor | 9 ++---- 9 files changed, 14 insertions(+), 44 deletions(-) diff --git a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs index b7d3958f..1d155901 100644 --- a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs +++ b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs @@ -364,7 +364,6 @@ protected override ValidationResult Validate(string property) } if (validationResults.Any(x => x.Value.Status == ValidationStatus.Error)) { - //TODO: Für jedes Objekt eine Nachricht erstellen und den Objektnamen voranstellen! var messages = validationResults.Values.Where(x => x.ValidationMessages != null).SelectMany(x => x.ValidationMessages!); validationResult = ValidationResult.Create(ValidationStatus.Error, messages); } diff --git a/AudioCuesheetEditor/Resources/Localization/MainLayout/de.json b/AudioCuesheetEditor/Resources/Localization/MainLayout/de.json index 3c05e8d5..bec6bc09 100644 --- a/AudioCuesheetEditor/Resources/Localization/MainLayout/de.json +++ b/AudioCuesheetEditor/Resources/Localization/MainLayout/de.json @@ -8,7 +8,7 @@ "Undo last change": "Letzte Änderung Rückgängig machen", "Redo last change": "Letzte Änderung wiederherstellen", "Export": "Export", - "Please check processinghints for errors, otherwise the file is not exportable": "Bitte prüfen sie die Bearbeitungshinweise auf Fehler. Andernfalls ist Datei nicht exportierbar.", + "Please check processinghints for errors, otherwise the file is not exportable: {0}": "Bitte prüfen sie die Bearbeitungshinweise auf Fehler. Andernfalls ist Datei nicht exportierbar: {0}", "Download cuesheet": "Cuesheet herunterladen", "Save project": "Projekt speichern", "Open exportprofiles": "Export Profile anzeigen", diff --git a/AudioCuesheetEditor/Resources/Localization/MainLayout/en.json b/AudioCuesheetEditor/Resources/Localization/MainLayout/en.json index 7f454e10..a3788458 100644 --- a/AudioCuesheetEditor/Resources/Localization/MainLayout/en.json +++ b/AudioCuesheetEditor/Resources/Localization/MainLayout/en.json @@ -8,7 +8,7 @@ "Undo last change": "Undo last change", "Redo last change": "Redo last change", "Export": "Export", - "Please check processinghints for errors, otherwise the file is not exportable": "Please check processing hints for errors. Otherwise the file is not exportable.", + "Please check processinghints for errors, otherwise the file is not exportable: {0}": "Please check processinghints for errors, otherwise the file is not exportable: {0}", "Download cuesheet": "Download cuesheet", "Save project": "Save project", "Open exportprofiles": "Display Export Profiles", diff --git a/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/de.json b/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/de.json index eac76c46..8f6b5874 100644 --- a/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/de.json +++ b/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/de.json @@ -11,7 +11,7 @@ "Download this file": "Diese Datei herunterladen", "Generate export files": "Exportdateien generieren", "Abort": "Abbrechen", - "Export files can not be generated. Please check validationerrors and solve errors in order to download export.": "Exportdateien können nicht generiert werden. Bitte prüfen Sie die Validierungsfehler und beheben Sie diese, um die Exportdateien herunterladen zu können.", + "Export files can not be generated. Please check validationerrors and solve errors in order to download export: {0}": "Exportdateien können nicht generiert werden. Bitte prüfen Sie die Validierungsfehler und beheben Sie diese, um die Exportdateien herunterladen zu können: {0}", "Close": "Schließen", "Download split audio file": "Verarbeitete Audiodatei herunterladen", "Generation in progress, please stand by ...": "Export wird durchgeführt, bitte warten Sie ...." diff --git a/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/en.json b/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/en.json index de38cb79..0636febf 100644 --- a/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/en.json +++ b/AudioCuesheetEditor/Resources/Localization/ModalExportdialog/en.json @@ -11,7 +11,7 @@ "Download this file": "Download this file", "Generate export files": "Generate export files", "Abort": "Abort", - "Export files can not be generated. Please check validationerrors and solve errors in order to download export.": "Export files can not be generated. Please check validationerrors and solve errors in order to download export.", + "Export files can not be generated. Please check validationerrors and solve errors in order to download export: {0}": "Export files can not be generated. Please check validationerrors and solve errors in order to download export: {0}", "Close": "Close", "Download split audio file": "Download split audio file", "Generation in progress, please stand by ...": "Generation in progress, please stand by ..." diff --git a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json index 65d8ef4b..d0f65374 100644 --- a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json +++ b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/de.json @@ -25,8 +25,9 @@ "SchemeType": "Schematyp", "Scheme": "Schema", "ENTER REGULAR EXPRESSION HERE": "Hier regulären Ausdruck eingeben", - "SchemeCuesheet": "Schema Cuesheet", - "SchemeTracks": "Schema Titel", + "SchemeHead": "Kopfschema", + "SchemeTracks": "Titelschema", + "SchemeFooter": "Fußschema", "Moment": "Zeitpunkt", "{0} must end with '{1}'!": "{0} musss mit '{1}' enden!", "{0} must have a filename!": "{0} muss einen Dateinamen haben!", diff --git a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json index 22fc6d00..8f217b4c 100644 --- a/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json +++ b/AudioCuesheetEditor/Resources/Localization/ValidationMessage/en.json @@ -25,8 +25,9 @@ "SchemeType": "Schemetype", "Scheme": "Scheme", "ENTER REGULAR EXPRESSION HERE": "Enter regular expression here", - "SchemeCuesheet": "Scheme cuesheet", - "SchemeTracks": "Scheme tracks", + "SchemeHead": "Headerscheme", + "SchemeTracks": "Trackscheme", + "SchemeFooter": "Footerscheme", "Moment": "Moment", "{0} must end with '{1}'!": "{0} must end with '{1}'!", "{0} must have a filename!": "{0} must have a filename!", diff --git a/AudioCuesheetEditor/Shared/MainLayout.razor b/AudioCuesheetEditor/Shared/MainLayout.razor index 276999b9..f2449c96 100644 --- a/AudioCuesheetEditor/Shared/MainLayout.razor +++ b/AudioCuesheetEditor/Shared/MainLayout.razor @@ -98,9 +98,7 @@ along with Foobar. If not, see - - - + @@ -430,7 +428,7 @@ along with Foobar. If not, see { foreach (var validationMessage in validationResult.ValidationMessages) { - detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine); + detailText += String.Format("{0}{1}", validationMessage.GetMessageLocalized(_validationMessageLocalizer), Environment.NewLine); } } return _localizer["Please check processinghints for errors, otherwise the file is not exportable: {0}", detailText]; @@ -441,30 +439,6 @@ along with Foobar. If not, see Boolean IsCuesheetExportable => IsCuesheetExportableTooltip == null; - string? IsExportprofileExportableTooltip - { - get - { - var generator = new ExportfileGenerator(ExportType.Exportprofile, _sessionStateContainer.Cuesheet, SelectedExportProfile, audioConverterService: _audioConverterService); - var validationResult = generator.Validate(); - if (validationResult.Status == Model.Entity.ValidationStatus.Error) - { - string? detailText = null; - if (validationResult.ValidationMessages != null) - { - foreach (var validationMessage in validationResult.ValidationMessages) - { - detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine); - } - } - return _localizer["Please check processinghints for errors, otherwise the file is not exportable: {0}", detailText]; - } - return null; - } - } - - Boolean IsExportprofileExportable => IsExportprofileExportableTooltip == null; - Boolean ModalExportdialogCuesheetLockUserInput { get diff --git a/AudioCuesheetEditor/Shared/ModalExportdialog.razor b/AudioCuesheetEditor/Shared/ModalExportdialog.razor index f8f9b7c3..9318493f 100644 --- a/AudioCuesheetEditor/Shared/ModalExportdialog.razor +++ b/AudioCuesheetEditor/Shared/ModalExportdialog.razor @@ -187,7 +187,7 @@ along with Foobar. If not, see { foreach (var validationMessage in validationResult.ValidationMessages) { - detailText += String.Format("{0}{1}", _validationMessageLocalizer[validationMessage.Message, validationMessage.Parameter], Environment.NewLine); + detailText += String.Format("{0}{1}", validationMessage.GetMessageLocalized(_validationMessageLocalizer), Environment.NewLine); } } return _localizer["Export files can not be generated. Please check validationerrors and solve errors in order to download export: {0}", detailText]; @@ -205,12 +205,7 @@ along with Foobar. If not, see { exportPossible = Validations.ValidateAll().GetAwaiter().GetResult(); } - //TODO: Warum nur bei exportPossible == false? - if (exportPossible == false) - { - exportPossible = ExportPossibleTooltip == null; - } - return exportPossible; + return exportPossible && ExportPossibleTooltip == null; } }