MetadataProviderId.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Jellyfin.Data.Interfaces;
  5. namespace Jellyfin.Data.Entities.Libraries
  6. {
  7. /// <summary>
  8. /// An entity representing a unique identifier for a metadata provider.
  9. /// </summary>
  10. public class MetadataProviderId : IHasConcurrencyToken
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="MetadataProviderId"/> class.
  14. /// </summary>
  15. /// <param name="providerId">The provider id.</param>
  16. /// <param name="itemMetadata">The metadata entity.</param>
  17. public MetadataProviderId(string providerId, ItemMetadata itemMetadata)
  18. {
  19. if (string.IsNullOrEmpty(providerId))
  20. {
  21. throw new ArgumentNullException(nameof(providerId));
  22. }
  23. ProviderId = providerId;
  24. if (itemMetadata == null)
  25. {
  26. throw new ArgumentNullException(nameof(itemMetadata));
  27. }
  28. itemMetadata.Sources.Add(this);
  29. }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="MetadataProviderId"/> class.
  32. /// </summary>
  33. /// <remarks>
  34. /// Default constructor. Protected due to required properties, but present because EF needs it.
  35. /// </remarks>
  36. protected MetadataProviderId()
  37. {
  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 provider id.
  49. /// </summary>
  50. /// <remarks>
  51. /// Required, Max length = 255.
  52. /// </remarks>
  53. [Required]
  54. [MaxLength(255)]
  55. [StringLength(255)]
  56. public string ProviderId { get; set; }
  57. /// <inheritdoc />
  58. [ConcurrencyCheck]
  59. public uint RowVersion { get; set; }
  60. /// <summary>
  61. /// Gets or sets the metadata provider.
  62. /// </summary>
  63. /// <remarks>
  64. /// Required.
  65. /// </remarks>
  66. public virtual MetadataProvider MetadataProvider { get; set; }
  67. /// <inheritdoc />
  68. public void OnSavingChanges()
  69. {
  70. RowVersion++;
  71. }
  72. }
  73. }