2016-11-18 08:39:20 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2019-01-06 15:00:30 +00:00
|
|
|
using System.Threading.Tasks;
|
2016-11-18 08:39:20 +00:00
|
|
|
using MediaBrowser.Model.Activity;
|
2019-01-06 15:00:30 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2016-11-18 08:39:20 +00:00
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.Activity
|
|
|
|
{
|
2019-01-06 15:00:30 +00:00
|
|
|
public class ActivityRepository : DbContext, IActivityRepository
|
2016-11-18 08:39:20 +00:00
|
|
|
{
|
2019-01-06 15:00:30 +00:00
|
|
|
protected string _dataDirPath;
|
2016-11-18 08:39:20 +00:00
|
|
|
|
2019-01-06 15:00:30 +00:00
|
|
|
public DbSet<ActivityLogEntry> ActivityLogs { get; set; }
|
2016-11-18 08:39:20 +00:00
|
|
|
|
2019-01-06 15:00:30 +00:00
|
|
|
public ActivityRepository(string dataDirPath)
|
2017-09-22 05:54:57 +00:00
|
|
|
{
|
2019-01-06 15:00:30 +00:00
|
|
|
_dataDirPath = dataDirPath;
|
2017-09-22 05:54:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-06 15:00:30 +00:00
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
2016-11-18 08:39:20 +00:00
|
|
|
{
|
2019-01-06 15:00:30 +00:00
|
|
|
// Ensure the dir exists
|
|
|
|
if (!Directory.Exists(_dataDirPath)) Directory.CreateDirectory(_dataDirPath);
|
2016-11-18 08:39:20 +00:00
|
|
|
|
2019-01-06 15:00:30 +00:00
|
|
|
optionsBuilder.UseSqlite($"Filename={Path.Combine(_dataDirPath, "activitylog.sqlite.db")}");
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-06 15:00:30 +00:00
|
|
|
public async Task CreateAsync(ActivityLogEntry entry)
|
2016-11-18 08:39:20 +00:00
|
|
|
{
|
2019-01-06 15:00:30 +00:00
|
|
|
await ActivityLogs.AddAsync(entry);
|
|
|
|
await SaveChangesAsync();
|
2016-11-18 08:39:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-06 15:00:30 +00:00
|
|
|
public IQueryable<ActivityLogEntry> GetActivityLogEntries()
|
|
|
|
=> ActivityLogs;
|
2016-11-18 08:39:20 +00:00
|
|
|
}
|
|
|
|
}
|