Skip to content

Commit

Permalink
2024.47.2
Browse files Browse the repository at this point in the history
- Output file format classes no longer use delegates to target file output contents, but by overriding methods instead.
  • Loading branch information
simon-techkid committed Jun 15, 2024
1 parent 8289291 commit 5fa4ea8
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 29 deletions.
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Csv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ namespace SpotifyGPX.Output;
public sealed partial class Csv : TxtSaveable
{
public override string FormatName => nameof(Csv).ToLower();
protected override DocumentAccessor SaveAction => GetDocument;

public Csv(Func<IEnumerable<SongPoint>> pairs, string? trackName) : base(pairs, trackName)
{
}

private string[] GetDocument(string? trackName)
protected override string[] GetDocument(string? trackName)
{
IEnumerable<SongPoint> pairs = DataProvider();

Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/FolderedKml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace SpotifyGPX.Output;
public sealed partial class FolderedKml : XmlSaveable
{
public override string FormatName => "kml";
protected override DocumentAccessor SaveAction => GetDocument;

public FolderedKml(Func<IEnumerable<SongPoint>> pairs, string trackName) : base(pairs, trackName)
{
}

private XDocument GetDocument(string? trackName)
protected override XDocument GetDocument(string? trackName)
{
IEnumerable<IGrouping<TrackInfo, SongPoint>> groups = GroupedDataProvider(pair => pair.Origin);

Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Gpx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace SpotifyGPX.Output;
public sealed partial class Gpx : XmlSaveable
{
public override string FormatName => nameof(Gpx).ToLower();
protected override DocumentAccessor SaveAction => GetDocument;

public Gpx(Func<IEnumerable<SongPoint>> pairs, string trackName) : base(pairs, trackName)
{
}

private XDocument GetDocument(string? trackName)
protected override XDocument GetDocument(string? trackName)
{
IEnumerable<SongPoint> pairs = DataProvider();

Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace SpotifyGPX.Output;
public sealed partial class Json : JsonSaveable
{
public override string FormatName => nameof(Json).ToLower();
protected override DocumentAccessor SaveAction => GetDocument;

public Json(Func<IEnumerable<SongPoint>> pairs, string? trackName) : base(pairs, trackName)
{
}

private List<JsonDocument> GetDocument(string? trackName)
protected override List<JsonDocument> GetDocument(string? trackName)
{
IEnumerable<SongPoint> Pairs = DataProvider();

Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/JsonReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace SpotifyGPX.Output;
public sealed partial class JsonReport : JsonSaveable
{
public override string FormatName => nameof(JsonReport).ToLower();
protected override DocumentAccessor SaveAction => GetDocument;

public JsonReport(Func<IEnumerable<SongPoint>> pairs, string? trackName) : base(pairs, trackName)
{
}

private List<JsonDocument> GetDocument(string? trackName)
protected override List<JsonDocument> GetDocument(string? trackName)
{
IEnumerable<IGrouping<TrackInfo, SongPoint>> tracks = GroupedDataProvider(pair => pair.Origin);

Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Kml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace SpotifyGPX.Output;
public sealed partial class Kml : XmlSaveable
{
public override string FormatName => nameof(Kml).ToLower();
protected override DocumentAccessor SaveAction => GetDocument;

public Kml(Func<IEnumerable<SongPoint>> pairs, string trackName) : base(pairs, trackName)
{
}

private XDocument GetDocument(string? trackName)
protected override XDocument GetDocument(string? trackName)
{
IEnumerable<SongPoint> pairs = DataProvider();

Expand Down
12 changes: 3 additions & 9 deletions SpotifyGPX/Output/SaveableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace SpotifyGPX.Output;
/// <typeparam name="THashed">The format type of the hashable portion of this document.</typeparam>
public abstract class SaveableBase<TDocument, THashed> : DisposableBase, IFileOutput
{
protected SaveableBase(Func<IEnumerable<SongPoint>> pairs, string? trackName)
protected SaveableBase(Func<IEnumerable<SongPoint>> pairs, string? trackName = null)
{
DataProvider = pairs;
Document = SaveAction(trackName);
Document = GetDocument(trackName);
}

public abstract string FormatName { get; }
Expand All @@ -41,16 +41,10 @@ protected SaveableBase(Func<IEnumerable<SongPoint>> pairs, string? trackName)
/// </summary>
protected Func<IEnumerable<SongPoint>> DataProvider { get; }

/// <summary>
/// A delegate to access the contents of the document in format <typeparamref name="TDocument"/>.
/// </summary>
/// <returns></returns>
protected delegate TDocument DocumentAccessor(string? trackName);

/// <summary>
/// Provides access to the document in format <typeparamref name="TDocument"/> that will be serialized and saved to the disk.
/// </summary>
protected abstract DocumentAccessor SaveAction { get; }
protected abstract TDocument GetDocument(string? trackName);

public void Save(string path)
{
Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Tsv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ namespace SpotifyGPX.Output;
public sealed partial class Tsv : TxtSaveable
{
public override string FormatName => "tsv";
protected override DocumentAccessor SaveAction => GetDocument;

public Tsv(Func<IEnumerable<SongPoint>> pairs, string? trackName) : base(pairs, trackName)
{
}

private string?[] GetDocument(string? trackName)
protected override string?[] GetDocument(string? trackName)
{
IEnumerable<SongPoint> pairs = DataProvider();

Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Txt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ namespace SpotifyGPX.Output;
public sealed partial class Txt : TxtSaveable
{
public override string FormatName => nameof(Txt).ToLower();
protected override DocumentAccessor SaveAction => GetDocument;

public Txt(Func<IEnumerable<SongPoint>> pairs, string? trackName) : base(pairs, trackName)
{
}

private string?[] GetDocument(string? trackName)
protected override string?[] GetDocument(string? trackName)
{
IEnumerable<SongPoint> Pairs = DataProvider();

Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Xlsx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public partial class Xlsx : ByteSaveable
{
public override string FormatName => nameof(Xlsx).ToLower();
private ExcelPackage Package { get; set; }
protected override DocumentAccessor SaveAction => GetDocument;

public Xlsx(Func<IEnumerable<SongPoint>> pairs, string? trackName) : base(pairs, trackName)
{
Expand All @@ -24,7 +23,7 @@ public Xlsx(Func<IEnumerable<SongPoint>> pairs, string? trackName) : base(pairs,
Count = GetPackage();
}

private byte[] GetDocument(string? trackName)
protected override byte[] GetDocument(string? trackName)
{
return Package.GetAsByteArray();
}
Expand Down
3 changes: 1 addition & 2 deletions SpotifyGPX/Output/Xspf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ namespace SpotifyGPX.Output;
public sealed partial class Xspf : XmlSaveable
{
public override string FormatName => nameof(Xspf).ToLower();
protected override DocumentAccessor SaveAction => GetDocument;

public Xspf(Func<IEnumerable<SongPoint>> pairs, string trackName) : base(pairs, trackName)
{
}

private XDocument GetDocument(string? trackName)
protected override XDocument GetDocument(string? trackName)
{
IEnumerable<SongPoint> pairs = DataProvider();

Expand Down

0 comments on commit 5fa4ea8

Please sign in to comment.