Example #1
0
        private void FindPartialViewInArea(ControllerContext controllerContext)
        {
            foreach (var type in _contentTypeModelScanner.ContentTypes)
            {
                var contentType = type;
                if (
                    _templateModelRepository.List(contentType)
                    .Any(p => p.TemplateTypeCategory.IsCategory(TemplateTypeCategories.MvcPartialView) && string.IsNullOrEmpty(p.Path)))
                {
                    continue;
                }

                // NOTE: this line in Release Mode was scanning only first area.
                // If there were more than one area and requested block would be located
                // in 2nd or any other area, EPiServer would add this template to noHit
                // cache and would assume that view does not exist at all.

                //  Replaced with view search directly via ViewEngines collection.
                // If this hits performance - we would need to search for another solution here.

                // var partialView = _viewEngineWrapper.FindPartialView(controllerContext, contentType.Name);
                var partialView = ViewEngines.Engines.FindPartialView(controllerContext, contentType.Name);

                if (partialView.View == null)
                {
                    continue;
                }

                var templateModel = new TemplateModel
                {
                    Name = contentType.Name,
                    TemplateTypeCategory = TemplateTypeCategories.MvcPartialView
                };

                var view = partialView.View as BuildManagerCompiledView;
                if (view != null)
                {
                    templateModel.Path = view.ViewPath;
                }

                _templateModelRepository.AddTemplates(contentType, templateModel);

                partialView.ViewEngine.ReleaseView(controllerContext, partialView.View);
            }
        }