private static void SetJs(string relativeUrl, JsRenderPlan plan) { lock (_locker) { cache[relativeUrl] = plan; } }
public static RenderRespnose RenderJs(CommandDiskSourceProvider sourceProvider, RenderOption option, RenderContext context, string RelativeUrl) { var fullname = sourceProvider.GetFullFileName(context, RelativeUrl); if (string.IsNullOrEmpty(fullname)) { return(new RenderRespnose() { Body = null }); } if (option.EnableMultilingual && RelativeUrl.ToLower().EndsWith(option.MultilingualJsFile)) { return(RenderJsLangFile(fullname, context)); } System.IO.FileInfo info = new System.IO.FileInfo(fullname); if (info != null && info.LastWriteTime != null) { JsRenderPlan renderplan = null; Guid hash = Lib.Security.Hash.ComputeGuidIgnoreCase(info.LastWriteTime.ToLongTimeString()); var cacheplan = GetJs(RelativeUrl); if (cacheplan != null && cacheplan.Hash == hash) { renderplan = cacheplan; } //either not key found not hash not the same. if (renderplan == null) { string fulltext = VirtualResources.ReadAllText(fullname); renderplan = new JsRenderPlan(); renderplan.Tasks = GetJsRenderPlan(fulltext); renderplan.Hash = hash; SetJs(RelativeUrl, renderplan); } if (renderplan != null) { string result = string.Empty; foreach (var task in renderplan.Tasks) { result += task.Render(sourceProvider, option, context, RelativeUrl); } return(new RenderRespnose() { Body = result, ContentType = "application/javascript" }); } } else { return(new RenderRespnose() { Body = null }); } return(new RenderRespnose() { Body = null }); }