mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-21 15:54:06 +02:00
.config
.run
.workdir
Agent
Common
Controller
Phantom.Controller
Phantom.Controller.Database
Converters
Entities
Factories
Repositories
AuditLogRepository.Writer.cs
AuditLogRepository.cs
EventLogRepository.cs
PermissionRepository.cs
RoleRepository.cs
UserRepository.cs
UserRoleRepository.cs
ApplicationDbContext.cs
DatabaseMigrator.cs
IDbContextProvider.cs
ILazyDbContext.cs
Phantom.Controller.Database.csproj
Phantom.Controller.Database.Postgres
Phantom.Controller.Minecraft
Phantom.Controller.Services
Docker
Utils
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
32 lines
1.3 KiB
C#
32 lines
1.3 KiB
C#
using System.Collections.Immutable;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Phantom.Common.Data.Web.EventLog;
|
|
using Phantom.Controller.Database.Entities;
|
|
using Phantom.Utils.Collections;
|
|
|
|
namespace Phantom.Controller.Database.Repositories;
|
|
|
|
public sealed class EventLogRepository {
|
|
private readonly ILazyDbContext db;
|
|
|
|
public EventLogRepository(ILazyDbContext db) {
|
|
this.db = db;
|
|
}
|
|
|
|
public void AddItem(Guid eventGuid, DateTime utcTime, Guid? agentGuid, EventLogEventType eventType, string subjectId, Dictionary<string, object?>? extra = null) {
|
|
db.Ctx.EventLog.Add(new EventLogEntity(eventGuid, utcTime, agentGuid, eventType, subjectId, extra));
|
|
}
|
|
|
|
public Task<ImmutableArray<EventLogItem>> GetMostRecentItems(ImmutableHashSet<Guid> agentGuids, int count, CancellationToken cancellationToken) {
|
|
return db.Ctx
|
|
.EventLog
|
|
.AsQueryable()
|
|
.OrderByDescending(static entity => entity.UtcTime)
|
|
.Where(entity => entity.AgentGuid == null || agentGuids.Contains(entity.AgentGuid.Value))
|
|
.Take(count)
|
|
.AsAsyncEnumerable()
|
|
.Select(static entity => new EventLogItem(entity.UtcTime, entity.AgentGuid, entity.EventType, entity.SubjectType, entity.SubjectId, entity.Data?.RootElement.ToString()))
|
|
.ToImmutableArrayAsync(cancellationToken);
|
|
}
|
|
}
|