mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 16:33:43 -04:00
Add Shipyard & Fix ShipLocker
Update File handling Update Journal handling Update README.md
This commit is contained in:
47
Pulsar/Features/Shipyard/ShipyardService.cs
Normal file
47
Pulsar/Features/Shipyard/ShipyardService.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Observatory.Framework.Files;
|
||||
|
||||
namespace Pulsar.Features.Shipyard;
|
||||
|
||||
public interface IShipyardService : IJournalHandler<ShipyardFile>;
|
||||
|
||||
public class ShipyardService(ILogger<ShipyardService> logger, IOptions<PulsarConfiguration> options,
|
||||
IEventHubContext hub) : IShipyardService
|
||||
{
|
||||
public string FileName => FileHandlerService.ShipyardFileName;
|
||||
public async Task<ShipyardFile> Get()
|
||||
{
|
||||
var shipyardFile = Path.Combine(options.Value.JournalDirectory, FileName);
|
||||
|
||||
if (!FileHelper.ValidateFile(shipyardFile))
|
||||
{
|
||||
return new ShipyardFile();
|
||||
}
|
||||
|
||||
await using var file = File.Open(shipyardFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
var shipyard = await JsonSerializer.DeserializeAsync<ShipyardFile>(file);
|
||||
if (shipyard != null) return shipyard;
|
||||
|
||||
logger.LogWarning("Failed to deserialize shipyard file {ShipyardFile}", shipyardFile);
|
||||
return new ShipyardFile();
|
||||
}
|
||||
|
||||
public async Task HandleFile(string path)
|
||||
{
|
||||
if (!FileHelper.ValidateFile(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var file = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
var shipyard = await JsonSerializer.DeserializeAsync<ShipyardFile>(file);
|
||||
|
||||
if (shipyard == null)
|
||||
{
|
||||
logger.LogWarning("Failed to deserialize status file {FilePath}", path);
|
||||
return;
|
||||
}
|
||||
|
||||
await hub.Clients.All.ShipyardUpdated(shipyard);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user