2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 08:23:42 -04:00

JournalService setup work in progress

This commit is contained in:
2024-05-07 12:02:43 +01:00
parent d59914e277
commit f3ce62b551
12 changed files with 215 additions and 85 deletions

View File

@ -8,7 +8,7 @@ namespace Pulsar.Features;
public interface IJournalHandler : IFileHandler
{
string FileName { get; }
public bool ValidateFile(string filePath);
}
@ -17,42 +17,6 @@ public interface IJournalHandler : IFileHandler
/// Only used for Controllers
/// </summary>
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();
}