Add a Scoped RepositoryCache that memoizes deserialized XML lists, keyed by absolute file path. Each XML file is loaded at most once per SignalR circuit; Save invalidates the corresponding entry so subsequent reads reload from disk. BaseRepository gains a LoadList<T>(fileName) helper; each of the seven repositories now defines Get*List() as a one-liner over that helper and takes RepositoryCache via the constructor. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Schaad.Accounting.Interfaces;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Repositories
|
|
{
|
|
public class SplitPredefinitionRepository : BaseRepository, ISplitPredefinitionRepository
|
|
{
|
|
private readonly string SPLIT_PREDEFINITION = "SplitPredefinitions.xml";
|
|
|
|
public SplitPredefinitionRepository(ISettingsService settingsService, RepositoryCache cache)
|
|
: base(settingsService, cache)
|
|
{
|
|
EnsureFileExists(SPLIT_PREDEFINITION);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load split predefinitions
|
|
/// </summary>
|
|
public List<SplitPredefinition> GetSplitPredefinitionList() => LoadList<SplitPredefinition>(SPLIT_PREDEFINITION);
|
|
|
|
/// <summary>
|
|
/// Save a split predefinition (insert/update)
|
|
/// </summary>
|
|
public void SaveSplitPredefinition(SplitPredefinition splitPredefinition)
|
|
{
|
|
var definitions = GetSplitPredefinitionList();
|
|
var existingDefinition = definitions.FirstOrDefault(a => a.Id == splitPredefinition.Id);
|
|
|
|
if (existingDefinition == null)
|
|
{
|
|
existingDefinition = new SplitPredefinition();
|
|
definitions.Add(existingDefinition);
|
|
splitPredefinition.Id = Guid.NewGuid().ToString();
|
|
}
|
|
splitPredefinition.Copy(existingDefinition);
|
|
Save(definitions, SPLIT_PREDEFINITION);
|
|
}
|
|
}
|
|
}
|