2
0

MediaFile.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.Enums;
  7. using Jellyfin.Data.Interfaces;
  8. namespace Jellyfin.Data.Entities.Libraries
  9. {
  10. /// <summary>
  11. /// An entity representing a file on disk.
  12. /// </summary>
  13. public class MediaFile : IHasConcurrencyToken
  14. {
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="MediaFile"/> class.
  17. /// </summary>
  18. /// <param name="path">The path relative to the LibraryRoot.</param>
  19. /// <param name="kind">The file kind.</param>
  20. /// <param name="release">The release.</param>
  21. public MediaFile(string path, MediaFileKind kind, Release release)
  22. {
  23. if (string.IsNullOrEmpty(path))
  24. {
  25. throw new ArgumentNullException(nameof(path));
  26. }
  27. Path = path;
  28. Kind = kind;
  29. if (release == null)
  30. {
  31. throw new ArgumentNullException(nameof(release));
  32. }
  33. release.MediaFiles.Add(this);
  34. MediaFileStreams = new HashSet<MediaFileStream>();
  35. }
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="MediaFile"/> class.
  38. /// </summary>
  39. /// <remarks>
  40. /// Default constructor. Protected due to required properties, but present because EF needs it.
  41. /// </remarks>
  42. protected MediaFile()
  43. {
  44. }
  45. /// <summary>
  46. /// Gets or sets the id.
  47. /// </summary>
  48. /// <remarks>
  49. /// Identity, Indexed, Required.
  50. /// </remarks>
  51. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  52. public int Id { get; protected set; }
  53. /// <summary>
  54. /// Gets or sets the path relative to the library root.
  55. /// </summary>
  56. /// <remarks>
  57. /// Required, Max length = 65535.
  58. /// </remarks>
  59. [Required]
  60. [MaxLength(65535)]
  61. [StringLength(65535)]
  62. public string Path { get; set; }
  63. /// <summary>
  64. /// Gets or sets the kind of media file.
  65. /// </summary>
  66. /// <remarks>
  67. /// Required.
  68. /// </remarks>
  69. public MediaFileKind Kind { get; set; }
  70. /// <inheritdoc />
  71. [ConcurrencyCheck]
  72. public uint RowVersion { get; set; }
  73. /// <summary>
  74. /// Gets or sets a collection containing the streams in this file.
  75. /// </summary>
  76. public virtual ICollection<MediaFileStream> MediaFileStreams { get; protected set; }
  77. /// <inheritdoc />
  78. public void OnSavingChanges()
  79. {
  80. RowVersion++;
  81. }
  82. }
  83. }