namespace Pulsar.Features.Cargo; using Observatory.Framework.Files; public interface ICargoService : IJournalHandler; public class CargoService(IOptions options, ILogger logger, IEventHubContext hub) : ICargoService { public string FileName => "Cargo.json"; public async Task HandleFile(string filePath) { if (!FileHelper.ValidateFile(filePath)) { return; } var file = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var moduleInfo = await JsonSerializer.DeserializeAsync(file); if (moduleInfo == null) { logger.LogWarning("Failed to deserialize status file {FilePath}", filePath); return; } await hub.Clients.All.CargoUpdated(moduleInfo); } public async Task Get() { var cargoFile = Path.Combine(options.Value.JournalDirectory, FileName); if (!FileHelper.ValidateFile(cargoFile)) { return new CargoFile(); } await using var file = File.Open(cargoFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var cargo = await JsonSerializer.DeserializeAsync(file); if (cargo != null) return cargo; logger.LogWarning("Failed to deserialize module info file {CargoFile}", cargoFile); return new CargoFile(); } }