public String GetMessage() { String emailMessage = null; Velocity.Init(); VelocityContext context = new VelocityContext(); context.Put("context", new { Title = _context.Title, Name = _context.Name, Email = _context.Email, Phone = _context.Phone, Description = _context.Description }); using (StringWriter writer = new StringWriter()) { try { Velocity.Evaluate(context, writer, String.Empty, _context.TemplateFile); emailMessage = writer.ToString(); } catch (Exception e) { writer.Close(); throw; } } return(emailMessage); }
public static string RenderEmail(Email email) { if ( !File.Exists(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString(), "Email\\Template\\" + email.Template + ".html"))) { throw new InvalidOperationException("Cannot found template " + "'Email\\Template\\" + email.Template + "'.html"); } Velocity.Init(); var velocityContext = new VelocityContext(); foreach (var templateVar in email.TemplateVars) { velocityContext.Put(templateVar.Name, templateVar.Data); } string template = string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString(), "Email\\Template\\" + email.Template + ".html"))); var sb = new StringBuilder(); Velocity.Evaluate( velocityContext, new StringWriter(sb), "", new StringReader(template)); return(sb.ToString()); }
public string PrimeiroAcesso() { var componente = new Componente(); componente.Chave = "primeiro_acesso"; componente.Get(); if (componente.Conteudo == null) { componente.Conteudo = ""; } var writer = new StringWriter(); var context = new VelocityContext(); context.Put("site", Pagina.Site()); var chaveAtivacaoCampanha = new ChaveAtivacaoCampanha(Campanha.Current()); chaveAtivacaoCampanha.Get(); context.Put("chaveAtivacaoCampanha", chaveAtivacaoCampanha); if (Session.Get("[Erro]PrimeiroAcesso") != null) { context.Put("erro", Session.Get("[Erro]PrimeiroAcesso").ToString()); Session.Invalidate("[Erro]PrimeiroAcesso"); } Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }
public string AlterarCadastro() { var componente = new Componente(); componente.Chave = "alterar-cadastro"; componente.Get(); if (componente.Conteudo == null) { componente.Conteudo = ""; } var writer = new StringWriter(); var context = new VelocityContext(); context.Put("site", Pagina.Site()); context.Put("usuario", Usuario.Current()); context.Put("tipoInput", new TipoInput()); if (Session.Get("[MSG]AlterarCadastro") != null) { context.Put("mensagem", Session.Get("[MSG]AlterarCadastro").ToString()); Session.Invalidate("[MSG]AlterarCadastro"); } if (Session.Get("[ERRO]AlterarCadastro") != null) { context.Put("erro", Session.Get("[ERRO]AlterarCadastro").ToString()); Session.Invalidate("[ERRO]AlterarCadastro"); } Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }
public string Include(string nome) { Velocity.Init(); var template = new Template(); template.Chave = nome; template.Get(); if (template.Conteudo == null) { template.Conteudo = ""; } var writer = new StringWriter(); var context = new VelocityContext(); context.Put("template", new Template()); context.Put("componente", new Componente()); var usuario = Usuario.Current(); if (usuario != null) { context.Put("usuario", usuario); } context.Put("site", Pagina.Site()); context.Put("area", Pagina.GetAreaCorrente(false)); Velocity.Evaluate(context, writer, "", template.Conteudo.Replace("'", "'")); return(writer.GetStringBuilder().ToString()); }
public override IEnumerable <Row> Execute(IEnumerable <Row> rows) { foreach (var row in rows) { if (ShouldRun(row)) { foreach (var pair in Parameters) { _context.Put(pair.Value.Name, pair.Value.Value ?? row[pair.Key]); } var sw = StringWriters.GetObject(); Velocity.Evaluate(_context, sw, string.Empty, Template); var sb = sw.GetStringBuilder(); row[OutKey] = Common.ConversionMap[OutType](sb.ToString()); sb.Clear(); StringWriters.PutObject(sw); foreach (var pair in Parameters) { _context.Remove(pair.Value.Name); } } else { Skip(); } yield return(row); } }
public string PreviewDinamicoNoTema(int id) { var pagina = Pagina.BuscaPorId(id); Velocity.Init(); var modelo = new { Header = "Lista de dados dinamicos", Itens = new[] { new { ID = 1, Nome = "Texto 001", Negrito = false }, new { ID = 2, Nome = "Texto 002", Negrito = true }, new { ID = 3, Nome = "Texto 003", Negrito = false } } }; var velocityContext = new VelocityContext(); velocityContext.Put("model", modelo); velocityContext.Put("paginas", new Pagina().Lista()); var html = new StringBuilder(); bool result = Velocity.Evaluate(velocityContext, new StringWriter(html), "NomeParaCapturarLogError", new StringReader(pagina.Conteudo)); return(html.ToString()); }
public string GetHtmlIncluirResponsavelHtml(int idHierarquia, List <Usuario> usuarios) { var hierarquia = new Hierarquia(idHierarquia); hierarquia.Get(); var componente = new Componente(); componente.Chave = "adesao-incluir-responsavel"; componente.Get(); if (componente.Conteudo == null) { return(""); } Velocity.Init(); var writer = new StringWriter(); var context = new VelocityContext(); context.Put("site", Pagina.Site()); context.Put("usuario", this); context.Put("hierarquia", hierarquia); context.Put("usuarios", usuarios); Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }
public string GetComboAdesao(int idHierarquia, int nivelAtual) { var usuario = Usuario.Current(); var componente = new Componente(); componente.Chave = "adesao-combo"; componente.Get(); if (componente.Conteudo == null) { return(""); } var estruturas = new List <Hierarquia>(); Velocity.Init(); var writer = new StringWriter(); var context = new VelocityContext(); context.Put("site", Pagina.Site()); context.Put("nivelAtual", nivelAtual); context.Put("nextNivel", (nivelAtual + 1)); context.Put("idHierarquia", idHierarquia); context.Put("estruturas", estruturas); Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }
public string GetCode(int id, string source) { if (source.Trim().Length < 1) { return("未设置模板"); } if (id < 1) { return("未选择数据库表"); } Velocity.Init(); VelocityContext vc = new VelocityContext(); vc.Put("data", TemplateDT.CreateTemplateDT(id)); try { using (StringWriter sw = new StringWriter()) { string log = ""; bool result = Velocity.Evaluate(vc, sw, log, source); return(sw.GetStringBuilder().ToString()); } } catch (System.Exception ex) { return(ex.ToString()); } }
public virtual void Test_Run() { StringWriter compare1 = new StringWriter(); VelocityContext context = new VelocityContext(); context.Put("name", "jason"); context.Put("Floog", "floogie woogie"); Velocity.Evaluate(context, compare1, "evaltest", input1); /* * FIXME: Not tested right now. * * StringWriter result2 = new StringWriter(); * Velocity.mergeTemplate("mergethis.vm", context, result2); * * StringWriter result3 = new StringWriter(); * Velocity.invokeVelocimacro("floog", "test", new String[2], * context, result3);*/ Assert.AreEqual(result1, compare1.ToString()); //if (!result1.Equals(compare1.ToString())) //{ //Assert.Fail("Output incorrect."); //} }
/// <summary> /// Renders a string using the context specified along with any context already in "in memory" /// The context supplied here will not be stored. This context will also override any "in memory" /// context for this render. /// </summary> /// <param name="textToRender">The text to render.</param> /// <param name="context">Hashtable of items that will be evaluated at runtime.</param> /// <returns>A rendered string.</returns> public string RenderView(string textToRender, Hashtable context) { var writer = new StringWriter(); if (context != null) { var velContext = new VelocityContext(context); foreach (object key in this.velocityContext.Keys) { if (!context.ContainsKey(key.ToString())) { context.Add(key.ToString(), this.velocityContext.InternalGet(key.ToString())); } } Velocity.Evaluate(velContext, writer, "View", textToRender); } else { Velocity.Evaluate(this.velocityContext, writer, "View", textToRender); } return(this.ReplaceNewLine ? writer.GetStringBuilder().ToString().Replace(Environment.NewLine, string.Empty).Replace("\t", string.Empty) : writer.GetStringBuilder().ToString()); }
public string Evaluate(string template) { var sb = new StringBuilder(); Velocity.Evaluate(_context, new StringWriter(sb), "TemplatedString", new StringReader(template)); return(sb.ToString()); }
public async Task <string> renderizar(Pagina pagina, string TextoHtml) { int[] numero = criarRows(pagina); var condicao = await verificaTable(pagina); await verificaBackground(pagina); var condicaoLogin = SignInManager.IsSignedIn(ContextAccessor.HttpContext.User); var username = UserManager.GetUserName(ContextAccessor.HttpContext.User); var redeFacebook = ""; var redeTwiter = ""; var redeInstagram = ""; if (pagina.Pedido != null) { redeFacebook = pagina.Pedido.Facebook; redeTwiter = pagina.Pedido.Twiter; redeInstagram = pagina.Pedido.Instagram; } Velocity.Init(); var Modelo = new { Usuario = username, Login = condicaoLogin, Pedidos = condicao, Musicbool = pagina.Music, arquivoMusic = pagina.ArquivoMusic, Pagina = pagina, titulo = pagina.Titulo, facebook = redeFacebook, twiter = redeTwiter, instagram = redeInstagram, Div1 = pagina.Div.OrderBy(d => d.Div.Ordem).ToList().First(), Div2 = pagina.Div.Skip(1).OrderBy(d => d.Div.Id).ToList().First(), Div3 = pagina.Div.Skip(2).OrderBy(d => d.Div.Id).ToList().First(), Div4 = pagina.Div.Skip(3).OrderBy(d => d.Div.Id).ToList().First(), Div5 = pagina.Div.Skip(4).OrderBy(d => d.Div.Id).ToList().First(), Div6 = pagina.Div.Skip(5).OrderBy(d => d.Div.Id).ToList().First(), divs = pagina.Div.Skip(6).OrderBy(d => d.Div.Ordem).ToList(), Rows = numero, espacamento = 0, indice = 1 }; var velocitycontext = new VelocityContext(); velocitycontext.Put("model", Modelo); velocitycontext.Put("divs", pagina.Div.Skip(6).OrderBy(d => d.Div.Ordem).ToList()); var html = new StringBuilder(); bool result = Velocity.Evaluate(velocitycontext, new StringWriter(html), "NomeParaCapturarLogError", new StringReader(TextoHtml)); return(html.ToString()); }
public virtual void Test_Run() { VelocityContext context = new VelocityContext(); StringWriter writer = new StringWriter(); Velocity.Evaluate(context, writer, "vm_chain1", template1); String output = writer.ToString(); Assert.AreEqual(result1, output); }
public void MathOperations() { System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; VelocityContext context = new VelocityContext(); context.Put("fval", 1.2f); context.Put("dval", 5.3); Velocity.Init(); StringWriter sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = 1 + 1)\r\n$total")); Assert.AreEqual("2", sw.GetStringBuilder().ToString()); sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = $fval + $fval)\r\n$total")); Assert.AreEqual("2.4", sw.GetStringBuilder().ToString()); sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = $dval + $dval)\r\n$total")); Assert.AreEqual("10.6", sw.GetStringBuilder().ToString()); sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = 1 + $dval)\r\n$total")); Assert.AreEqual("6.3", sw.GetStringBuilder().ToString()); sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = $fval * $dval)\r\n$total")); Assert.AreEqual("6.36000025272369", sw.GetStringBuilder().ToString()); sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = $fval - $dval)\r\n$total")); Assert.AreEqual("-4.09999995231628", sw.GetStringBuilder().ToString()); sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = $fval % $dval)\r\n$total")); Assert.AreEqual("1.20000004768372", sw.GetStringBuilder().ToString()); sw = new StringWriter(); Assert.IsTrue(Velocity.Evaluate(context, sw, string.Empty, "#set($total = $fval / $dval)\r\n$total")); Assert.AreEqual("0.22641510333655", sw.GetStringBuilder().ToString()); }
private string GetTargetName(string template, Item parent) { string unique = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("U"); VelocityContext context = new VelocityContext(); context.Put("unique", unique); context.Put("parent", parent); using (StringWriter writer = new StringWriter()) { Velocity.Evaluate(context, writer, "template", template); return(writer.GetStringBuilder().ToString()); } }
private static string ApplyMacros(string stringToFormat, object model) { Velocity.Init(); var velocityContext = new VelocityContext(); velocityContext.Put("model", model); var sb = new StringBuilder(); Velocity.Evaluate(velocityContext, new StringWriter(sb), "test template", new StringReader(stringToFormat)); return(sb.ToString()); }
public virtual void Test_Run() { VelocityContext context = new VelocityContext(); System.IO.StringWriter writer = new System.IO.StringWriter(); Velocity.Evaluate(context, writer, "vm_chain1", template1); System.String out_Renamed = writer.ToString(); if (!result1.Equals(out_Renamed)) { Assertion.Fail("output incorrect."); } }
/// <summary> /// Processes the template, expanding all known values /// </summary> /// <param name="value">Template to process</param> /// <returns>Rendered template</returns> protected virtual string ProcessValue(string value, Item item) { StringWriter result = new StringWriter(); try { Velocity.Evaluate(velocityContext, result, "Extended mail action", value); } catch (NVelocity.Exception.ParseErrorException ex) { Log.Error(string.Format("Error parsing template for the {0} item \n {1}", item.Paths.Path, ex.ToString()), this); } return(result.GetStringBuilder().ToString()); }
public string GenByStr(string str, Dictionary <string, object> vars) { string temp = str; VelocityContext context = new VelocityContext(); if (vars != null) { foreach (KeyValuePair <string, object> kvp in vars) { context.Put(kvp.Key, kvp.Value); } } StringWriter writer = new StringWriter(); Velocity.Evaluate(context, writer, "", str); temp = writer.GetStringBuilder().ToString(); return(temp); }
public static string MergeTemplateWithResults(string template, object obj) { try { Velocity.Init(); VelocityContext context = new VelocityContext(); context.Put("DynamicSearch", obj); context.Put("Tools", new VelocityTools()); StringWriter writer = new StringWriter(); Velocity.Evaluate(context, writer, "", template); return(writer.GetStringBuilder().ToString()); } catch (Exception ex) { log.Error("MergeTemplateWithResults(): Failed when evaluating results template and object.", ex); throw (ex); } }
public string AdesaoCombos() { var componente = new Componente(); componente.Chave = "adesao"; componente.Get(); if (componente.Conteudo == null) { componente.Conteudo = ""; } var writer = new StringWriter(); var context = new VelocityContext(); context.Put("usuario", Usuario.Current()); context.Put("site", Pagina.Site()); Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }
public string Evaluate(string tplString, IDictionary <string, object> dict) { VelocityContext context = new VelocityContext(); if (dict != null) { foreach (KeyValuePair <string, object> item in dict) { context.Put(item.Key, item.Value); } } StringWriter writer = new StringWriter(); Velocity.Evaluate(context, writer, String.Empty, tplString); return(writer.GetStringBuilder().ToString()); }
public string GetConteudoRenderizado(Hashtable parans) { Velocity.Init(); var context = new VelocityContext(parans); context.Put("template", new Template()); context.Put("componente", new Componente()); context.Put("site", Pagina.Site()); context.Put("area", Pagina.GetAreaCorrente(false)); var usuario = Usuario.Current(); if (usuario != null) { context.Put("usuario", usuario); } var writer = new StringWriter(); Velocity.Evaluate(context, writer, "", this.Conteudo.Replace("'", "'")); return(writer.GetStringBuilder().ToString()); }
public static string Evaluate(string template, Hashtable variables) { string returnValue; if (variables.Count == 0) { returnValue = template; } else { VelocityContext context = new VelocityContext(variables); Velocity.Init(); using (StringWriter velocityOutput = new StringWriter()) { Velocity.Evaluate(context, velocityOutput, "", template); returnValue = velocityOutput.GetStringBuilder().ToString(); } } return(returnValue); }
private string HtmlMenu(Componente componente) { if (componente.Conteudo == null) { componente.Conteudo = ""; } var writer = new StringWriter(); var context = new VelocityContext(); context.Put("menu", Pagina.GetPaginasUsuario()); context.Put("area", Pagina.GetAreaCorrente(false)); context.Put("site", Pagina.Site()); var pagina = Pagina.Current(); if (pagina != null) { context.Put("pagina_corrente", pagina); } Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }
public static string RenderTemplate(HttpRequest request, String templateName, VelocityContext context) { Velocity.Init(); StringWriter body = new StringWriter(); StreamReader sr = null; try { sr = new StreamReader(request.PhysicalApplicationPath + "/App_LocalResources/" + templateName); Velocity.Evaluate(context, body, "", sr); } finally { if (sr != null) { sr.Close(); } } return(body.ToString()); }
public string EsqueciSenha() { var componente = new Componente(); componente.Chave = "esqueci_senha"; componente.Get(); if (componente.Conteudo == null) { componente.Conteudo = ""; } var writer = new StringWriter(); var context = new VelocityContext(); context.Put("site", Pagina.Site()); if (Session.Get("[EsqueciSenha]Login") != null) { context.Put("mensagem", Session.Get("[EsqueciSenha]Login").ToString()); Session.Invalidate("[EsqueciSenha]Login"); } Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }
public string Login() { var componente = new Componente(); componente.Chave = "form_login"; componente.Get(); if (componente.Conteudo == null) { componente.Conteudo = ""; } var writer = new StringWriter(); var context = new VelocityContext(); context.Put("site", Pagina.Site()); if (Session.Get("[Erro]Login") != null) { context.Put("erro", Session.Get("[Erro]Login").ToString()); Session.Invalidate("[Erro]Login"); } Velocity.Evaluate(context, writer, "", componente.Conteudo); return(writer.GetStringBuilder().ToString()); }