MediaFile.cs 2.2 KB

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