2018-12-11 04:41:15 +00:00
|
|
|
|
using CsvHelper;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Roadie.Library.Enums;
|
|
|
|
|
using Roadie.Library.Utility;
|
|
|
|
|
using System;
|
2018-11-11 20:10:10 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-05-22 03:08:22 +00:00
|
|
|
|
using System.Diagnostics;
|
2018-12-11 04:41:15 +00:00
|
|
|
|
using System.IO;
|
2018-11-11 20:10:10 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Roadie.Library.Data
|
|
|
|
|
{
|
|
|
|
|
public partial class Collection
|
|
|
|
|
{
|
|
|
|
|
public static string CacheRegionUrn(Guid Id)
|
|
|
|
|
{
|
|
|
|
|
return string.Format("urn:collection:{0}", Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string CacheUrn(Guid Id)
|
|
|
|
|
{
|
|
|
|
|
return $"urn:collection_by_id:{ Id }";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string CacheKey
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Collection.CacheUrn(this.RoadieId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-11 04:41:15 +00:00
|
|
|
|
|
2018-12-12 14:31:39 +00:00
|
|
|
|
public string CacheRegion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Collection.CacheRegionUrn(this.RoadieId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 04:41:15 +00:00
|
|
|
|
public int? _positionColumn = null;
|
|
|
|
|
public int PositionColumn
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (this._positionColumn == null)
|
|
|
|
|
{
|
|
|
|
|
var looper = -1;
|
|
|
|
|
foreach (var pos in this.ListInCSVFormat.Split(','))
|
|
|
|
|
{
|
|
|
|
|
looper++;
|
|
|
|
|
if (pos.ToLower().Equals("position"))
|
|
|
|
|
{
|
|
|
|
|
this._positionColumn = looper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this._positionColumn.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int? _artistColumn = null;
|
|
|
|
|
public int ArtistColumn
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (this._artistColumn == null)
|
|
|
|
|
{
|
|
|
|
|
var looper = -1;
|
|
|
|
|
foreach (var pos in this.ListInCSVFormat.Split(','))
|
|
|
|
|
{
|
|
|
|
|
looper++;
|
|
|
|
|
if (pos.ToLower().Equals("artist"))
|
|
|
|
|
{
|
|
|
|
|
this._artistColumn = looper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this._artistColumn.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int? _releaseColumn = null;
|
|
|
|
|
public int ReleaseColumn
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (this._releaseColumn == null)
|
|
|
|
|
{
|
|
|
|
|
var looper = -1;
|
|
|
|
|
foreach (var pos in this.ListInCSVFormat.Split(','))
|
|
|
|
|
{
|
|
|
|
|
looper++;
|
|
|
|
|
if (pos.ToLower().Equals("release"))
|
|
|
|
|
{
|
|
|
|
|
this._releaseColumn = looper;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return this._releaseColumn.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-06-15 22:33:24 +00:00
|
|
|
|
private IEnumerable<PositionArtistRelease> _positionArtistReleases = null;
|
2018-12-11 04:41:15 +00:00
|
|
|
|
|
2019-06-15 22:33:24 +00:00
|
|
|
|
public IEnumerable<PositionArtistRelease> PositionArtistReleases()
|
2018-12-11 04:41:15 +00:00
|
|
|
|
{
|
2019-06-15 22:33:24 +00:00
|
|
|
|
if (this._positionArtistReleases == null)
|
2018-12-11 04:41:15 +00:00
|
|
|
|
{
|
2019-06-15 22:33:24 +00:00
|
|
|
|
var rows = new List<PositionArtistRelease>();
|
2018-12-11 04:41:15 +00:00
|
|
|
|
using (var sr = new StringReader(this.ListInCSV))
|
|
|
|
|
{
|
|
|
|
|
var index = 0;
|
2019-05-22 03:08:22 +00:00
|
|
|
|
var configuration = new CsvHelper.Configuration.Configuration
|
|
|
|
|
{
|
|
|
|
|
MissingFieldFound = null,
|
|
|
|
|
HasHeaderRecord = false
|
|
|
|
|
};
|
|
|
|
|
configuration.BadDataFound = context =>
|
|
|
|
|
{
|
|
|
|
|
Trace.WriteLine($"PositionArtistReleases: Bad data found on row '{context.RawRow}'");
|
|
|
|
|
};
|
|
|
|
|
var csv = new CsvReader(sr, configuration);
|
2018-12-11 04:41:15 +00:00
|
|
|
|
while (csv.Read())
|
|
|
|
|
{
|
|
|
|
|
index++;
|
2019-06-15 22:33:24 +00:00
|
|
|
|
rows.Add(new PositionArtistRelease
|
2018-12-11 04:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
Index = index,
|
|
|
|
|
Position = csv.GetField<int>(this.PositionColumn),
|
|
|
|
|
Artist = SafeParser.ToString(csv.GetField<string>(this.ArtistColumn)),
|
|
|
|
|
Release = SafeParser.ToString(csv.GetField<string>(this.ReleaseColumn)),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-15 22:33:24 +00:00
|
|
|
|
this._positionArtistReleases = rows;
|
2018-12-11 04:41:15 +00:00
|
|
|
|
}
|
2019-06-15 22:33:24 +00:00
|
|
|
|
return this._positionArtistReleases;
|
2018-12-11 04:41:15 +00:00
|
|
|
|
}
|
2019-01-26 20:55:58 +00:00
|
|
|
|
|
|
|
|
|
public Collection()
|
|
|
|
|
{
|
2019-06-28 21:24:32 +00:00
|
|
|
|
this.Releases = new HashSet<CollectionRelease>();
|
|
|
|
|
this.Comments = new HashSet<Comment>();
|
2019-01-26 20:55:58 +00:00
|
|
|
|
ListInCSVFormat = "Position,Release,Artist";
|
|
|
|
|
CollectionType = Enums.CollectionType.Rank;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"Id [{ this.Id }], Name [{ this.Name }]";
|
|
|
|
|
}
|
2018-12-11 04:41:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2019-06-15 22:33:24 +00:00
|
|
|
|
public class PositionArtistRelease
|
2018-12-11 04:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public Statuses Status { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty("Status")]
|
|
|
|
|
public string StatusVerbose
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.Status.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is the index (position in the list regardless of the position number)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is the position number for the list (can be a year "1984" can be a number "14")
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Position { get; set; }
|
|
|
|
|
public string Artist { get; set; }
|
|
|
|
|
public string Release { get; set; }
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return string.Format("Position [{0}], Artist [{1}], Release [{2}]", this.Position, this.Artist, this.Release);
|
|
|
|
|
}
|
2018-11-11 20:10:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|