Esempio n. 1
0
        private ViewEngineResult findViewInternal(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, bool useCache)
        {
            var searchedLocations = new List<string>();
            var targetNamespace = actionContext.ActionNamespace;

            var descriptorParams = new BuildDescriptorParams(
                targetNamespace,
                actionContext.ActionName,
                viewName,
                masterName,
                findDefaultMaster,
                DescriptorBuilder.GetExtraParameters(actionContext));

            ISparkViewEntry entry;
            if (useCache)
            {
                if (tryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent())
                {
                    return buildResult(entry);
                }

                return new ViewEngineResult(new List<string> { "Cache" });
            }

            var descriptor = DescriptorBuilder.BuildDescriptor(descriptorParams, searchedLocations);

            if (descriptor == null)
            {
                return new ViewEngineResult(searchedLocations);
            }

            entry = Engine.CreateEntry(descriptor);
            setCacheValue(descriptorParams, entry);

            return buildResult(entry);
        }
Esempio n. 2
0
 public SparkViewDescriptor CreateDescriptor(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, ICollection<string> searchedLocations)
 {
     return DescriptorBuilder.BuildDescriptor(
         new BuildDescriptorParams(
             actionContext.ActionNamespace,
             actionContext.ActionName,
             viewName,
             masterName,
             findDefaultMaster,
             DescriptorBuilder.GetExtraParameters(actionContext)),
         searchedLocations);
 }
Esempio n. 3
0
 public ViewEngineResult FindView(ActionContext actionContext, string viewName, string masterName)
 {
     return findViewInternal(actionContext, viewName, masterName, true, false);
 }
Esempio n. 4
0
 public virtual ViewEngineResult FindPartialView(ActionContext actionContext, string partialViewName)
 {
     return findViewInternal(actionContext, partialViewName, null /*masterName*/, false, false);
 }
Esempio n. 5
0
        public SparkViewDescriptor CreateDescriptor(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, ICollection<string> searchedLocations)
        {
            string targetNamespace = actionContext.ActionNamespace;

            string actionName = actionContext.RouteData.GetRequiredString("controller");

            return DescriptorBuilder.BuildDescriptor(
                new BuildDescriptorParams(
                    targetNamespace,
                    actionName,
                    viewName,
                    masterName,
                    findDefaultMaster,
                    DescriptorBuilder.GetExtraParameters(actionContext)),
                searchedLocations);
        }
Esempio n. 6
0
        private ViewEngineResult FindViewInternal(ActionContext actionContext, string viewName, string masterName, bool findDefaultMaster, bool useCache)
        {
            var searchedLocations = new List<string>();
            string targetNamespace = actionContext.ActionNamespace;

            string controllerName = actionContext.RouteData.GetRequiredString("controller");

            var descriptorParams = new BuildDescriptorParams(
                targetNamespace,
                controllerName,
                viewName,
                masterName,
                findDefaultMaster,
                DescriptorBuilder.GetExtraParameters(actionContext));

            ISparkViewEntry entry;
            if (useCache)
            {
                if (TryGetCacheValue(descriptorParams, out entry) && entry.IsCurrent())
                {
                    return BuildResult(actionContext.HttpContext, entry);
                }
                return new ViewEngineResult(new List<string> { "Cache" });
            }

            SparkViewDescriptor descriptor = DescriptorBuilder.BuildDescriptor(
                descriptorParams,
                searchedLocations);

            if (descriptor == null)
                return new ViewEngineResult(searchedLocations);

            entry = Engine.CreateEntry(descriptor);
            SetCacheValue(descriptorParams, entry);
            return BuildResult(actionContext.HttpContext, entry);
        }
Esempio n. 7
0
        public ISparkView FindView(HttpContextBase httpContext, string actionNamespace, string actionName, string viewName, string masterName)
        {
            var routeData = new RouteData();
            routeData.Values.Add("controller", actionName.RemoveSuffix("Controller"));
            var actionContext = new ActionContext(httpContext, routeData, actionNamespace);

            ViewEngineResult viewResult = FindView(actionContext, viewName, masterName);
            return viewResult.View;
        }