public override SparkViewDescriptor BuildDescriptor(BuildDescriptorParams buildDescriptorParams, System.Collections.Generic.ICollection<string> searchedLocations) { var newParams = new BuildDescriptorParams(buildDescriptorParams.TargetNamespace, buildDescriptorParams.ControllerName, buildDescriptorParams.ViewName, buildDescriptorParams.MasterName, true, buildDescriptorParams.Extra); return base.BuildDescriptor(newParams, searchedLocations); }
public virtual SparkViewDescriptor BuildDescriptor(BuildDescriptorParams buildDescriptorParams, ICollection <string> searchedLocations) { var descriptor = new SparkViewDescriptor { TargetNamespace = buildDescriptorParams.TargetNamespace }; if (!LocatePotentialTemplate( PotentialViewLocations(buildDescriptorParams.ControllerName, buildDescriptorParams.ViewName, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return(null); } if (!string.IsNullOrEmpty(buildDescriptorParams.MasterName)) { if (!LocatePotentialTemplate( PotentialMasterLocations(buildDescriptorParams.MasterName, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return(null); } } else if (buildDescriptorParams.FindDefaultMaster && TrailingUseMasterName(descriptor) == null /*empty is a valid value*/) { LocatePotentialTemplate( PotentialDefaultMasterLocations(buildDescriptorParams.ControllerName, buildDescriptorParams.Extra), descriptor.Templates, null); } var trailingUseMaster = TrailingUseMasterName(descriptor); while (buildDescriptorParams.FindDefaultMaster && !string.IsNullOrEmpty(trailingUseMaster)) { if (!LocatePotentialTemplate( PotentialMasterLocations(trailingUseMaster, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return(null); } trailingUseMaster = TrailingUseMasterName(descriptor); } return(descriptor); }
public virtual SparkViewDescriptor BuildDescriptor(BuildDescriptorParams buildDescriptorParams, ICollection<string> searchedLocations) { var descriptor = new SparkViewDescriptor { TargetNamespace = buildDescriptorParams.TargetNamespace }; if (!LocatePotentialTemplate( PotentialViewLocations(buildDescriptorParams.ControllerName, buildDescriptorParams.ViewName, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return null; } if (!string.IsNullOrEmpty(buildDescriptorParams.LayoutName)) { if (!LocatePotentialTemplate( PotentialMasterLocations(buildDescriptorParams.LayoutName, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return null; } } else if (buildDescriptorParams.FindDefaultMaster && string.IsNullOrEmpty(TrailingUseMasterName(descriptor))) { LocatePotentialTemplate( PotentialDefaultMasterLocations(buildDescriptorParams.ControllerName, buildDescriptorParams.Extra), descriptor.Templates, null); } var trailingUseMaster = TrailingUseMasterName(descriptor); while (buildDescriptorParams.FindDefaultMaster && !string.IsNullOrEmpty(trailingUseMaster)) { if (!LocatePotentialTemplate( PotentialMasterLocations(trailingUseMaster, buildDescriptorParams.Extra), descriptor.Templates, searchedLocations)) { return null; } trailingUseMaster = TrailingUseMasterName(descriptor); } return descriptor; }
private SparkViewDescriptor GetViewDescriptor(string controllerName, string viewName, string masterName) { var searchLocations = new List<string>(); var buildDescriptorParams = new BuildDescriptorParams(String.Empty, controllerName, viewName, masterName, false, new Dictionary<string, object>()); var viewDescriptor = _descriptorBuilder.BuildDescriptor(buildDescriptorParams, searchLocations); viewDescriptor.Language = LanguageType.Javascript; return viewDescriptor; }
//private readonly ViewEngineResult _cacheMissResult = new ViewEngineResult(new string[0]); private ViewEngineResult FindViewInternal(ControllerContext controllerContext, string viewName, string masterName, bool findDefaultMaster, bool useCache) { var searchedLocations = new List <string>(); var targetNamespace = controllerContext.Controller.GetType().Namespace; var controllerName = controllerContext.RouteData.GetRequiredString("controller"); var descriptorParams = new BuildDescriptorParams( targetNamespace, controllerName, viewName, masterName, findDefaultMaster, DescriptorBuilder.GetExtraParameters(controllerContext)); ISparkViewEntry entry; if (useCache) { if (TryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent()) { return(BuildResult(controllerContext.RequestContext, entry)); } return(_cacheMissResult); } var descriptor = DescriptorBuilder.BuildDescriptor( descriptorParams, searchedLocations); if (descriptor == null) { return(new ViewEngineResult(searchedLocations)); } entry = Engine.CreateEntry(descriptor); SetCacheValue(descriptorParams, entry); return(BuildResult(controllerContext.RequestContext, entry)); }
private bool TryGetCacheValue(BuildDescriptorParams descriptorParams, out ISparkViewEntry entry) { lock (_cache) return _cache.TryGetValue(descriptorParams, out entry); }
private void SetCacheValue(BuildDescriptorParams descriptorParams, ISparkViewEntry entry) { lock (_cache) _cache[descriptorParams] = entry; }
private ViewEngineResult FindViewInternal(ControllerContext controllerContext, string viewName, string masterName, bool findDefaultMaster, bool useCache) { var searchedLocations = new List<string>(); var targetNamespace = controllerContext.Controller.GetType().Namespace; var controllerName = controllerContext.RouteData.GetRequiredString("controller"); var descriptorParams = new BuildDescriptorParams( targetNamespace, controllerName, viewName, masterName, findDefaultMaster, DescriptorBuilder.GetExtraParameters(controllerContext)); ISparkViewEntry entry; if (useCache) { if (TryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent()) { return BuildResult(entry); } return _cacheMissResult; } var descriptor = DescriptorBuilder.BuildDescriptor( descriptorParams, searchedLocations); if (descriptor == null) return new ViewEngineResult(searchedLocations); entry = Engine.CreateEntry(descriptor); SetCacheValue(descriptorParams, entry); return BuildResult(entry); }
private bool TryGetCacheValue(BuildDescriptorParams descriptorParams, out ISparkViewEntry entry) { lock (_cache) return(_cache.TryGetValue(descriptorParams, out entry)); }
/// <summary> /// Given a set of MVC-specific parameters, a descriptor for the target view is created. This can /// be a bit more expensive because the existence of files is tested at various candidate locations. /// </summary> /// <param name="buildDescriptorParams">Contains all of the standard and extra parameters which contribute to a descriptor</param> /// <param name="searchedLocations">Candidate locations are added to this collection so an information-rich error may be returned</param> /// <returns>The descriptor with all of the detected view locations in order</returns> public SparkViewDescriptor BuildDescriptor(BuildDescriptorParams buildDescriptorParams, ICollection<string> searchedLocations) { return null; }