private string GetPathFromSpecificName(ControllerArgs controllerContext, ViewType viewType, string name) { var virtualPath = name; if (!FileExists(controllerContext, name)) { throw new Exception(virtualPath); } ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, controllerContext.GetChacheKey(viewType, name), virtualPath); return(virtualPath); }
private string GetPath(ControllerArgs controllerContext, ViewType viewType, string name, bool useCache) { if (string.IsNullOrEmpty(name)) { throw new Exception("Имя вида не задано"); } if (!useCache) { return(IsSpecificPath(name) ? GetPathFromSpecificName(controllerContext, viewType, name) : GetPathFromGeneralName(controllerContext, viewType, name)); } string key = controllerContext.GetChacheKey(viewType, name); var viewLocation = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, key); return(viewLocation ?? (IsSpecificPath(name) ? GetPathFromSpecificName(controllerContext, viewType, name) : GetPathFromGeneralName(controllerContext, viewType, name))); }
private string GetPathFromGeneralName(ControllerArgs controllerContext, ViewType viewType, string name) { var virtualPath = string.Empty; var locations = ViewLocations.Where(x => x.ViewType == viewType).ToList(); if ((locations == null) || (locations.Count == 0)) { throw new InvalidOperationException("locations must not be null or emtpy."); } List <string> sl = new List <string>(locations.Count); foreach (var loc in locations) { virtualPath = loc.GetPath(controllerContext, name); if (FileExists(controllerContext, virtualPath)) { ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, controllerContext.GetChacheKey(viewType, name), virtualPath); return(virtualPath); } sl.Add(virtualPath); } var str = string.Join("\n", sl); throw new DirectoryNotFoundException(str); }