當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。