-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for CLI and CSV import (WIP)
- Loading branch information
1 parent
2b20d49
commit 131350c
Showing
25 changed files
with
785 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/MusicCatalogue.Entities/CommandLine/CommandLineOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MusicCatalogue.Entities.CommandLine | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class CommandLineOption | ||
{ | ||
public CommandLineOptionType OptionType { get; set; } | ||
public string Name { get; set; } = ""; | ||
public string ShortName { get; set; } = ""; | ||
public string Description { get; set; } = ""; | ||
public int MinimumNumberOfValues { get; set; } = 0; | ||
public int MaximumNumberOfValues { get; set; } = 0; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/MusicCatalogue.Entities/CommandLine/CommandLineOptionType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace MusicCatalogue.Entities.CommandLine | ||
{ | ||
public enum CommandLineOptionType | ||
{ | ||
Unknown, | ||
Lookup, | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/MusicCatalogue.Entities/CommandLine/CommandLineOptionValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MusicCatalogue.Entities.CommandLine | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class CommandLineOptionValue | ||
{ | ||
public CommandLineOption? Option { get; set; } | ||
public List<string> Values { get; private set; } = new List<string>(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/MusicCatalogue.Entities/DataExchange/FlattenedTrack.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using MusicCatalogue.Entities.Database; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MusicCatalogue.Entities.DataExchange | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class FlattenedTrack : TrackBase | ||
{ | ||
public const int ArtistField = 0; | ||
public const int AlbumField = 1; | ||
private const int GenreField = 2; | ||
private const int ReleasedField = 3; | ||
private const int CoverField = 4; | ||
private const int TrackNumberField = 5; | ||
private const int TitleField = 6; | ||
private const int DurationField = 7; | ||
|
||
public const string CsvRecordPattern = @"^(""[a-zA-Z0-9-() \/']+"",){3}""[0-9]+"",("".*"",)""[0-9]+"",(""[a-zA-Z0-9-() \/']+"",)""[0-9]+\:[0-9]{2}""$"; | ||
|
||
public string ArtistName{ get; set; } = ""; | ||
public string AlbumTitle { get; set; } = ""; | ||
public string Genre { get; set; } = ""; | ||
public int? Released { get; set; } | ||
public string? CoverUrl { get; set; } = ""; | ||
public int TrackNumber { get; set; } | ||
public string Title { get; set; } = ""; | ||
|
||
/// <summary> | ||
/// Create a representation of the flattened track in CSV format | ||
/// </summary> | ||
/// <returns></returns> | ||
public string ToCsv() | ||
{ | ||
var representation = $"\"{ArtistName}\",\"{AlbumTitle}\",\"{Genre}\",\"{Released}\",\"{CoverUrl}\",\"{Title}\",\"{FormattedDuration()}\""; | ||
return representation; | ||
} | ||
|
||
/// <summary> | ||
/// Create a flattened track record from a CSV string | ||
/// </summary> | ||
/// <param name="record"></param> | ||
/// <returns></returns> | ||
public static FlattenedTrack FromCsv(string record) | ||
{ | ||
// Split the record into words | ||
var words = record.Split(new string[] { "\",\"" }, StringSplitOptions.None); | ||
|
||
// Get the release date and cover URL, both of which may be NULL | ||
int? releaseYear = !string.IsNullOrEmpty(words[ReleasedField]) ? int.Parse(words[ReleasedField]) : null; | ||
string? coverUrl = !string.IsNullOrEmpty(words[CoverField]) ? words[CoverField] : null; | ||
|
||
// Split the duration on the ":" separator and convert to milliseconds | ||
var durationWords = words[DurationField][..^1].Split(new string[] { ":" }, StringSplitOptions.None); | ||
var durationMs = 1000 * (60 * int.Parse(durationWords[0]) + 1000 * int.Parse(durationWords[1])); | ||
|
||
// Create a new "flattened" record containing artist, album and track details | ||
return new FlattenedTrack | ||
{ | ||
ArtistName = words[ArtistField][1..], | ||
AlbumTitle = words[AlbumField], | ||
Genre = words[GenreField], | ||
Released = releaseYear, | ||
CoverUrl = coverUrl, | ||
TrackNumber = int.Parse(words[TrackNumberField]), | ||
Title = words[TitleField], | ||
Duration = durationMs | ||
}; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/MusicCatalogue.Entities/DataExchange/TrackDataExchangeEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace MusicCatalogue.Entities.DataExchange | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
public class TrackDataExchangeEventArgs : EventArgs | ||
{ | ||
public long RecordCount { get; set; } | ||
public FlattenedTrack? Track { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MusicCatalogue.Entities.Database | ||
{ | ||
public abstract class TrackBase | ||
{ | ||
public int? Duration { get; set; } | ||
|
||
/// <summary> | ||
/// Format the duration in MM:SS format | ||
/// </summary> | ||
/// <returns></returns> | ||
public string? FormattedDuration() | ||
{ | ||
string? formatted = null; | ||
|
||
if (Duration != null) | ||
{ | ||
int seconds = (Duration ?? 0) / 1000; | ||
int minutes = seconds / 60; | ||
seconds -= 60 * minutes; | ||
formatted = $"{minutes:00}:{seconds:00}"; | ||
} | ||
|
||
return formatted; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/MusicCatalogue.Entities/Exceptions/DuplicateOptionException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.Serialization; | ||
|
||
namespace MusicCatalogue.Entities.Exceptions | ||
{ | ||
|
||
[Serializable] | ||
[ExcludeFromCodeCoverage] | ||
public class DuplicateOptionException : Exception | ||
{ | ||
public DuplicateOptionException() | ||
{ | ||
} | ||
|
||
public DuplicateOptionException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public DuplicateOptionException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
|
||
protected DuplicateOptionException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) | ||
{ | ||
} | ||
|
||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
base.GetObjectData(info, context); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/MusicCatalogue.Entities/Exceptions/InvalidRecordFormatException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.Serialization; | ||
|
||
namespace MusicCatalogue.Entities.Exceptions | ||
{ | ||
[Serializable] | ||
[ExcludeFromCodeCoverage] | ||
public class InvalidRecordFormatException : Exception | ||
{ | ||
public InvalidRecordFormatException() | ||
{ | ||
} | ||
|
||
public InvalidRecordFormatException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public InvalidRecordFormatException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
|
||
protected InvalidRecordFormatException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) | ||
{ | ||
} | ||
|
||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
base.GetObjectData(info, context); | ||
} | ||
} | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
src/MusicCatalogue.Entities/Exceptions/MalformedCommandLineException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.Serialization; | ||
|
||
namespace MusicCatalogue.Entities.Exceptions | ||
{ | ||
[Serializable] | ||
[ExcludeFromCodeCoverage] | ||
public class MalformedCommandLineException : Exception | ||
{ | ||
public MalformedCommandLineException() | ||
{ | ||
} | ||
|
||
public MalformedCommandLineException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public MalformedCommandLineException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
|
||
protected MalformedCommandLineException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) | ||
{ | ||
} | ||
|
||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
base.GetObjectData(info, context); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/MusicCatalogue.Entities/Exceptions/TooFewValuesException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.Serialization; | ||
|
||
namespace MusicCatalogue.Entities.Exceptions | ||
{ | ||
[Serializable] | ||
[ExcludeFromCodeCoverage] | ||
public class TooFewValuesException : Exception | ||
{ | ||
public TooFewValuesException() | ||
{ | ||
} | ||
|
||
public TooFewValuesException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public TooFewValuesException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
|
||
protected TooFewValuesException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) | ||
{ | ||
} | ||
|
||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
base.GetObjectData(info, context); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/MusicCatalogue.Entities/Exceptions/TooManyValuesException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MusicCatalogue.Entities.Exceptions | ||
{ | ||
[Serializable] | ||
[ExcludeFromCodeCoverage] | ||
public class TooManyValuesException : Exception | ||
{ | ||
public TooManyValuesException() | ||
{ | ||
} | ||
|
||
public TooManyValuesException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public TooManyValuesException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
|
||
protected TooManyValuesException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) | ||
{ | ||
} | ||
|
||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
base.GetObjectData(info, context); | ||
} | ||
} | ||
} |
Oops, something went wrong.