jellyfin/Jellyfin.Data/Entities/ActivityLog.cs

142 lines
3.9 KiB
C#
Raw Normal View History

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