Example #1
0
 public override string Execute(string virtualfile, object Model)
 {
     try
     {
         Template.NamingConvention = new CSharpNamingConvention();
         Template template = Template.Parse(VirtualPathProviderHelper.Load(virtualfile));
         return(template.Render(Hash.FromAnonymousObject(new { Model = Model, ModelToJson = Model.ToJson(), ModelDump = ObjectDumper.Dump(Model) })));
     }
     catch (Exception ex)
     {
         return(" " + virtualfile + " " + ex.Message);
     }
 }
Example #2
0
        public string ReadTemplateFile(Context context, string templateName)
        {
            var templatePath = (string)context[templateName];

            if (templatePath == null || !Regex.IsMatch(templatePath, @"^[a-zA-Z0-9_]+$"))
            {
                throw new FileSystemException("Error - Illegal template name '{0}'", templatePath);
            }

            string fullPath = Path.Combine(PortalSettings.Current.HomeDirectoryMapPath, string.Format(FileNameFormat, templatePath));

            if (!HostingEnvironment.VirtualPathProvider.FileExists(fullPath))
            {
                throw new FileSystemException("Error - No such template. Looked in the following locations:<br />{0}", string.Join("<br />", ""));
            }



            return(VirtualPathProviderHelper.Load(fullPath));
        }