LANCommander/LANCommander.Server.Services/ScriptService.cs

45 lines
1.5 KiB
C#
Raw Normal View History

2024-08-04 18:44:33 -05:00
using LANCommander.Server.Data;
using LANCommander.Server.Data.Models;
using LANCommander.Server.Models;
using Microsoft.Extensions.Logging;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using ZiggyCreatures.Caching.Fusion;
2024-08-04 18:44:33 -05:00
namespace LANCommander.Server.Services
{
public sealed class ScriptService(
ILogger<ScriptService> logger,
IFusionCache cache,
IMapper mapper,
IDbContextFactory<DatabaseContext> contextFactory) : BaseDatabaseService<Script>(logger, cache, mapper, contextFactory)
{
2025-02-02 14:58:07 -06:00
public async override Task<Script> UpdateAsync(Script entity)
{
2025-02-02 14:58:07 -06:00
return await base.UpdateAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(s => s.Game);
await context.UpdateRelationshipAsync(s => s.Redistributable);
await context.UpdateRelationshipAsync(s => s.Server);
});
}
public static IEnumerable<Snippet> GetSnippets()
{
var files = Directory.GetFiles(@"Snippets", "*.ps1", SearchOption.AllDirectories);
return files.Select(f =>
{
2023-12-04 18:30:34 +01:00
var split = f.Split(Path.DirectorySeparatorChar);
return new Snippet()
{
Name = Path.GetFileNameWithoutExtension(f),
Group = split[1],
Content = File.ReadAllText(f)
};
});
}
}
}