MediaFile.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. public MediaFile(string path, MediaFileKind kind)
  20. {
  21. if (string.IsNullOrEmpty(path))
  22. {
  23. throw new ArgumentNullException(nameof(path));
  24. }
  25. Path = path;
  26. Kind = kind;
  27. MediaFileStreams = new HashSet<MediaFileStream>();
  28. }
  29. /// <summary>
  30. /// Gets the id.
  31. /// </summary>
  32. /// <remarks>
  33. /// Identity, Indexed, Required.
  34. /// </remarks>
  35. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  36. public int Id { get; private set; }
  37. /// <summary>
  38. /// Gets or sets the path relative to the library root.
  39. /// </summary>
  40. /// <remarks>
  41. /// Required, Max length = 65535.
  42. /// </remarks>
  43. [MaxLength(65535)]
  44. [StringLength(65535)]
  45. public string Path { get; set; }
  46. /// <summary>
  47. /// Gets or sets the kind of media file.
  48. /// </summary>
  49. /// <remarks>
  50. /// Required.
  51. /// </remarks>
  52. public MediaFileKind Kind { get; set; }
  53. /// <inheritdoc />
  54. [ConcurrencyCheck]
  55. public uint RowVersion { get; private set; }
  56. /// <summary>
  57. /// Gets a collection containing the streams in this file.
  58. /// </summary>
  59. public virtual ICollection<MediaFileStream> MediaFileStreams { get; private set; }
  60. /// <inheritdoc />
  61. public void OnSavingChanges()
  62. {
  63. RowVersion++;
  64. }
  65. }
  66. }