ItemMetadata.cs 4.9 KB

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