当前位置: 首页>>代码示例>>C#>>正文


C# VelocityEngine.Evaluate方法代码示例

本文整理汇总了C#中NVelocity.App.VelocityEngine.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# VelocityEngine.Evaluate方法的具体用法?C# VelocityEngine.Evaluate怎么用?C# VelocityEngine.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NVelocity.App.VelocityEngine的用法示例。


在下文中一共展示了VelocityEngine.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderTemplate

        public void RenderTemplate(string templateName, object model)
        {
            string templateFullPath = applicationInfo.AbsolutizePath("Web/Pages/Templates/" + templateName + ".vm.html");

            ITemplateSource template = new CacheableFileTemplate(
                templateFullPath,
                fileCache);
            string templateText = template.GetTemplate();

            VelocityEngine velocity = new VelocityEngine();
            velocity.Init();

            VelocityContext velocityContext = new VelocityContext();
            velocityContext.Put("m", model);
            velocityContext.Put("h", this);

            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                if (false == velocity.Evaluate(velocityContext, stringWriter, null, templateText))
                    throw new InvalidOperationException("Template expansion failed");

                writer.InnerWriter.Write(stringWriter.ToString());
            }

            writer.WriteLine();
        }
开发者ID:Ryks,项目名称:detergent,代码行数:26,代码来源:NVelocityHtmlRenderHelper.cs

示例2: Format

        /// <summary>The format.</summary>
        /// <param name="text">The text.</param>
        /// <param name="items">The items.</param>
        /// <returns>The format.</returns>
        /// <exception cref="TemplateException"></exception>
        public string Format(string text, Dictionary<string, object> items)
        {
            try
            {
                VelocityContext velocityContext = new VelocityContext();

                if (items != null)
                {
                    foreach (var pair in items)
                    {
                        velocityContext.Put(pair.Key, pair.Value);
                    }
                }

                StringWriter sw = new StringWriter();
                VelocityEngine velocityEngine = new VelocityEngine();
                velocityEngine.Init();

                bool ok = velocityEngine.Evaluate(velocityContext, sw, "ContextTest.CaseInsensitive", text);

                if (!ok)
                {
                    throw new TemplateException("Template run error (try adding an extra newline at the end of the file)");
                }

                return sw.ToString();
            }
            catch (ParseErrorException parseErrorException)
            {
                throw new TemplateException(parseErrorException.Message, parseErrorException);
            }
        }
开发者ID:ClusterReply,项目名称:minisqlquery,代码行数:37,代码来源:NVelocityWrapper.cs

