wabbajack/Wabbajack.Server/DataModels/TarLog.cs

48 lines
1.2 KiB
C#
Raw Normal View History

2023-05-02 23:01:12 +00:00
using Microsoft.Extensions.Logging;
2022-02-09 18:24:31 +00:00
using Wabbajack.BuildServer;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.Server.DataModels;
public class TarLog
{
private Task<HashSet<string>> _tarKeys;
private readonly AppSettings _settings;
2023-05-02 23:01:12 +00:00
private readonly ILogger<TarLog> _logger;
2022-02-09 18:24:31 +00:00
2023-05-02 23:01:12 +00:00
public TarLog(AppSettings settings, ILogger<TarLog> logger)
2022-02-09 18:24:31 +00:00
{
_settings = settings;
2023-05-02 23:01:12 +00:00
_logger = logger;
2022-02-09 18:24:31 +00:00
Load();
}
private void Load()
{
if (_settings.TarKeyFile.ToAbsolutePath().FileExists())
{
2023-05-02 23:01:12 +00:00
_tarKeys = Task.Run(async () =>
{
var keys = await _settings.TarKeyFile.ToAbsolutePath()
.ReadAllLinesAsync()
.Select(line => line.Trim())
.ToHashSetAsync();
_logger.LogInformation("Loaded {Count} tar keys", keys.Count);
return keys;
});
2022-02-09 18:24:31 +00:00
}
else
{
_tarKeys = Task.Run(async () => new HashSet<string>());
}
2023-05-02 23:01:12 +00:00
2022-02-09 18:24:31 +00:00
}
public async Task<bool> Contains(string metricsKey)
{
return (await _tarKeys).Contains(metricsKey);
}
}