jellyfin/Jellyfin.Data/Entities/ActivityLog.cs

143 lines
4 KiB
C#
Raw Normal View History

2020-05-03 00:32:22 +02:00
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Jellyfin.Data.Interfaces;
2020-05-13 21:03:35 +02:00
using Microsoft.Extensions.Logging;
2020-05-03 00:32:22 +02:00
namespace Jellyfin.Data.Entities
{
2020-05-14 23:13:45 +02:00
/// <summary>
/// An entity referencing an activity log entry.
/// </summary>
2020-09-01 17:12:31 +02:00
public class ActivityLog : IHasConcurrencyToken
2020-05-03 00:32:22 +02:00
{
/// <summary>
2020-05-14 23:13:45 +02:00
/// Initializes a new instance of the <see cref="ActivityLog"/> class.
/// Public constructor with required data.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-05-14 23:13:45 +02:00
/// <param name="name">The name.</param>
/// <param name="type">The type.</param>
/// <param name="userId">The user id.</param>
/// <param name="logLevel">The log level.</param>
public ActivityLog(string name, string type, Guid userId, LogLevel logLevel = LogLevel.Information)
2020-05-03 00:32:22 +02:00
{
2020-05-13 21:03:35 +02:00
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException(nameof(name));
}
2020-05-03 00:32:22 +02:00
2020-05-13 21:03:35 +02:00
if (string.IsNullOrEmpty(type))
{
throw new ArgumentNullException(nameof(type));
}
2020-05-03 00:32:22 +02:00
2020-09-01 17:12:31 +02:00
Name = name;
Type = type;
UserId = userId;
DateCreated = DateTime.UtcNow;
LogSeverity = logLevel;
2020-05-03 00:32:22 +02:00
}
2020-05-14 23:13:45 +02:00
/// <summary>
/// Initializes a new instance of the <see cref="ActivityLog"/> class.
/// Default constructor. Protected due to required properties, but present because EF needs it.
/// </summary>
protected ActivityLog()
{
2020-05-03 00:32:22 +02:00
}
/// <summary>
2020-05-15 18:51:18 +02:00
/// Gets or sets the identity of this instance.
2020-05-14 23:13:45 +02:00
/// This is the key in the backing database.
2020-05-03 00:32:22 +02:00
/// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; protected set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the name.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Required, Max length = 512.
/// </remarks>
2020-05-03 00:32:22 +02:00
[Required]
[MaxLength(512)]
[StringLength(512)]
public string Name { get; set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the overview.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Max length = 512.
/// </remarks>
2020-05-03 00:32:22 +02:00
[MaxLength(512)]
[StringLength(512)]
public string Overview { get; set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the short overview.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Max length = 512.
/// </remarks>
2020-05-03 00:32:22 +02:00
[MaxLength(512)]
[StringLength(512)]
public string ShortOverview { get; set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the type.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Required, Max length = 256.
/// </remarks>
2020-05-03 00:32:22 +02:00
[Required]
[MaxLength(256)]
[StringLength(256)]
public string Type { get; set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the user id.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Required.
/// </remarks>
2020-05-03 00:32:22 +02:00
public Guid UserId { get; set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the item id.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Max length = 256.
/// </remarks>
2020-05-03 00:32:22 +02:00
[MaxLength(256)]
[StringLength(256)]
public string ItemId { get; set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the date created. This should be in UTC.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Required.
/// </remarks>
2020-05-03 00:32:22 +02:00
public DateTime DateCreated { get; set; }
/// <summary>
2020-05-14 23:13:45 +02:00
/// Gets or sets the log severity. Default is <see cref="LogLevel.Trace"/>.
2020-05-03 00:32:22 +02:00
/// </summary>
2020-09-01 17:12:31 +02:00
/// <remarks>
/// Required.
/// </remarks>
2020-05-13 21:03:35 +02:00
public LogLevel LogSeverity { get; set; }
2020-05-03 00:32:22 +02:00
2020-09-01 17:12:31 +02:00
/// <inheritdoc />
2020-05-03 00:32:22 +02:00
[ConcurrencyCheck]
public uint RowVersion { get; set; }
2020-05-14 23:13:45 +02:00
/// <inheritdoc />
2020-05-03 00:32:22 +02:00
public void OnSavingChanges()
{
RowVersion++;
}
}
}