using CoreRCON; using LANCommander.SDK.Enums; using LANCommander.Server.Data; using LANCommander.Server.Data.Models; using Microsoft.Extensions.Logging; using System.Diagnostics; using System.Net; using AutoMapper; using Microsoft.EntityFrameworkCore; using ZiggyCreatures.Caching.Fusion; namespace LANCommander.Server.Services { public sealed class ServerConsoleService( ILogger logger, IFusionCache cache, IMapper mapper, IDbContextFactory contextFactory) : BaseDatabaseService(logger, cache, mapper, contextFactory) { 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); } } }