using CoreRCON; using LANCommander.SDK.Enums; using LANCommander.Server.Data; using LANCommander.Server.Data.Models; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using ZiggyCreatures.Caching.Fusion; namespace LANCommander.Server.Services { public sealed class ServerConsoleService( ILogger logger, SettingsProvider settingsProvider, IFusionCache cache, IHttpContextAccessor httpContextAccessor, IDbContextFactory contextFactory) : BaseDatabaseService(logger, settingsProvider, cache, httpContextAccessor, contextFactory) { public override async Task AddAsync(ServerConsole entity) { return await base.AddAsync(entity, async context => { await context.UpdateRelationshipAsync(sc => sc.Server); }); } public override async Task UpdateAsync(ServerConsole entity) { return await base.UpdateAsync(entity, async context => { await context.UpdateRelationshipAsync(sc => sc.Server); }); } public async Task ReadLogAsync(Guid logId) { var log = await GetAsync(logId); if (log.Type != ServerConsoleType.LogFile) throw new Exception("Invalid console type"); var logPath = Path.Combine(log.Server.WorkingDirectory, log.Path); return await File.ReadAllLinesAsync(logPath); } } }