public Template Parse(ViewLocationResult location) { var contextKey = "vc-cms-file-" + location.Location; var value = HttpRuntime.Cache.Get(contextKey); if (value != null) { return value as Template; } if (location.Contents == null) return null; var contents = location.Contents; var template = Template.Parse(contents); var path = HostingEnvironment.MapPath(_baseDirectoryPath); var allDirectories = Directory.GetDirectories(path, "*", SearchOption.AllDirectories); HttpRuntime.Cache.Insert(contextKey, template, new CacheDependency(allDirectories)); return template; }
private ViewLocationResult FindView(IEnumerable<string> locations, string viewName, string fileNameFormat = "{0}", bool throwException = false) { var checkedLocations = new List<string>(); var viewFound = false; var context = new HttpContextWrapper(HttpContext.Current); var viewNameWithExtension = string.Format(fileNameFormat, viewName); ViewLocationResult foundView = null; var cacheKey = String.Format("{0}-{1}", this.ThemeDirectory, viewNameWithExtension); // check cache first foundView = ViewLocationCache.GetViewLocation(context, cacheKey) as ViewLocationResult; if (foundView != null) return foundView; foreach (var fullPath in locations.Select(viewLocation => Combine(this._baseDirectoryPath, this.ThemeDirectory, viewLocation, viewNameWithExtension))) { var file = VirtualPathProviderHelper.GetFile(fullPath); if (file != null) { foundView = new FileViewLocationResult(file, file.VirtualPath); viewFound = true; break; } checkedLocations.Add(fullPath); } // now search in global location // App_Data/Themes/_Global if (!viewFound) { foreach (var fullPath in locations.Select( viewLocation => Combine(this._baseDirectoryPath, "_global", viewLocation, viewNameWithExtension))) { var file = VirtualPathProviderHelper.GetFile(fullPath); if (file != null) { foundView = new FileViewLocationResult(file, file.VirtualPath); viewFound = true; break; } checkedLocations.Add(Path.Combine(this._baseDirectoryPath, fullPath)); } } if (foundView == null /*!viewFound && throwException*/) { foundView = new ViewLocationResult(checkedLocations.ToArray()); } ViewLocationCache.InsertViewLocation(context, cacheKey, foundView); return foundView; }