props/Props/Services/Textual/CachedTextualManager.cs
Harrison Deng 38ffb3c7e1 Added logging to module framework
Implemented logging to Adafruit and changed database loading behavior.
2021-08-07 17:20:46 -05:00

29 lines
861 B
C#

using System.IO;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using Props.Options;
namespace Props.Services.Content
{
public class CachedTextualManager<TPage> : ITextualManager<TPage>
{
private dynamic data;
private readonly TextualOptions options;
private readonly string fileName;
dynamic ITextualManager<TPage>.Json
{
get
{
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(options.Dir, fileName)));
return data;
}
}
public CachedTextualManager(IConfiguration configuration)
{
this.options = configuration.GetSection(TextualOptions.Textual).Get<TextualOptions>();
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
}
}
}