Skip to content

Commit

Permalink
made import services thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Aug 28, 2024
1 parent b916590 commit 1517812
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
4 changes: 4 additions & 0 deletions AudioCuesheetEditor/Model/IO/Import/CuesheetImportfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet.Import;

namespace AudioCuesheetEditor.Model.IO.Import
{
public class CuesheetImportfile : IImportfile
Expand All @@ -23,5 +25,7 @@ public class CuesheetImportfile : IImportfile
public IEnumerable<String?>? FileContentRecognized { get; set; }
/// <inheritdoc />
public Exception? AnalyseException { get; set; }
/// <inheritdoc />
public ImportCuesheet? AnalysedCuesheet { get; set; }
}
}
12 changes: 9 additions & 3 deletions AudioCuesheetEditor/Model/IO/Import/IImportfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet.Import;

namespace AudioCuesheetEditor.Model.IO.Import
{
public interface IImportfile
{
/// <summary>
/// File content (each element is a file line)
/// </summary>
public IEnumerable<String?>? FileContent { get; set; }
IEnumerable<String?>? FileContent { get; set; }
/// <summary>
/// File content with marking which passages has been reconized by scheme
/// </summary>
public IEnumerable<String?>? FileContentRecognized { get; set; }
IEnumerable<String?>? FileContentRecognized { get; set; }
/// <summary>
/// Exception that has been thrown while readinng out the file
/// </summary>
public Exception? AnalyseException { get; set; }
Exception? AnalyseException { get; set; }
/// <summary>
/// The cuesheet which was created during analysing the <see cref="FileContent"/>
/// </summary>
ImportCuesheet? AnalysedCuesheet { get; set; }
}
}
9 changes: 3 additions & 6 deletions AudioCuesheetEditor/Model/IO/Import/TextImportfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.Options;
using AudioCuesheetEditor.Model.Utility;
using System.Reflection;
using System.Text.RegularExpressions;
using AudioCuesheetEditor.Model.AudioCuesheet.Import;

