Skip to content

Commit

Permalink
Merge pull request #325 from NeoCoderMatrix86/313-add-detailed-messag…
Browse files Browse the repository at this point in the history
…e-why-an-export-can-not-be-done

Add detailed message why an export can not be done
  • Loading branch information
NeoCoderMatrix86 authored Apr 2, 2024
2 parents c3905af + 44260ca commit 29c42b8
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 119 deletions.
2 changes: 1 addition & 1 deletion AudioCuesheetEditor/Model/Entity/IValidateable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ValidationResult
{
private List<ValidationMessage>? validationMessages;

public static ValidationResult Create(ValidationStatus validationStatus, IReadOnlyCollection<ValidationMessage>? validationMessages = null)
public static ValidationResult Create(ValidationStatus validationStatus, IEnumerable<ValidationMessage>? validationMessages = null)
{
return new ValidationResult() { Status = validationStatus, ValidationMessages = validationMessages?.ToList() };
}
Expand Down
148 changes: 104 additions & 44 deletions AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,62 +30,27 @@ public enum ExportType
Exportprofile
}

public class ExportfileGenerator
public class ExportfileGenerator : Validateable<ExportfileGenerator>
{
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;
}

/// <summary>
/// Is an export of the <see cref="Cuesheet"/> possible?
/// </summary>
/// <param name="exportType">Which type of export should be done?</param>
/// <returns>Boolean indicating if export is possible or not</returns>
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<IReadOnlyCollection<Exportfile>> GenerateExportfilesAsync(ExportType exportType)
public async Task<IReadOnlyCollection<Exportfile>> GenerateExportfilesAsync()
{
List<Exportfile> exportfiles = new();
if (CanWrite(exportType))
if (Validate().Status != ValidationStatus.Error)
{
if (Cuesheet.SplitPoints.Count != 0)
{
Expand All @@ -99,7 +64,7 @@ public async Task<IReadOnlyCollection<Exportfile>> 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);
Expand All @@ -124,7 +89,7 @@ public async Task<IReadOnlyCollection<Exportfile>> 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);
Expand All @@ -148,7 +113,7 @@ public async Task<IReadOnlyCollection<Exportfile>> GenerateExportfilesAsync(Expo
{
String filename = String.Empty;
String? content = null;
switch (exportType)
switch (ExportType)
{
case ExportType.Cuesheet:
var cuesheetfilename = ApplicationOptions?.CuesheetFilename;
Expand Down Expand Up @@ -381,5 +346,100 @@ 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<IValidateable, ValidationResult>
{
{ 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))
{
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 (ExportType == ExportType.Cuesheet)
{
if (ApplicationOptions == null)
{
var validationMessages = new List<ValidationMessage>()
{
new("{0} has no value!", nameof(ApplicationOptions))
};
validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages);
}
else
{
validationResult = ValidationResult.Create(ValidationStatus.Success);
}
}
else
{
validationResult = ValidationResult.Create(ValidationStatus.NoValidation);
}
break;
case nameof(Exportprofile):
if (ExportType == ExportType.Exportprofile)
{
if (Exportprofile != null)
{
validationResult = Exportprofile.Validate();
}
else
{
var validationMessages = new List<ValidationMessage>()
{
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<ValidationMessage>()
{
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;
}
}
}
4 changes: 2 additions & 2 deletions AudioCuesheetEditor/Model/Options/ApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static IReadOnlyCollection<CultureInfo> AvailableCultures
{
var cultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("de-DE")
new("en-US"),
new("de-DE")
};
return cultures.AsReadOnly();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
46 changes: 15 additions & 31 deletions AudioCuesheetEditor/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ along with Foobar. If not, see
<Button Color="Color.Primary" Clicked="() => ControlModalDialog(modalDownloadProjectfile, true)">@_localizer["Save project"]</Button>
</BarDropdownItem>
<BarDropdownItem>
<Tooltip Placement="TooltipPlacement.Right" Text="@IsCuesheetExportableTooltip">
<Button Color="Color.Primary" Clicked="OnDisplayExportProfilesClicked" Disabled="!IsExportprofileExportable">@_localizer["Open exportprofiles"]</Button>
</Tooltip>
<Button Color="Color.Primary" Clicked="OnDisplayExportProfilesClicked">@_localizer["Open exportprofiles"]</Button>
</BarDropdownItem>
</BarDropdownMenu>
</BarDropdown>
Expand Down Expand Up @@ -421,39 +419,25 @@ 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"];
}
return text;
}
}

Boolean IsCuesheetExportable
{
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
{
return false;
string? detailText = null;
if (validationResult.ValidationMessages != null)
{
foreach (var validationMessage in validationResult.ValidationMessages)
{
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];
}
return null;
}
}

Boolean IsExportprofileExportable
{
get
{
var generator = new ExportfileGenerator(_sessionStateContainer.Cuesheet, SelectedExportProfile, audioConverterService: _audioConverterService);
return generator.CanWrite(ExportType.Exportprofile);
}
}
Boolean IsCuesheetExportable => IsCuesheetExportableTooltip == null;

Boolean ModalExportdialogCuesheetLockUserInput
{
Expand Down
Loading

0 comments on commit 29c42b8

Please sign in to comment.