MediaFile.cs 2.7 KB

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