LANCommander/LANCommander.Server.Services/ServerLogService.cs

50 lines
1.7 KiB
C#
Raw Normal View History

using CoreRCON;
2024-08-12 00:15:16 -05:00
using LANCommander.SDK.Enums;
2024-08-04 18:44:33 -05:00
using LANCommander.Server.Data;
using LANCommander.Server.Data.Models;
using Microsoft.Extensions.Logging;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using ZiggyCreatures.Caching.Fusion;
2023-08-17 19:06:23 -05:00
2024-08-04 18:44:33 -05:00
namespace LANCommander.Server.Services
2023-08-17 19:06:23 -05:00
{
public sealed class ServerConsoleService(
ILogger<ServerConsoleService> logger,
SettingsProvider<Settings.Settings> settingsProvider,
IFusionCache cache,
IMapper mapper,
IHttpContextAccessor httpContextAccessor,
IDbContextFactory<DatabaseContext> contextFactory) : BaseDatabaseService<ServerConsole>(logger, settingsProvider, cache, mapper, httpContextAccessor, contextFactory)
2023-08-17 19:06:23 -05:00
{
2025-02-23 08:49:43 -06:00
public override async Task<ServerConsole> AddAsync(ServerConsole entity)
{
return await base.AddAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(sc => sc.Server);
});
}
2025-02-02 14:58:07 -06:00
public override async Task<ServerConsole> UpdateAsync(ServerConsole entity)
{
2025-02-02 14:58:07 -06:00
return await base.UpdateAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(sc => sc.Server);
});
}
public async Task<string[]> ReadLogAsync(Guid logId)
2023-08-17 19:06:23 -05:00
{
var log = await GetAsync(logId);
2023-08-17 19:06:23 -05:00
if (log.Type != ServerConsoleType.LogFile)
throw new Exception("Invalid console type");
2023-08-17 19:06:23 -05:00
var logPath = Path.Combine(log.Server.WorkingDirectory, log.Path);
return await File.ReadAllLinesAsync(logPath);
}
}
}