mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 16:33:43 -04:00
Rework JournalHandler Again
Reduce Code Dupe Finished ModulesInfo Started ShipLocker
This commit is contained in:
@ -4,21 +4,47 @@ using Observatory.Framework.Files;
|
||||
|
||||
public interface IModulesInfoService : IJournalHandler<ModuleInfoFile>;
|
||||
|
||||
public class ModulesInfoService : IModulesInfoService
|
||||
public class ModulesInfoService(
|
||||
ILogger<ModulesInfoService> logger,
|
||||
IOptions<PulsarConfiguration> options,
|
||||
IEventHubContext hub)
|
||||
: JournalHandlerBase<ModuleInfoFile>(logger), IModulesInfoService
|
||||
{
|
||||
public string FileName => FileHandlerService.ModulesInfoFileName;
|
||||
public Task HandleFile(string filePath)
|
||||
public override string FileName => FileHandlerService.ModulesInfoFileName;
|
||||
|
||||
public override async Task HandleFile(string filePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool ValidateFile(string filePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (!ValidateFile(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var file = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
var moduleInfo = await JsonSerializer.DeserializeAsync<ModuleInfoFile>(file);
|
||||
|
||||
if (moduleInfo == null)
|
||||
{
|
||||
logger.LogWarning("Failed to deserialize status file {FilePath}", filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
await hub.Clients.All.ModuleInfoUpdated(moduleInfo);
|
||||
}
|
||||
|
||||
public Task<ModuleInfoFile> Get()
|
||||
public override async Task<ModuleInfoFile> Get()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var moduleInfoFile = Path.Combine(options.Value.JournalDirectory, FileName);
|
||||
|
||||
if (!ValidateFile(moduleInfoFile))
|
||||
{
|
||||
return new ModuleInfoFile();
|
||||
}
|
||||
|
||||
await using var file = File.Open(moduleInfoFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
var moduleInfo = await JsonSerializer.DeserializeAsync<ModuleInfoFile>(file);
|
||||
if (moduleInfo != null) return moduleInfo;
|
||||
|
||||
logger.LogWarning("Failed to deserialize module info file {ModuleInfoFile}", moduleInfoFile);
|
||||
return new ModuleInfoFile();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user