ItemMetadata.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. /// Gets or sets the id.
  41. /// </summary>
  42. /// <remarks>
  43. /// Identity, Indexed, Required.
  44. /// </remarks>
  45. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  46. public int Id { get; protected set; }
  47. /// <summary>
  48. /// Gets or sets the title.
  49. /// </summary>
  50. /// <remarks>
  51. /// Required, Max length = 1024.
  52. /// </remarks>
  53. [MaxLength(1024)]
  54. [StringLength(1024)]
  55. public string Title { get; set; }
  56. /// <summary>
  57. /// Gets or sets the original title.
  58. /// </summary>
  59. /// <remarks>
  60. /// Max length = 1024.
  61. /// </remarks>
  62. [MaxLength(1024)]
  63. [StringLength(1024)]
  64. public string? OriginalTitle { get; set; }
  65. /// <summary>
  66. /// Gets or sets the sort title.
  67. /// </summary>
  68. /// <remarks>
  69. /// Max length = 1024.
  70. /// </remarks>
  71. [MaxLength(1024)]
  72. [StringLength(1024)]
  73. public string? SortTitle { get; set; }
  74. /// <summary>
  75. /// Gets or sets the language.
  76. /// </summary>
  77. /// <remarks>
  78. /// Required, Min length = 3, Max length = 3.
  79. /// ISO-639-3 3-character language codes.
  80. /// </remarks>
  81. [MinLength(3)]
  82. [MaxLength(3)]
  83. [StringLength(3)]
  84. public string Language { get; set; }
  85. /// <summary>
  86. /// Gets or sets the release date.
  87. /// </summary>
  88. public DateTimeOffset? ReleaseDate { get; set; }
  89. /// <summary>
  90. /// Gets or sets the date added.
  91. /// </summary>
  92. /// <remarks>
  93. /// Required.
  94. /// </remarks>
  95. public DateTime DateAdded { get; protected set; }
  96. /// <summary>
  97. /// Gets or sets the date modified.
  98. /// </summary>
  99. /// <remarks>
  100. /// Required.
  101. /// </remarks>
  102. public DateTime DateModified { get; set; }
  103. /// <summary>
  104. /// Gets or sets the row version.
  105. /// </summary>
  106. /// <remarks>
  107. /// Required, ConcurrencyToken.
  108. /// </remarks>
  109. [ConcurrencyCheck]
  110. public uint RowVersion { get; set; }
  111. /// <summary>
  112. /// Gets or sets a collection containing the person roles for this item.
  113. /// </summary>
  114. public virtual ICollection<PersonRole> PersonRoles { get; protected set; }
  115. /// <summary>
  116. /// Gets or sets a collection containing the genres for this item.
  117. /// </summary>
  118. public virtual ICollection<Genre> Genres { get; protected set; }
  119. /// <inheritdoc />
  120. public virtual ICollection<Artwork> Artwork { get; protected set; }
  121. /// <summary>
  122. /// Gets or sets a collection containing the ratings for this item.
  123. /// </summary>
  124. public virtual ICollection<Rating> Ratings { get; protected set; }
  125. /// <summary>
  126. /// Gets or sets a collection containing the metadata sources for this item.
  127. /// </summary>
  128. public virtual ICollection<MetadataProviderId> Sources { get; protected set; }
  129. /// <inheritdoc />
  130. public void OnSavingChanges()
  131. {
  132. RowVersion++;
  133. }
  134. }
  135. }