2
0

ActivityLog.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Microsoft.Extensions.Logging;
  5. namespace Jellyfin.Data.Entities
  6. {
  7. /// <summary>
  8. /// An entity referencing an activity log entry.
  9. /// </summary>
  10. public partial class ActivityLog : ISavingChanges
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="ActivityLog"/> class.
  14. /// Public constructor with required data.
  15. /// </summary>
  16. /// <param name="name">The name.</param>
  17. /// <param name="type">The type.</param>
  18. /// <param name="userId">The user id.</param>
  19. public ActivityLog(string name, string type, Guid userId)
  20. {
  21. if (string.IsNullOrEmpty(name))
  22. {
  23. throw new ArgumentNullException(nameof(name));
  24. }
  25. if (string.IsNullOrEmpty(type))
  26. {
  27. throw new ArgumentNullException(nameof(type));
  28. }
  29. this.Name = name;
  30. this.Type = type;
  31. this.UserId = userId;
  32. this.DateCreated = DateTime.UtcNow;
  33. this.LogSeverity = LogLevel.Trace;
  34. Init();
  35. }
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="ActivityLog"/> class.
  38. /// Default constructor. Protected due to required properties, but present because EF needs it.
  39. /// </summary>
  40. protected ActivityLog()
  41. {
  42. Init();
  43. }
  44. /// <summary>
  45. /// Static create function (for use in LINQ queries, etc.)
  46. /// </summary>
  47. /// <param name="name">The name.</param>
  48. /// <param name="type">The type.</param>
  49. /// <param name="userId">The user's id.</param>
  50. /// <returns>The new <see cref="ActivityLog"/> instance.</returns>
  51. public static ActivityLog Create(string name, string type, Guid userId)
  52. {
  53. return new ActivityLog(name, type, userId);
  54. }
  55. /*************************************************************************
  56. * Properties
  57. *************************************************************************/
  58. /// <summary>
  59. /// Gets or sets the identity of this instance.
  60. /// This is the key in the backing database.
  61. /// </summary>
  62. [Key]
  63. [Required]
  64. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  65. public int Id { get; protected set; }
  66. /// <summary>
  67. /// Gets or sets the name.
  68. /// Required, Max length = 512.
  69. /// </summary>
  70. [Required]
  71. [MaxLength(512)]
  72. [StringLength(512)]
  73. public string Name { get; set; }
  74. /// <summary>
  75. /// Gets or sets the overview.
  76. /// Max length = 512.
  77. /// </summary>
  78. [MaxLength(512)]
  79. [StringLength(512)]
  80. public string Overview { get; set; }
  81. /// <summary>
  82. /// Gets or sets the short overview.
  83. /// Max length = 512.
  84. /// </summary>
  85. [MaxLength(512)]
  86. [StringLength(512)]
  87. public string ShortOverview { get; set; }
  88. /// <summary>
  89. /// Gets or sets the type.
  90. /// Required, Max length = 256.
  91. /// </summary>
  92. [Required]
  93. [MaxLength(256)]
  94. [StringLength(256)]
  95. public string Type { get; set; }
  96. /// <summary>
  97. /// Gets or sets the user id.
  98. /// Required.
  99. /// </summary>
  100. [Required]
  101. public Guid UserId { get; set; }
  102. /// <summary>
  103. /// Gets or sets the item id.
  104. /// Max length = 256.
  105. /// </summary>
  106. [MaxLength(256)]
  107. [StringLength(256)]
  108. public string ItemId { get; set; }
  109. /// <summary>
  110. /// Gets or sets the date created. This should be in UTC.
  111. /// Required.
  112. /// </summary>
  113. [Required]
  114. public DateTime DateCreated { get; set; }
  115. /// <summary>
  116. /// Gets or sets the log severity. Default is <see cref="LogLevel.Trace"/>.
  117. /// Required.
  118. /// </summary>
  119. [Required]
  120. public LogLevel LogSeverity { get; set; }
  121. /// <summary>
  122. /// Gets or sets the row version.
  123. /// Required, ConcurrencyToken.
  124. /// </summary>
  125. [ConcurrencyCheck]
  126. [Required]
  127. public uint RowVersion { get; set; }
  128. partial void Init();
  129. /// <inheritdoc />
  130. public void OnSavingChanges()
  131. {
  132. RowVersion++;
  133. }
  134. }
  135. }