mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-02 00:43:42 -04:00
Fix issues with Journal handling
Implement basic database Handle startup events only send events after the most recent LoadGame
This commit is contained in:
46
Pulsar/Features/NavRoute/NavRouteService.cs
Normal file
46
Pulsar/Features/NavRoute/NavRouteService.cs
Normal file
@ -0,0 +1,46 @@
|
||||
namespace Pulsar.Features.NavRoute;
|
||||
|
||||
using Observatory.Framework.Files;
|
||||
|
||||
public interface INavRouteService : IJournalHandler<NavRouteFile>;
|
||||
|
||||
public class NavRouteService(IOptions<PulsarConfiguration> options, ILogger<NavRouteService> logger, IEventHubContext hub) : INavRouteService
|
||||
{
|
||||
public async Task<NavRouteFile> Get()
|
||||
{
|
||||
var navRouteFile = Path.Combine(options.Value.JournalDirectory, FileName);
|
||||
|
||||
if (!FileHelper.ValidateFile(navRouteFile))
|
||||
{
|
||||
return new NavRouteFile();
|
||||
}
|
||||
|
||||
await using var file = File.Open(navRouteFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
var shipLocker = await JsonSerializer.DeserializeAsync<NavRouteFile>(file);
|
||||
if (shipLocker != null) return shipLocker;
|
||||
|
||||
logger.LogWarning("Failed to deserialize nav route file {ShipLockerFile}", navRouteFile);
|
||||
return new NavRouteFile();
|
||||
}
|
||||
|
||||
public async Task HandleFile(string path, CancellationToken token = new ())
|
||||
{
|
||||
if (!FileHelper.ValidateFile(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var file = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
var navRoute = await JsonSerializer.DeserializeAsync<NavRouteFile>(file, cancellationToken: token);
|
||||
|
||||
if (navRoute == null)
|
||||
{
|
||||
logger.LogWarning("Failed to deserialize nav route {FilePath}", file);
|
||||
return;
|
||||
}
|
||||
|
||||
await hub.Clients.All.NavRouteUpdated(navRoute);
|
||||
}
|
||||
|
||||
public string FileName => FileHandlerService.NavRouteFileName;
|
||||
}
|
Reference in New Issue
Block a user