diff --git a/AudioCuesheetEditor/Extensions/SessionStateContainer.cs b/AudioCuesheetEditor/Extensions/SessionStateContainer.cs index 86203de7..82035a6d 100644 --- a/AudioCuesheetEditor/Extensions/SessionStateContainer.cs +++ b/AudioCuesheetEditor/Extensions/SessionStateContainer.cs @@ -63,10 +63,6 @@ public Cuesheet? ImportCuesheet } } - public TextImportfile? TextImportFile { get; set; } - - public CuesheetImportfile? CuesheetImportFile{ get; set; } - public Audiofile? ImportAudiofile { get => importAudiofile; @@ -91,26 +87,11 @@ public ViewMode CurrentViewMode } } - public IImportfile? Importfile - { - get - { - if (TextImportFile != null) - { - return TextImportFile; - } - if (CuesheetImportFile != null) - { - return CuesheetImportFile; - } - return null; - } - } + public IImportfile? Importfile{ get; set; } public void ResetImport() { - TextImportFile = null; - CuesheetImportFile = null; + Importfile = null; ImportAudiofile = null; } diff --git a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs index 8f786e6d..dfcbf18d 100644 --- a/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs +++ b/AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs @@ -42,9 +42,6 @@ public class CuesheetSectionAddRemoveEventArgs(CuesheetSection section) : EventA public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validateable, ITraceable, ICuesheet { - public const String MimeType = "text/*"; - public const String FileExtension = ".cue"; - private readonly object syncLock = new(); private List tracks = []; diff --git a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs index a587558e..8190dc1f 100644 --- a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs +++ b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs @@ -57,7 +57,7 @@ public IReadOnlyCollection GenerateExportfiles() { case ExportType.Cuesheet: content = WriteCuesheet(audioFileName, section); - filename = String.Format("{0}({1}){2}", Path.GetFileNameWithoutExtension(ApplicationOptions?.CuesheetFilename), counter, Cuesheet.FileExtension); + filename = String.Format("{0}({1}){2}", Path.GetFileNameWithoutExtension(ApplicationOptions?.CuesheetFilename), counter, FileExtensions.Cuesheet); break; case ExportType.Exportprofile: if (Exportprofile != null) diff --git a/AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs b/AudioCuesheetEditor/Model/IO/FileExtensions.cs similarity index 50% rename from AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs rename to AudioCuesheetEditor/Model/IO/FileExtensions.cs index 5cc243b1..d4b76535 100644 --- a/AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs +++ b/AudioCuesheetEditor/Model/IO/FileExtensions.cs @@ -1,4 +1,4 @@ -//This file is part of AudioCuesheetEditor. +//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 @@ -13,22 +13,12 @@ //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.IO.Import +namespace AudioCuesheetEditor.Model.IO { - public class TextImportfile : IImportfile + public class FileExtensions { - public const String MimeType = "text/plain"; - public const String FileExtension = ".txt"; - - /// - public IEnumerable? FileContent { get; set; } - /// - public IEnumerable? FileContentRecognized { get; set; } - /// - public Exception? AnalyseException { get;set; } - /// - public ImportCuesheet? AnalysedCuesheet { get; set; } + public const string Text = ".txt"; + public const string Projectfile = ".ace"; + public const string Cuesheet = ".cue"; } } diff --git a/AudioCuesheetEditor/Model/IO/FileMimeTypes.cs b/AudioCuesheetEditor/Model/IO/FileMimeTypes.cs new file mode 100644 index 00000000..a6edaf11 --- /dev/null +++ b/AudioCuesheetEditor/Model/IO/FileMimeTypes.cs @@ -0,0 +1,24 @@ +//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.IO +{ + public static class FileMimeTypes + { + public const string Text = "text/plain"; + public const string Projectfile = "text/*"; + public const string Cuesheet = "text/*"; + } +} diff --git a/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs b/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs index e0250a0b..b99d07b0 100644 --- a/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs +++ b/AudioCuesheetEditor/Model/IO/Import/IImportfile.cs @@ -14,6 +14,7 @@ //along with Foobar. If not, see //. using AudioCuesheetEditor.Model.AudioCuesheet.Import; +using AudioCuesheetEditor.Services.IO; namespace AudioCuesheetEditor.Model.IO.Import { @@ -35,5 +36,6 @@ public interface IImportfile /// The cuesheet which was created during analysing the /// ImportCuesheet? AnalysedCuesheet { get; set; } + ImportFileType FileType { get; set; } } } diff --git a/AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs b/AudioCuesheetEditor/Model/IO/Import/Importfile.cs similarity index 86% rename from AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs rename to AudioCuesheetEditor/Model/IO/Import/Importfile.cs index fecdfd01..033e1989 100644 --- a/AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs +++ b/AudioCuesheetEditor/Model/IO/Import/Importfile.cs @@ -1,4 +1,4 @@ -//This file is part of AudioCuesheetEditor. +//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 @@ -14,10 +14,11 @@ //along with Foobar. If not, see //. using AudioCuesheetEditor.Model.AudioCuesheet.Import; +using AudioCuesheetEditor.Services.IO; namespace AudioCuesheetEditor.Model.IO.Import { - public class CuesheetImportfile : IImportfile + public class Importfile : IImportfile { /// public IEnumerable? FileContent { get; set; } @@ -27,5 +28,6 @@ public class CuesheetImportfile : IImportfile public Exception? AnalyseException { get; set; } /// public ImportCuesheet? AnalysedCuesheet { get; set; } + public ImportFileType FileType { get; set; } } } diff --git a/AudioCuesheetEditor/Model/IO/Projectfile.cs b/AudioCuesheetEditor/Model/IO/Projectfile.cs index 46eac1c3..da0b73e2 100644 --- a/AudioCuesheetEditor/Model/IO/Projectfile.cs +++ b/AudioCuesheetEditor/Model/IO/Projectfile.cs @@ -22,9 +22,6 @@ namespace AudioCuesheetEditor.Model.IO { public class Projectfile(Cuesheet cuesheet) { - public const String MimeType = "text/*"; - public const String FileExtension = ".ace"; - public static readonly String DefaultFilename = "Project.ace"; public static readonly JsonSerializerOptions Options = new() diff --git a/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs b/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs index 2f33d15d..b2b58e12 100644 --- a/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs +++ b/AudioCuesheetEditor/Model/Options/ApplicationOptions.cs @@ -110,10 +110,10 @@ protected override ValidationResult Validate(string property) else { var extension = Path.GetExtension(CuesheetFilename); - if (extension.Equals(Cuesheet.FileExtension, StringComparison.OrdinalIgnoreCase) == false) + if (extension.Equals(FileExtensions.Cuesheet, StringComparison.OrdinalIgnoreCase) == false) { validationMessages ??= []; - validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(CuesheetFilename), Cuesheet.FileExtension)); + validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(CuesheetFilename), FileExtensions.Cuesheet)); } var filenameWithoutExtension = Path.GetFileNameWithoutExtension(CuesheetFilename); if (string.IsNullOrEmpty(filenameWithoutExtension)) @@ -133,10 +133,10 @@ protected override ValidationResult Validate(string property) else { var extension = Path.GetExtension(ProjectFilename); - if (extension.Equals(Projectfile.FileExtension, StringComparison.OrdinalIgnoreCase) == false) + if (extension.Equals(FileExtensions.Projectfile, StringComparison.OrdinalIgnoreCase) == false) { validationMessages ??= []; - validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(ProjectFilename), Projectfile.FileExtension)); + validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(ProjectFilename), FileExtensions.Projectfile)); } var filename = Path.GetFileNameWithoutExtension(ProjectFilename); if (String.IsNullOrEmpty(filename)) diff --git a/AudioCuesheetEditor/Model/Utility/IOUtility.cs b/AudioCuesheetEditor/Model/Utility/IOUtility.cs index 450d14de..eade907c 100644 --- a/AudioCuesheetEditor/Model/Utility/IOUtility.cs +++ b/AudioCuesheetEditor/Model/Utility/IOUtility.cs @@ -27,13 +27,13 @@ public static Boolean CheckFileMimeType(IFileEntry file, String mimeType, String { if (String.IsNullOrEmpty(file.Type) == false) { - fileMimeTypeMatches = file.Type.ToLower() == mimeType.ToLower(); + fileMimeTypeMatches = file.Type.Equals(mimeType, StringComparison.CurrentCultureIgnoreCase); } else { //Try to find by file extension - var extension = Path.GetExtension(file.Name).ToLower(); - fileMimeTypeMatches = extension == fileExtension.ToLower(); + var extension = Path.GetExtension(file.Name); + fileMimeTypeMatches = extension.Equals(fileExtension, StringComparison.CurrentCultureIgnoreCase); } } return fileMimeTypeMatches; @@ -47,7 +47,7 @@ public static Boolean CheckFileMimeTypeForAudioCodec(IFileEntry file) public static AudioCodec? GetAudioCodec(IFileEntry fileEntry) { AudioCodec? foundAudioCodec = null; - var extension = Path.GetExtension(fileEntry.Name).ToLower(); + var extension = Path.GetExtension(fileEntry.Name); // First search with mime type and file extension var audioCodecsFound = Audiofile.AudioCodecs.Where(x => x.MimeType.Equals(fileEntry.Type, StringComparison.OrdinalIgnoreCase) && x.FileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase)); if (audioCodecsFound.Count() <= 1) diff --git a/AudioCuesheetEditor/Pages/ViewModeImport.razor b/AudioCuesheetEditor/Pages/ViewModeImport.razor index c936d73e..ae38f0f2 100644 --- a/AudioCuesheetEditor/Pages/ViewModeImport.razor +++ b/AudioCuesheetEditor/Pages/ViewModeImport.razor @@ -56,7 +56,7 @@ along with Foobar. If not, see @_localizer["Textfile"] - + @@ -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 = [];