From 8b334924b7a0b03fa6a9f5a7a525f956a6b632de Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Mon, 26 Aug 2024 10:12:47 +0200
Subject: [PATCH 01/33] Added service for text import
---
.../Model/IO/Import/CuesheetImportfile.cs | 32 ++-
.../Model/IO/Import/IImportfile.cs | 8 +-
.../Model/IO/Import/TextImportfile.cs | 266 +-----------------
.../Model/Utility/TimeSpanUtility.cs | 41 +++
AudioCuesheetEditor/Program.cs | 5 +
.../Services/IO/ImportManager.cs | 121 ++++++++
.../Services/IO/TextImportService.cs | 163 +++++++++++
.../UI/ApplicationOptionsTimeSpanParser.cs | 86 ++++++
8 files changed, 446 insertions(+), 276 deletions(-)
create mode 100644 AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs
create mode 100644 AudioCuesheetEditor/Services/IO/ImportManager.cs
create mode 100644 AudioCuesheetEditor/Services/IO/TextImportService.cs
create mode 100644 AudioCuesheetEditor/Services/UI/ApplicationOptionsTimeSpanParser.cs
diff --git a/AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs b/AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs
index c5656c54..92e86745 100644
--- a/AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs
+++ b/AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs
@@ -14,6 +14,7 @@
//along with Foobar. If not, see
//.
using AudioCuesheetEditor.Model.AudioCuesheet;
+using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.Options;
using System.Text.RegularExpressions;
@@ -22,12 +23,12 @@ namespace AudioCuesheetEditor.Model.IO.Import
{
public class CuesheetImportfile : IImportfile
{
- private IEnumerable fileContent;
+ private IEnumerable? fileContent;
public EventHandler? AnalysisFinished;
///
- public IEnumerable FileContent
+ public IEnumerable? FileContent
{
get => fileContent;
set
@@ -38,9 +39,10 @@ public IEnumerable FileContent
}
///
- public IEnumerable FileContentRecognized { get; private set; }
- public Exception? AnalyseException { get; private set; }
- public Cuesheet? Cuesheet { get; private set; }
+ public IEnumerable? FileContentRecognized { get; set; }
+ ///
+ public Exception? AnalyseException { get; set; }
+ public ImportCuesheet? Cuesheet { get; private set; }
public ApplicationOptions ApplicationOptions { get; private set; }
public CuesheetImportfile(MemoryStream fileContentStream, ApplicationOptions applicationOptions)
@@ -62,7 +64,7 @@ private void Analyse()
{
try
{
- Cuesheet = new Cuesheet();
+ Cuesheet = new ImportCuesheet();
var cuesheetArtistGroupName = "CuesheetArtist";
var cuesheetTitleGroupName = "CuesheetTitle";
var cuesheetFileNameGroupName = "CuesheetFileName";
@@ -132,8 +134,9 @@ private void Analyse()
var matchGroup = match.Groups.GetValueOrDefault(cuesheetFileNameGroupName);
if (matchGroup != null)
{
- var audioFile = matchGroup.Value;
- Cuesheet.Audiofile = new Audiofile(audioFile);
+ //TODO
+ //var audioFile = matchGroup.Value;
+ //Cuesheet.Audiofile = new Audiofile(audioFile);
}
else
{
@@ -147,8 +150,9 @@ private void Analyse()
var matchGroup = match.Groups.GetValueOrDefault(cuesheetCDTextfileGroupName);
if (matchGroup != null)
{
- var cdTextfile = matchGroup.Value;
- Cuesheet.CDTextfile = new CDTextfile(cdTextfile);
+ //TODO
+ //var cdTextfile = matchGroup.Value;
+ //Cuesheet.CDTextfile = new CDTextfile(cdTextfile);
}
else
{
@@ -162,8 +166,9 @@ private void Analyse()
var matchGroup = match.Groups.GetValueOrDefault(cuesheetCatalogueNumberGroupName);
if (matchGroup != null)
{
- var catalogueNumber = matchGroup.Value;
- Cuesheet.Cataloguenumber.Value = catalogueNumber;
+ //TODO
+ //var catalogueNumber = matchGroup.Value;
+ //Cuesheet.Cataloguenumber.Value = catalogueNumber;
}
else
{
@@ -277,7 +282,8 @@ private void Analyse()
}
if (track != null)
{
- Cuesheet.AddTrack(track, ApplicationOptions);
+ //TODO
+ //Cuesheet.AddTrack(track, ApplicationOptions);
}
else
{
diff --git a/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs b/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs
index 44bd3490..92959ce5 100644
--- a/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs
+++ b/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs
@@ -20,10 +20,14 @@ public interface IImportfile
///
/// File content (each element is a file line)
///
- public IEnumerable FileContent { get; set; }
+ public IEnumerable? FileContent { get; set; }
///
/// File content with marking which passages has been reconized by scheme
///
- public IEnumerable FileContentRecognized { get; }
+ public IEnumerable? FileContentRecognized { get; set; }
+ ///
+ /// Exception that has been thrown while readinng out the file
+ ///
+ public Exception? AnalyseException { get; set; }
}
}
diff --git a/AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs b/AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs
index 3e38db41..5eaaf07e 100644
--- a/AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs
+++ b/AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs
@@ -22,272 +22,16 @@
namespace AudioCuesheetEditor.Model.IO.Import
{
- public class TextImportfile : IImportfile, IDisposable
+ public class TextImportfile : IImportfile
{
public const String MimeType = "text/plain";
public const String FileExtension = ".txt";
- public EventHandler? AnalysisFinished;
-
- private TextImportScheme textImportScheme;
- private TimeSpanFormat? timeSpanFormat;
- private bool disposedValue;
- private IEnumerable fileContent;
-
- public TextImportfile(MemoryStream fileContentStream, ImportOptions? importOptions = null)
- {
- FileContentRecognized = [];
- textImportScheme = new TextImportScheme();
- fileContent = [];
- fileContentStream.Position = 0;
- using var reader = new StreamReader(fileContentStream);
- List lines = [];
- while (reader.EndOfStream == false)
- {
- lines.Add(reader.ReadLine());
- }
- FileContent = lines.AsReadOnly();
- TimeSpanFormat = new TimeSpanFormat();
- if (importOptions == null)
- {
- TextImportScheme = TextImportScheme.DefaultTextImportScheme;
- }
- else
- {
- if (importOptions.TimeSpanFormat != null)
- {
- TimeSpanFormat = importOptions.TimeSpanFormat;
- }
- TextImportScheme = importOptions.TextImportScheme;
- }
- }
-
///
- public IEnumerable FileContent
- {
- get => fileContent;
- set
- {
- fileContent = value;
- Analyse();
- }
- }
-
+ public IEnumerable? FileContent { get; set; }
///
- public IEnumerable FileContentRecognized { get; private set; }
-
- public TextImportScheme TextImportScheme
- {
- get { return textImportScheme; }
- set
- {
- textImportScheme.SchemeChanged -= TextImportScheme_SchemeChanged;
- textImportScheme = value;
- textImportScheme.SchemeChanged += TextImportScheme_SchemeChanged;
- Analyse();
- }
- }
-
- public Exception? AnalyseException { get; private set; }
-
- public Boolean IsValid { get { return AnalyseException == null; } }
-
- public Cuesheet? Cuesheet { get; private set; }
-
- public TimeSpanFormat TimeSpanFormat
- {
- get
- {
- timeSpanFormat ??= new TimeSpanFormat();
- return timeSpanFormat;
- }
- set
- {
- if (timeSpanFormat != null)
- {
- timeSpanFormat.SchemeChanged -= TimeSpanFormat_SchemeChanged;
- }
- timeSpanFormat = value;
- if (timeSpanFormat != null)
- {
- timeSpanFormat.SchemeChanged += TimeSpanFormat_SchemeChanged;
- }
- }
- }
-
- private void TextImportScheme_SchemeChanged(object? sender, string e)
- {
- Analyse();
- }
-
- private void TimeSpanFormat_SchemeChanged(object? sender, EventArgs eventArgs)
- {
- Analyse();
- }
-
- private void Analyse()
- {
- try
- {
- Cuesheet = new Cuesheet();
- FileContentRecognized = [];
- AnalyseException = null;
- Boolean cuesheetRecognized = false;
- List recognizedFileContent = [];
- foreach (var line in FileContent)
- {
- var recognizedLine = line;
- if (String.IsNullOrEmpty(line) == false)
- {
- Boolean recognized = false;
- if ((recognized == false) && (cuesheetRecognized == false) && (String.IsNullOrEmpty(TextImportScheme.SchemeCuesheet) == false))
- {
- //Remove entity names
- var expression = TextImportScheme.SchemeCuesheet.Replace(String.Format("{0}.", nameof(AudioCuesheet.Cuesheet)), String.Empty).Replace(String.Format("{0}.", nameof(Track)), String.Empty);
- var regExCuesheet = new Regex(expression);
- recognizedLine = AnalyseLine(line, Cuesheet, regExCuesheet);
- recognized = recognizedLine != null;
- cuesheetRecognized = recognizedLine != null;
- }
- if ((recognized == false) && (String.IsNullOrEmpty(TextImportScheme.SchemeTracks) == false))
- {
- //Remove entity names
- var expression = TextImportScheme.SchemeTracks.Replace(String.Format("{0}.", nameof(AudioCuesheet.Cuesheet)), String.Empty).Replace(String.Format("{0}.", nameof(Track)), String.Empty);
- var regExTracks = new Regex(expression);
- var track = new Track();
- recognizedLine = AnalyseLine(line, track, regExTracks);
- recognized = recognizedLine != null;
- Cuesheet.AddTrack(track);
- }
- }
- recognizedFileContent.Add(recognizedLine);
- }
- if (recognizedFileContent.Count > 0)
- {
- FileContentRecognized = recognizedFileContent.AsReadOnly();
- }
- }
- catch (Exception ex)
- {
- FileContentRecognized = FileContent;
- AnalyseException = ex;
- Cuesheet = null;
- }
- AnalysisFinished?.Invoke(this, EventArgs.Empty);
- }
-
- ///
- /// Analyses a line and sets the properties on the entity
- ///
- /// Line to analyse
- /// Entity to set properties on
- /// Regular expression to use for analysis
- /// Analysed line with marking what has been matched or empty string
- /// Occurs when property or group could not be found!
- private String? AnalyseLine(String line, ICuesheetEntity entity, Regex regex)
- {
- String? recognized = null;
- string? recognizedLine = line;
- if (String.IsNullOrEmpty(line) == false)
- {
- var match = regex.Match(line);
- if (match.Success)
- {
- for (int groupCounter = 1; groupCounter < match.Groups.Count; groupCounter++)
- {
- var key = match.Groups.Keys.ElementAt(groupCounter);
- var group = match.Groups.GetValueOrDefault(key);
- if ((group != null) && (group.Success))
- {
- var property = entity.GetType().GetProperty(key, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
- if (property != null)
- {
- SetValue(entity, property, group.Value);
- recognizedLine = string.Concat(recognizedLine.AsSpan(0, group.Index + (13 * (groupCounter - 1)))
- , String.Format(CuesheetConstants.RecognizedMarkHTML, group.Value)
- , recognizedLine.AsSpan(group.Index + (13 * (groupCounter - 1)) + group.Length));
- }
- else
- {
- throw new NullReferenceException(String.Format("Property '{0}' was not found for line content {1}", key, line));
- }
- }
- else
- {
- throw new NullReferenceException(String.Format("Group '{0}' could not be found!", key));
- }
- }
- if (recognizedLine.Contains(CuesheetConstants.RecognizedMarkHTML.Substring(0, CuesheetConstants.RecognizedMarkHTML.IndexOf("{0}"))))
- {
- recognized = recognizedLine;
- }
- }
- else
- {
- recognized = line;
- }
- }
- return recognized;
- }
-
- ///
- /// Set the value on the entity
- ///
- /// Entity object to set the value on
- /// Property to set
- /// Value to set
- private void SetValue(ICuesheetEntity entity, PropertyInfo property, string value)
- {
- if (property.PropertyType == typeof(TimeSpan?))
- {
- var utility = new DateTimeUtility(TimeSpanFormat);
- property.SetValue(entity, utility.ParseTimeSpan(value));
- }
- if (property.PropertyType == typeof(uint?))
- {
- property.SetValue(entity, Convert.ToUInt32(value));
- }
- if (property.PropertyType == typeof(String))
- {
- property.SetValue(entity, value);
- }
- if (property.PropertyType == typeof(IReadOnlyCollection))
- {
- var list = Flag.AvailableFlags.Where(x => value.Contains(x.CuesheetLabel));
- ((Track)entity).SetFlags(list);
- }
- if (property.PropertyType == typeof(Audiofile))
- {
- property.SetValue(entity, new Audiofile(value));
- }
- if (property.PropertyType == typeof(Cataloguenumber))
- {
- ((Cuesheet)entity).Cataloguenumber.Value = value;
- }
- if (property.PropertyType == typeof(CDTextfile))
- {
- property.SetValue(entity, new CDTextfile(value));
- }
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- TimeSpanFormat.SchemeChanged -= TimeSpanFormat_SchemeChanged;
- textImportScheme.SchemeChanged -= TextImportScheme_SchemeChanged;
- }
- disposedValue = true;
- }
- }
-
- public void Dispose()
- {
- // Ändern Sie diesen Code nicht. Fügen Sie Bereinigungscode in der Methode "Dispose(bool disposing)" ein.
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
+ public IEnumerable? FileContentRecognized { get; set; }
+ ///
+ public Exception? AnalyseException { get;set; }
}
}
diff --git a/AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs b/AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs
new file mode 100644
index 00000000..230a6c0a
--- /dev/null
+++ b/AudioCuesheetEditor/Model/Utility/TimeSpanUtility.cs
@@ -0,0 +1,41 @@
+//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
+//.
+namespace AudioCuesheetEditor.Model.Utility
+{
+ public class TimeSpanUtility
+ {
+ //TODO: Unit Tests
+ public static TimeSpan? ParseTimeSpan(String input, TimeSpanFormat? timeSpanFormat = null)
+ {
+ TimeSpan? result = null;
+ if (String.IsNullOrEmpty(input) == false)
+ {
+ if (String.IsNullOrEmpty(timeSpanFormat?.Scheme))
+ {
+ if (TimeSpan.TryParse(input, out var parsed))
+ {
+ result = parsed;
+ }
+ }
+ else
+ {
+ result = timeSpanFormat.ParseTimeSpan(input);
+ }
+ }
+ return result;
+ }
+ }
+}
diff --git a/AudioCuesheetEditor/Program.cs b/AudioCuesheetEditor/Program.cs
index 287ee61f..adda0d11 100644
--- a/AudioCuesheetEditor/Program.cs
+++ b/AudioCuesheetEditor/Program.cs
@@ -19,6 +19,8 @@
using AudioCuesheetEditor.Extensions;
using AudioCuesheetEditor.Model.UI;
using AudioCuesheetEditor.Model.Utility;
+using AudioCuesheetEditor.Services.IO;
+using AudioCuesheetEditor.Services.UI;
using BlazorDownloadFile;
using Blazorise;
using Blazorise.Bootstrap5;
@@ -53,6 +55,9 @@
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
+builder.Services.AddScoped();
+builder.Services.AddScoped();
+builder.Services.AddScoped();
builder.Services.AddLogging();
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
diff --git a/AudioCuesheetEditor/Services/IO/ImportManager.cs b/AudioCuesheetEditor/Services/IO/ImportManager.cs
new file mode 100644
index 00000000..59f0abe6
--- /dev/null
+++ b/AudioCuesheetEditor/Services/IO/ImportManager.cs
@@ -0,0 +1,121 @@
+//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.Data.Options;
+using AudioCuesheetEditor.Extensions;
+using AudioCuesheetEditor.Model.AudioCuesheet;
+using AudioCuesheetEditor.Model.IO;
+using AudioCuesheetEditor.Model.IO.Audio;
+using AudioCuesheetEditor.Model.IO.Import;
+using AudioCuesheetEditor.Model.Options;
+using AudioCuesheetEditor.Model.Utility;
+using Blazorise;
+using Microsoft.JSInterop;
+
+namespace AudioCuesheetEditor.Services.IO
+{
+ public enum ImportFileType
+ {
+ Unknown,
+ ProjectFile,
+ Cuesheet,
+ Textfile,
+ Audiofile
+ }
+ public class ImportManager(SessionStateContainer sessionStateContainer, LocalStorageOptionsProvider localStorageOptionsProvider, IJSRuntime jsRuntime, HttpClient httpClient, TextImportService textImportService)
+ {
+ private readonly SessionStateContainer _sessionStateContainer = sessionStateContainer;
+ private readonly LocalStorageOptionsProvider _localStorageOptionsProvider = localStorageOptionsProvider;
+ private readonly IJSRuntime _jsRuntime = jsRuntime;
+ private readonly HttpClient _httpClient = httpClient;
+ private readonly TextImportService _textImportService = textImportService;
+
+ public async Task> ImportFilesAsync(IEnumerable files)
+ {
+ Dictionary importFileTypes = [];
+ foreach (var file in files)
+ {
+ if (IOUtility.CheckFileMimeType(file, Projectfile.MimeType, Projectfile.FileExtension))
+ {
+ //TODO
+ //var fileContent = await ReadFileContentAsync(file);
+ //var cuesheet = Projectfile.ImportFile(fileContent.ToArray());
+ //if (cuesheet != null)
+ //{
+ // _sessionStateContainer.ImportCuesheet = cuesheet;
+ //}
+ //importFileTypes.Add(file, ImportFileType.ProjectFile);
+ }
+ if (IOUtility.CheckFileMimeType(file, Cuesheet.MimeType, Cuesheet.FileExtension))
+ {
+ var fileContent = await ReadFileContentAsync(file);
+ var options = await _localStorageOptionsProvider.GetOptions();
+ _sessionStateContainer.CuesheetImportFile = new CuesheetImportfile(fileContent, options);
+ importFileTypes.Add(file, ImportFileType.Cuesheet);
+ }
+ if (IOUtility.CheckFileMimeType(file, TextImportfile.MimeType, TextImportfile.FileExtension))
+ {
+ var fileContent = await ReadFileContentAsync(file);
+ var options = await _localStorageOptionsProvider.GetOptions();
+ var applicationOptions = await _localStorageOptionsProvider.GetOptions();
+ fileContent.Position = 0;
+ using var reader = new StreamReader(fileContent);
+ List lines = [];
+ while (reader.EndOfStream == false)
+ {
+ lines.Add(reader.ReadLine());
+ }
+ _sessionStateContainer.TextImportFile = _textImportService.Analyse(options, lines);
+ //TODO
+ if (_textImportService.AnalysedCuesheet != null)
+ {
+ var importCuesheet = new Cuesheet();
+ importCuesheet.Import(_textImportService.AnalysedCuesheet, applicationOptions);
+ _sessionStateContainer.ImportCuesheet = importCuesheet;
+ }
+ //_textImportService.Analyse(options)
+ //TODO: use new import service
+ //if (_sessionStateContainer.TextImportFile != null)
+ //{
+ // _sessionStateContainer.TextImportFile.TimeSpanFormat.ValidateablePropertyChanged -= Timespanformat_ValidateablePropertyChanged;
+ // _sessionStateContainer.TextImportFile.TextImportScheme.ValidateablePropertyChanged -= TextImportScheme_ValidateablePropertyChanged;
+ //}
+ //_sessionStateContainer.TextImportFile = new TextImportfile(memoryStream, options);
+ //_sessionStateContainer.TextImportFile.TimeSpanFormat.ValidateablePropertyChanged += Timespanformat_ValidateablePropertyChanged;
+ //_sessionStateContainer.TextImportFile.TextImportScheme.ValidateablePropertyChanged += TextImportScheme_ValidateablePropertyChanged;
+ importFileTypes.Add(file, ImportFileType.Textfile);
+ }
+ if (IOUtility.CheckFileMimeTypeForAudioCodec(file))
+ {
+ var audioFileObjectURL = await _jsRuntime.InvokeAsync("getObjectURL", "dropFileInput");
+ var codec = IOUtility.GetAudioCodec(file);
+ var audiofile = new Audiofile(file.Name, audioFileObjectURL, codec, _httpClient);
+ _ = audiofile.LoadContentStream();
+ _sessionStateContainer.ImportAudiofile = audiofile;
+ importFileTypes.Add(file, ImportFileType.Audiofile);
+ }
+ }
+ return importFileTypes;
+ }
+ private static async Task ReadFileContentAsync(IFileEntry file)
+ {
+ var fileContent = new MemoryStream();
+ var stream = file.OpenReadStream();
+ await stream.CopyToAsync(fileContent);
+ stream.Close();
+ return fileContent;
+ }
+ }
+}
diff --git a/AudioCuesheetEditor/Services/IO/TextImportService.cs b/AudioCuesheetEditor/Services/IO/TextImportService.cs
new file mode 100644
index 00000000..5edfb5a3
--- /dev/null
+++ b/AudioCuesheetEditor/Services/IO/TextImportService.cs
@@ -0,0 +1,163 @@
+//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.AudioCuesheet.Import;
+using AudioCuesheetEditor.Model.IO.Audio;
+using AudioCuesheetEditor.Model.IO.Import;
+using AudioCuesheetEditor.Model.Options;
+using AudioCuesheetEditor.Model.Utility;
+using System.Reflection;
+using System.Text.RegularExpressions;
+
+namespace AudioCuesheetEditor.Services.IO
+{
+ public class TextImportService
+ {
+ public ImportCuesheet? AnalysedCuesheet { get; private set; }
+ public ImportOptions? ImportOptions { get; private set; }
+ //TODO: Unit Test
+ public TextImportfile Analyse(ImportOptions importOptions, IEnumerable fileContent)
+ {
+ TextImportfile importfile = new();
+ try
+ {
+ ImportOptions = importOptions;
+ AnalysedCuesheet = new ImportCuesheet();
+ Boolean cuesheetRecognized = false;
+ List recognizedFileContent = [];
+ foreach (var line in fileContent)
+ {
+ var recognizedLine = line;
+ if (String.IsNullOrEmpty(line) == false)
+ {
+ Boolean recognized = false;
+ if ((recognized == false) && (cuesheetRecognized == false) && (String.IsNullOrEmpty(ImportOptions.TextImportScheme.SchemeCuesheet) == false))
+ {
+ //Remove entity names
+ var expression = ImportOptions.TextImportScheme.SchemeCuesheet.Replace(String.Format("{0}.", nameof(Cuesheet)), String.Empty).Replace(String.Format("{0}.", nameof(Track)), String.Empty);
+ var regExCuesheet = new Regex(expression);
+ recognizedLine = AnalyseLine(line, AnalysedCuesheet, regExCuesheet);
+ recognized = recognizedLine != null;
+ cuesheetRecognized = recognizedLine != null;
+ }
+ if ((recognized == false) && (String.IsNullOrEmpty(ImportOptions.TextImportScheme.SchemeTracks) == false))
+ {
+ //Remove entity names
+ var expression = ImportOptions.TextImportScheme.SchemeTracks.Replace(String.Format("{0}.", nameof(Cuesheet)), String.Empty).Replace(String.Format("{0}.", nameof(Track)), String.Empty);
+ var regExTracks = new Regex(expression);
+ var track = new ImportTrack();
+ recognizedLine = AnalyseLine(line, track, regExTracks);
+ recognized = recognizedLine != null;
+ AnalysedCuesheet.Tracks = AnalysedCuesheet.Tracks.Append(track);
+ }
+ }
+ recognizedFileContent.Add(recognizedLine);
+ }
+ if (recognizedFileContent.Count > 0)
+ {
+ importfile.FileContentRecognized = recognizedFileContent.AsReadOnly();
+ }
+ }
+ catch (Exception ex)
+ {
+ importfile.FileContentRecognized = fileContent;
+ importfile.AnalyseException = ex;
+ AnalysedCuesheet = null;
+ }
+ return importfile;
+ }
+
+ private String? AnalyseLine(String line, object entity, Regex regex)
+ {
+ String? recognized = null;
+ string? recognizedLine = line;
+ if (String.IsNullOrEmpty(line) == false)
+ {
+ var match = regex.Match(line);
+ if (match.Success)
+ {
+ for (int groupCounter = 1; groupCounter < match.Groups.Count; groupCounter++)
+ {
+ var key = match.Groups.Keys.ElementAt(groupCounter);
+ var group = match.Groups.GetValueOrDefault(key);
+ if ((group != null) && (group.Success))
+ {
+ var property = entity.GetType().GetProperty(key, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
+ if (property != null)
+ {
+ SetValue(entity, property, group.Value);
+ recognizedLine = string.Concat(recognizedLine.AsSpan(0, group.Index + (13 * (groupCounter - 1)))
+ , String.Format(CuesheetConstants.RecognizedMarkHTML, group.Value)
+ , recognizedLine.AsSpan(group.Index + (13 * (groupCounter - 1)) + group.Length));
+ }
+ else
+ {
+ throw new NullReferenceException(String.Format("Property '{0}' was not found for line content {1}", key, line));
+ }
+ }
+ else
+ {
+ throw new NullReferenceException(String.Format("Group '{0}' could not be found!", key));
+ }
+ }
+ if (recognizedLine.Contains(CuesheetConstants.RecognizedMarkHTML.Substring(0, CuesheetConstants.RecognizedMarkHTML.IndexOf("{0}"))))
+ {
+ recognized = recognizedLine;
+ }
+ }
+ else
+ {
+ recognized = line;
+ }
+ }
+ return recognized;
+ }
+
+ private void SetValue(object entity, PropertyInfo property, string value)
+ {
+ if (property.PropertyType == typeof(TimeSpan?))
+ {
+ property.SetValue(entity, TimeSpanUtility.ParseTimeSpan(value, ImportOptions?.TimeSpanFormat));
+ }
+ if (property.PropertyType == typeof(uint?))
+ {
+ property.SetValue(entity, Convert.ToUInt32(value));
+ }
+ if (property.PropertyType == typeof(String))
+ {
+ property.SetValue(entity, value);
+ }
+ if (property.PropertyType == typeof(IReadOnlyCollection))
+ {
+ var list = Flag.AvailableFlags.Where(x => value.Contains(x.CuesheetLabel));
+ ((Track)entity).SetFlags(list);
+ }
+ if (property.PropertyType == typeof(Audiofile))
+ {
+ property.SetValue(entity, new Audiofile(value));
+ }
+ if (property.PropertyType == typeof(Cataloguenumber))
+ {
+ ((Cuesheet)entity).Cataloguenumber.Value = value;
+ }
+ if (property.PropertyType == typeof(CDTextfile))
+ {
+ property.SetValue(entity, new CDTextfile(value));
+ }
+ }
+ }
+}
diff --git a/AudioCuesheetEditor/Services/UI/ApplicationOptionsTimeSpanParser.cs b/AudioCuesheetEditor/Services/UI/ApplicationOptionsTimeSpanParser.cs
new file mode 100644
index 00000000..2cead9b1
--- /dev/null
+++ b/AudioCuesheetEditor/Services/UI/ApplicationOptionsTimeSpanParser.cs
@@ -0,0 +1,86 @@
+//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.Data.Options;
+using AudioCuesheetEditor.Model.Options;
+using AudioCuesheetEditor.Model.Utility;
+using System.Linq.Expressions;
+using System.Reflection;
+
+namespace AudioCuesheetEditor.Services.UI
+{
+ public class ApplicationOptionsTimeSpanParser
+ {
+ private readonly LocalStorageOptionsProvider _localStorageOptionsProvider;
+
+ private ApplicationOptions? applicationOptions;
+ private bool disposedValue;
+
+ public ApplicationOptionsTimeSpanParser(LocalStorageOptionsProvider localStorageOptionsProvider)
+ {
+ _localStorageOptionsProvider = localStorageOptionsProvider;
+ _localStorageOptionsProvider.OptionSaved += LocalStorageOptionsProvider_OptionSaved;
+ Task.Run(InitAsync);
+ }
+
+ public async Task TimespanTextChanged(T entity, Expression> expression, String value)
+ {
+ if (expression.Body is not MemberExpression memberExpression)
+ {
+ throw new ArgumentException("'expression' should be a member expression");
+ }
+ if (applicationOptions == null)
+ {
+ await InitAsync();
+ }
+ TimeSpan? result = TimeSpanUtility.ParseTimeSpan(value, applicationOptions?.TimeSpanFormat);
+ switch (memberExpression.Member.MemberType)
+ {
+ case MemberTypes.Property:
+ ((PropertyInfo)memberExpression.Member).SetValue(entity, result);
+ break;
+ default:
+ throw new NotImplementedException();
+ }
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ // Verwalteten Zustand (verwaltete Objekte) bereinigen
+ _localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
+ }
+
+ disposedValue = true;
+ }
+ }
+
+ private async Task InitAsync()
+ {
+ applicationOptions ??= await _localStorageOptionsProvider.GetOptions();
+ }
+
+ private void LocalStorageOptionsProvider_OptionSaved(object? sender, IOptions options)
+ {
+ if (options is ApplicationOptions applicationOption)
+ {
+ applicationOptions = applicationOption;
+ }
+ }
+ }
+}
From 1b3ff1f07452bdd4cfbf370a02aaaf2617ff6db6 Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Mon, 26 Aug 2024 13:01:56 +0200
Subject: [PATCH 02/33] added EditImportOptions component
---
.../AudioCuesheetEditor.csproj | 4 +
.../Model/Options/ImportOptions.cs | 21 +--
AudioCuesheetEditor/Pages/EditSections.razor | 10 +-
.../Localization/EditImportOptions/de.json | 21 +++
.../Localization/EditImportOptions/en.json | 21 +++
.../Services/IO/TextImportService.cs | 1 +
.../Shared/EditImportOptions.razor | 171 ++++++++++++++++++
.../Shared/EditTrackModal.razor | 22 +--
AudioCuesheetEditor/Shared/TracksTable.razor | 12 +-
AudioCuesheetEditor/_Imports.razor | 2 +
10 files changed, 252 insertions(+), 33 deletions(-)
create mode 100644 AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json
create mode 100644 AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json
create mode 100644 AudioCuesheetEditor/Shared/EditImportOptions.razor
diff --git a/AudioCuesheetEditor/AudioCuesheetEditor.csproj b/AudioCuesheetEditor/AudioCuesheetEditor.csproj
index 7bb5869e..f0b6f137 100644
--- a/AudioCuesheetEditor/AudioCuesheetEditor.csproj
+++ b/AudioCuesheetEditor/AudioCuesheetEditor.csproj
@@ -53,6 +53,8 @@
+
+
@@ -98,6 +100,8 @@
+
+
diff --git a/AudioCuesheetEditor/Model/Options/ImportOptions.cs b/AudioCuesheetEditor/Model/Options/ImportOptions.cs
index 1ee000a1..6231381d 100644
--- a/AudioCuesheetEditor/Model/Options/ImportOptions.cs
+++ b/AudioCuesheetEditor/Model/Options/ImportOptions.cs
@@ -21,18 +21,13 @@ namespace AudioCuesheetEditor.Model.Options
{
public class ImportOptions : IOptions
{
- public TextImportScheme TextImportScheme { get; set; }
- public TimeSpanFormat? TimeSpanFormat { get; set; }
-
- public ImportOptions()
- {
- TextImportScheme = TextImportScheme.DefaultTextImportScheme;
- }
-
- public ImportOptions(TextImportfile textImportfile)
- {
- TextImportScheme = textImportfile.TextImportScheme;
- TimeSpanFormat = textImportfile.TimeSpanFormat;
- }
+ public TextImportScheme TextImportScheme { get; set; } = TextImportScheme.DefaultTextImportScheme;
+ public TimeSpanFormat TimeSpanFormat { get; set; } = new();
+ //TODO
+ //public ImportOptions(TextImportfile textImportfile)
+ //{
+ // TextImportScheme = textImportfile.TextImportScheme;
+ // TimeSpanFormat = textImportfile.TimeSpanFormat;
+ //}
}
}
diff --git a/AudioCuesheetEditor/Pages/EditSections.razor b/AudioCuesheetEditor/Pages/EditSections.razor
index 4f9c19ea..3a2c4ddf 100644
--- a/AudioCuesheetEditor/Pages/EditSections.razor
+++ b/AudioCuesheetEditor/Pages/EditSections.razor
@@ -20,7 +20,7 @@ along with Foobar. If not, see
@inject ITextLocalizer _localizer
@inject SessionStateContainer _sessionStateContainer
@inject ITextLocalizer _validationMessageLocalizer
-@inject DateTimeUtility _dateTimeUtility
+@inject ApplicationOptionsTimeSpanParser _applicationOptionsTimeSpanParser
@inject ITextLocalizerService _localizationService
@inject TraceChangeManager _traceChangeManager
@inject IJSRuntime _jsRuntime
@@ -77,7 +77,7 @@ along with Foobar. If not, see
-
+
@@ -86,7 +86,7 @@ along with Foobar. If not, see
-
+
@@ -161,7 +161,9 @@ along with Foobar. If not, see
switch (_sessionStateContainer.CurrentViewMode)
{
case ViewMode.ViewModeImport:
- cuesheet = _sessionStateContainer.ImportCuesheet;
+ //TODO
+ // cuesheet = _sessionStateContainer.ImportCuesheet;
+ cuesheet = null;
break;
default:
cuesheet = _sessionStateContainer.Cuesheet;
diff --git a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json
new file mode 100644
index 00000000..4003da94
--- /dev/null
+++ b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json
@@ -0,0 +1,21 @@
+{
+ "culture": "de",
+ "translations": {
+ "Enter textimportscheme cuesheet tooltip": "Textschema für den Import von Cuesheeteigenschaften hier eingeben. Die Identifikation wird über reguläre Ausdrücke ausgeführt.",
+ "Enter textimportscheme cuesheet here": "Textschema für den Import von Cuesheeteigenschaften hier eingeben",
+ "Select placeholder": "Platzhalter auswählen",
+ "Enter textimportscheme track tooltip": "Textschema für den Import von Titeleigenschaften hier eingeben. Die Identifikation wird über reguläre Ausdrücke ausgeführt.",
+ "Enter textimportscheme track here": "Textschema für den Import von Titeleigenschaften hier eingeben",
+ "Textimportscheme cuesheet": "Import Schema Cuesheet",
+ "Textimportscheme track": "Import Schema Titel",
+ "Import Options": "Importoptionen",
+ "ENTER REGULAR EXPRESSION HERE": "Hier regulären Ausdruck eingeben",
+ "Enter custom timespan format here": "Hier können Sie bei Bedarf ein angepasstes Format für Zeitspannen eingeben. Details können der Hilfe entnommen werden.",
+ "Customized timespan format import": "Zeitspannenformat für Import",
+ "Days": "Tage",
+ "Hours": "Stunden",
+ "Minutes": "Minuten",
+ "Seconds": "Sekunden",
+ "Milliseconds": "Millisekunden"
+ }
+}
\ No newline at end of file
diff --git a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json
new file mode 100644
index 00000000..e5966508
--- /dev/null
+++ b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json
@@ -0,0 +1,21 @@
+{
+ "culture": "en",
+ "translations": {
+ "Enter textimportscheme cuesheet tooltip": "Enter textscheme for cuesheet properties import here. Identification will be done using regular expressions.",
+ "Enter textimportscheme cuesheet here": "Enter textscheme for cuesheet properties import here",
+ "Select placeholder": "Select placeholder",
+ "Enter textimportscheme track tooltip": "Enter textscheme for track properties import here. Identification will be done using regular expressions.",
+ "Enter textimportscheme track here": "Enter textscheme for track properties import here",
+ "Textimportscheme cuesheet": "Textimport scheme cuesheet",
+ "Textimportscheme track": "Textimport scheme track",
+ "Import Options": "Import options",
+ "ENTER REGULAR EXPRESSION HERE": "Enter regular expression here",
+ "Enter custom timespan format here": "You can enter a custom format for timespan here. Details can be found in help.",
+ "Customized timespan format import": "Timespan format for import",
+ "Days": "Days",
+ "Hours": "Hours",
+ "Minutes": "Minutes",
+ "Seconds": "Seconds",
+ "Milliseconds": "Milliseconds"
+ }
+}
\ No newline at end of file
diff --git a/AudioCuesheetEditor/Services/IO/TextImportService.cs b/AudioCuesheetEditor/Services/IO/TextImportService.cs
index 5edfb5a3..faca1fad 100644
--- a/AudioCuesheetEditor/Services/IO/TextImportService.cs
+++ b/AudioCuesheetEditor/Services/IO/TextImportService.cs
@@ -35,6 +35,7 @@ public TextImportfile Analyse(ImportOptions importOptions, IEnumerable
TextImportfile importfile = new();
try
{
+ importfile.FileContent = fileContent;
ImportOptions = importOptions;
AnalysedCuesheet = new ImportCuesheet();
Boolean cuesheetRecognized = false;
diff --git a/AudioCuesheetEditor/Shared/EditImportOptions.razor b/AudioCuesheetEditor/Shared/EditImportOptions.razor
new file mode 100644
index 00000000..b6308d71
--- /dev/null
+++ b/AudioCuesheetEditor/Shared/EditImportOptions.razor
@@ -0,0 +1,171 @@
+
+
+@implements IDisposable
+
+@inject ITextLocalizerService _localizationService
+@inject ITextLocalizer _localizer
+@inject ITextLocalizer _validationMessageLocalizer
+@inject LocalStorageOptionsProvider _localStorageOptionsProvider
+
+
+
+
+
+
+ @_localizer["Textimportscheme cuesheet"]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @_localizer["Select placeholder"]
+
+
+ @foreach (var availableSchemeTrack in TextImportScheme.AvailableSchemeCuesheet)
+ {
+ @_localizer[availableSchemeTrack.Key]
+ }
+
+
+
+
+
+
+
+
+
+
+
+ @_localizer["Textimportscheme track"]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @_localizer["Select placeholder"]
+
+
+ @foreach (var availableSchemeTrack in TextImportScheme.AvailableSchemesTrack)
+ {
+ @_localizer[availableSchemeTrack.Key]
+ }
+
+
+
+
+
+
+
+
+
+
+
+ @_localizer["Customized timespan format import"]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @_localizer["Select placeholder"]
+
+
+ @foreach (var availableFormat in TimeSpanFormat.AvailableTimespanScheme)
+ {
+ @_localizer[availableFormat.Key]
+ }
+
+
+
+
+
+
+
+
+
+@code{
+ //TODO: Changes to ImportOptions need to do a reanalysis
+ public ImportOptions? ImportOptions { get; private set; }
+
+ public void Dispose()
+ {
+ _localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
+ _localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionsSaved;
+ }
+
+ protected override async Task OnInitializedAsync()
+ {
+ _localizationService.LocalizationChanged += LocalizationService_LocalizationChanged;
+ _localStorageOptionsProvider.OptionSaved += LocalStorageOptionsProvider_OptionsSaved;
+
+ ImportOptions = await _localStorageOptionsProvider.GetOptions();
+
+ await base.OnInitializedAsync();
+ }
+
+ void LocalizationService_LocalizationChanged(object? sender, EventArgs args)
+ {
+ StateHasChanged();
+ }
+
+ void LocalStorageOptionsProvider_OptionsSaved(object? sender, IOptions options)
+ {
+ if (options is ImportOptions importOptions)
+ {
+ ImportOptions = importOptions;
+ StateHasChanged();
+ }
+ }
+
+ async Task TextChangedAsync(Action setter, string text)
+ {
+ if (ImportOptions == null)
+ {
+ throw new NullReferenceException();
+ }
+ setter(ImportOptions, text);
+ await _localStorageOptionsProvider.SaveOptions(ImportOptions);
+ }
+}
\ No newline at end of file
diff --git a/AudioCuesheetEditor/Shared/EditTrackModal.razor b/AudioCuesheetEditor/Shared/EditTrackModal.razor
index b0b83d9c..3f42c390 100644
--- a/AudioCuesheetEditor/Shared/EditTrackModal.razor
+++ b/AudioCuesheetEditor/Shared/EditTrackModal.razor
@@ -25,7 +25,7 @@ along with Foobar. If not, see
@inject TraceChangeManager _traceChangeManager
@inject HotKeys _hotKeys
@inject ITextLocalizer _validationMessageLocalizer
-@inject DateTimeUtility _dateTimeUtility
+@inject ApplicationOptionsTimeSpanParser _applicationOptionsTimeSpanParser
@@ -102,7 +102,7 @@ along with Foobar. If not, see
@_localizer["Begin"]
-
+
@@ -114,7 +114,7 @@ along with Foobar. If not, see
@_localizer["End"]
-
+
@@ -126,7 +126,7 @@ along with Foobar. If not, see
@_localizer["Length"]
-
+
@@ -149,7 +149,7 @@ along with Foobar. If not, see
@_localizer["PreGap"]
-
+
@@ -161,7 +161,7 @@ along with Foobar. If not, see
@_localizer["PostGap"]
-
+
@@ -253,7 +253,7 @@ along with Foobar. If not, see
-
+
@@ -271,7 +271,7 @@ along with Foobar. If not, see
-
+
@@ -289,7 +289,7 @@ along with Foobar. If not, see
-
+
@@ -319,7 +319,7 @@ along with Foobar. If not, see
-
+
@@ -337,7 +337,7 @@ along with Foobar. If not, see
-
+
diff --git a/AudioCuesheetEditor/Shared/TracksTable.razor b/AudioCuesheetEditor/Shared/TracksTable.razor
index 6252e512..e47751ff 100644
--- a/AudioCuesheetEditor/Shared/TracksTable.razor
+++ b/AudioCuesheetEditor/Shared/TracksTable.razor
@@ -26,7 +26,7 @@ along with Foobar. If not, see
@inject ITextLocalizerService _localizationService
@inject MusicBrainzDataProvider _musicBrainzDataProvider
@inject ITextLocalizer _validationMessageLocalizer
-@inject DateTimeUtility _dateTimeUtility
+@inject ApplicationOptionsTimeSpanParser _applicationOptionsTimeSpanParser
@if (_sessionStateContainer.CurrentViewMode == ViewMode.ViewModeFull)
@@ -341,7 +341,7 @@ along with Foobar. If not, see
}
-
+
@@ -353,7 +353,7 @@ along with Foobar. If not, see
-
+
@@ -364,7 +364,7 @@ along with Foobar. If not, see
-
+
@@ -408,7 +408,9 @@ along with Foobar. If not, see
switch (_sessionStateContainer.CurrentViewMode)
{
case ViewMode.ViewModeImport:
- cuesheet = _sessionStateContainer.ImportCuesheet;
+ //TODO
+ cuesheet = null;
+ // cuesheet = _sessionStateContainer.ImportCuesheet;
break;
default:
cuesheet = _sessionStateContainer.Cuesheet;
diff --git a/AudioCuesheetEditor/_Imports.razor b/AudioCuesheetEditor/_Imports.razor
index f00ca655..b86c652b 100644
--- a/AudioCuesheetEditor/_Imports.razor
+++ b/AudioCuesheetEditor/_Imports.razor
@@ -24,6 +24,8 @@
@using AudioCuesheetEditor.Data.Options
@using AudioCuesheetEditor.Model.Utility
@using AudioCuesheetEditor.Data.Services
+@using AudioCuesheetEditor.Services.IO
+@using AudioCuesheetEditor.Services.UI
@using Microsoft.Extensions.Logging
@using Blazorise
@using Blazorise.Components
From 31cf057bd439a2a5fe542d9667f5da62b4738098 Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Mon, 26 Aug 2024 15:10:41 +0200
Subject: [PATCH 03/33] switched import to use services
---
.../Extensions/SessionStateContainer.cs | 47 +---
.../Model/AudioCuesheet/Cuesheet.cs | 27 +--
.../Model/AudioCuesheet/ICuesheet.cs | 26 +++
.../Model/AudioCuesheet/ICuesheetEntity.cs | 1 +
.../Model/AudioCuesheet/ITrack.cs | 30 +++
.../AudioCuesheet/Import/ImportCuesheet.cs | 28 +++
.../Model/AudioCuesheet/Import/ImportTrack.cs | 31 +++
.../Model/AudioCuesheet/Track.cs | 38 ++--
.../Model/Options/ImportOptions.cs | 6 -
.../Model/Utility/DateTimeUtility.cs | 4 +-
.../Pages/ViewModeImport.razor | 203 +-----------------
.../Services/IO/TextImportService.cs | 2 +-
.../Shared/EditImportOptions.razor | 5 +
AudioCuesheetEditor/Shared/TracksTable.razor | 4 +-
14 files changed, 178 insertions(+), 274 deletions(-)
create mode 100644 AudioCuesheetEditor/Model/AudioCuesheet/ICuesheet.cs
create mode 100644 AudioCuesheetEditor/Model/AudioCuesheet/ITrack.cs
create mode 100644 AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportCuesheet.cs
create mode 100644 AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs
diff --git a/AudioCuesheetEditor/Extensions/SessionStateContainer.cs b/AudioCuesheetEditor/Extensions/SessionStateContainer.cs
index cbc900d4..179031cc 100644
--- a/AudioCuesheetEditor/Extensions/SessionStateContainer.cs
+++ b/AudioCuesheetEditor/Extensions/SessionStateContainer.cs
@@ -14,6 +14,7 @@
//along with Foobar. If not, see
//.
using AudioCuesheetEditor.Model.AudioCuesheet;
+using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.IO.Import;
using AudioCuesheetEditor.Model.Options;
@@ -31,7 +32,6 @@ public class SessionStateContainer
private ViewMode currentViewMode;
private Cuesheet cuesheet;
private Cuesheet? importCuesheet;
- private TextImportfile? textImportFile;
private CuesheetImportfile? cuesheetImportFile;
private Audiofile? importAudiofile;
@@ -65,28 +65,8 @@ public Cuesheet? ImportCuesheet
}
}
- public TextImportfile? TextImportFile
- {
- get { return textImportFile; }
- set
- {
- if (textImportFile != null)
- {
- textImportFile.AnalysisFinished -= TextImportScheme_AnalysisFinished;
- }
- textImportFile = value;
- if (textImportFile != null)
- {
- textImportFile.AnalysisFinished += TextImportScheme_AnalysisFinished;
- ImportCuesheet = textImportFile.Cuesheet;
- }
- else
- {
- ImportCuesheet = null;
- }
- }
- }
-
+ public TextImportfile? TextImportFile { get; set; }
+
public CuesheetImportfile? CuesheetImportFile
{
get { return cuesheetImportFile; }
@@ -100,7 +80,8 @@ public CuesheetImportfile? CuesheetImportFile
if ((CuesheetImportFile != null) && (CuesheetImportFile.Cuesheet != null))
{
CuesheetImportFile.AnalysisFinished += CuesheetImportFile_AnalysisFinished;
- ImportCuesheet = CuesheetImportFile.Cuesheet;
+ //TODO
+ //ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
{
@@ -160,7 +141,8 @@ public void StartImportCuesheet(ApplicationOptions applicationOptions)
{
if (ImportCuesheet != null)
{
- Cuesheet.Import(ImportCuesheet, applicationOptions, _traceChangeManager);
+ //TODO
+ //Cuesheet.Import(ImportCuesheet, applicationOptions, _traceChangeManager);
ImportCuesheet = null;
}
ResetImport();
@@ -175,17 +157,7 @@ private void SetCuesheetReference(Cuesheet value)
_traceChangeManager.TraceChanges(Cuesheet);
CuesheetChanged?.Invoke(this, EventArgs.Empty);
}
- private void TextImportScheme_AnalysisFinished(object? sender, EventArgs eventArgs)
- {
- if (textImportFile != null)
- {
- ImportCuesheet = textImportFile.Cuesheet;
- }
- else
- {
- ImportCuesheet = null;
- }
- }
+
private void Cuesheet_CuesheetImported(object? sender, EventArgs e)
{
CuesheetChanged?.Invoke(this, EventArgs.Empty);
@@ -195,7 +167,8 @@ void CuesheetImportFile_AnalysisFinished(object? sender, EventArgs e)
{
if (CuesheetImportFile != null)
{
- ImportCuesheet = CuesheetImportFile.Cuesheet;
+ //TODO
+ //ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
{
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
index 4b17102c..652e2cc2 100644
--- a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
@@ -13,6 +13,7 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//.
+using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO;
using AudioCuesheetEditor.Model.IO.Audio;
@@ -39,7 +40,7 @@ public class CuesheetSectionAddRemoveEventArgs(CuesheetSection section) : EventA
public CuesheetSection Section { get; } = section;
}
- public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validateable, ICuesheetEntity, ITraceable
+ public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validateable, ICuesheetEntity, ITraceable, ICuesheet
{
public const String MimeType = "text/*";
public const String FileExtension = ".cue";
@@ -393,7 +394,7 @@ public void MoveTrack(Track track, MoveDirection moveDirection)
}
}
- public void Import(Cuesheet cuesheet, ApplicationOptions applicationOptions, TraceChangeManager? traceChangeManager = null)
+ public void Import(ImportCuesheet cuesheet, ApplicationOptions applicationOptions, TraceChangeManager? traceChangeManager = null)
{
//Since we use a stack for several changes we need to lock execution for everything else
lock (syncLock)
@@ -559,25 +560,27 @@ private void ReCalculateTrackProperties(Track trackToCalculate)
///
/// Reference to import cuesheet
/// Reference to application options
- private void CopyValues(Cuesheet cuesheet, ApplicationOptions applicationOptions)
+ private void CopyValues(ImportCuesheet cuesheet, ApplicationOptions applicationOptions)
{
Artist = cuesheet.Artist;
Title = cuesheet.Title;
- Audiofile = cuesheet.Audiofile;
- CDTextfile = cuesheet.CDTextfile;
- Cataloguenumber = cuesheet.Cataloguenumber;
+ //TODO
+ //Audiofile = cuesheet.Audiofile;
+ //CDTextfile = cuesheet.CDTextfile;
+ //Cataloguenumber = cuesheet.Cataloguenumber;
foreach (var importTrack in cuesheet.Tracks)
{
//We don't want to copy the cuesheet reference since we are doing a copy and want to assign the track to this object
var track = new Track(importTrack, false);
AddTrack(track, applicationOptions);
}
- // Copy sections
- foreach (var splitPoint in cuesheet.Sections)
- {
- var newSplitPoint = AddSection();
- newSplitPoint.CopyValues(splitPoint);
- }
+ //TODO
+ //// Copy sections
+ //foreach (var splitPoint in cuesheet.Sections)
+ //{
+ // var newSplitPoint = AddSection();
+ // newSplitPoint.CopyValues(splitPoint);
+ //}
}
private void Track_RankPropertyValueChanged(object? sender, string e)
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/ICuesheet.cs b/AudioCuesheetEditor/Model/AudioCuesheet/ICuesheet.cs
new file mode 100644
index 00000000..90d2adbf
--- /dev/null
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/ICuesheet.cs
@@ -0,0 +1,26 @@
+//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.Import;
+
+namespace AudioCuesheetEditor.Model.AudioCuesheet
+{
+ public interface ICuesheet
+ {
+ public String? Artist { get; set; }
+ public String? Title { get; set; }
+ }
+}
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/ICuesheetEntity.cs b/AudioCuesheetEditor/Model/AudioCuesheet/ICuesheetEntity.cs
index 4e0b86f4..d48ca867 100644
--- a/AudioCuesheetEditor/Model/AudioCuesheet/ICuesheetEntity.cs
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/ICuesheetEntity.cs
@@ -20,6 +20,7 @@
namespace AudioCuesheetEditor.Model.AudioCuesheet
{
+ //TODO: Check if this can be removed
///
/// Interface for cuesheet entities (Cuesheet, track, etc.)
///
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/ITrack.cs b/AudioCuesheetEditor/Model/AudioCuesheet/ITrack.cs
new file mode 100644
index 00000000..c0256822
--- /dev/null
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/ITrack.cs
@@ -0,0 +1,30 @@
+//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
+//.
+namespace AudioCuesheetEditor.Model.AudioCuesheet
+{
+ public interface ITrack
+ {
+ public string? Artist { get; set; }
+ public string? Title { get; set; }
+ public uint? Position { get; set; }
+ public TimeSpan? Begin { get; set; }
+ public TimeSpan? End { get; set; }
+ public TimeSpan? Length { get; set; }
+ //TODO: Flags
+ public TimeSpan? PreGap { get; set; }
+ public TimeSpan? PostGap { get; set; }
+ }
+}
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportCuesheet.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportCuesheet.cs
new file mode 100644
index 00000000..001caa58
--- /dev/null
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportCuesheet.cs
@@ -0,0 +1,28 @@
+//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
+//.
+
+namespace AudioCuesheetEditor.Model.AudioCuesheet.Import
+{
+ public class ImportCuesheet : ICuesheet
+ {
+ public string? Artist { get; set; }
+ public string? Title { get; set; }
+ //TODO Audiofile
+ //TODO CDTextfile
+ public string? Cataloguenumber { get; set; }
+ public ICollection Tracks { get; set; } = [];
+ }
+}
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs
new file mode 100644
index 00000000..70b80fe5
--- /dev/null
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs
@@ -0,0 +1,31 @@
+//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
+//.
+
+namespace AudioCuesheetEditor.Model.AudioCuesheet.Import
+{
+ public class ImportTrack : ITrack
+ {
+ public string? Artist { get; set; }
+ public string? Title { get; set; }
+ public uint? Position { get; set; }
+ public TimeSpan? Begin { get; set; }
+ public TimeSpan? End { get; set; }
+ public TimeSpan? Length { get; set; }
+ //TODO: Flags
+ public TimeSpan? PreGap { get; set; }
+ public TimeSpan? PostGap { get; set; }
+ }
+}
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Track.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Track.cs
index 7e67d2c2..7cf70bc2 100644
--- a/AudioCuesheetEditor/Model/AudioCuesheet/Track.cs
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/Track.cs
@@ -13,6 +13,7 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//.
+using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.UI;
using System.Text.Json.Serialization;
@@ -25,7 +26,7 @@ public enum SetFlagMode
Remove
}
- public class Track : Validateable
@@ -72,7 +72,7 @@ along with Foobar. If not, see
@_localizer["Cuesheet"]
-
+
@@ -88,7 +88,7 @@ along with Foobar. If not, see
@_localizer["Project filename"]
-
+
@@ -147,7 +147,7 @@ along with Foobar. If not, see
- @if (_sessionStateContainer.TextImportFile?.AnalyseException != null)
+ @if (_sessionStateContainer.Importfile?.AnalyseException != null)
{
@@ -156,7 +156,7 @@ along with Foobar. If not, see
- @_localizer["Error during textimport"] : @_sessionStateContainer.TextImportFile.AnalyseException.Message
+ @_localizer["Error during textimport"] : @_sessionStateContainer.Importfile.AnalyseException.Message
}
}
@@ -199,7 +199,7 @@ along with Foobar. If not, see
@code {
String selectedStep = "selectFiles";
- String dragNDropUploadFilter = String.Join(',', TextImportfile.MimeType, Cuesheet.FileExtension, Projectfile.FileExtension);
+ String dragNDropUploadFilter = String.Join(',', FileMimeTypes.Text, FileExtensions.Cuesheet, FileExtensions.Projectfile);
Boolean cuesheetDataVisible = true;
Boolean cuesheetTracksVisible = true;
Boolean cuesheetSplitPointsVisible = true;
@@ -247,7 +247,7 @@ along with Foobar. If not, see
selectedStep = name;
break;
case "validateData":
- if ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.TextImportFile != null))
+ if ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.Importfile != null))
{
selectFilesCompleted = true;
selectedStep = name;
@@ -271,7 +271,7 @@ along with Foobar. If not, see
{
get
{
- if ((userChangedSelectedStep == false) && ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.TextImportFile != null)))
+ if ((userChangedSelectedStep == false) && ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.Importfile != null)))
{
selectFilesCompleted = true;
selectedStep = "validateData";
@@ -286,7 +286,7 @@ along with Foobar. If not, see
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
- if (IOUtility.CheckFileMimeType(file, TextImportfile.MimeType, TextImportfile.FileExtension) == false)
+ if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Text, FileExtensions.Text) == false)
{
invalidTextImportFileNames.Add(file.Name);
}
@@ -304,7 +304,7 @@ along with Foobar. If not, see
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
- if (IOUtility.CheckFileMimeType(file, Cuesheet.MimeType, Cuesheet.FileExtension) == false)
+ if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Cuesheet, FileExtensions.Cuesheet) == false)
{
invalidCuesheetfileNames.Add(file.Name);
}
@@ -322,7 +322,7 @@ along with Foobar. If not, see
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
- if (IOUtility.CheckFileMimeType(file, Projectfile.MimeType, Projectfile.FileExtension) == false)
+ if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Projectfile, FileExtensions.Projectfile) == false)
{
invalidProjectfileNames.Add(file.Name);
}
@@ -339,9 +339,9 @@ along with Foobar. If not, see
invalidDropFileNames.Clear();
foreach (var file in e.Files)
{
- if ((IOUtility.CheckFileMimeType(file, Projectfile.MimeType, Projectfile.FileExtension) == false)
- && (IOUtility.CheckFileMimeType(file, Cuesheet.MimeType, Cuesheet.FileExtension) == false)
- && (IOUtility.CheckFileMimeType(file, TextImportfile.MimeType, TextImportfile.FileExtension) == false)
+ if ((IOUtility.CheckFileMimeType(file, FileMimeTypes.Projectfile, FileExtensions.Projectfile) == false)
+ && (IOUtility.CheckFileMimeType(file, FileMimeTypes.Cuesheet, FileExtensions.Cuesheet) == false)
+ && (IOUtility.CheckFileMimeType(file, FileMimeTypes.Text, FileExtensions.Text) == false)
&& (IOUtility.CheckFileMimeTypeForAudioCodec(file) == false))
{
invalidDropFileNames.Add(file.Name);
@@ -469,9 +469,9 @@ along with Foobar. If not, see
async Task EditImportOptions_OptionsChanged(ImportOptions importOptions)
{
- if (_sessionStateContainer.TextImportFile?.FileContent != null)
+ if ((_sessionStateContainer.Importfile?.FileType == ImportFileType.Textfile) && (_sessionStateContainer.Importfile?.FileContent != null))
{
- await _importManager.ImportTextAsync(_sessionStateContainer.TextImportFile.FileContent);
+ await _importManager.ImportTextAsync(_sessionStateContainer.Importfile.FileContent);
}
}
}
diff --git a/AudioCuesheetEditor/Services/IO/CuesheetImportService.cs b/AudioCuesheetEditor/Services/IO/CuesheetImportService.cs
index d6784cca..648109dc 100644
--- a/AudioCuesheetEditor/Services/IO/CuesheetImportService.cs
+++ b/AudioCuesheetEditor/Services/IO/CuesheetImportService.cs
@@ -22,12 +22,15 @@ namespace AudioCuesheetEditor.Services.IO
{
public class CuesheetImportService
{
- public static CuesheetImportfile Analyse(IEnumerable fileContent)
+ public static IImportfile Analyse(IEnumerable fileContent)
{
- CuesheetImportfile cuesheetImportfile = new();
+ Importfile importfile = new()
+ {
+ FileType = ImportFileType.Cuesheet
+ };
try
{
- cuesheetImportfile.AnalysedCuesheet = new();
+ importfile.AnalysedCuesheet = new();
var cuesheetArtistGroupName = "CuesheetArtist";
var cuesheetTitleGroupName = "CuesheetTitle";
var cuesheetFileNameGroupName = "CuesheetFileName";
@@ -68,7 +71,7 @@ public static CuesheetImportfile Analyse(IEnumerable fileContent)
if (matchGroup != null)
{
var artist = matchGroup.Value;
- cuesheetImportfile.AnalysedCuesheet.Artist = artist;
+ importfile.AnalysedCuesheet.Artist = artist;
}
else
{
@@ -83,7 +86,7 @@ public static CuesheetImportfile Analyse(IEnumerable fileContent)
if (matchGroup != null)
{
var title = matchGroup.Value;
- cuesheetImportfile.AnalysedCuesheet.Title = title;
+ importfile.AnalysedCuesheet.Title = title;
}
else
{
@@ -98,7 +101,7 @@ public static CuesheetImportfile Analyse(IEnumerable fileContent)
if (matchGroup != null)
{
var audioFile = matchGroup.Value;
- cuesheetImportfile.AnalysedCuesheet.Audiofile = audioFile;
+ importfile.AnalysedCuesheet.Audiofile = audioFile;
}
else
{
@@ -113,7 +116,7 @@ public static CuesheetImportfile Analyse(IEnumerable fileContent)
if (matchGroup != null)
{
var cdTextfile = matchGroup.Value;
- cuesheetImportfile.AnalysedCuesheet.CDTextfile = cdTextfile;
+ importfile.AnalysedCuesheet.CDTextfile = cdTextfile;
}
else
{
@@ -128,7 +131,7 @@ public static CuesheetImportfile Analyse(IEnumerable fileContent)
if (matchGroup != null)
{
var catalogueNumber = matchGroup.Value;
- cuesheetImportfile.AnalysedCuesheet.Cataloguenumber = catalogueNumber;
+ importfile.AnalysedCuesheet.Cataloguenumber = catalogueNumber;
}
else
{
@@ -242,7 +245,7 @@ public static CuesheetImportfile Analyse(IEnumerable fileContent)
}
if (track != null)
{
- cuesheetImportfile.AnalysedCuesheet.Tracks.Add(track);
+ importfile.AnalysedCuesheet.Tracks.Add(track);
}
else
{
@@ -276,16 +279,16 @@ public static CuesheetImportfile Analyse(IEnumerable fileContent)
}
recognizedLines.Add(recognizedLine);
}
- cuesheetImportfile.FileContent = lines.AsReadOnly();
- cuesheetImportfile.FileContentRecognized = recognizedLines.AsReadOnly();
+ importfile.FileContent = lines.AsReadOnly();
+ importfile.FileContentRecognized = recognizedLines.AsReadOnly();
}
catch (Exception ex)
{
- cuesheetImportfile.AnalyseException = ex;
- cuesheetImportfile.AnalysedCuesheet = null;
- cuesheetImportfile.FileContentRecognized = fileContent;
+ importfile.AnalyseException = ex;
+ importfile.AnalysedCuesheet = null;
+ importfile.FileContentRecognized = fileContent;
}
- return cuesheetImportfile;
+ return importfile;
}
}
}
diff --git a/AudioCuesheetEditor/Services/IO/ImportManager.cs b/AudioCuesheetEditor/Services/IO/ImportManager.cs
index a4ea3be1..2807d950 100644
--- a/AudioCuesheetEditor/Services/IO/ImportManager.cs
+++ b/AudioCuesheetEditor/Services/IO/ImportManager.cs
@@ -43,7 +43,7 @@ public async Task> ImportFilesAsync(IEnum
Dictionary importFileTypes = [];
foreach (var file in files)
{
- if (IOUtility.CheckFileMimeType(file, Projectfile.MimeType, Projectfile.FileExtension))
+ if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Projectfile, FileExtensions.Projectfile))
{
var fileContent = await ReadFileContentAsync(file);
var cuesheet = Projectfile.ImportFile(fileContent.ToArray());
@@ -53,7 +53,7 @@ public async Task> ImportFilesAsync(IEnum
}
importFileTypes.Add(file, ImportFileType.ProjectFile);
}
- if (IOUtility.CheckFileMimeType(file, Cuesheet.MimeType, Cuesheet.FileExtension))
+ if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Cuesheet, FileExtensions.Cuesheet))
{
var fileContent = await ReadFileContentAsync(file);
fileContent.Position = 0;
@@ -66,7 +66,7 @@ public async Task> ImportFilesAsync(IEnum
await ImportCuesheetAsync(lines);
importFileTypes.Add(file, ImportFileType.Cuesheet);
}
- if (IOUtility.CheckFileMimeType(file, TextImportfile.MimeType, TextImportfile.FileExtension))
+ if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Text, FileExtensions.Text))
{
var fileContent = await ReadFileContentAsync(file);
fileContent.Position = 0;
@@ -86,24 +86,24 @@ public async Task> ImportFilesAsync(IEnum
public async Task ImportTextAsync(IEnumerable fileContent)
{
var options = await _localStorageOptionsProvider.GetOptions();
- _sessionStateContainer.TextImportFile = _textImportService.Analyse(options, fileContent);
- if (_sessionStateContainer.TextImportFile.AnalysedCuesheet != null)
+ _sessionStateContainer.Importfile = _textImportService.Analyse(options, fileContent);
+ if (_sessionStateContainer.Importfile.AnalysedCuesheet != null)
{
var applicationOptions = await _localStorageOptionsProvider.GetOptions();
var importCuesheet = new Cuesheet();
- importCuesheet.Import(_sessionStateContainer.TextImportFile.AnalysedCuesheet, applicationOptions);
+ importCuesheet.Import(_sessionStateContainer.Importfile.AnalysedCuesheet, applicationOptions);
_sessionStateContainer.ImportCuesheet = importCuesheet;
}
}
private async Task ImportCuesheetAsync(IEnumerable fileContent)
{
- _sessionStateContainer.CuesheetImportFile = CuesheetImportService.Analyse(fileContent);
- if (_sessionStateContainer.CuesheetImportFile.AnalysedCuesheet != null)
+ _sessionStateContainer.Importfile = CuesheetImportService.Analyse(fileContent);
+ if (_sessionStateContainer.Importfile.AnalysedCuesheet != null)
{
var applicationOptions = await _localStorageOptionsProvider.GetOptions();
var importCuesheet = new Cuesheet();
- importCuesheet.Import(_sessionStateContainer.CuesheetImportFile.AnalysedCuesheet, applicationOptions);
+ importCuesheet.Import(_sessionStateContainer.Importfile.AnalysedCuesheet, applicationOptions);
_sessionStateContainer.ImportCuesheet = importCuesheet;
}
}
diff --git a/AudioCuesheetEditor/Services/IO/TextImportService.cs b/AudioCuesheetEditor/Services/IO/TextImportService.cs
index 883a9f2f..7d1836fd 100644
--- a/AudioCuesheetEditor/Services/IO/TextImportService.cs
+++ b/AudioCuesheetEditor/Services/IO/TextImportService.cs
@@ -28,9 +28,12 @@ namespace AudioCuesheetEditor.Services.IO
public class TextImportService
{
public ImportOptions? ImportOptions { get; private set; }
- public TextImportfile Analyse(ImportOptions importOptions, IEnumerable fileContent)
+ public IImportfile Analyse(ImportOptions importOptions, IEnumerable fileContent)
{
- TextImportfile importfile = new();
+ Importfile importfile = new()
+ {
+ FileType = ImportFileType.Textfile
+ };
try
{
importfile.FileContent = fileContent;
diff --git a/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs b/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs
index 7b2c0210..b150554b 100644
--- a/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs
+++ b/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs
@@ -247,8 +247,7 @@ public async Task ImportTestAsync()
};
localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
var textImportService = new TextImportService();
- var cuesheetImportService = new CuesheetImportService();
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, cuesheetImportService);
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
await importManager.ImportTextAsync(fileContent);
var testHelper = new TestHelper();
// Act
@@ -286,15 +285,14 @@ public async Task ImportTestCalculateEndCorrectlyAsync()
var importOptions = new ImportOptions();
importOptions.TextImportScheme.SchemeCuesheet = null;
localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
- var textImportService = new TextImportService();
- var cuesheetImportService = new CuesheetImportService();
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, cuesheetImportService);
+ var textImportService = new TextImportService();;
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
await importManager.ImportTextAsync(fileContent);
var cuesheet = new Cuesheet();
// Act
cuesheet.Import(sessionStateContainer.ImportCuesheet!, testHelper.ApplicationOptions);
// Assert
- Assert.IsNull(sessionStateContainer.TextImportFile?.AnalyseException);
+ Assert.IsNull(sessionStateContainer.Importfile?.AnalyseException);
Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
Assert.AreEqual(39, sessionStateContainer.ImportCuesheet.Tracks.Count);
Assert.AreEqual(39, cuesheet.Tracks.Count);
@@ -592,8 +590,7 @@ public async Task ImportSamplesTestAsync()
};
localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
var textImportService = new TextImportService();
- var cuesheetImportService = new CuesheetImportService();
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, cuesheetImportService);
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
await importManager.ImportTextAsync(fileContent);
var cuesheet = new Cuesheet
{
@@ -603,7 +600,7 @@ public async Task ImportSamplesTestAsync()
// Act
cuesheet.Import(sessionStateContainer.ImportCuesheet!, testHelper.ApplicationOptions);
// Assert
- Assert.IsNull(sessionStateContainer.TextImportFile?.AnalyseException);
+ Assert.IsNull(sessionStateContainer.Importfile?.AnalyseException);
Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
Assert.AreEqual("CuesheetArtist", cuesheet.Artist);
Assert.AreEqual("CuesheetTitle", cuesheet.Title);
@@ -624,8 +621,7 @@ public async Task ImportSamples2TestAsync()
importOptions.TextImportScheme.SchemeCuesheet = null;
localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(new ImportOptions());
var textImportService = new TextImportService();
- var cuesheetImportService = new CuesheetImportService();
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, cuesheetImportService);
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
await importManager.ImportTextAsync(fileContent);
var cuesheet = new Cuesheet
{
@@ -635,7 +631,7 @@ public async Task ImportSamples2TestAsync()
// Act
cuesheet.Import(sessionStateContainer.ImportCuesheet!, testHelper.ApplicationOptions);
// Assert
- Assert.IsNull(sessionStateContainer.TextImportFile?.AnalyseException);
+ Assert.IsNull(sessionStateContainer.Importfile?.AnalyseException);
Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
Assert.IsNull(cuesheet.Artist);
Assert.IsNull(cuesheet.Title);
diff --git a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
index dcdc0925..9128b69d 100644
--- a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
+++ b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
@@ -154,7 +154,6 @@ public void ImportCuesheetTest()
{
var testhelper = new TestHelper();
var manager = new TraceChangeManager(TestHelper.CreateLogger());
- //TODO
var textImportMemoryStream = new MemoryStream(Resources.Textimport_with_Cuesheetdata);
using var reader = new StreamReader(textImportMemoryStream);
List lines = [];
From 95079249e495e06a57ea30101373fed0da90e722 Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Thu, 29 Aug 2024 15:34:57 +0200
Subject: [PATCH 29/33] Update ImportManager.cs
---
AudioCuesheetEditor/Services/IO/ImportManager.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/AudioCuesheetEditor/Services/IO/ImportManager.cs b/AudioCuesheetEditor/Services/IO/ImportManager.cs
index 2807d950..e30e1206 100644
--- a/AudioCuesheetEditor/Services/IO/ImportManager.cs
+++ b/AudioCuesheetEditor/Services/IO/ImportManager.cs
@@ -17,7 +17,6 @@
using AudioCuesheetEditor.Extensions;
using AudioCuesheetEditor.Model.AudioCuesheet;
using AudioCuesheetEditor.Model.IO;
-using AudioCuesheetEditor.Model.IO.Import;
using AudioCuesheetEditor.Model.Options;
using AudioCuesheetEditor.Model.Utility;
using Blazorise;
From 9c02366ff521332f49f20d9936195d16e754f261 Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Fri, 30 Aug 2024 08:49:24 +0200
Subject: [PATCH 30/33] made import to work with service
---
.../Extensions/SessionStateContainer.cs | 15 +-
.../Model/AudioCuesheet/Cuesheet.cs | 80 +----------
.../Model/UI/TraceChangeManager.cs | 46 ++----
.../Pages/ViewModeImport.razor | 3 +-
.../Services/IO/ImportManager.cs | 76 +++++++++-
.../Extensions/SessionStateContainerTests.cs | 2 +-
.../Model/AudioCuesheet/CuesheetTests.cs | 76 ++++------
.../Model/UI/TraceChangeManagerTests.cs | 132 ++++++++++++++----
8 files changed, 218 insertions(+), 212 deletions(-)
diff --git a/AudioCuesheetEditor/Extensions/SessionStateContainer.cs b/AudioCuesheetEditor/Extensions/SessionStateContainer.cs
index 82035a6d..1a988975 100644
--- a/AudioCuesheetEditor/Extensions/SessionStateContainer.cs
+++ b/AudioCuesheetEditor/Extensions/SessionStateContainer.cs
@@ -93,29 +93,18 @@ public void ResetImport()
{
Importfile = null;
ImportAudiofile = null;
- }
-
- public void StartImportCuesheet(ApplicationOptions applicationOptions)
- {
- if (ImportCuesheet != null)
- {
- Cuesheet.Import(ImportCuesheet, applicationOptions, _traceChangeManager);
- ImportCuesheet = null;
- }
- ResetImport();
+ ImportCuesheet = null;
}
private void SetCuesheetReference(Cuesheet value)
{
- cuesheet.CuesheetImported -= Cuesheet_CuesheetImported;
cuesheet = value;
- cuesheet.CuesheetImported += Cuesheet_CuesheetImported;
_traceChangeManager.Reset();
_traceChangeManager.TraceChanges(Cuesheet);
CuesheetChanged?.Invoke(this, EventArgs.Empty);
}
- private void Cuesheet_CuesheetImported(object? sender, EventArgs e)
+ public void FireCuesheetImported()
{
CuesheetChanged?.Invoke(this, EventArgs.Empty);
}
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
index dfcbf18d..755f4d14 100644
--- a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
@@ -13,9 +13,7 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//.
-using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.Entity;
-using AudioCuesheetEditor.Model.IO;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.IO.Export;
using AudioCuesheetEditor.Model.Options;
@@ -60,7 +58,6 @@ public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validatea
public event EventHandler? TrackRemoved;
public event EventHandler? SectionAdded;
public event EventHandler? SectionRemoved;
- public event EventHandler? CuesheetImported;
[JsonInclude]
public IReadOnlyCollection Tracks
@@ -174,7 +171,7 @@ public TimeSpan? RecordingTime
}
[JsonIgnore]
- public Boolean IsImporting { get; private set; }
+ public Boolean IsImporting { get; set; }
[JsonInclude]
public IReadOnlyCollection Sections
@@ -391,27 +388,6 @@ public void MoveTrack(Track track, MoveDirection moveDirection)
}
}
- public void Import(ICuesheet cuesheet, ApplicationOptions applicationOptions, TraceChangeManager? traceChangeManager = null)
- {
- //Since we use a stack for several changes we need to lock execution for everything else
- lock (syncLock)
- {
- IsImporting = true;
- //We are doing a bulk edit, so inform the TraceChangeManager
- if (traceChangeManager != null)
- {
- traceChangeManager.BulkEdit = true;
- }
- CopyValues(cuesheet, applicationOptions);
- if (traceChangeManager != null)
- {
- traceChangeManager.BulkEdit = false;
- }
- IsImporting = false;
- }
- CuesheetImported?.Invoke(this, EventArgs.Empty);
- }
-
public void StartRecording()
{
recordingStart = DateTime.UtcNow;
@@ -552,60 +528,6 @@ private void ReCalculateTrackProperties(Track trackToCalculate)
}
}
- ///
- /// Copy values from import cuesheet to this cuesheet
- ///
- /// Reference to import cuesheet
- /// Reference to application options
- private void CopyValues(ICuesheet cuesheet, ApplicationOptions applicationOptions)
- {
- Artist = cuesheet.Artist;
- Title = cuesheet.Title;
- IEnumerable? tracks = null;
- if (cuesheet is Cuesheet originCuesheet)
- {
- tracks = originCuesheet.tracks;
- // Copy sections
- foreach (var section in originCuesheet.Sections)
- {
- var newSplitPoint = AddSection();
- newSplitPoint.CopyValues(section);
- }
- Audiofile = originCuesheet.Audiofile;
- CDTextfile = originCuesheet.CDTextfile;
- Cataloguenumber = originCuesheet.Cataloguenumber;
- }
- if (cuesheet is ImportCuesheet importCuesheet)
- {
- tracks = importCuesheet.Tracks;
- if (String.IsNullOrEmpty(importCuesheet.Audiofile) == false)
- {
- Audiofile = new Audiofile(importCuesheet.Audiofile);
- }
- if (String.IsNullOrEmpty(importCuesheet.CDTextfile) == false)
- {
- CDTextfile = new CDTextfile(importCuesheet.CDTextfile);
- }
- Cataloguenumber = new Cataloguenumber()
- {
- Value = importCuesheet.Cataloguenumber
- };
- }
- if (tracks != null)
- {
- foreach (var importTrack in tracks)
- {
- //We don't want to copy the cuesheet reference since we are doing a copy and want to assign the track to this object
- var track = new Track(importTrack, false);
- AddTrack(track, applicationOptions);
- }
- }
- else
- {
- throw new NullReferenceException();
- }
- }
-
private void Track_RankPropertyValueChanged(object? sender, string e)
{
if (sender is Track trackRaisedEvent)
diff --git a/AudioCuesheetEditor/Model/UI/TraceChangeManager.cs b/AudioCuesheetEditor/Model/UI/TraceChangeManager.cs
index 78b5ca1c..a4321ad1 100644
--- a/AudioCuesheetEditor/Model/UI/TraceChangeManager.cs
+++ b/AudioCuesheetEditor/Model/UI/TraceChangeManager.cs
@@ -13,28 +13,15 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//.
-using AudioCuesheetEditor.Model.AudioCuesheet;
-using AudioCuesheetEditor.Pages;
-using Markdig.Extensions.Yaml;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
namespace AudioCuesheetEditor.Model.UI
{
///
/// Class for tracing changes on an object
///
- public class TracedChange
+ public class TracedChange(ITraceable traceableObject, TraceableChange traceableChange)
{
- private readonly WeakReference _tracedObject;
- public TracedChange(ITraceable traceableObject, TraceableChange traceableChange)
- {
- _tracedObject = new WeakReference(traceableObject, false);
- TraceableChange = traceableChange;
- }
+ private readonly WeakReference _tracedObject = new(traceableObject, false);
+
public ITraceable? TraceableObject
{
get
@@ -47,26 +34,21 @@ public ITraceable? TraceableObject
}
}
- public TraceableChange TraceableChange { get; }
+ public TraceableChange TraceableChange { get; } = traceableChange;
}
- public class TracedChanges
+ public class TracedChanges(IEnumerable changes)
{
- public TracedChanges(IEnumerable changes)
- {
- Changes = new(changes);
- }
-
- public List Changes { get; }
+ public List Changes { get; } = new(changes);
public Boolean HasTraceableObject { get { return Changes.Any(x => x.TraceableObject != null); } }
}
///
/// Manager for Undo and Redo operations on objects.
///
- public class TraceChangeManager
+ public class TraceChangeManager(ILogger logger)
{
- private readonly ILogger _logger;
+ private readonly ILogger _logger = logger;
private readonly Stack undoStack = new();
private readonly Stack redoStack = new();
@@ -77,7 +59,7 @@ public class TraceChangeManager
public event EventHandler? UndoDone;
public event EventHandler? RedoDone;
- public Boolean CurrentlyHandlingRedoOrUndoChanges { get; private set; }
+ public Boolean CurrentlyHandlingRedoOrUndoChanges { get; private set; } = false;
///
/// Is Undo() currently possible (are there any changes)?
///
@@ -100,12 +82,6 @@ public Boolean CanRedo
}
}
- public TraceChangeManager(ILogger logger)
- {
- CurrentlyHandlingRedoOrUndoChanges = false;
- _logger = logger;
- }
-
public void TraceChanges(ITraceable traceable)
{
traceable.TraceablePropertyChanged += Traceable_TraceablePropertyChanged;
@@ -229,7 +205,7 @@ public Boolean BulkEdit
_logger.LogDebug("Set BulkEdit called with {value}", value);
if (value)
{
- bulkEditTracedChanges = new();
+ bulkEditTracedChanges = [];
}
else
{
@@ -293,7 +269,7 @@ private void Traceable_TraceablePropertyChanged(object? sender, TraceablePropert
if (BulkEdit == false)
{
//Single change
- var changes = new TracedChanges(new List() { new((ITraceable)sender, e.TraceableChange) });
+ var changes = new TracedChanges([new((ITraceable)sender, e.TraceableChange)]);
undoStack.Push(changes);
redoStack.Clear();
TracedObjectHistoryChanged?.Invoke(this, EventArgs.Empty);
diff --git a/AudioCuesheetEditor/Pages/ViewModeImport.razor b/AudioCuesheetEditor/Pages/ViewModeImport.razor
index ae38f0f2..03cc51b3 100644
--- a/AudioCuesheetEditor/Pages/ViewModeImport.razor
+++ b/AudioCuesheetEditor/Pages/ViewModeImport.razor
@@ -400,8 +400,7 @@ along with Foobar. If not, see
private async Task ImportData()
{
- var options = await _localStorageOptionsProvider.GetOptions();
- _sessionStateContainer.StartImportCuesheet(options);
+ await _importManager.ImportCuesheetAsync();
_sessionStateContainer.CurrentViewMode = ViewMode.ViewModeFull;
StateHasChanged();
}
diff --git a/AudioCuesheetEditor/Services/IO/ImportManager.cs b/AudioCuesheetEditor/Services/IO/ImportManager.cs
index e30e1206..09acd171 100644
--- a/AudioCuesheetEditor/Services/IO/ImportManager.cs
+++ b/AudioCuesheetEditor/Services/IO/ImportManager.cs
@@ -16,8 +16,11 @@
using AudioCuesheetEditor.Data.Options;
using AudioCuesheetEditor.Extensions;
using AudioCuesheetEditor.Model.AudioCuesheet;
+using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.IO;
+using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.Options;
+using AudioCuesheetEditor.Model.UI;
using AudioCuesheetEditor.Model.Utility;
using Blazorise;
@@ -31,11 +34,12 @@ public enum ImportFileType
Textfile,
Audiofile
}
- public class ImportManager(SessionStateContainer sessionStateContainer, ILocalStorageOptionsProvider localStorageOptionsProvider, TextImportService textImportService)
+ public class ImportManager(SessionStateContainer sessionStateContainer, ILocalStorageOptionsProvider localStorageOptionsProvider, TextImportService textImportService, TraceChangeManager traceChangeManager)
{
private readonly SessionStateContainer _sessionStateContainer = sessionStateContainer;
private readonly ILocalStorageOptionsProvider _localStorageOptionsProvider = localStorageOptionsProvider;
private readonly TextImportService _textImportService = textImportService;
+ private readonly TraceChangeManager _traceChangeManager = traceChangeManager;
public async Task> ImportFilesAsync(IEnumerable files)
{
@@ -88,21 +92,28 @@ public async Task ImportTextAsync(IEnumerable fileContent)
_sessionStateContainer.Importfile = _textImportService.Analyse(options, fileContent);
if (_sessionStateContainer.Importfile.AnalysedCuesheet != null)
{
- var applicationOptions = await _localStorageOptionsProvider.GetOptions();
var importCuesheet = new Cuesheet();
- importCuesheet.Import(_sessionStateContainer.Importfile.AnalysedCuesheet, applicationOptions);
+ await CopyCuesheetAsync(importCuesheet, _sessionStateContainer.Importfile.AnalysedCuesheet);
_sessionStateContainer.ImportCuesheet = importCuesheet;
}
}
+ public async Task ImportCuesheetAsync()
+ {
+ if (_sessionStateContainer.ImportCuesheet != null)
+ {
+ await CopyCuesheetAsync(_sessionStateContainer.Cuesheet, _sessionStateContainer.ImportCuesheet);
+ }
+ _sessionStateContainer.ResetImport();
+ }
+
private async Task ImportCuesheetAsync(IEnumerable fileContent)
{
_sessionStateContainer.Importfile = CuesheetImportService.Analyse(fileContent);
if (_sessionStateContainer.Importfile.AnalysedCuesheet != null)
{
- var applicationOptions = await _localStorageOptionsProvider.GetOptions();
var importCuesheet = new Cuesheet();
- importCuesheet.Import(_sessionStateContainer.Importfile.AnalysedCuesheet, applicationOptions);
+ await CopyCuesheetAsync(importCuesheet, _sessionStateContainer.Importfile.AnalysedCuesheet);
_sessionStateContainer.ImportCuesheet = importCuesheet;
}
}
@@ -115,5 +126,60 @@ private static async Task ReadFileContentAsync(IFileEntry file)
stream.Close();
return fileContent;
}
+
+ private async Task CopyCuesheetAsync(Cuesheet target, ICuesheet cuesheetToCopy)
+ {
+ _traceChangeManager.BulkEdit = true;
+ target.IsImporting = true;
+ target.Artist = cuesheetToCopy.Artist;
+ target.Title = cuesheetToCopy.Title;
+ IEnumerable? tracks = null;
+ if (cuesheetToCopy is Cuesheet originCuesheet)
+ {
+ tracks = originCuesheet.Tracks;
+ // Copy sections
+ foreach (var section in originCuesheet.Sections)
+ {
+ var newSplitPoint = target.AddSection();
+ newSplitPoint.CopyValues(section);
+ }
+ target.Audiofile = originCuesheet.Audiofile;
+ target.CDTextfile = originCuesheet.CDTextfile;
+ target.Cataloguenumber = originCuesheet.Cataloguenumber;
+ }
+ if (cuesheetToCopy is ImportCuesheet importCuesheet)
+ {
+ tracks = importCuesheet.Tracks;
+ if (String.IsNullOrEmpty(importCuesheet.Audiofile) == false)
+ {
+ target.Audiofile = new Audiofile(importCuesheet.Audiofile);
+ }
+ if (String.IsNullOrEmpty(importCuesheet.CDTextfile) == false)
+ {
+ target.CDTextfile = new CDTextfile(importCuesheet.CDTextfile);
+ }
+ target.Cataloguenumber = new Cataloguenumber()
+ {
+ Value = importCuesheet.Cataloguenumber
+ };
+ }
+ if (tracks != null)
+ {
+ var applicationOptions = await _localStorageOptionsProvider.GetOptions();
+ foreach (var importTrack in tracks)
+ {
+ //We don't want to copy the cuesheet reference since we are doing a copy and want to assign the track to this object
+ var track = new Track(importTrack, false);
+ target.AddTrack(track, applicationOptions);
+ }
+ }
+ else
+ {
+ throw new NullReferenceException();
+ }
+ target.IsImporting = false;
+ _traceChangeManager.BulkEdit = false;
+ _sessionStateContainer.FireCuesheetImported();
+ }
}
}
diff --git a/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs b/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs
index 87b97a64..c18c1854 100644
--- a/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs
+++ b/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs
@@ -43,7 +43,7 @@ public void SessionStateContainerFireCuesheetChangedTest()
cuesheetChangedFired = true;
};
Assert.IsFalse(cuesheetChangedFired);
- container.Cuesheet.Import(new Cuesheet(), helper.ApplicationOptions);
+ container.FireCuesheetImported();
Assert.IsTrue(cuesheetChangedFired);
}
}
diff --git a/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs b/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs
index b150554b..00373876 100644
--- a/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs
+++ b/AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs
@@ -247,23 +247,22 @@ public async Task ImportTestAsync()
};
localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
var textImportService = new TextImportService();
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
- await importManager.ImportTextAsync(fileContent);
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
var testHelper = new TestHelper();
// Act
- sessionStateContainer.StartImportCuesheet(testHelper.ApplicationOptions);
+ await importManager.ImportTextAsync(fileContent);
// Assert
- Assert.IsNull(sessionStateContainer.Cuesheet.CDTextfile);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(0).Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(1).Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(2).Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(3).Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(4).Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(5).Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(6).Validate().Status);
- Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.Cuesheet.Tracks.ElementAt(7).Validate().Status);
+ Assert.IsNull(sessionStateContainer.ImportCuesheet?.CDTextfile);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(0).Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(1).Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(2).Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(3).Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(4).Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(5).Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(6).Validate().Status);
+ Assert.AreEqual(ValidationStatus.Success, sessionStateContainer.ImportCuesheet?.Tracks.ElementAt(7).Validate().Status);
}
[TestMethod()]
@@ -285,19 +284,16 @@ public async Task ImportTestCalculateEndCorrectlyAsync()
var importOptions = new ImportOptions();
importOptions.TextImportScheme.SchemeCuesheet = null;
localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
- var textImportService = new TextImportService();;
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
- await importManager.ImportTextAsync(fileContent);
- var cuesheet = new Cuesheet();
+ var textImportService = new TextImportService();
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
// Act
- cuesheet.Import(sessionStateContainer.ImportCuesheet!, testHelper.ApplicationOptions);
+ await importManager.ImportTextAsync(fileContent);
// Assert
Assert.IsNull(sessionStateContainer.Importfile?.AnalyseException);
Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
Assert.AreEqual(39, sessionStateContainer.ImportCuesheet.Tracks.Count);
- Assert.AreEqual(39, cuesheet.Tracks.Count);
- Assert.AreEqual(new TimeSpan(0, 5, 24), cuesheet.Tracks.ElementAt(0).End);
- Assert.AreEqual(new TimeSpan(3, 13, 13), cuesheet.Tracks.ElementAt(38).Begin);
+ Assert.AreEqual(new TimeSpan(0, 5, 24), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(0).End);
+ Assert.AreEqual(new TimeSpan(3, 13, 13), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(38).Begin);
}
[TestMethod()]
@@ -590,22 +586,16 @@ public async Task ImportSamplesTestAsync()
};
localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
var textImportService = new TextImportService();
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
- await importManager.ImportTextAsync(fileContent);
- var cuesheet = new Cuesheet
- {
- Artist = "Testartist",
- Title = "Testtitle"
- };
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
// Act
- cuesheet.Import(sessionStateContainer.ImportCuesheet!, testHelper.ApplicationOptions);
+ await importManager.ImportTextAsync(fileContent);
// Assert
Assert.IsNull(sessionStateContainer.Importfile?.AnalyseException);
Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
- Assert.AreEqual("CuesheetArtist", cuesheet.Artist);
- Assert.AreEqual("CuesheetTitle", cuesheet.Title);
- Assert.AreEqual(8, cuesheet.Tracks.Count);
- Assert.AreEqual(new TimeSpan(1, 15, 54), cuesheet.Tracks.Last().End);
+ Assert.AreEqual("CuesheetArtist", sessionStateContainer.ImportCuesheet.Artist);
+ Assert.AreEqual("CuesheetTitle", sessionStateContainer.ImportCuesheet.Title);
+ Assert.AreEqual(8, sessionStateContainer.ImportCuesheet.Tracks.Count);
+ Assert.AreEqual(new TimeSpan(1, 15, 54), sessionStateContainer.ImportCuesheet.Tracks.Last().End);
}
[TestMethod()]
@@ -619,24 +609,18 @@ public async Task ImportSamples2TestAsync()
var localStorageOptionsProviderMock = new Mock();
var importOptions = new ImportOptions();
importOptions.TextImportScheme.SchemeCuesheet = null;
- localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(new ImportOptions());
+ localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
var textImportService = new TextImportService();
- var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService);
- await importManager.ImportTextAsync(fileContent);
- var cuesheet = new Cuesheet
- {
- Artist = "Testartist",
- Title = "Testtitle"
- };
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
// Act
- cuesheet.Import(sessionStateContainer.ImportCuesheet!, testHelper.ApplicationOptions);
+ await importManager.ImportTextAsync(fileContent);
// Assert
Assert.IsNull(sessionStateContainer.Importfile?.AnalyseException);
Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
- Assert.IsNull(cuesheet.Artist);
- Assert.IsNull(cuesheet.Title);
- Assert.AreEqual(8, cuesheet.Tracks.Count);
- Assert.AreEqual(new TimeSpan(1, 15, 54), cuesheet.Tracks.Last().End);
+ Assert.IsNull(sessionStateContainer.ImportCuesheet.Artist);
+ Assert.IsNull(sessionStateContainer.ImportCuesheet.Title);
+ Assert.AreEqual(8, sessionStateContainer.ImportCuesheet.Tracks.Count);
+ Assert.AreEqual(new TimeSpan(1, 15, 54), sessionStateContainer.ImportCuesheet.Tracks.Last().End);
}
[TestMethod()]
diff --git a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
index 9128b69d..5c79cf59 100644
--- a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
+++ b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
@@ -13,6 +13,9 @@
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.Options;
using AudioCuesheetEditor.Services.IO;
+using AudioCuesheetEditor.Extensions;
+using AudioCuesheetEditor.Data.Options;
+using Moq;
namespace AudioCuesheetEditor.Model.UI.Tests
{
@@ -150,10 +153,12 @@ public void TrackListTest()
}
[TestMethod()]
- public void ImportCuesheetTest()
+ public async Task Import_ValidTextfile_IsUndoable()
{
+ // Arrange
var testhelper = new TestHelper();
- var manager = new TraceChangeManager(TestHelper.CreateLogger());
+ var traceChangeManager = new TraceChangeManager(TestHelper.CreateLogger());
+ var sessionStateContainer = new SessionStateContainer(traceChangeManager);
var textImportMemoryStream = new MemoryStream(Resources.Textimport_with_Cuesheetdata);
using var reader = new StreamReader(textImportMemoryStream);
List lines = [];
@@ -162,44 +167,109 @@ public void ImportCuesheetTest()
lines.Add(reader.ReadLine());
}
var fileContent = lines.AsReadOnly();
- var importService = new TextImportService();
- var importOptions = new ImportOptions
+ var localStorageOptionsProviderMock = new Mock();
+ var importOptions = new ImportOptions();
+ importOptions.TextImportScheme.SchemeCuesheet = "(?'Artist'\\A.*) - (?'Title'[a-zA-Z0-9_ .();äöü&:,]{1,}) - (?'Cataloguenumber'.{1,})";
+ importOptions.TextImportScheme.SchemeTracks = TextImportScheme.DefaultSchemeTracks;
+ localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
+ var textImportService = new TextImportService();
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
+ Boolean eventFired = false;
+ sessionStateContainer.Cuesheet.TrackAdded += delegate
{
- TextImportScheme = new TextImportScheme()
- {
- SchemeCuesheet = "(?'Artist'\\A.*) - (?'Title'[a-zA-Z0-9_ .();äöü&:,]{1,}) - (?'Cataloguenumber'.{1,})",
- SchemeTracks = TextImportScheme.DefaultSchemeTracks
- }
+ eventFired = true;
};
- var importfile = importService.Analyse(importOptions, fileContent);
- var cuesheet = new Cuesheet();
+ // Act
+ await importManager.ImportTextAsync(fileContent);
+ // Assert
+ Assert.IsTrue(traceChangeManager.CanUndo);
+ Assert.IsFalse(traceChangeManager.CanRedo);
+ Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
+ Assert.AreEqual("DJFreezeT", sessionStateContainer.ImportCuesheet.Artist);
+ Assert.AreEqual("0123456789123", sessionStateContainer.ImportCuesheet.Cataloguenumber.Value);
+ Assert.AreNotEqual(0, sessionStateContainer.ImportCuesheet.Tracks.Count);
+ Assert.IsTrue(traceChangeManager.CanUndo);
+ Assert.IsFalse(eventFired);
+ }
+
+ [TestMethod()]
+ public async Task UndoImport_ValidTextfile_ResetsToEmptyCuesheet()
+ {
+ // Arrange
+ var testhelper = new TestHelper();
+ var traceChangeManager = new TraceChangeManager(TestHelper.CreateLogger());
+ var sessionStateContainer = new SessionStateContainer(traceChangeManager);
+ var textImportMemoryStream = new MemoryStream(Resources.Textimport_with_Cuesheetdata);
+ using var reader = new StreamReader(textImportMemoryStream);
+ List lines = [];
+ while (reader.EndOfStream == false)
+ {
+ lines.Add(reader.ReadLine());
+ }
+ var fileContent = lines.AsReadOnly();
+ var localStorageOptionsProviderMock = new Mock();
+ var importOptions = new ImportOptions();
+ importOptions.TextImportScheme.SchemeCuesheet = "(?'Artist'\\A.*) - (?'Title'[a-zA-Z0-9_ .();äöü&:,]{1,}) - (?'Cataloguenumber'.{1,})";
+ importOptions.TextImportScheme.SchemeTracks = TextImportScheme.DefaultSchemeTracks;
+ localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
+ var textImportService = new TextImportService();
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
Boolean eventFired = false;
- cuesheet.TrackAdded += delegate
+ sessionStateContainer.Cuesheet.TrackAdded += delegate
{
eventFired = true;
};
- manager.TraceChanges(cuesheet);
- Assert.IsFalse(manager.CanUndo);
- Assert.IsFalse(manager.CanRedo);
- Assert.IsNotNull(importfile.AnalysedCuesheet);
- cuesheet.Import(importfile.AnalysedCuesheet, testhelper.ApplicationOptions, manager);
- Assert.AreEqual("DJFreezeT", cuesheet.Artist);
- Assert.AreEqual("0123456789123", cuesheet.Cataloguenumber.Value);
- Assert.AreNotEqual(0, cuesheet.Tracks.Count);
- Assert.IsTrue(manager.CanUndo);
- manager.Undo();
- Assert.AreEqual(0, cuesheet.Tracks.Count);
- Assert.IsTrue(String.IsNullOrEmpty(cuesheet.Artist));
- Assert.IsTrue(String.IsNullOrEmpty(cuesheet.Cataloguenumber.Value));
- Assert.IsFalse(manager.CanUndo);
- Assert.IsTrue(manager.CanRedo);
- manager.Redo();
- Assert.AreEqual("DJFreezeT", cuesheet.Artist);
- Assert.AreEqual("0123456789123", cuesheet.Cataloguenumber.Value);
- Assert.AreNotEqual(0, cuesheet.Tracks.Count);
+ await importManager.ImportTextAsync(fileContent);
+ // Act
+ traceChangeManager.Undo();
+ // Assert
+ Assert.AreEqual(0, sessionStateContainer.ImportCuesheet?.Tracks.Count);
+ Assert.IsTrue(String.IsNullOrEmpty(sessionStateContainer.ImportCuesheet?.Artist));
+ Assert.IsTrue(String.IsNullOrEmpty(sessionStateContainer.ImportCuesheet?.Cataloguenumber.Value));
+ Assert.IsFalse(traceChangeManager.CanUndo);
+ Assert.IsTrue(traceChangeManager.CanRedo);
Assert.IsFalse(eventFired);
}
+ [TestMethod()]
+ public async Task UndoAndRedoImport_ValidTextfile_ResetsTextfileValues()
+ {
+ // Arrange
+ var testhelper = new TestHelper();
+ var traceChangeManager = new TraceChangeManager(TestHelper.CreateLogger());
+ var sessionStateContainer = new SessionStateContainer(traceChangeManager);
+ var textImportMemoryStream = new MemoryStream(Resources.Textimport_with_Cuesheetdata);
+ using var reader = new StreamReader(textImportMemoryStream);
+ List lines = [];
+ while (reader.EndOfStream == false)
+ {
+ lines.Add(reader.ReadLine());
+ }
+ var fileContent = lines.AsReadOnly();
+ var localStorageOptionsProviderMock = new Mock();
+ var importOptions = new ImportOptions();
+ importOptions.TextImportScheme.SchemeCuesheet = "(?'Artist'\\A.*) - (?'Title'[a-zA-Z0-9_ .();äöü&:,]{1,}) - (?'Cataloguenumber'.{1,})";
+ importOptions.TextImportScheme.SchemeTracks = TextImportScheme.DefaultSchemeTracks;
+ localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
+ var textImportService = new TextImportService();
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
+ Boolean eventFired = false;
+ sessionStateContainer.Cuesheet.TrackAdded += delegate
+ {
+ eventFired = true;
+ };
+ await importManager.ImportTextAsync(fileContent);
+ traceChangeManager.Undo();
+ // Act
+ traceChangeManager.Redo();
+ // Assert
+ Assert.AreEqual("DJFreezeT", sessionStateContainer.ImportCuesheet?.Artist);
+ Assert.AreEqual("0123456789123", sessionStateContainer.ImportCuesheet?.Cataloguenumber.Value);
+ Assert.AreEqual(39, sessionStateContainer.ImportCuesheet?.Tracks.Count);
+ Assert.IsFalse(eventFired);
+
+ }
+
[TestMethod()]
public void RemoveTracksTest()
{
From 4935fca2196beed6f9cd10378eaeeb77fa8a3b23 Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Fri, 30 Aug 2024 09:02:34 +0200
Subject: [PATCH 31/33] Fixed import and tracing changes
---
AudioCuesheetEditor/Services/IO/ImportManager.cs | 4 ++--
.../Model/UI/TraceChangeManagerTests.cs | 10 +++++-----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/AudioCuesheetEditor/Services/IO/ImportManager.cs b/AudioCuesheetEditor/Services/IO/ImportManager.cs
index 09acd171..278c4080 100644
--- a/AudioCuesheetEditor/Services/IO/ImportManager.cs
+++ b/AudioCuesheetEditor/Services/IO/ImportManager.cs
@@ -102,7 +102,9 @@ public async Task ImportCuesheetAsync()
{
if (_sessionStateContainer.ImportCuesheet != null)
{
+ _traceChangeManager.BulkEdit = true;
await CopyCuesheetAsync(_sessionStateContainer.Cuesheet, _sessionStateContainer.ImportCuesheet);
+ _traceChangeManager.BulkEdit = false;
}
_sessionStateContainer.ResetImport();
}
@@ -129,7 +131,6 @@ private static async Task ReadFileContentAsync(IFileEntry file)
private async Task CopyCuesheetAsync(Cuesheet target, ICuesheet cuesheetToCopy)
{
- _traceChangeManager.BulkEdit = true;
target.IsImporting = true;
target.Artist = cuesheetToCopy.Artist;
target.Title = cuesheetToCopy.Title;
@@ -178,7 +179,6 @@ private async Task CopyCuesheetAsync(Cuesheet target, ICuesheet cuesheetToCopy)
throw new NullReferenceException();
}
target.IsImporting = false;
- _traceChangeManager.BulkEdit = false;
_sessionStateContainer.FireCuesheetImported();
}
}
diff --git a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
index 5c79cf59..254f39f7 100644
--- a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
+++ b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
@@ -182,13 +182,12 @@ public async Task Import_ValidTextfile_IsUndoable()
// Act
await importManager.ImportTextAsync(fileContent);
// Assert
- Assert.IsTrue(traceChangeManager.CanUndo);
+ Assert.IsFalse(traceChangeManager.CanUndo);
Assert.IsFalse(traceChangeManager.CanRedo);
Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
Assert.AreEqual("DJFreezeT", sessionStateContainer.ImportCuesheet.Artist);
Assert.AreEqual("0123456789123", sessionStateContainer.ImportCuesheet.Cataloguenumber.Value);
Assert.AreNotEqual(0, sessionStateContainer.ImportCuesheet.Tracks.Count);
- Assert.IsTrue(traceChangeManager.CanUndo);
Assert.IsFalse(eventFired);
}
@@ -220,12 +219,13 @@ public async Task UndoImport_ValidTextfile_ResetsToEmptyCuesheet()
eventFired = true;
};
await importManager.ImportTextAsync(fileContent);
+ await importManager.ImportCuesheetAsync();
// Act
traceChangeManager.Undo();
// Assert
- Assert.AreEqual(0, sessionStateContainer.ImportCuesheet?.Tracks.Count);
- Assert.IsTrue(String.IsNullOrEmpty(sessionStateContainer.ImportCuesheet?.Artist));
- Assert.IsTrue(String.IsNullOrEmpty(sessionStateContainer.ImportCuesheet?.Cataloguenumber.Value));
+ Assert.AreEqual(0, sessionStateContainer.Cuesheet.Tracks.Count);
+ Assert.IsTrue(String.IsNullOrEmpty(sessionStateContainer.Cuesheet.Artist));
+ Assert.IsTrue(String.IsNullOrEmpty(sessionStateContainer.Cuesheet.Cataloguenumber.Value));
Assert.IsFalse(traceChangeManager.CanUndo);
Assert.IsTrue(traceChangeManager.CanRedo);
Assert.IsFalse(eventFired);
From eaace6859c6112086846bebcdfc1c466e7cba677 Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Fri, 30 Aug 2024 16:07:29 +0200
Subject: [PATCH 32/33] added import of startdatetime
---
.../Model/AudioCuesheet/Import/ImportTrack.cs | 1 +
.../Model/IO/Import/TextImportScheme.cs | 5 +-
.../Model/Options/ApplicationOptions.cs | 1 -
.../Localization/EditImportOptions/de.json | 3 +-
.../Localization/EditImportOptions/en.json | 3 +-
.../Services/IO/ImportManager.cs | 21 +++-
.../Services/IO/TextImportService.cs | 7 ++
.../Extensions/SessionStateContainerTests.cs | 27 +++--
.../Model/UI/TraceChangeManagerTests.cs | 39 ++++--
.../Services/IO/ImportManagerTests.cs | 111 ++++++++++++++++++
10 files changed, 191 insertions(+), 27 deletions(-)
create mode 100644 AudioCuesheetEditorTests/Services/IO/ImportManagerTests.cs
diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs
index f5760424..88f9033d 100644
--- a/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs
+++ b/AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs
@@ -28,6 +28,7 @@ public class ImportTrack : ITrack
public IReadOnlyCollection Flags => flags;
public TimeSpan? PreGap { get; set; }
public TimeSpan? PostGap { get; set; }
+ public DateTime? StartDateTime { get; set; }
public void SetFlags(IEnumerable flags)
{
this.flags.Clear();
diff --git a/AudioCuesheetEditor/Model/IO/Import/TextImportScheme.cs b/AudioCuesheetEditor/Model/IO/Import/TextImportScheme.cs
index 7eab81b1..f5d3e865 100644
--- a/AudioCuesheetEditor/Model/IO/Import/TextImportScheme.cs
+++ b/AudioCuesheetEditor/Model/IO/Import/TextImportScheme.cs
@@ -14,6 +14,7 @@
//along with Foobar. If not, see
//.
using AudioCuesheetEditor.Model.AudioCuesheet;
+using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.Entity;
using Blazorise.Localization;
@@ -54,6 +55,7 @@ static TextImportScheme()
var schemeTrackFlags = String.Format("(?'{0}.{1}'{2})", nameof(Track), nameof(Track.Flags), EnterRegularExpressionHere);
var schemeTrackPreGap = String.Format("(?'{0}.{1}'{2})", nameof(Track), nameof(Track.PreGap), EnterRegularExpressionHere);
var schemeTrackPostGap = String.Format("(?'{0}.{1}'{2})", nameof(Track), nameof(Track.PostGap), EnterRegularExpressionHere);
+ var schemeTrackStartDateTime = String.Format("(?'{0}.{1}'{2})", nameof(Track), nameof(ImportTrack.StartDateTime), EnterRegularExpressionHere);
AvailableSchemesTrack = new Dictionary
{
@@ -65,7 +67,8 @@ static TextImportScheme()
{ nameof(Track.Length), schemeTrackLength },
{ nameof(Track.Flags), schemeTrackFlags },
{ nameof(Track.PreGap), schemeTrackPreGap },
- { nameof(Track.PostGap), schemeTrackPostGap }
+ { nameof(Track.PostGap), schemeTrackPostGap },
+ { nameof(ImportTrack.StartDateTime), schemeTrackStartDateTime }
};
}
diff --git a/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs b/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs
index b2b58e12..79f88022 100644
--- a/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs
+++ b/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs
@@ -13,7 +13,6 @@
//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.IO;
using AudioCuesheetEditor.Model.IO.Export;
diff --git a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json
index 393b254f..1d41f3e2 100644
--- a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json
+++ b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json
@@ -27,6 +27,7 @@
"Hours": "Stunden",
"Minutes": "Minuten",
"Seconds": "Sekunden",
- "Milliseconds": "Millisekunden"
+ "Milliseconds": "Millisekunden",
+ "StartDateTime": "Startzeitpunkt"
}
}
\ No newline at end of file
diff --git a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json
index bd91ef70..b453cd98 100644
--- a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json
+++ b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json
@@ -26,6 +26,7 @@
"Hours": "Hours",
"Minutes": "Minutes",
"Seconds": "Seconds",
- "Milliseconds": "Milliseconds"
+ "Milliseconds": "Milliseconds",
+ "StartDateTime": "Startdatetime"
}
}
\ No newline at end of file
diff --git a/AudioCuesheetEditor/Services/IO/ImportManager.cs b/AudioCuesheetEditor/Services/IO/ImportManager.cs
index 278c4080..8eca0d48 100644
--- a/AudioCuesheetEditor/Services/IO/ImportManager.cs
+++ b/AudioCuesheetEditor/Services/IO/ImportManager.cs
@@ -167,10 +167,29 @@ private async Task CopyCuesheetAsync(Cuesheet target, ICuesheet cuesheetToCopy)
if (tracks != null)
{
var applicationOptions = await _localStorageOptionsProvider.GetOptions();
- foreach (var importTrack in tracks)
+ var begin = TimeSpan.Zero;
+ for (int i = 0; i < tracks.Count(); i++)
{
+ var importTrack = tracks.ElementAt(i);
//We don't want to copy the cuesheet reference since we are doing a copy and want to assign the track to this object
var track = new Track(importTrack, false);
+ if (importTrack is ImportTrack importTrackReference)
+ {
+ if (importTrackReference.StartDateTime != null)
+ {
+ if (i < tracks.Count() - 1)
+ {
+ var nextTrack = (ImportTrack)tracks.ElementAt(i + 1);
+ var length = nextTrack.StartDateTime - importTrackReference.StartDateTime;
+ track.Begin = begin;
+ track.End = begin + length;
+ if (track.End.HasValue)
+ {
+ begin = track.End.Value;
+ }
+ }
+ }
+ }
target.AddTrack(track, applicationOptions);
}
}
diff --git a/AudioCuesheetEditor/Services/IO/TextImportService.cs b/AudioCuesheetEditor/Services/IO/TextImportService.cs
index 7d1836fd..c90ce366 100644
--- a/AudioCuesheetEditor/Services/IO/TextImportService.cs
+++ b/AudioCuesheetEditor/Services/IO/TextImportService.cs
@@ -156,6 +156,13 @@ private void SetValue(object entity, PropertyInfo property, string value)
{
((Cuesheet)entity).Cataloguenumber.Value = value;
}
+ if (property.PropertyType == typeof(DateTime?))
+ {
+ if (DateTime.TryParse(value, out var date))
+ {
+ property.SetValue(entity, date);
+ }
+ }
}
}
}
diff --git a/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs b/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs
index c18c1854..885fe83e 100644
--- a/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs
+++ b/AudioCuesheetEditorTests/Extensions/SessionStateContainerTests.cs
@@ -1,13 +1,22 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using AudioCuesheetEditor.Extensions;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using AudioCuesheetEditorTests.Utility;
-using AudioCuesheetEditor.Model.UI;
+//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.UI;
+using AudioCuesheetEditorTests.Utility;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AudioCuesheetEditor.Extensions.Tests
{
diff --git a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
index 254f39f7..fe31187a 100644
--- a/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
+++ b/AudioCuesheetEditorTests/Model/UI/TraceChangeManagerTests.cs
@@ -1,21 +1,34 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using AudioCuesheetEditor.Model.UI;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+//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.Data.Options;
+using AudioCuesheetEditor.Extensions;
using AudioCuesheetEditor.Model.AudioCuesheet;
-using AudioCuesheetEditorTests.Utility;
-using AudioCuesheetEditor.Model.IO.Import;
-using System.IO;
-using AudioCuesheetEditorTests.Properties;
using AudioCuesheetEditor.Model.Entity;
+using AudioCuesheetEditor.Model.IO.Import;
using AudioCuesheetEditor.Model.Options;
using AudioCuesheetEditor.Services.IO;
-using AudioCuesheetEditor.Extensions;
-using AudioCuesheetEditor.Data.Options;
+using AudioCuesheetEditorTests.Properties;
+using AudioCuesheetEditorTests.Utility;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
namespace AudioCuesheetEditor.Model.UI.Tests
{
diff --git a/AudioCuesheetEditorTests/Services/IO/ImportManagerTests.cs b/AudioCuesheetEditorTests/Services/IO/ImportManagerTests.cs
new file mode 100644
index 00000000..bd98e833
--- /dev/null
+++ b/AudioCuesheetEditorTests/Services/IO/ImportManagerTests.cs
@@ -0,0 +1,111 @@
+//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.Data.Options;
+using AudioCuesheetEditor.Extensions;
+using AudioCuesheetEditor.Model.IO.Import;
+using AudioCuesheetEditor.Model.Options;
+using AudioCuesheetEditor.Model.UI;
+using AudioCuesheetEditorTests.Utility;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace AudioCuesheetEditor.Services.IO.Tests
+{
+ [TestClass()]
+ public class ImportManagerTests
+ {
+ [TestMethod()]
+ public async Task ImportTextAsync_TextfileWithStartDateTime_CreatesValidCuesheetAsync()
+ {
+ // Arrange
+ var fileContent = new List
+ {
+ "Innellea~The Golden Fort~02.08.2024 20:10:48",
+ "Nora En Pure~Diving with Whales (Daniel Portman Remix)~02.08.2024 20:15:21",
+ "WhoMadeWho & Adriatique~Miracle (RÜFÜS DU SOL Remix)~02.08.2024 20:20:42",
+ "Ella Wild~Poison D'araignee (Original Mix)~02.08.2024 20:28:03",
+ "Stil & Bense~On The Edge (Original Mix)~02.08.2024 20:32:42",
+ "Nebula~Clairvoyant Dreams~02.08.2024 20:39:01",
+ "Valentina Black~I'm a Tree (Extended Mix)~02.08.2024 20:47:08",
+ "Nebula~Clairvoyant Dreams~02.08.2024 20:53:20",
+ "Kiko & Dave Davis feat. Phoebe~Living in Space (Dub Mix)~02.08.2024 20:58:11",
+ "Lilly Palmer~Before Acid~02.08.2024 21:03:53",
+ "Sofi Tukker~Drinkee (Vintage Culture & John Summit Extended Mix)~02.08.2024 21:09:52",
+ "CID & Truth x Lies~Caroline (Extended Mix)~02.08.2024 21:14:09",
+ "Moby~Why Does My Heart Feel So Bad? (Oxia Remix)~02.08.2024 21:17:15",
+ "Ammo Avenue~Little Gurl (Extended Mix)~02.08.2024 21:22:46",
+ "James Hurr & Smokin Jo & Stealth~Beggin' For Change~02.08.2024 21:28:37",
+ "Kristine Blond~Love Shy (Sam Divine & CASSIMM Extended Remix)~02.08.2024 21:30:47",
+ "Vanilla Ace~Work On You (Original Mix)~02.08.2024 21:36:28",
+ "Truth X Lies~Like This~02.08.2024 21:42:05",
+ "Terri-Anne~Round Round~02.08.2024 21:44:07",
+ "Joanna Magik~Maneater~02.08.2024 21:46:32",
+ "Jen Payne & Kevin McKay~Feed Your Soul~02.08.2024 21:48:45",
+ "Kevin McKay & Eppers & Notelle~On My Own~02.08.2024 21:51:37",
+ "Nader Razdar & Kevin McKay~Get Ur Freak On (Kevin McKay Extended Mix)~02.08.2024 21:53:49",
+ "Philip Z~Yala (Extended Mix)~02.08.2024 21:59:40",
+ "Kyle Kinch & Kevin McKay~Hella~02.08.2024 22:05:53",
+ "Roze Wild~B-O-D-Y~02.08.2024 22:08:26",
+ "Jey Kurmis~Snoop~02.08.2024 22:11:09",
+ "Bootie Brown & Tame Impala & Gorillaz~New Gold (Dom Dolla Remix Extended)~02.08.2024 22:16:23",
+ "Eli Brown & Love Regenerator~Don't You Want Me (Original Mix)~02.08.2024 22:21:23",
+ "Local Singles~Voices~02.08.2024 22:25:59"
+ };
+
+ var traceChangeManager = new TraceChangeManager(TestHelper.CreateLogger());
+ var sessionStateContainer = new SessionStateContainer(traceChangeManager);
+ var localStorageOptionsProviderMock = new Mock();
+ var importOptions = new ImportOptions
+ {
+ TextImportScheme = new TextImportScheme()
+ {
+ SchemeCuesheet = null,
+ SchemeTracks = @"(?'Track.Artist'[a-zA-Z0-9_ .();äöü&:,'*-?:]{1,})~(?'Track.Title'[a-zA-Z0-9_ .();äöü&'*-?:Ü]{1,})~(?'Track.StartDateTime'.{1,})"
+ }
+ };
+ localStorageOptionsProviderMock.Setup(x => x.GetOptions()).ReturnsAsync(importOptions);
+ var textImportService = new TextImportService();
+ var importManager = new ImportManager(sessionStateContainer, localStorageOptionsProviderMock.Object, textImportService, traceChangeManager);
+ var testHelper = new TestHelper();
+ // Act
+ await importManager.ImportTextAsync(fileContent);
+ // Assert
+ Assert.IsNull(sessionStateContainer.Importfile?.AnalyseException);
+ Assert.IsNotNull(sessionStateContainer.ImportCuesheet);
+ Assert.AreEqual(30, sessionStateContainer.ImportCuesheet.Tracks.Count);
+ Assert.AreEqual("Innellea", sessionStateContainer.ImportCuesheet.Tracks.ElementAt(0).Artist);
+ Assert.AreEqual("The Golden Fort", sessionStateContainer.ImportCuesheet.Tracks.ElementAt(0).Title);
+ Assert.AreEqual(TimeSpan.Zero, sessionStateContainer.ImportCuesheet.Tracks.ElementAt(0).Begin);
+ Assert.AreEqual(new TimeSpan(0, 4, 33), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(0).End);
+ Assert.AreEqual(new TimeSpan(0, 4, 33), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(0).Length);
+ Assert.AreEqual("Nora En Pure", sessionStateContainer.ImportCuesheet.Tracks.ElementAt(1).Artist);
+ Assert.AreEqual("Diving with Whales (Daniel Portman Remix)", sessionStateContainer.ImportCuesheet.Tracks.ElementAt(1).Title);
+ Assert.AreEqual(new TimeSpan(0, 4, 33), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(1).Begin);
+ Assert.AreEqual(new TimeSpan(0, 9, 54), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(1).End);
+ Assert.AreEqual(new TimeSpan(0, 5, 21), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(1).Length);
+ Assert.AreEqual("Local Singles", sessionStateContainer.ImportCuesheet.Tracks.ElementAt(29).Artist);
+ Assert.AreEqual("Voices", sessionStateContainer.ImportCuesheet.Tracks.ElementAt(29).Title);
+ Assert.AreEqual(new TimeSpan(2, 15, 11), sessionStateContainer.ImportCuesheet.Tracks.ElementAt(29).Begin);
+ Assert.IsNull(sessionStateContainer.ImportCuesheet.Tracks.ElementAt(29).End);
+ Assert.IsNull(sessionStateContainer.ImportCuesheet.Tracks.ElementAt(29).Length);
+ }
+ }
+}
\ No newline at end of file
From ded97b54ef2bcd5d21a549156aad9788b4f644fe Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Mon, 2 Sep 2024 09:13:03 +0200
Subject: [PATCH 33/33] best practise corrections
---
AudioCuesheetEditor/Pages/Index.razor | 12 ++++++----
AudioCuesheetEditor/Pages/RecordControl.razor | 9 ++++---
AudioCuesheetEditor/Shared/AudioPlayer.razor | 24 ++++++++++---------
.../Shared/EditTrackModal.razor | 10 ++++----
AudioCuesheetEditor/Shared/MainLayout.razor | 9 ++++---
AudioCuesheetEditor/Shared/ModalDialog.razor | 10 ++++----
.../Shared/ModalExportdialog.razor | 9 ++++---
.../Shared/OptionsDialog.razor | 10 ++++----
8 files changed, 56 insertions(+), 37 deletions(-)
diff --git a/AudioCuesheetEditor/Pages/Index.razor b/AudioCuesheetEditor/Pages/Index.razor
index d3e38b67..b9d76fc5 100644
--- a/AudioCuesheetEditor/Pages/Index.razor
+++ b/AudioCuesheetEditor/Pages/Index.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@page "/"
@inject IJSRuntime _jsRuntime
@@ -78,12 +77,15 @@ along with Foobar. If not, see
@code {
-
- public void Dispose()
+
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_sessionStateContainer.CurrentViewModeChanged -= CurrentViewModeChanged;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
[CascadingParameter]
diff --git a/AudioCuesheetEditor/Pages/RecordControl.razor b/AudioCuesheetEditor/Pages/RecordControl.razor
index c4260bea..a167e0fd 100644
--- a/AudioCuesheetEditor/Pages/RecordControl.razor
+++ b/AudioCuesheetEditor/Pages/RecordControl.razor
@@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-@implements IDisposable
+@implements IAsyncDisposable
@inject SessionStateContainer _sessionStateContainer
@inject ITextLocalizer _localizer
@@ -131,12 +131,15 @@ along with Foobar. If not, see
[Parameter]
public EventCallback StopRecordClicked { get; set; }
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged;
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionsSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
protected override async Task OnInitializedAsync()
diff --git a/AudioCuesheetEditor/Shared/AudioPlayer.razor b/AudioCuesheetEditor/Shared/AudioPlayer.razor
index 5d0ca5eb..ee987d0e 100644
--- a/AudioCuesheetEditor/Shared/AudioPlayer.razor
+++ b/AudioCuesheetEditor/Shared/AudioPlayer.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject IHowl _howl
@@ -77,7 +76,7 @@ along with Foobar. If not, see
@code {
- Timer audioUpdateTimer = default!;
+ Timer? audioUpdateTimer;
int soundId;
Track? currentlyPlayingTrack;
HotKeysContext? hotKeysContext;
@@ -92,20 +91,23 @@ along with Foobar. If not, see
public TimeSpan? TotalTime { get; private set; }
public Boolean AudioIsPlaying { get; private set; }
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_howl.OnPlay -= HowlOnPlay;
_howl.OnPause -= HowlOnPause;
_howl.OnEnd -= HowlOnEnd;
_howl.OnStop -= HowlOnStop;
- audioUpdateTimer.Dispose();
+ _localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
+ _sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged;
if (_sessionStateContainer.Cuesheet != null)
{
_sessionStateContainer.Cuesheet.AudioFileChanged -= Cuesheet_AudioFileChanged;
}
- _localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
- _sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged;
+ audioUpdateTimer?.Dispose();
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public Boolean PlaybackPossible
@@ -242,7 +244,7 @@ along with Foobar. If not, see
void HowlOnPlay(Howler.Blazor.Components.Events.HowlPlayEventArgs args)
{
paused = false;
- audioUpdateTimer.Start();
+ audioUpdateTimer?.Start();
}
void HowlOnPause(Howler.Blazor.Components.Events.HowlEventArgs args)
@@ -253,7 +255,7 @@ along with Foobar. If not, see
void HowlOnEnd(Howler.Blazor.Components.Events.HowlEventArgs args)
{
paused = false;
- audioUpdateTimer.Stop();
+ audioUpdateTimer?.Stop();
CurrentlyPlayingTrack = null;
CurrentPlaybackPosition = null;
AudioIsPlaying = false;
@@ -263,7 +265,7 @@ along with Foobar. If not, see
void HowlOnStop(Howler.Blazor.Components.Events.HowlEventArgs args)
{
paused = false;
- audioUpdateTimer.Stop();
+ audioUpdateTimer?.Stop();
CurrentlyPlayingTrack = null;
CurrentPlaybackPosition = null;
AudioIsPlaying = false;
diff --git a/AudioCuesheetEditor/Shared/EditTrackModal.razor b/AudioCuesheetEditor/Shared/EditTrackModal.razor
index 1829e4ee..84f5e846 100644
--- a/AudioCuesheetEditor/Shared/EditTrackModal.razor
+++ b/AudioCuesheetEditor/Shared/EditTrackModal.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject MusicBrainzDataProvider _musicBrainzDataProvider
@@ -420,10 +419,13 @@ along with Foobar. If not, see
Validations? validations;
ApplicationOptions? applicationOptions;
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
protected override async Task OnInitializedAsync()
diff --git a/AudioCuesheetEditor/Shared/MainLayout.razor b/AudioCuesheetEditor/Shared/MainLayout.razor
index 7fc6d42d..ea35a241 100644
--- a/AudioCuesheetEditor/Shared/MainLayout.razor
+++ b/AudioCuesheetEditor/Shared/MainLayout.razor
@@ -18,7 +18,7 @@ along with Foobar. If not, see
@inherits LayoutComponentBase
-@implements IDisposable
+@implements IAsyncDisposable
@inject NavigationManager _navigationManager
@inject ITextLocalizer _localizer
@@ -484,9 +484,8 @@ along with Foobar. If not, see
await base.OnInitializedAsync();
}
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
_traceChangeManager.TracedObjectHistoryChanged -= TraceChangeManager_TracedObjectHistoryChanged;
@@ -500,6 +499,10 @@ along with Foobar. If not, see
{
modalExportdialogCuesheet.GenerateExportfilesClicked -= ModalExportdialogCuesheet_GenerateExportfilesClicked;
}
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public void SetDisplayMenuBar(Boolean display)
diff --git a/AudioCuesheetEditor/Shared/ModalDialog.razor b/AudioCuesheetEditor/Shared/ModalDialog.razor
index c19fc165..8355b413 100644
--- a/AudioCuesheetEditor/Shared/ModalDialog.razor
+++ b/AudioCuesheetEditor/Shared/ModalDialog.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject HotKeys _hotKeys
@@ -65,10 +64,13 @@ along with Foobar. If not, see
@code {
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
protected override Task OnInitializedAsync()
diff --git a/AudioCuesheetEditor/Shared/ModalExportdialog.razor b/AudioCuesheetEditor/Shared/ModalExportdialog.razor
index 271cb00c..fd83b9df 100644
--- a/AudioCuesheetEditor/Shared/ModalExportdialog.razor
+++ b/AudioCuesheetEditor/Shared/ModalExportdialog.razor
@@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject ILogger _logger
@@ -198,10 +198,13 @@ along with Foobar. If not, see
await base.OnInitializedAsync();
}
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public async Task Show()
diff --git a/AudioCuesheetEditor/Shared/OptionsDialog.razor b/AudioCuesheetEditor/Shared/OptionsDialog.razor
index fa7ea1bc..a0491b87 100644
--- a/AudioCuesheetEditor/Shared/OptionsDialog.razor
+++ b/AudioCuesheetEditor/Shared/OptionsDialog.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ILocalStorageOptionsProvider _localStorageOptionsProvider
@inject ITextLocalizer _localizer
@@ -159,11 +158,14 @@ along with Foobar. If not, see
HotKeysContext? hotKeysContext;
Validation? timespanformatValidation;
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public async Task Show()