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