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