namespace AudioCuesheetEditor.Model.IO.Import
{
Expand All @@ -33,5 +28,7 @@ public class TextImportfile : IImportfile
public IEnumerable<String?>? FileContentRecognized { get; set; }
/// <inheritdoc />
public Exception? AnalyseException { get;set; }
/// <inheritdoc />
public ImportCuesheet? AnalysedCuesheet { get; set; }
}
}
20 changes: 9 additions & 11 deletions AudioCuesheetEditor/Services/IO/CuesheetImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ namespace AudioCuesheetEditor.Services.IO
{
public class CuesheetImportService
{
public ImportCuesheet? AnalysedCuesheet { get; private set; }
//TODO: Unit Test
public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
public static CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
{
CuesheetImportfile cuesheetImportfile = new();
try
{
AnalysedCuesheet = new ImportCuesheet();
cuesheetImportfile.AnalysedCuesheet = new();
var cuesheetArtistGroupName = "CuesheetArtist";
var cuesheetTitleGroupName = "CuesheetTitle";
var cuesheetFileNameGroupName = "CuesheetFileName";
Expand Down Expand Up @@ -70,7 +68,7 @@ public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
if (matchGroup != null)
{
var artist = matchGroup.Value;
AnalysedCuesheet.Artist = artist;
cuesheetImportfile.AnalysedCuesheet.Artist = artist;
}
else
{
Expand All @@ -85,7 +83,7 @@ public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
if (matchGroup != null)
{
var title = matchGroup.Value;
AnalysedCuesheet.Title = title;
cuesheetImportfile.AnalysedCuesheet.Title = title;
}
else
{
Expand All @@ -100,7 +98,7 @@ public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
if (matchGroup != null)
{
var audioFile = matchGroup.Value;
AnalysedCuesheet.Audiofile = audioFile;
cuesheetImportfile.AnalysedCuesheet.Audiofile = audioFile;
}
else
{
Expand All @@ -115,7 +113,7 @@ public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
if (matchGroup != null)
{
var cdTextfile = matchGroup.Value;
AnalysedCuesheet.CDTextfile = cdTextfile;
cuesheetImportfile.AnalysedCuesheet.CDTextfile = cdTextfile;
}
else
{
Expand All @@ -130,7 +128,7 @@ public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
if (matchGroup != null)
{
var catalogueNumber = matchGroup.Value;
AnalysedCuesheet.Cataloguenumber = catalogueNumber;
cuesheetImportfile.AnalysedCuesheet.Cataloguenumber = catalogueNumber;
}
else
{
Expand Down Expand Up @@ -244,7 +242,7 @@ public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
}
if (track != null)
{
AnalysedCuesheet.Tracks.Add(track);
cuesheetImportfile.AnalysedCuesheet.Tracks.Add(track);
}
else
{
Expand Down Expand Up @@ -284,7 +282,7 @@ public CuesheetImportfile Analyse(IEnumerable<String?> fileContent)
catch (Exception ex)
{
cuesheetImportfile.AnalyseException = ex;
AnalysedCuesheet = null;
cuesheetImportfile.AnalysedCuesheet = null;
cuesheetImportfile.FileContentRecognized = fileContent;
}
return cuesheetImportfile;
Expand Down
10 changes: 5 additions & 5 deletions AudioCuesheetEditor/Services/IO/ImportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ public async Task ImportTextAsync(IEnumerable<String?> fileContent)
{
var options = await _localStorageOptionsProvider.GetOptions<ImportOptions>();
_sessionStateContainer.TextImportFile = _textImportService.Analyse(options, fileContent);
if (_textImportService.AnalysedCuesheet != null)
if (_sessionStateContainer.TextImportFile.AnalysedCuesheet != null)
{
var applicationOptions = await _localStorageOptionsProvider.GetOptions<ApplicationOptions>();
var importCuesheet = new Cuesheet();
importCuesheet.Import(_textImportService.AnalysedCuesheet, applicationOptions);
importCuesheet.Import(_sessionStateContainer.TextImportFile.AnalysedCuesheet, applicationOptions);
_sessionStateContainer.ImportCuesheet = importCuesheet;
}
}

private async Task ImportCuesheetAsync(IEnumerable<String?> fileContent)
{
_sessionStateContainer.CuesheetImportFile = _cuesheetImportService.Analyse(fileContent);
if (_cuesheetImportService.AnalysedCuesheet != null)
_sessionStateContainer.CuesheetImportFile = CuesheetImportService.Analyse(fileContent);
if (_sessionStateContainer.CuesheetImportFile.AnalysedCuesheet != null)
{
var applicationOptions = await _localStorageOptionsProvider.GetOptions<ApplicationOptions>();
var importCuesheet = new Cuesheet();
importCuesheet.Import(_cuesheetImportService.AnalysedCuesheet, applicationOptions);
importCuesheet.Import(_sessionStateContainer.CuesheetImportFile.AnalysedCuesheet, applicationOptions);
_sessionStateContainer.ImportCuesheet = importCuesheet;
}
}
Expand Down
9 changes: 4 additions & 5 deletions AudioCuesheetEditor/Services/IO/TextImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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<String?> fileContent)
Expand All @@ -37,7 +36,7 @@ public TextImportfile Analyse(ImportOptions importOptions, IEnumerable<String?>
{
importfile.FileContent = fileContent;
ImportOptions = importOptions;
AnalysedCuesheet = new ImportCuesheet();
importfile.AnalysedCuesheet = new ImportCuesheet();
Boolean cuesheetRecognized = false;
List<String?> recognizedFileContent = [];
foreach (var line in fileContent)
Expand All @@ -51,7 +50,7 @@ public TextImportfile Analyse(ImportOptions importOptions, IEnumerable<String?>
//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);
recognizedLine = AnalyseLine(line, importfile.AnalysedCuesheet, regExCuesheet);
recognized = recognizedLine != null;
cuesheetRecognized = recognizedLine != null;
}
Expand All @@ -63,7 +62,7 @@ public TextImportfile Analyse(ImportOptions importOptions, IEnumerable<String?>
var track = new ImportTrack();
recognizedLine = AnalyseLine(line, track, regExTracks);
recognized = recognizedLine != null;
AnalysedCuesheet.Tracks.Add(track);
importfile.AnalysedCuesheet.Tracks.Add(track);
}
}
recognizedFileContent.Add(recognizedLine);
Expand All @@ -77,7 +76,7 @@ public TextImportfile Analyse(ImportOptions importOptions, IEnumerable<String?>
{
importfile.FileContentRecognized = fileContent;
importfile.AnalyseException = ex;
AnalysedCuesheet = null;
importfile.AnalysedCuesheet = null;
}
return importfile;
}
Expand Down

0 comments on commit 1517812

Please sign in to comment.