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


C# VelocityEngine.SetProperty方法代码示例

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


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

示例1: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            DataBooks book=new DataBooks();
            book.name = context.Request["bookname"];
            book.type = context.Request["booktype"];
            if(book.name!=null)
                bookcollector.Add(book);

            context.Response.ContentType = "text/html";
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();

            VelocityContext vltContext = new VelocityContext();

            //vltContext.Put("msg", "");
            vltContext.Put("bookcollector", bookcollector);
            vltContext.Put("book", book);

            Template vltTemplate = vltEngine.GetTemplate("Front/ShopingCar.html");//模版文件所在位置

            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            string html = vltWriter.GetStringBuilder().ToString();
            context.Response.Write(html);
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:27,代码来源:ShopingCar.ashx.cs

示例2: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";

            string username = context.Request.Form["username"];
            string password = context.Request.Form["password"];

            if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password))
            {

                VelocityEngine vltEngine = new VelocityEngine();
                vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                vltEngine.Init();

                VelocityContext vltContext = new VelocityContext();
                //vltContext.Put("p", person);//设置参数,在模板中可以通过$data来引用
                vltContext.Put("username", "");
                vltContext.Put("password", "");
                vltContext.Put("msg", "");

                Template vltTemplate = vltEngine.GetTemplate("Front/login.html");//模版文件所在位置

                System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                vltTemplate.Merge(vltContext, vltWriter);

                string html = vltWriter.GetStringBuilder().ToString();
                context.Response.Write(html);
            }
            else
            {
                if (dataaccess(username, password))
                {
                    context.Session["username"] = username;
                    context.Response.Redirect("Index.ashx");
                }
                else
                {

                    VelocityEngine vltEngine = new VelocityEngine();
                    vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                    vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                    vltEngine.Init();

                    VelocityContext vltContext = new VelocityContext();
                    //vltContext.Put("p", person);//设置参数,在模板中可以通过$data来引用
                    vltContext.Put("username", username);
                    vltContext.Put("password", password);
                    vltContext.Put("msg", "用户名密码错误");

                    Template vltTemplate = vltEngine.GetTemplate("Front/login.html");//模版文件所在位置

                    System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                    vltTemplate.Merge(vltContext, vltWriter);

                    string html = vltWriter.GetStringBuilder().ToString();
                    context.Response.Write(html);
                }
            }
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:60,代码来源:Login.ashx.cs

示例3: RenderHtml

        /// <summary>
        /// 用data数据填充templateName模板,渲染生成html返回
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string RenderHtml(string templateName, object data)
        {
            //第一步:Creating a VelocityEngine也就是创建一个VelocityEngine的实例
            VelocityEngine vltEngine = new VelocityEngine();   //也可以使用带参构造函数直接实例
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();
            //vltEngine.AddProperty(RuntimeConstants.INPUT_ENCODING, "gb2312");
            //vltEngine.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "gb2312");

            //第二步:Creating the Template加载模板文件
            //这时通过的是Template类,并使用VelocityEngine的GetTemplate方法加载模板
            Template vltTemplate = vltEngine.GetTemplate(templateName);

            //第三步:Merging the template整合模板
            VelocityContext vltContext = new VelocityContext();
            vltContext.Put("Data", data);//设置参数,在模板中可以通过$data来引用

            //第四步:创建一个IO流来输出模板内容推荐使用StringWriter(因为template中以string形式存放)
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);

            string html = vltWriter.GetStringBuilder().ToString();
            return html;
        }
开发者ID:zhangtaoxgu,项目名称:aspnetProject,代码行数:31,代码来源:CommonHelper.cs

示例4: Helper

        public Helper()
        {
            vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory);

            vltEngine.Init();
        }
开发者ID:yunchenglk,项目名称:XY.Application,代码行数:8,代码来源:Helper.cs

