roadie/Roadie.Api.Library/Data/ArtistPartial.cs

86 lines
2.1 KiB
C#
Raw Normal View History

2018-11-04 14:33:37 -06:00
using Roadie.Library.Configuration;
2018-11-03 16:21:36 -05:00
using Roadie.Library.Utility;
using System;
using System.Linq;
namespace Roadie.Library.Data
{
public partial class Artist
{
2018-11-11 10:20:33 -06:00
public static string CacheRegionUrn(Guid Id)
{
2018-11-11 10:20:33 -06:00
return $"urn:artist:{ Id}";
}
2018-11-22 17:12:57 -06:00
public static string CacheUrnByName(string name)
{
return $"urn:artist_by_name:{ name }";
}
2018-11-11 10:20:33 -06:00
public static string CacheUrn(Guid Id)
{
return $"urn:artist_by_id:{ Id }";
}
public string CacheKey
{
get
{
return Artist.CacheUrn(this.RoadieId);
}
}
2018-11-03 16:21:36 -05:00
public string CacheRegion
{
get
{
2018-11-11 10:20:33 -06:00
return Artist.CacheRegionUrn(this.RoadieId);
2018-11-03 16:21:36 -05:00
}
}
public string Etag
{
get
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
2018-11-04 09:16:52 -06:00
return String.Concat(md5.ComputeHash(System.Text.Encoding.Default.GetBytes(string.Format("{0}{1}", this.RoadieId, this.LastUpdated))).Select(x => x.ToString("D2")));
2018-11-03 16:21:36 -05:00
}
}
}
2018-11-04 14:33:37 -06:00
public bool IsNew
2018-11-03 16:21:36 -05:00
{
get
{
2018-11-04 14:33:37 -06:00
return this.Id < 1;
2018-11-03 16:21:36 -05:00
}
}
2018-11-04 14:33:37 -06:00
public bool IsValid
2018-11-03 16:21:36 -05:00
{
get
{
2018-11-04 14:33:37 -06:00
return !string.IsNullOrEmpty(this.Name);
2018-11-03 16:21:36 -05:00
}
}
public string SortNameValue
{
get
{
return string.IsNullOrEmpty(this.SortName) ? this.Name : this.SortName;
}
}
2018-11-04 14:33:37 -06:00
public string ArtistFileFolder(IRoadieSettings configuration, string destinationRoot)
2018-11-03 16:21:36 -05:00
{
return FolderPathHelper.ArtistPath(configuration, this.SortNameValue, destinationRoot);
}
2018-11-04 14:33:37 -06:00
public override string ToString()
{
return string.Format("Id [{0}], Name [{1}], SortName [{2}], RoadieId [{3}]", this.Id, this.Name, this.SortNameValue, this.RoadieId);
}
2018-11-03 16:21:36 -05:00
}
2018-11-04 14:33:37 -06:00
}