Metadata.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using Jellyfin.Data.Interfaces;
  6. namespace Jellyfin.Data.Entities.Libraries
  7. {
  8. /// <summary>
  9. /// An abstract class that holds metadata.
  10. /// </summary>
  11. public abstract class Metadata : IHasArtwork, IHasConcurrencyToken
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="Metadata"/> class.
  15. /// </summary>
  16. /// <param name="title">The title or name of the object.</param>
  17. /// <param name="language">ISO-639-3 3-character language codes.</param>
  18. protected Metadata(string title, string language)
  19. {
  20. if (string.IsNullOrEmpty(title))
  21. {
  22. throw new ArgumentNullException(nameof(title));
  23. }
  24. if (string.IsNullOrEmpty(language))
  25. {
  26. throw new ArgumentNullException(nameof(language));
  27. }
  28. Title = title;
  29. Language = language;
  30. DateAdded = DateTime.UtcNow;
  31. DateModified = DateAdded;
  32. PersonRoles = new HashSet<PersonRole>();
  33. Genres = new HashSet<Genre>();
  34. Artwork = new HashSet<Artwork>();
  35. Ratings = new HashSet<Rating>();
  36. Sources = new HashSet<MetadataProviderId>();
  37. }
  38. /// <summary>
  39. /// Initializes a new instance of the <see cref="Metadata"/> class.
  40. /// </summary>
  41. /// <remarks>
  42. /// Default constructor. Protected due to being abstract.
  43. /// </remarks>
  44. protected Metadata()
  45. {
  46. }
  47. /// <summary>
  48. /// Gets or sets the id.
  49. /// </summary>
  50. /// <remarks>
  51. /// Identity, Indexed, Required.
  52. /// </remarks>
  53. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  54. public int Id { get; protected set; }
  55. /// <summary>
  56. /// Gets or sets the title.
  57. /// </summary>
  58. /// <remarks>
  59. /// Required, Max length = 1024.
  60. /// </remarks>
  61. [Required]
  62. [MaxLength(1024)]
  63. [StringLength(1024)]
  64. public string Title { get; set; }
  65. /// <summary>
  66. /// Gets or sets the original title.
  67. /// </summary>
  68. /// <remarks>
  69. /// Max length = 1024.
  70. /// </remarks>
  71. [MaxLength(1024)]
  72. [StringLength(1024)]
  73. public string OriginalTitle { get; set; }
  74. /// <summary>
  75. /// Gets or sets the sort title.
  76. /// </summary>
  77. /// <remarks>
  78. /// Max length = 1024.
  79. /// </remarks>
  80. [MaxLength(1024)]
  81. [StringLength(1024)]
  82. public string SortTitle { get; set; }
  83. /// <summary>
  84. /// Gets or sets the language.
  85. /// </summary>
  86. /// <remarks>
  87. /// Required, Min length = 3, Max length = 3.
  88. /// ISO-639-3 3-character language codes.
  89. /// </remarks>
  90. [Required]
  91. [MinLength(3)]
  92. [MaxLength(3)]
  93. [StringLength(3)]
  94. public string Language { get; set; }
  95. /// <summary>
  96. /// Gets or sets the release date.
  97. /// </summary>
  98. public DateTimeOffset? ReleaseDate { get; set; }
  99. /// <summary>
  100. /// Gets or sets the date added.
  101. /// </summary>
  102. /// <remarks>
  103. /// Required.
  104. /// </remarks>
  105. public DateTime DateAdded { get; protected set; }
  106. /// <summary>
  107. /// Gets or sets the date modified.
  108. /// </summary>
  109. /// <remarks>
  110. /// Required.
  111. /// </remarks>
  112. public DateTime DateModified { get; set; }
  113. /// <summary>
  114. /// Gets or sets the row version.
  115. /// </summary>
  116. /// <remarks>
  117. /// Required, ConcurrencyToken.
  118. /// </remarks>
  119. [ConcurrencyCheck]
  120. public uint RowVersion { get; set; }
  121. /// <summary>
  122. /// Gets or sets a collection containing the person roles for this item.
  123. /// </summary>
  124. public virtual ICollection<PersonRole> PersonRoles { get; protected set; }
  125. /// <summary>
  126. /// Gets or sets a collection containing the generes for this item.
  127. /// </summary>
  128. public virtual ICollection<Genre> Genres { get; protected set; }
  129. /// <inheritdoc />
  130. public virtual ICollection<Artwork> Artwork { get; protected set; }
  131. /// <summary>
  132. /// Gets or sets a collection containing the ratings for this item.
  133. /// </summary>
  134. public virtual ICollection<Rating> Ratings { get; protected set; }
  135. /// <summary>
  136. /// Gets or sets a collection containing the metadata sources for this item.
  137. /// </summary>
  138. public virtual ICollection<MetadataProviderId> Sources { get; protected set; }
  139. /// <inheritdoc />
  140. public void OnSavingChanges()
  141. {
  142. RowVersion++;
  143. }
  144. }
  145. }