示例5: Program

        static Program()
        {
            VelocityEngine velocity = new VelocityEngine();

            velocity.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            velocity.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, @"C:\test\Com.Hertkorn.DevelopmentTree\Com.Hertkorn.DevelopmentTree\template");
            velocity.Init();
            Engine = velocity;
        }
开发者ID:dun3,项目名称:dun3,代码行数:9,代码来源:Program.cs

示例6: readerHtml

        public static string readerHtml(string path, string name, object data)
        {
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath(path));//模板文件所在的文件夹
            vltEngine.Init();

            VelocityContext vltContext = new VelocityContext();
            vltContext.Put("Data", data);//设置参数,在模板中可以通过$data来引用

            Template vltTemplate = vltEngine.GetTemplate(name);
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            return vltWriter.GetStringBuilder().ToString();
        }
开发者ID:liuker0x007,项目名称:InfoSecPracticeSystem,代码行数:15,代码来源:writeHtml.cs

示例7: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            string searchid= context.Request.Form["searchid"];
            string searchtext = context.Request.Form["searchtext"];
            dataaccess(searchid, searchtext);
            if (searchid == "2")
            {
                //book
                context.Response.ContentType = "text/html";
                VelocityEngine vltEngine = new VelocityEngine();
                vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                vltEngine.Init();
                VelocityContext vltContext = new VelocityContext();

                vltContext.Put("object", searchtext);
                string show="<img src='books/"+book.ser+"' width='210' height='150' />";
                vltContext.Put("result", show);

                Template vltTemplate = vltEngine.GetTemplate("Front/Search.html");//模版文件所在位置

                System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                vltTemplate.Merge(vltContext, vltWriter);
                string html = vltWriter.GetStringBuilder().ToString();
                context.Response.Write(html);
            }
            else if (searchid == "3")
            {
                //news
                context.Response.ContentType = "text/html";
                VelocityEngine vltEngine = new VelocityEngine();
                vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                vltEngine.Init();

                VelocityContext vltContext = new VelocityContext();

                vltContext.Put("object", searchtext);
                vltContext.Put("result", news.news);

                Template vltTemplate = vltEngine.GetTemplate("Front/Search.html");//模版文件所在位置
                System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                vltTemplate.Merge(vltContext, vltWriter);
                string html = vltWriter.GetStringBuilder().ToString();
                context.Response.Write(html);
            }
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:47,代码来源:Search.ashx.cs

示例8: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            //创建一个模板引擎
            VelocityEngine vltEngine = new VelocityEngine();
            //文件型模板,还可以是 assembly ,则使用资源文件
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            //模板存放目录
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("/template"));//模板文件所在的文件夹
            vltEngine.Init();
            //定义一个模板上下文
            VelocityContext vltContext = new VelocityContext();
            //传入模板所需要的参数
            vltContext.Put("Title", "标题"); //设置参数,在模板中可以通过$Title来引用
            vltContext.Put("Body", "内容");  //设置参数,在模板中可以通过$Body来引用
            vltContext.Put("Date", DateTime.Now); //设置参数,在模板中可以通过$Date来引用
            //获取我们刚才所定义的模板,上面已设置模板目录
            Template vltTemplate = vltEngine.GetTemplate("basic.html");
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            //根据模板的上下文,将模板生成的内容写进刚才定义的字符串输出流中
            vltTemplate.Merge(vltContext, vltWriter);
            string html = vltWriter.GetStringBuilder().ToString();
            context.Response.Write(html);

            ////字符串模板源,这里就是你的邮件模板等等的字符串
            //const string templateStr = "$Title,$Body,$Date";

            ////创建一个模板引擎
            //VelocityEngine vltEngine = new VelocityEngine();
            ////文件型模板,还可以是 assembly ,则使用资源文件
            //vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            //vltEngine.Init();
            ////定义一个模板上下文
            //VelocityContext vltContext = new VelocityContext();
            ////传入模板所需要的参数
            //vltContext.Put("Title", "标题"); //设置参数,在模板中可以通过$Title来引用
            //vltContext.Put("Body", "内容");  //设置参数,在模板中可以通过$Body来引用
            //vltContext.Put("Date", DateTime.Now); //设置参数,在模板中可以通过$Date来引用
            ////定义一个字符串输出流
            //StringWriter vltWriter = new StringWriter();
            ////输出字符串流中的数据
            //vltEngine.Evaluate(vltContext, vltWriter, null, templateStr);
            //context.Response.Write(vltWriter.GetStringBuilder().ToString());
        }
