private string LoadFromExternal(string viewKey, string filename) { if (viewCache.TryFind(viewKey, out var viewData)) { return(viewData); } if (Path.DirectorySeparatorChar != '\\') { filename = filename.Replace("\\", Path.DirectorySeparatorChar.ToString()); } filename = Path.GetFullPath(filename); var fileInfo = new FileInfo(filename); if (!fileInfo.Exists) { throw new ApplicationException($"External View '{filename}' could not be found!"); } var lastWrite = fileInfo.LastWriteTimeUtc; var view = new CachedView { IsExpiredFunc = () => File.GetLastWriteTimeUtc(filename) != lastWrite, }; using (var stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new StreamReader(stream)) { view.Data = reader.ReadToEnd(); } viewCache.Update(viewKey, view); return(view.Data); }
private string LoadFromAssembly(string viewKey, Assembly assembly, string path) { if (viewCache.TryFind(viewKey, out var viewData)) { return(viewData); } var view = new CachedView { IsExpiredFunc = () => false, }; using (var stream = assembly.GetManifestResourceStream(path)) { if (stream == null) { throw new ApplicationException($"Assembly View '{path}' could not be found!"); } using (var reader = new StreamReader(stream)) { view.Data = reader.ReadToEnd(); } } viewCache.Update(viewKey, view); return(view.Data); }
public void Update(string viewKey, CachedView view) { viewCacheList.AddOrUpdate(viewKey, k => view, (k, v) => view); }