ActivityLog.cs 4.5 KB

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