开发者ID:proson,项目名称:project,代码行数:44,代码来源:basic.ashx.cs

示例9: Initialize

        private static void Initialize()
        {
            if (!_isInitialized)
            {
                lock (lockedObject)
                {
                    if (!_isInitialized)
                    {
                        engine = new VelocityEngine();

                        engine.SetProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "NVelocity.Runtime.Log.NullLogSystem");
                        engine.SetProperty(RuntimeConstants.RESOURCE_MANAGER_CLASS, "NVelocity.Runtime.Resource.ResourceManagerImpl");
                        engine.SetProperty(RuntimeConstants.COUNTER_NAME, "count");
                        //engine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,HttpContext.Current.Server.MapPath("~/files/themes/"));
                        engine.Init();

                        _isInitialized = true;
                    }
                }
            }
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:21,代码来源:TemplateEngine.cs

示例10: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();

            VelocityContext vltContext = new VelocityContext();

            //vltContext.Put("msg", "");
            dataaccess();

            vltContext.Put("NewsPool", NewsPool);
            vltContext.Put("s", new GotNews());

            Template vltTemplate = vltEngine.GetTemplate("Front/News.html");//模版文件所在位置
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            string html = vltWriter.GetStringBuilder().ToString();
            context.Response.Write(html);
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:22,代码来源:News.ashx.cs

示例11: GetEngine

        /// <summary>
        /// Initialize the engine with required properties.
        /// </summary>
        /// <returns>Engine instance</returns>
        private static VelocityEngine GetEngine()
        {
            NVelocity.App.VelocityEngine engine = new NVelocity.App.VelocityEngine();

            //set log class type
            engine.SetProperty(NVelocity.Runtime.RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, typeof(TemplateEngineLog));

            //switch to local context, this way each macro/recursive execution uses its own variables.
            engine.SetProperty(NVelocity.Runtime.RuntimeConstants.VM_CONTEXT_LOCALSCOPE, "true");

            //allows #set to accept null values in the right hand side.
            engine.SetProperty(NVelocity.Runtime.RuntimeConstants.SET_NULL_ALLOWED, "true");

            //set template resource loader to strings
            engine.SetProperty("resource.loader", "string");
            engine.SetProperty("string.resource.loader.class", "NVelocity.Runtime.Resource.Loader.StringResourceLoader");
            //engine.SetProperty("string.resource.loader.repository.class", "NVelocity.Runtime.Resource.Util.StringResourceRepositoryImpl");

            //initialize engine.
            engine.Init();

            return engine;
        }
开发者ID:kiszu,项目名称:ForBlog,代码行数:27,代码来源:TemplateEngine.cs

示例12: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";

            VelocityEngine velocityEngine = new VelocityEngine();
            velocityEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            velocityEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("/template"));
            velocityEngine.Init();

            //定义一个模板上下文
            VelocityContext velocityContext = new VelocityContext();
            //定义类对象
            Person p = new Person()
            {
                Name = "王三",
                Age = 20

            };
            velocityContext.Put("p", p);
            //定义键值对
            Dictionary<string,string> dic=new Dictionary<string, string>();
            dic["aa"] = "李四";
            dic["bb"] = "30";
            velocityContext.Put("dic", dic);

            //定义list集合
            List<string> list=new List<string>(){"张五","马六"};
            velocityContext.Put("list", list);

            //获取定义的模板
            Template template = velocityEngine.GetTemplate("baseobject.html");
            StringWriter stringWriter = new StringWriter();
            template.Merge(velocityContext, stringWriter);
            string html = stringWriter.GetStringBuilder().ToString();
            context.Response.Write(html);
        }