示例3: ParamArraySupport1

		public void ParamArraySupport1()
		{
			VelocityContext c = new VelocityContext();
			c.Put("x", new Something() );
			
			StringWriter sw = new StringWriter();

			VelocityEngine ve = new VelocityEngine();
			ve.Init();

			Boolean ok = false;

			ok = ve.Evaluate(c, sw, 
				"ContextTest.CaseInsensitive", 
				"$x.Print( \"aaa\" )");

			Assert.IsTrue(ok, "Evalutation returned failure");
			Assert.AreEqual("aaa", sw.ToString());

			sw = new StringWriter();

			ok = ve.Evaluate(c, sw, 
				"ContextTest.CaseInsensitive", 
				"$x.Contents()");

			Assert.IsTrue(ok, "Evalutation returned failure");
			Assert.AreEqual("", sw.ToString());

			sw = new StringWriter();

			ok = ve.Evaluate(c, sw, 
				"ContextTest.CaseInsensitive", 
				"$x.Contents( \"x\" )");

			Assert.IsTrue(ok, "Evalutation returned failure");
			Assert.AreEqual("x", sw.ToString());

			sw = new StringWriter();

			ok = ve.Evaluate(c, sw, 
				"ContextTest.CaseInsensitive", 
				"$x.Contents( \"x\", \"y\" )");

			Assert.IsTrue(ok, "Evalutation returned failure");
			Assert.AreEqual("x,y", sw.ToString());
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:46,代码来源:ContextTest.cs

示例4: EvaluateTemplate

 private static string EvaluateTemplate(VelocityEngine engine, IContext context, string templateString)
 {
     using (var writer = new StringWriter())
     {
         engine.Evaluate(context, writer, "", templateString);
         return writer.GetStringBuilder().ToString();
     }
 }
开发者ID:kodkatten,项目名称:TeamRynkeby,代码行数:8,代码来源:MailTemplateService.cs

示例5: ApplyTemplate

 private static string ApplyTemplate(string template, VelocityContext context)
 {
     VelocityEngine velocity = new VelocityEngine();
     ExtendedProperties props = new ExtendedProperties();
     velocity.Init(props);
     using (var writer = new StringWriter(CultureInfo.CurrentCulture))
     {
         velocity.Evaluate(context, writer, string.Empty, template);
         return writer.GetStringBuilder().ToString();
     }
 }
开发者ID:cloudguy,项目名称:Storage-Monster,代码行数:11,代码来源:VelocityTemplateEngine.cs

示例6: Evaluate

 public string Evaluate(string template, IDictionary<string, object> context)
 {
     var velocityContext = new VelocityContext();
     foreach (var keyValuePair in context)
     {
         velocityContext.Put(keyValuePair.Key, keyValuePair.Value);
     }
     var velocity = new VelocityEngine();
     velocity.Init();
     var writer = new StringWriter();
     velocity.Evaluate(velocityContext, writer, null, template);
     return writer.GetStringBuilder().ToString();
 }
开发者ID:smartinz,项目名称:randomhacking,代码行数:13,代码来源:NVelocityEvaluator.cs

示例7: DoesNotGiveNullReferenceExceptionWhenAmbiguousMatchBecauseOfNullArg

        public void DoesNotGiveNullReferenceExceptionWhenAmbiguousMatchBecauseOfNullArg()
        {
            VelocityEngine engine = new VelocityEngine();
            engine.Init();

            VelocityContext ctx = new VelocityContext();
            ctx.Put("test", new TestClass());
            ctx.Put("nullObj", null);
            StringWriter writer = new StringWriter();

            Assert.IsTrue(engine.Evaluate(ctx, writer, "testEval", "$test.DoSomething($nullObj)"));
            Assert.AreEqual("$test.DoSomething($nullObj)", writer.GetStringBuilder().ToString());
        }
开发者ID:rasmus-toftdahl-olesen,项目名称:NVelocity,代码行数:13,代码来源:NVelocity11.cs

示例8: VTLTest1

		public void VTLTest1()
		{
//	    VelocityCharStream vcs = new VelocityCharStream(new StringReader(":=t#${A.T1}ms"), 1, 1);
//	    Parser p = new Parser(vcs);
//	    SimpleNode root = p.process();
//
//	    String nodes = String.Empty;
//	    if (root != null) {
//		Token t = root.FirstToken;
//		nodes += t.kind.ToString();
//		while (t != root.LastToken) {
//		    t = t.next;
//		    nodes += "," + t.kind.ToString();
//		}
//	    }
//
//	    throw new System.Exception(nodes);

			VelocityEngine ve = new VelocityEngine();
			ve.Init();

			VelocityContext c = new VelocityContext();
			c.Put("A", new A());

			// modified version so Bernhard could continue
			StringWriter sw = new StringWriter();
			Boolean ok = ve.Evaluate(c, sw, "VTLTest1", "#set($hash = \"#\"):=t${hash}${A.T1}ms");
			Assert.IsTrue(ok, "Evalutation returned failure");
			Assert.AreEqual(":=t#0ms", sw.ToString());

			// the actual problem reported
			sw = new StringWriter();
			ok = ve.Evaluate(c, sw, "VTLTest1", ":=t#${A.T1}ms");
			Assert.IsTrue(ok, "Evalutation returned failure");
			Assert.AreEqual(":=t#0ms", sw.ToString());

		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:37,代码来源:VTLTest.cs

示例9: ExceptionForAmbiguousMatches

		public void ExceptionForAmbiguousMatches()
		{
			StringWriter sw = new StringWriter();

			VelocityContext c = new VelocityContext();
			c.Put("x", (decimal) 1.2);
			c.Put("model", new ModelClass());

			VelocityEngine ve = new VelocityEngine();
			ve.Init();

			ve.Evaluate(c, sw,
				"ContextTest.CaseInsensitive",
				"$model.Amount.ToString(null)");
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:15,代码来源:AmbiguousExceptionTestCase.cs

示例10: StringMerge

 public static string StringMerge(string templateContext, Hashtable table)
 {
     var engine = new VelocityEngine();
     engine.Init();
     var content = new VelocityContext();
     if (table != null)
         foreach (DictionaryEntry entry in table)
         {
             content.Put(entry.Key.ToString(), entry.Value);
         }
     using (var writer = new StringWriter())
     {
         engine.Evaluate(content, writer, "", templateContext);
         return writer.GetStringBuilder().ToString();
     }
 }
开发者ID:ChalmerLin,项目名称:dnt_v3.6.711,代码行数:16,代码来源:NVelocity.cs

示例11: ProcessVelocityTemplate

        public static string ProcessVelocityTemplate(string content, Dictionary<string, object> dict)
        {
            var engine = new VelocityEngine();
            engine.Init();

            var ctx = new Hashtable();
            foreach (string key in dict.Keys)
                ctx.Add(key, dict[key]);

            var context = new VelocityContext(ctx);

            using (var writer = new StringWriter())
            {
                engine.Evaluate(context, writer, "", content);
                return writer.GetStringBuilder().ToString();
            }
        }
开发者ID:s-leonard,项目名称:Tarts,代码行数:17,代码来源:Templating.cs

示例12: CreateCode

 public static string CreateCode(string codeString,NVelocity.VelocityContext context)
 {
     StringWriter writer = new StringWriter();
     try
     {
         VelocityEngine engine= new VelocityEngine();
         engine.Init();
         if (context == null)
             context = new VelocityContext();
         engine.Evaluate(context, writer, "", codeString);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return writer.ToString();
 }
开发者ID:Tony-Liang,项目名称:CodeGenernate,代码行数:17,代码来源:VelocityWrapper.cs

示例13: RenderFromContentTemplate

        public string RenderFromContentTemplate(string content, IDictionary<string, object> data)
        {
            StringWriter writer = new StringWriter();

            VelocityEngine e = new VelocityEngine();
            e.Init();
            var context = new VelocityContext();
            var templateData = data ?? new Dictionary<string, object>();

            foreach (var key in templateData.Keys)
            {
                context.Put(key, templateData[key]);
            }
            e.Evaluate(context, writer, "template", content);
            return writer.ToString();

        }
开发者ID:rcarubbi,项目名称:Carubbi.Components,代码行数:17,代码来源:NVelocityEngine.cs

示例14: DuplicateMethodNames

		public void DuplicateMethodNames()
		{
			StringWriter sw = new StringWriter();

			VelocityContext c = new VelocityContext();
			c.Put("model", new ModelClass());

			VelocityEngine velocityEngine = new VelocityEngine();
			velocityEngine.Init();

			bool ok = velocityEngine.Evaluate(c, sw,
			                                  "ContextTest.CaseInsensitive",
			                                  "$model.DoSome('y') $model.DoSome(2) ");

			Assert.IsTrue(ok, "Evaluation returned failure");
			Assert.AreEqual("x:y 4 ", sw.ToString());
		}
开发者ID:ralescano,项目名称:castle,代码行数:17,代码来源:AmbiguousExceptionTestCase.cs

示例15: CreateChildControls

        protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
        {
            int count = 0;

            if (string.IsNullOrEmpty(TemplateMarkup))
            {
                DisplayError("No template specified.");
            }
            else if (!dataBinding)
            {
                DisplayError("Control is not databound.");
            }
            else if (dataSource == null)
            {
                DisplayError("Data source was null.");
            }
            else
            {
                VelocityEngine velocity = new VelocityEngine();
                velocity.Init();

                Hashtable contextHashtable = new Hashtable {
                    { "Model", dataSource},
                    { "HttpContextCurrent", HttpContext.Current}
                };

                // TODO: Add ResourceManager and other useful things

                var velocityContext = new VelocityContext(contextHashtable);
                string evaluatedTemplate;
                using (StringWriter stringWriter = new StringWriter())
                {
                    velocity.Evaluate(velocityContext, stringWriter, /*logTag:*/ string.Empty, TemplateMarkup);
                    evaluatedTemplate = stringWriter.ToString();
                }

                Controls.Add(new LiteralControl { Text = evaluatedTemplate });
            }

            return count;
        }
开发者ID:nmitha,项目名称:Sandbox,代码行数:41,代码来源:TemplateBasedViewControl.cs


注:本文中的NVelocity.App.VelocityEngine.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。