ActivityLog.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.Information;
  35. }
  36. /// <summary>
  37. /// Gets the identity of this instance.
  38. /// </summary>
  39. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  40. public int Id { get; private set; }
  41. /// <summary>
  42. /// Gets or sets the name.
  43. /// </summary>
  44. /// <remarks>
  45. /// Required, Max length = 512.
  46. /// </remarks>
  47. [MaxLength(512)]
  48. [StringLength(512)]
  49. public string Name { get; set; }
  50. /// <summary>
  51. /// Gets or sets the overview.
  52. /// </summary>
  53. /// <remarks>
  54. /// Max length = 512.
  55. /// </remarks>
  56. [MaxLength(512)]
  57. [StringLength(512)]
  58. public string? Overview { get; set; }
  59. /// <summary>
  60. /// Gets or sets the short overview.
  61. /// </summary>
  62. /// <remarks>
  63. /// Max length = 512.
  64. /// </remarks>
  65. [MaxLength(512)]
  66. [StringLength(512)]
  67. public string? ShortOverview { get; set; }
  68. /// <summary>
  69. /// Gets or sets the type.
  70. /// </summary>
  71. /// <remarks>
  72. /// Required, Max length = 256.
  73. /// </remarks>
  74. [MaxLength(256)]
  75. [StringLength(256)]
  76. public string Type { get; set; }
  77. /// <summary>
  78. /// Gets or sets the user id.
  79. /// </summary>
  80. /// <remarks>
  81. /// Required.
  82. /// </remarks>
  83. public Guid UserId { get; set; }
  84. /// <summary>
  85. /// Gets or sets the item id.
  86. /// </summary>
  87. /// <remarks>
  88. /// Max length = 256.
  89. /// </remarks>
  90. [MaxLength(256)]
  91. [StringLength(256)]
  92. public string? ItemId { get; set; }
  93. /// <summary>
  94. /// Gets or sets the date created. This should be in UTC.
  95. /// </summary>
  96. /// <remarks>
  97. /// Required.
  98. /// </remarks>
  99. public DateTime DateCreated { get; set; }
  100. /// <summary>
  101. /// Gets or sets the log severity. Default is <see cref="LogLevel.Trace"/>.
  102. /// </summary>
  103. /// <remarks>
  104. /// Required.
  105. /// </remarks>
  106. public LogLevel LogSeverity { get; set; }
  107. /// <inheritdoc />
  108. [ConcurrencyCheck]
  109. public uint RowVersion { get; private set; }
  110. /// <inheritdoc />
  111. public void OnSavingChanges()
  112. {
  113. RowVersion++;
  114. }
  115. }
  116. }