mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-28 01:52:27 -04:00
Using links in the common objects
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
public class Link<T1, T2>
|
||||
where T1 : class, IResource
|
||||
where T2 : class, IResource
|
||||
{
|
||||
public static Expression<Func<Link<T1, T2>, object>> PrimaryKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return x => new {LibraryID = x.FirstID, ProviderID = x.SecondID};
|
||||
}
|
||||
}
|
||||
|
||||
public int FirstID { get; set; }
|
||||
public virtual T1 First { get; set; }
|
||||
public int SecondID { get; set; }
|
||||
public virtual T2 Second { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,11 @@ namespace Kyoo.Models
|
||||
[LoadableRelation] public virtual ICollection<Show> Shows { get; set; }
|
||||
[LoadableRelation] public virtual ICollection<Library> Libraries { get; set; }
|
||||
|
||||
#if ENABLE_INTERNAL_LINKS
|
||||
[SerializeIgnore] public virtual ICollection<Link<Collection, Show>> ShowLinks { get; set; }
|
||||
[SerializeIgnore] public virtual ICollection<Link<Library, Collection>> LibraryLinks { get; set; }
|
||||
#endif
|
||||
|
||||
public Collection() { }
|
||||
|
||||
public Collection(string slug, string name, string overview, string poster)
|
||||
|
||||
@@ -10,7 +10,12 @@ namespace Kyoo.Models
|
||||
public string Name { get; set; }
|
||||
|
||||
[LoadableRelation] public virtual ICollection<Show> Shows { get; set; }
|
||||
|
||||
|
||||
#if ENABLE_INTERNAL_LINKS
|
||||
[SerializeIgnore] public virtual ICollection<Link<Show, Genre>> ShowLinks { get; set; }
|
||||
#endif
|
||||
|
||||
|
||||
public Genre() {}
|
||||
|
||||
public Genre(string name)
|
||||
|
||||
@@ -9,16 +9,6 @@ namespace Kyoo.Models
|
||||
public string Slug { get; }
|
||||
}
|
||||
|
||||
public interface IResourceLink<out T, out T2>
|
||||
where T : IResource
|
||||
where T2 : IResource
|
||||
{
|
||||
public T Parent { get; }
|
||||
public int ParentID { get; }
|
||||
public T2 Child { get; }
|
||||
public int ChildID { get; }
|
||||
}
|
||||
|
||||
public class ResourceComparer<T> : IEqualityComparer<T> where T : IResource
|
||||
{
|
||||
public bool Equals(T x, T y)
|
||||
@@ -37,27 +27,4 @@ namespace Kyoo.Models
|
||||
return HashCode.Combine(obj.ID, obj.Slug);
|
||||
}
|
||||
}
|
||||
|
||||
public class LinkComparer<T, T1, T2> : IEqualityComparer<T>
|
||||
where T : IResourceLink<T1, T2>
|
||||
where T1 : IResource
|
||||
where T2 : IResource
|
||||
{
|
||||
public bool Equals(T x, T y)
|
||||
{
|
||||
if (ReferenceEquals(x, y))
|
||||
return true;
|
||||
if (ReferenceEquals(x, null))
|
||||
return false;
|
||||
if (ReferenceEquals(y, null))
|
||||
return false;
|
||||
return Utility.LinkEquals(x.Parent, x.ParentID, y.Parent, y.ParentID)
|
||||
&& Utility.LinkEquals(x.Child, x.ChildID, y.Child, y.ChildID);
|
||||
}
|
||||
|
||||
public int GetHashCode(T obj)
|
||||
{
|
||||
return HashCode.Combine(obj.Parent, obj.ParentID, obj.Child, obj.ChildID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,12 @@ namespace Kyoo.Models
|
||||
[LoadableRelation] public virtual ICollection<Show> Shows { get; set; }
|
||||
[LoadableRelation] public virtual ICollection<Collection> Collections { get; set; }
|
||||
|
||||
#if ENABLE_INTERNAL_LINKS
|
||||
[SerializeIgnore] public virtual ICollection<Link<Library, ProviderID>> ProviderLinks { get; set; }
|
||||
[SerializeIgnore] public virtual ICollection<Link<Library, Show>> ShowLinks { get; set; }
|
||||
[SerializeIgnore] public virtual ICollection<Link<Library, Collection>> CollectionLinks { get; set; }
|
||||
#endif
|
||||
|
||||
public Library() { }
|
||||
|
||||
public Library(string slug, string name, IEnumerable<string> paths, IEnumerable<ProviderID> providers)
|
||||
|
||||
@@ -10,8 +10,12 @@ namespace Kyoo.Models
|
||||
public string Name { get; set; }
|
||||
public string Logo { get; set; }
|
||||
|
||||
[LoadableRelation] public ICollection<Library> Libraries { get; set; }
|
||||
|
||||
[LoadableRelation] public virtual ICollection<Library> Libraries { get; set; }
|
||||
|
||||
#if ENABLE_INTERNAL_LINKS
|
||||
[SerializeIgnore] public virtual ICollection<Link<Library, ProviderID>> LibraryLinks { get; set; }
|
||||
#endif
|
||||
|
||||
public ProviderID() { }
|
||||
|
||||
public ProviderID(string name, string logo)
|
||||
|
||||
@@ -35,6 +35,13 @@ namespace Kyoo.Models
|
||||
[LoadableRelation] public virtual ICollection<Episode> Episodes { get; set; }
|
||||
[LoadableRelation] public virtual ICollection<Library> Libraries { get; set; }
|
||||
[LoadableRelation] public virtual ICollection<Collection> Collections { get; set; }
|
||||
|
||||
#if ENABLE_INTERNAL_LINKS
|
||||
[SerializeIgnore] public virtual ICollection<Link<Library, Show>> LibraryLinks { get; set; }
|
||||
[SerializeIgnore] public virtual ICollection<Link<Collection, Show>> CollectionLinks { get; set; }
|
||||
[SerializeIgnore] public virtual ICollection<Link<Show, Genre>> GenreLinks { get; set; }
|
||||
#endif
|
||||
|
||||
|
||||
public Show() { }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user