コード例 #1
0
		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);
		}
コード例 #2
0
        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);
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        //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));
        }
コード例 #6
0
ファイル: SparkViewFactory.cs プロジェクト: bbarry/spark
 private bool TryGetCacheValue(BuildDescriptorParams descriptorParams, out ISparkViewEntry entry)
 {
     lock (_cache) return _cache.TryGetValue(descriptorParams, out entry);
 }
コード例 #7
0
ファイル: SparkViewFactory.cs プロジェクト: bbarry/spark
 private void SetCacheValue(BuildDescriptorParams descriptorParams, ISparkViewEntry entry)
 {
     lock (_cache) _cache[descriptorParams] = entry;
 }
コード例 #8
0
ファイル: SparkViewFactory.cs プロジェクト: bbarry/spark
        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);
        }
コード例 #9
0
 private void SetCacheValue(BuildDescriptorParams descriptorParams, ISparkViewEntry entry)
 {
     lock (_cache) _cache[descriptorParams] = entry;
 }
コード例 #10
0
 private bool TryGetCacheValue(BuildDescriptorParams descriptorParams, out ISparkViewEntry entry)
 {
     lock (_cache) return(_cache.TryGetValue(descriptorParams, out entry));
 }
コード例 #11
0
 /// <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;
 }