Ejemplo n.º 1
0
 /// <summary>
 /// Recupera a chave do template.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="templateType"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public ITemplateKey GetKey(string name, ResolveType templateType, ITemplateKey context)
 {
     if (System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists(name))
     {
         var virtualFile = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(name);
         var cache       = virtualFile as ITemplateCacheSupport;
         RazorEngine.Templating.ITemplateKey templateKey = null;
         if (cache != null)
         {
             if (cache.TemplateKey == null)
             {
                 templateKey = new NameOnlyTemplateKey(name, templateType, context);
                 cache.Register(templateKey);
             }
             else
             {
                 templateKey = cache.TemplateKey;
             }
         }
         else
         {
             templateKey = new NameOnlyTemplateKey(name, templateType, context);
         }
         return(templateKey);
     }
     return(new NameOnlyTemplateKey(name, templateType, context));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Resolve o nome do modelo.
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public string Resolve(string name)
 {
     if (System.Web.Hosting.HostingEnvironment.VirtualPathProvider.FileExists(name))
     {
         var virtualFile = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(name);
         var cache       = virtualFile as ITemplateCacheSupport;
         RazorEngine.Templating.ITemplateKey templateKey = null;
         if (cache != null)
         {
             if (cache.TemplateKey == null)
             {
                 templateKey = _templateGetKey(name, RazorEngine.Templating.ResolveType.Global);
                 cache.Register(templateKey);
             }
             else
             {
                 templateKey = cache.TemplateKey;
             }
         }
         using (var stream = virtualFile.Open())
         {
             var reader = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8);
             return(reader.ReadToEnd());
         }
     }
     return("");
 }