开发者ID:proson,项目名称:project,代码行数:36,代码来源:baseobject.ashx.cs

示例13: NVelocityView

        static NVelocityView()
        {
            engine = new VelocityEngine();
            engine.SetProperty("resource.loader", "file");
            engine.SetProperty("file.resource.loader.path", HttpContext.Current.Server.MapPath("~"));
#if DEBUG
            engine.SetProperty("file.resource.loader.cache", false);
#else
            engine.SetProperty("file.resource.loader.cache", true);
            engine.SetProperty("file.resource.loader.modificationCheckInterval", 60L);
#endif

            engine.SetProperty("input.encoding", "utf-8");
            engine.Init();
        }
开发者ID:yhhno,项目名称:MvcInfrastructure,代码行数:15,代码来源:NVelocityView.cs

示例14: TemplatingService

 public TemplatingService(String templatesPath)
 {
     _engine = new VelocityEngine();
     _engine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatesPath);
     _engine.Init();
 }
开发者ID:bea-project,项目名称:bea-web,代码行数:6,代码来源:TemplatingService.cs

示例15: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            string login = context.Request.Form["login"];
            string register = context.Request.Form["register"];
            if (context.Session["username"]==null)
            {
                if (!string.IsNullOrEmpty(login))
                {
                    context.Response.Redirect("Login.ashx");
                }
                else
                {
                    if (!string.IsNullOrEmpty(register))
                    {
                        context.Response.Redirect("Register.ashx");
                    }
                    context.Response.ContentType = "text/html";
                    VelocityEngine vltEngine = new VelocityEngine();
                    vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                    vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                    vltEngine.Init();
                    VelocityContext vltContext = new VelocityContext();

                    string hide = "<div id='start'style='float: right;'><form action='Index.ashx' method='post'><input class='a_demo_four' name='login' type='submit'  value='登录'/><input class='a_demo_four' name='register'  type='submit' value='注册' /></form></div>";
                    vltContext.Put("hide", hide);
                    vltContext.Put("show", "");

                    Template vltTemplate = vltEngine.GetTemplate("Front/Index.html");//模版文件所在位置

                    System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                    vltTemplate.Merge(vltContext, vltWriter);

                    string html = vltWriter.GetStringBuilder().ToString();
                    context.Response.Write(html);

                }
            }

            else
            {

                string quit = context.Request.Form["quit"];
                if (string.IsNullOrEmpty(quit))
                {
                    context.Response.ContentType = "text/html";

                    VelocityEngine vltEngine = new VelocityEngine();
                    vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                    vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                    vltEngine.Init();

                    VelocityContext vltContext = new VelocityContext();
                    //vltContext.Put("p", person);//设置参数,在模板中可以通过$data来引用
                    //vltContext.Put("username", "");
                    //vltContext.Put("password", "");
                    //vltContext.Put("msg", "");

                    string show = "<div id='start' style='float: right;'><form action='Index.ashx' method='post'><span style='font-size:20px;color:white;background-color:green;'>" + context.Session["username"].ToString() + " 欢迎你!" + "</span><input class='a_demo_four' name='quit' type='submit'  value='注销'/></form></div>";
                    vltContext.Put("show", show);
                    vltContext.Put("hide", "");
                    Template vltTemplate = vltEngine.GetTemplate("Front/Index.html");//模版文件所在位置

                    System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                    vltTemplate.Merge(vltContext, vltWriter);

                    string html = vltWriter.GetStringBuilder().ToString();
                    context.Response.Write(html);
                }
                else
                {
                    context.Session.Remove("username");
                    context.Response.Redirect("Index.ashx");
                }

            }
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:76,代码来源:Index.ashx.cs


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