From 27173104b5f0a05c4f3184def7076fe1df790d86 Mon Sep 17 00:00:00 2001
From: Sven <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Thu, 12 Mar 2026 11:19:42 +0100
Subject: [PATCH 1/3] remove sections
---
.../Model/AudioCuesheet/Cuesheet.cs | 38 ---
.../Model/IO/Export/CuesheetSection.cs | 217 ------------------
.../Model/Options/ExportOptions.cs | 2 +-
.../Services/IO/CuesheetExportService.cs | 88 +++----
.../Services/IO/ExportfileGenerator.cs | 92 +++-----
.../Services/IO/ImportManager.cs | 7 -
AudioCuesheetEditor/Services/Result.cs | 117 ++++++++++
.../Shared/Cuesheet/EditSections.de.resx | 150 ------------
.../Shared/Cuesheet/EditSections.razor | 154 -------------
.../Shared/Cuesheet/EditSections.resx | 150 ------------
.../Dialogs/GenerateCuesheetDialog.razor | 37 +--
.../Dialogs/GenerateExportDialog.de.resx | 16 +-
.../Shared/Dialogs/GenerateExportDialog.razor | 65 ++----
.../Shared/Dialogs/GenerateExportDialog.resx | 16 +-
.../Shared/TrackList/TrackList.de.resx | 6 -
.../Shared/TrackList/TrackList.razor | 6 -
.../Shared/TrackList/TrackList.resx | 6 -
.../Shared/ViewModes/ViewModeFull.de.resx | 3 -
.../Shared/ViewModes/ViewModeFull.razor | 9 -
.../Shared/ViewModes/ViewModeFull.resx | 3 -
20 files changed, 223 insertions(+), 959 deletions(-)
delete mode 100644 AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs
create mode 100644 AudioCuesheetEditor/Services/Result.cs
delete mode 100644 AudioCuesheetEditor/Shared/Cuesheet/EditSections.de.resx
delete mode 100644 AudioCuesheetEditor/Shared/Cuesheet/EditSections.razor
delete mode 100644 AudioCuesheetEditor/Shared/Cuesheet/EditSections.resx
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
index c0501fdf..d4c73211 100644
--- a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
@@ -15,7 +15,6 @@
//.
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO.Audio;
-using AudioCuesheetEditor.Model.IO.Export;
using AudioCuesheetEditor.Model.UI;
using System.Text.Json.Serialization;
@@ -43,7 +42,6 @@ public class Cuesheet() : Validateable, ITraceable, ICuesheet
private CDTextfile? cDTextfile;
private String? catalogueNumber;
private readonly List> currentlyHandlingLinkedTrackPropertyChange = [];
- private List sections = [];
public event EventHandler? TraceablePropertyChanged;
public event EventHandler? IsRecordingChanged;
@@ -151,42 +149,6 @@ public IEnumerable IsRecordingPossible
[JsonIgnore]
public Boolean IsImporting { get; set; }
-
- [JsonInclude]
- public IReadOnlyCollection Sections
- {
- get => sections;
- private set
- {
- foreach(var section in value.Where(x => x.Cuesheet != this))
- {
- section.Cuesheet = this;
- }
- sections = [.. value];
- }
- }
-
- public CuesheetSection AddSection()
- {
- var previousValue = new List(sections);
- var section = new CuesheetSection(this);
- sections.Add(section);
- OnTraceablePropertyChanged(previousValue, nameof(Sections));
- return section;
- }
-
- public void RemoveSections(IEnumerable sectionsToRemove)
- {
- var previousValue = new List(sections);
- var intersection = sections.Intersect(sectionsToRemove);
- sections = [.. sections.Except(intersection)];
- OnTraceablePropertyChanged(previousValue, nameof(Sections));
- }
-
- public CuesheetSection? GetSection(Track track)
- {
- return Sections?.FirstOrDefault(x => track.Begin <= x.Begin && track.End >= x.Begin);
- }
///
/// Get the previous linked track of a track object
diff --git a/AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs b/AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs
deleted file mode 100644
index 534b65d3..00000000
--- a/AudioCuesheetEditor/Model/IO/Export/CuesheetSection.cs
+++ /dev/null
@@ -1,217 +0,0 @@
-//This file is part of AudioCuesheetEditor.
-
-//AudioCuesheetEditor is free software: you can redistribute it and/or modify
-//it under the terms of the GNU General Public License as published by
-//the Free Software Foundation, either version 3 of the License, or
-//(at your option) any later version.
-
-//AudioCuesheetEditor is distributed in the hope that it will be useful,
-//but WITHOUT ANY WARRANTY; without even the implied warranty of
-//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-//GNU General Public License for more details.
-
-//You should have received a copy of the GNU General Public License
-//along with Foobar. If not, see
-//.
-using AudioCuesheetEditor.Model.AudioCuesheet;
-using AudioCuesheetEditor.Model.Entity;
-using AudioCuesheetEditor.Model.UI;
-using System.Text.Json.Serialization;
-
-namespace AudioCuesheetEditor.Model.IO.Export
-{
- public class CuesheetSection : Validateable, ITraceable
- {
- private Cuesheet? cuesheet;
- private TimeSpan? begin;
- private TimeSpan? end;
- private String? artist;
- private String? title;
- private String? audiofileName;
-
- public event EventHandler? TraceablePropertyChanged;
-
- public CuesheetSection(Cuesheet cuesheet)
- {
- Cuesheet = cuesheet;
- artist = Cuesheet.Artist;
- title = Cuesheet.Title;
- audiofileName = Cuesheet.Audiofile?.Name;
- //Try to set begin
- begin = Cuesheet.Sections?.LastOrDefault()?.End;
- if (Begin.HasValue == false)
- {
- begin = Cuesheet.Tracks.Min(x => x.Begin);
- }
- end = Cuesheet.Tracks.Max(x => x.End);
- }
-
- [JsonConstructor]
- public CuesheetSection() { }
- public Cuesheet? Cuesheet
- {
- get => cuesheet;
- set
- {
- if (cuesheet == null)
- {
- cuesheet = value;
- }
- else
- {
- throw new InvalidOperationException();
- }
- }
- }
-
- public String? Artist
- {
- get => artist;
- set
- {
- var previousValue = artist;
- artist = value;
- OnValidateablePropertyChanged(nameof(Artist));
- OnTraceablePropertyChanged(previousValue, nameof(Artist));
- }
- }
-
- public String? Title
- {
- get => title;
- set
- {
- var previousValue = title;
- title = value;
- OnValidateablePropertyChanged(nameof(Title));
- OnTraceablePropertyChanged(previousValue, nameof(Title));
- }
- }
-
- public TimeSpan? Begin
- {
- get => begin;
- set
- {
- var previousValue = begin;
- begin = value;
- OnValidateablePropertyChanged(nameof(Begin));
- OnTraceablePropertyChanged(previousValue, nameof(Begin));
- }
- }
-
- public TimeSpan? End
- {
- get => end;
- set
- {
- var previousValue = end;
- end = value;
- OnValidateablePropertyChanged(nameof(End));
- OnTraceablePropertyChanged(previousValue, nameof(End));
- }
- }
-
- public String? AudiofileName
- {
- get => audiofileName;
- set
- {
- var previousValue = audiofileName;
- audiofileName = value;
- OnValidateablePropertyChanged(nameof(AudiofileName));
- OnTraceablePropertyChanged(previousValue, nameof(AudiofileName));
- }
- }
-
- public void CopyValues(CuesheetSection splitPoint)
- {
- Artist = splitPoint.Artist;
- Title = splitPoint.Title;
- Begin = splitPoint.Begin;
- }
-
- public override ValidationResult Validate(string property)
- {
- ValidationStatus validationStatus = ValidationStatus.NoValidation;
- List? validationMessages = null;
- switch (property)
- {
- case nameof(Begin):
- validationStatus = ValidationStatus.Success;
- if (Begin == null)
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Begin)));
- }
- else
- {
- var minBegin = Cuesheet?.Tracks.Min(x => x.Begin);
- if (Begin < minBegin)
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} should be greater than or equal '{1}'!", nameof(Begin), minBegin));
- }
- if (Begin > End)
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} should be less than or equal '{1}'!", nameof(Begin), End));
- }
- }
- break;
- case nameof(End):
- validationStatus = ValidationStatus.Success;
- if (End == null)
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(End)));
- }
- else
- {
- var maxEnd = Cuesheet?.Tracks.Max(x => x.End);
- if (End > maxEnd)
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} should be less than or equal '{1}'!", nameof(End), maxEnd));
- }
- if (End < Begin)
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} should be greater than or equal '{1}'!", nameof(End), Begin));
- }
- }
- break;
- case nameof(Artist):
- validationStatus = ValidationStatus.Success;
- if (String.IsNullOrEmpty(Artist))
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Artist)));
- }
- break;
- case nameof(Title):
- validationStatus = ValidationStatus.Success;
- if (String.IsNullOrEmpty(Title))
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Title)));
- }
- break;
- case nameof(AudiofileName):
- validationStatus = ValidationStatus.Success;
- if (String.IsNullOrEmpty(AudiofileName))
- {
- validationMessages ??= [];
- validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(AudiofileName)));
- }
- break;
- }
- return ValidationResult.Create(validationStatus, validationMessages);
- }
-
- private void OnTraceablePropertyChanged(object? previousValue, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = "")
- {
- TraceablePropertyChanged?.Invoke(this, new TraceablePropertiesChangedEventArgs(new TraceableChange(previousValue, propertyName)));
- }
- }
-}
diff --git a/AudioCuesheetEditor/Model/Options/ExportOptions.cs b/AudioCuesheetEditor/Model/Options/ExportOptions.cs
index dfa267a2..3f8457ac 100644
--- a/AudioCuesheetEditor/Model/Options/ExportOptions.cs
+++ b/AudioCuesheetEditor/Model/Options/ExportOptions.cs
@@ -60,7 +60,7 @@ public ExportOptions()
public ExportOptions(ICollection exportProfiles, Guid? selectedProfileId = null)
{
ExportProfiles = exportProfiles;
- SelectedProfileId = selectedProfileId ?? ExportProfiles.First().Id;
+ SelectedProfileId = selectedProfileId ?? ExportProfiles.FirstOrDefault()?.Id;
}
public ICollection ExportProfiles { get; set; }
[JsonIgnore]
diff --git a/AudioCuesheetEditor/Services/IO/CuesheetExportService.cs b/AudioCuesheetEditor/Services/IO/CuesheetExportService.cs
index 835cad77..eefeac07 100644
--- a/AudioCuesheetEditor/Services/IO/CuesheetExportService.cs
+++ b/AudioCuesheetEditor/Services/IO/CuesheetExportService.cs
@@ -17,16 +17,19 @@
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO;
using AudioCuesheetEditor.Model.IO.Export;
+using AudioCuesheetEditor.Model.IO.Import;
using AudioCuesheetEditor.Services.UI;
+using Microsoft.Extensions.Localization;
using System.Text;
namespace AudioCuesheetEditor.Services.IO
{
- public class CuesheetExportService(ISessionStateContainer sessionStateContainer)
+ public class CuesheetExportService(ISessionStateContainer sessionStateContainer, IStringLocalizer localizer)
{
private readonly ISessionStateContainer _sessionStateContainer = sessionStateContainer;
+ private readonly IStringLocalizer _localizer = localizer;
- public IEnumerable CanGenerateExportfiles(string? filename)
+ public Result CanGenerateExportfile(string? filename)
{
List validationMessages = [];
var extension = Path.GetExtension(filename);
@@ -37,52 +40,36 @@ public IEnumerable CanGenerateExportfiles(string? filename)
}
validationMessages.AddRange(_sessionStateContainer.Cuesheet.Validate().ValidationMessages);
validationMessages.AddRange(_sessionStateContainer.Cuesheet.Tracks.Select(x => x.Validate()).SelectMany(x => x.ValidationMessages));
- return validationMessages;
+ if (validationMessages.Count != 0)
+ {
+ return Result.Failure(new Error(ErrorType.ValidationFailed, string.Join(Environment.NewLine, validationMessages.Select(x => x.GetMessageLocalized(_localizer)))));
+ }
+ return Result.Success();
}
- public IReadOnlyCollection GenerateExportfiles(string? filename)
+ public Result GenerateExportfile(string? filename)
{
- List exportfiles = [];
- if (!CanGenerateExportfiles(filename).Any())
+ var validationResult = CanGenerateExportfile(filename);
+ if (validationResult.IsSuccess == false)
{
- if (_sessionStateContainer.Cuesheet.Sections.Count != 0)
- {
- var counter = 1;
- string? content = null;
- string? audioFileName = null;
- foreach (var section in _sessionStateContainer.Cuesheet.Sections.OrderBy(x => x.Begin))
- {
- audioFileName = section.AudiofileName;
- if (section.Validate().Status == ValidationStatus.Success)
- {
- content = WriteCuesheet(audioFileName, section);
- var name = string.Format("{0}({1}){2}", Path.GetFileNameWithoutExtension(filename), counter, FileExtensions.Cuesheet);
- exportfiles.Add(new Exportfile() { Name = name, Content = content, Begin = section.Begin, End = section.End });
- counter++;
- }
- }
- }
- else
- {
- string? content = null;
- var extension = Path.GetExtension(filename);
- if (extension?.Equals(FileExtensions.Cuesheet, StringComparison.OrdinalIgnoreCase) == false)
- {
- filename = $"{filename}{FileExtensions.Cuesheet}";
- }
- if (_sessionStateContainer.Cuesheet.Audiofile != null)
- {
- content = WriteCuesheet(_sessionStateContainer.Cuesheet.Audiofile.Name);
- }
- var begin = _sessionStateContainer.Cuesheet.Tracks.Min(x => x.Begin);
- var end = _sessionStateContainer.Cuesheet.Tracks.Max(x => x.End);
- exportfiles.Add(new Exportfile() { Name = filename!, Content = content, Begin = begin, End = end });
- }
+ return Result.Failure(new Error(ErrorType.ValidationFailed, validationResult.Error!.Message));
+ }
+ string? content = null;
+ var extension = Path.GetExtension(filename);
+ if (extension?.Equals(FileExtensions.Cuesheet, StringComparison.OrdinalIgnoreCase) == false)
+ {
+ filename = $"{filename}{FileExtensions.Cuesheet}";
+ }
+ if (_sessionStateContainer.Cuesheet.Audiofile != null)
+ {
+ content = WriteCuesheet(_sessionStateContainer.Cuesheet.Audiofile.Name);
}
- return exportfiles;
+ var begin = _sessionStateContainer.Cuesheet.Tracks.Min(x => x.Begin);
+ var end = _sessionStateContainer.Cuesheet.Tracks.Max(x => x.End);
+ return Result.Success(new Exportfile() { Name = filename!, Content = content, Begin = begin, End = end });
}
- private string WriteCuesheet(string? audiofileName, CuesheetSection? section = null)
+ private string WriteCuesheet(string? audiofileName)
{
var builder = new StringBuilder();
if (string.IsNullOrEmpty(_sessionStateContainer.Cuesheet.Cataloguenumber) == false)
@@ -93,14 +80,10 @@ private string WriteCuesheet(string? audiofileName, CuesheetSection? section = n
{
builder.AppendLine(string.Format("{0} \"{1}\"", CuesheetConstants.CuesheetCDTextfile, _sessionStateContainer.Cuesheet.CDTextfile.Name));
}
- builder.AppendLine(string.Format("{0} \"{1}\"", CuesheetConstants.CuesheetTitle, section != null ? section.Title : _sessionStateContainer.Cuesheet.Title));
- builder.AppendLine(string.Format("{0} \"{1}\"", CuesheetConstants.CuesheetArtist, section != null ? section.Artist : _sessionStateContainer.Cuesheet.Artist));
+ builder.AppendLine(string.Format("{0} \"{1}\"", CuesheetConstants.CuesheetTitle, _sessionStateContainer.Cuesheet.Title));
+ builder.AppendLine(string.Format("{0} \"{1}\"", CuesheetConstants.CuesheetArtist, _sessionStateContainer.Cuesheet.Artist));
builder.AppendLine(string.Format("{0} \"{1}\" {2}", CuesheetConstants.CuesheetFileName, audiofileName, _sessionStateContainer.Cuesheet.Audiofile?.AudioFileType));
IEnumerable