ActivityLog.cs 4.5 KB

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