Using links in the common objects

This commit is contained in:
Zoe Roux
2021-03-06 00:53:21 +01:00
parent b8fcc5b7cf
commit 76cdbc77a3
23 changed files with 191 additions and 4931 deletions
+23
View File
@@ -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)
+6 -1
View File
@@ -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)
-33
View File
@@ -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);
}
}
}
+6
View File
@@ -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)
+6 -2
View File
@@ -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)
+7
View File
@@ -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() { }