2021-07-20 19:08:57 -05:00
|
|
|
using System.IO;
|
2021-07-24 02:33:43 -05:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2021-07-20 19:08:57 -05:00
|
|
|
using Newtonsoft.Json.Linq;
|
2021-07-24 02:33:43 -05:00
|
|
|
using Props.Options;
|
2021-07-20 19:08:57 -05:00
|
|
|
|
2021-07-21 01:58:49 -05:00
|
|
|
namespace Props.Services.Content
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
2021-08-07 17:20:46 -05:00
|
|
|
public class CachedTextualManager<TPage> : ITextualManager<TPage>
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
|
|
|
private dynamic data;
|
2021-08-07 17:20:46 -05:00
|
|
|
private readonly TextualOptions options;
|
2021-07-20 19:08:57 -05:00
|
|
|
private readonly string fileName;
|
|
|
|
|
2021-08-07 17:20:46 -05:00
|
|
|
dynamic ITextualManager<TPage>.Json
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2021-07-24 02:33:43 -05:00
|
|
|
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(options.Dir, fileName)));
|
2021-07-20 19:08:57 -05:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-07 17:20:46 -05:00
|
|
|
public CachedTextualManager(IConfiguration configuration)
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
2021-08-07 17:20:46 -05:00
|
|
|
this.options = configuration.GetSection(TextualOptions.Textual).Get<TextualOptions>();
|
2021-07-22 16:12:27 -05:00
|
|
|
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
|
2021-07-20 19:08:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|