Example #1
0
        public ITemplateKey GetKey(string name, ResolveType resolveType, ITemplateKey context)
        {
            if (ManifestResourceHelper.checkExistsManifestResource(name))
            {
                return(new ResourcePathTemplateKey(name, name, resolveType, context));
            }

            var existsResourceNames = layoutRoots.Select(m =>
            {
                string resourcePath = string.Format(m, name);
                if (ManifestResourceHelper.checkExistsManifestResource(resourcePath))
                {
                    return(resourcePath);
                }
                resourcePath += ".cshtml";
                if (ManifestResourceHelper.checkExistsManifestResource(resourcePath))
                {
                    return(resourcePath);
                }
                return(null);
            });

            var resourceName = existsResourceNames.Where(m => !string.IsNullOrEmpty(m)).FirstOrDefault();

            if (resourceName == null)
            {
                throw new InvalidOperationException(string.Format("Could not resolve template {0}", name));
            }

            return(new ResourcePathTemplateKey(name, resourceName, resolveType, context));
        }
Example #2
0
        public ITemplateSource Resolve(ITemplateKey key)
        {
            ResourcePathTemplateKey resourcePathTemplateKey = key as ResourcePathTemplateKey;

            if (resourcePathTemplateKey == null)
            {
                throw new NotSupportedException("You can only use ResourcePathTemplateKey with this manager");
            }
            return(new LoadedTemplateSource(ManifestResourceHelper.getManifestResourceString(resourcePathTemplateKey.ResourcePath),
                                            resourcePathTemplateKey.ResourcePath));
        }