ActivityLog.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Jellyfin.Data.Interfaces;
  5. using Microsoft.Extensions.Logging;
  6. namespace Jellyfin.Data.Entities
  7. {
  8. /// <summary>
  9. /// An entity referencing an activity log entry.
  10. /// </summary>
  11. public class ActivityLog : IHasConcurrencyToken
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="ActivityLog"/> class.
  15. /// Public constructor with required data.
  16. /// </summary>
  17. /// <param name="name">The name.</param>
  18. /// <param name="type">The type.</param>
  19. /// <param name="userId">The user id.</param>
  20. public ActivityLog(string name, string type, Guid userId)
  21. {
  22. if (string.IsNullOrEmpty(name))
  23. {
  24. throw new ArgumentNullException(nameof(name));
  25. }
  26. if (string.IsNullOrEmpty(type))
  27. {
  28. throw new ArgumentNullException(nameof(type));
  29. }
  30. Name = name;
  31. Type = type;
  32. UserId = userId;
  33. DateCreated = DateTime.UtcNow;
  34. LogSeverity = LogLevel.Trace;
  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. }
  43. /// <summary>
  44. /// Gets or sets the identity of this instance.
  45. /// This is the key in the backing database.
  46. /// </summary>
  47. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  48. public int Id { get; protected set; }
  49. /// <summary>
  50. /// Gets or sets the name.
  51. /// </summary>
  52. /// <remarks>
  53. /// Required, Max length = 512.
  54. /// </remarks>
  55. [Required]
  56. [MaxLength(512)]
  57. [StringLength(512)]
  58. public string Name { get; set; }
  59. /// <summary>
  60. /// Gets or sets the overview.
  61. /// </summary>
  62. /// <remarks>
  63. /// Max length = 512.
  64. /// </remarks>
  65. [MaxLength(512)]
  66. [StringLength(512)]
  67. public string Overview { get; set; }
  68. /// <summary>
  69. /// Gets or sets the short overview.
  70. /// </summary>
  71. /// <remarks>
  72. /// Max length = 512.
  73. /// </remarks>
  74. [MaxLength(512)]
  75. [StringLength(512)]
  76. public string ShortOverview { get; set; }
  77. /// <summary>
  78. /// Gets or sets the type.
  79. /// </summary>
  80. /// <remarks>
  81. /// Required, Max length = 256.
  82. /// </remarks>
  83. [Required]
  84. [MaxLength(256)]
  85. [StringLength(256)]
  86. public string Type { get; set; }
  87. /// <summary>
  88. /// Gets or sets the user id.
  89. /// </summary>
  90. /// <remarks>
  91. /// Required.
  92. /// </remarks>
  93. public Guid UserId { get; set; }
  94. /// <summary>
  95. /// Gets or sets the item id.
  96. /// </summary>
  97. /// <remarks>
  98. /// Max length = 256.
  99. /// </remarks>
  100. [MaxLength(256)]
  101. [StringLength(256)]
  102. public string ItemId { get; set; }
  103. /// <summary>
  104. /// Gets or sets the date created. This should be in UTC.
  105. /// </summary>
  106. /// <remarks>
  107. /// Required.
  108. /// </remarks>
  109. public DateTime DateCreated { get; set; }
  110. /// <summary>
  111. /// Gets or sets the log severity. Default is <see cref="LogLevel.Trace"/>.
  112. /// </summary>
  113. /// <remarks>
  114. /// Required.
  115. /// </remarks>
  116. public LogLevel LogSeverity { get; set; }
  117. /// <inheritdoc />
  118. [ConcurrencyCheck]
  119. public uint RowVersion { get; set; }
  120. /// <inheritdoc />
  121. public void OnSavingChanges()
  122. {
  123. RowVersion++;
  124. }
  125. }
  126. }