2021-07-20 19:08:57 -05:00
|
|
|
using System.IO;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
2021-07-21 01:58:49 -05:00
|
|
|
namespace Props.Services.Content
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
2021-07-22 16:12:27 -05:00
|
|
|
public class CachedContentManager<TPage> : IContentManager<TPage>
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
|
|
|
private dynamic data;
|
|
|
|
private readonly string directory;
|
|
|
|
private readonly string fileName;
|
|
|
|
|
2021-07-22 16:12:27 -05:00
|
|
|
dynamic IContentManager<TPage>.Json
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(directory, fileName)));
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 16:12:27 -05:00
|
|
|
public CachedContentManager(string directory = "content")
|
2021-07-20 19:08:57 -05:00
|
|
|
{
|
|
|
|
this.directory = directory;
|
2021-07-22 16:12:27 -05:00
|
|
|
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
|
2021-07-20 19:08:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|