MediaFile.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. namespace Jellyfin.Data.Entities
  6. {
  7. public partial class MediaFile
  8. {
  9. partial void Init();
  10. /// <summary>
  11. /// Default constructor. Protected due to required properties, but present because EF needs it.
  12. /// </summary>
  13. protected MediaFile()
  14. {
  15. MediaFileStreams = new HashSet<MediaFileStream>();
  16. Init();
  17. }
  18. /// <summary>
  19. /// Replaces default constructor, since it's protected. Caller assumes responsibility for setting all required values before saving.
  20. /// </summary>
  21. public static MediaFile CreateMediaFileUnsafe()
  22. {
  23. return new MediaFile();
  24. }
  25. /// <summary>
  26. /// Public constructor with required data.
  27. /// </summary>
  28. /// <param name="path">Relative to the LibraryRoot.</param>
  29. /// <param name="kind"></param>
  30. /// <param name="_release0"></param>
  31. public MediaFile(string path, Enums.MediaFileKind kind, Release _release0)
  32. {
  33. if (string.IsNullOrEmpty(path))
  34. {
  35. throw new ArgumentNullException(nameof(path));
  36. }
  37. this.Path = path;
  38. this.Kind = kind;
  39. if (_release0 == null)
  40. {
  41. throw new ArgumentNullException(nameof(_release0));
  42. }
  43. _release0.MediaFiles.Add(this);
  44. this.MediaFileStreams = new HashSet<MediaFileStream>();
  45. Init();
  46. }
  47. /// <summary>
  48. /// Static create function (for use in LINQ queries, etc.)
  49. /// </summary>
  50. /// <param name="path">Relative to the LibraryRoot.</param>
  51. /// <param name="kind"></param>
  52. /// <param name="_release0"></param>
  53. public static MediaFile Create(string path, Enums.MediaFileKind kind, Release _release0)
  54. {
  55. return new MediaFile(path, kind, _release0);
  56. }
  57. /*************************************************************************
  58. * Properties
  59. *************************************************************************/
  60. /// <summary>
  61. /// Backing field for Id.
  62. /// </summary>
  63. internal int _Id;
  64. /// <summary>
  65. /// When provided in a partial class, allows value of Id to be changed before setting.
  66. /// </summary>
  67. partial void SetId(int oldValue, ref int newValue);
  68. /// <summary>
  69. /// When provided in a partial class, allows value of Id to be changed before returning.
  70. /// </summary>
  71. partial void GetId(ref int result);
  72. /// <summary>
  73. /// Identity, Indexed, Required.
  74. /// </summary>
  75. [Key]
  76. [Required]
  77. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  78. public int Id
  79. {
  80. get
  81. {
  82. int value = _Id;
  83. GetId(ref value);
  84. return _Id = value;
  85. }
  86. protected set
  87. {
  88. int oldValue = _Id;
  89. SetId(oldValue, ref value);
  90. if (oldValue != value)
  91. {
  92. _Id = value;
  93. }
  94. }
  95. }
  96. /// <summary>
  97. /// Backing field for Path.
  98. /// </summary>
  99. protected string _Path;
  100. /// <summary>
  101. /// When provided in a partial class, allows value of Path to be changed before setting.
  102. /// </summary>
  103. partial void SetPath(string oldValue, ref string newValue);
  104. /// <summary>
  105. /// When provided in a partial class, allows value of Path to be changed before returning.
  106. /// </summary>
  107. partial void GetPath(ref string result);
  108. /// <summary>
  109. /// Required, Max length = 65535
  110. /// Relative to the LibraryRoot.
  111. /// </summary>
  112. [Required]
  113. [MaxLength(65535)]
  114. [StringLength(65535)]
  115. public string Path
  116. {
  117. get
  118. {
  119. string value = _Path;
  120. GetPath(ref value);
  121. return _Path = value;
  122. }
  123. set
  124. {
  125. string oldValue = _Path;
  126. SetPath(oldValue, ref value);
  127. if (oldValue != value)
  128. {
  129. _Path = value;
  130. }
  131. }
  132. }
  133. /// <summary>
  134. /// Backing field for Kind.
  135. /// </summary>
  136. protected Enums.MediaFileKind _Kind;
  137. /// <summary>
  138. /// When provided in a partial class, allows value of Kind to be changed before setting.
  139. /// </summary>
  140. partial void SetKind(Enums.MediaFileKind oldValue, ref Enums.MediaFileKind newValue);
  141. /// <summary>
  142. /// When provided in a partial class, allows value of Kind to be changed before returning.
  143. /// </summary>
  144. partial void GetKind(ref Enums.MediaFileKind result);
  145. /// <summary>
  146. /// Required.
  147. /// </summary>
  148. [Required]
  149. public Enums.MediaFileKind Kind
  150. {
  151. get
  152. {
  153. Enums.MediaFileKind value = _Kind;
  154. GetKind(ref value);
  155. return _Kind = value;
  156. }
  157. set
  158. {
  159. Enums.MediaFileKind oldValue = _Kind;
  160. SetKind(oldValue, ref value);
  161. if (oldValue != value)
  162. {
  163. _Kind = value;
  164. }
  165. }
  166. }
  167. /// <summary>
  168. /// Required, ConcurrenyToken.
  169. /// </summary>
  170. [ConcurrencyCheck]
  171. [Required]
  172. public uint RowVersion { get; set; }
  173. public void OnSavingChanges()
  174. {
  175. RowVersion++;
  176. }
  177. /*************************************************************************
  178. * Navigation properties
  179. *************************************************************************/
  180. [ForeignKey("MediaFileStream_MediaFileStreams_Id")]
  181. public virtual ICollection<MediaFileStream> MediaFileStreams { get; protected set; }
  182. }
  183. }