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