コード例 #1
0
        public virtual SparkViewDescriptor BuildDescriptor(
			DescriptorParameters descriptorParameters, ICollection<string> searchedLocations)
        {
            var descriptor = new SparkViewDescriptor {
                TargetNamespace = descriptorParameters.ViewPath
            };

            IEnumerable<string> potentialLocations = PotentialViewLocations(
                descriptorParameters.ViewPath, descriptorParameters.ViewName, descriptorParameters.Extra);
            if (!LocatePotentialTemplate(potentialLocations, descriptor.Templates, searchedLocations))
            {
                return null;
            }

            if (!string.IsNullOrEmpty(descriptorParameters.MasterName))
            {
                potentialLocations = PotentialMasterLocations(
                    descriptorParameters.MasterName, descriptorParameters.Extra);
                if (!LocatePotentialTemplate(potentialLocations, descriptor.Templates, searchedLocations))
                {
                    return null;
                }
            }
            else if (descriptorParameters.FindDefaultMaster && TrailingUseMasterName(descriptor) == null /*empty is a valid value*/)
            {
                potentialLocations = PotentialDefaultMasterLocations(
                    descriptorParameters.ViewPath, descriptorParameters.Extra);
                LocatePotentialTemplate(potentialLocations, descriptor.Templates, null);
            }

            var trailingUseMaster = TrailingUseMasterName(descriptor);
            while (descriptorParameters.FindDefaultMaster && !string.IsNullOrEmpty(trailingUseMaster))
            {
                if (!LocatePotentialTemplate(PotentialMasterLocations(trailingUseMaster, descriptorParameters.Extra),
                                             descriptor.Templates, searchedLocations))
                {
                    return null;
                }
                trailingUseMaster = TrailingUseMasterName(descriptor);
            }

            return descriptor;
        }
コード例 #2
0
ファイル: TemplateEngine.cs プロジェクト: dylanmei/MailPimp
        public TemplateViewResult CreateView(ITemplateViewFolder finder, Template template)
        {
            var viewPath = template.Folder;
            var viewName = template.Name;
            var searchedLocations = new List<string>();
            var descriptorParams = new DescriptorParameters(
                viewPath, viewName, null, true, null);

            engine.ViewFolder = finder;
            var descriptor = descriptorBuilder.BuildDescriptor(
                descriptorParams, searchedLocations);

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

            var entry = engine.CreateEntry(descriptor);
            var view = entry.CreateInstance() as TemplateView;

            return new TemplateViewResult(view);
        }