mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 08:23:42 -04:00
Rework JournalHandler Again
Reduce Code Dupe Finished ModulesInfo Started ShipLocker
This commit is contained in:
@ -8,7 +8,7 @@ namespace Pulsar.Features;
|
||||
public interface IJournalHandler : IFileHandler
|
||||
{
|
||||
string FileName { get; }
|
||||
Task HandleFile(string filePath);
|
||||
|
||||
public bool ValidateFile(string filePath);
|
||||
}
|
||||
|
||||
@ -20,4 +20,39 @@ public interface IJournalHandler<T> : IJournalHandler
|
||||
where T: IJournal
|
||||
{
|
||||
Task<T> Get();
|
||||
}
|
||||
|
||||
public abstract class JournalHandlerBase<T>(ILogger logger) : IJournalHandler<T>
|
||||
where T: IJournal
|
||||
{
|
||||
public abstract string FileName { get; }
|
||||
|
||||
public abstract Task HandleFile(string filePath);
|
||||
|
||||
public bool ValidateFile(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
logger.LogWarning("Journal file {JournalFile} does not exist", filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
var fileInfo = new FileInfo(filePath);
|
||||
|
||||
if (!string.Equals(fileInfo.Name, FileName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
logger.LogWarning("Journal file {JournalFile} is not a {NameOfCurrentHandler} file", filePath, nameof(T));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fileInfo.Length == 0)
|
||||
{
|
||||
logger.LogWarning("Journal file {JournalFile} is empty", filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract Task<T> Get();
|
||||
}
|
Reference in New Issue
Block a user