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


C# VelocityEngine.AddProperty方法代码示例

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


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

示例1: NVelocityHelper

 public NVelocityHelper(string key, object value)
 {
     //1.创建Velocity 引擎(VelocityEngine)并设置属性
     velocityEngine = new VelocityEngine();
     velocityEngine.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");           // Velocity加载类型
     velocityEngine.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,          // Velocity加载文件路径
        HttpContext.Current.Server.MapPath("~/Templates/"));
     velocityEngine.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");          // 输入编码格式设置
     velocityEngine.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");         // 输出编码格式设置
     velocityEngine.Init();
     //2.Velocity 上下文对象设置
     vc = new VelocityContext();
     vc.Put(key, value);
 }
开发者ID:taohonggou,项目名称:MyPhotos,代码行数:14,代码来源:NVelocityHelper.cs

示例2: ExecuteTask

	//	public virtual ExtendedProperties GetContextProperties() {
	//		return contextProperties;
	//	}
	//
	//	public virtual bool UseClasspath {
	//	    set {
	//		this.useClasspath = value;
	//	    }
	//	}





	/// <summary>
	/// Execute the input script with Velocity
	/// @throws BuildException
	/// BuildExceptions are thrown when required attributes are missing.
	/// Exceptions thrown by Velocity are rethrown as BuildExceptions.
	/// </summary>
	protected override void ExecuteTask() {
	    // Make sure the template path is set.
	    if (templatePath == null && useClasspath == false) {
		throw new BuildException("The template path needs to be defined if you are not using " + "the classpath for locating templates!");
	    }

	    // Make sure the control template is set.
	    if (controlTemplate == null) {
		throw new BuildException("The control template needs to be defined!");
	    }

	    // Make sure the output directory is set.
	    if (outputDirectory == null) {
		throw new BuildException("The output directory needs to be defined!");
	    }

	    // Make sure there is an output file.
	    if (outputFile == null) {
		throw new BuildException("The output file needs to be defined!");
	    }

	    VelocityEngine ve = new VelocityEngine();

	    try {
		// Setup the Velocity Runtime.
		if (templatePath != null) {
		    //log("Using templatePath: " + templatePath, project.MSG_VERBOSE);
		    Log.WriteLine(LogPrefix + "Using templatePath: " + templatePath);
		    ve.SetProperty(RuntimeConstants_Fields.FILE_RESOURCE_LOADER_PATH, templatePath);
		}

		if (useClasspath) {
		    Log.WriteLine(LogPrefix + "Using classpath");
		    ve.AddProperty(RuntimeConstants_Fields.RESOURCE_LOADER, "classpath");
		    ve.SetProperty("classpath." + RuntimeConstants_Fields.RESOURCE_LOADER + ".class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
		    ve.SetProperty("classpath." + RuntimeConstants_Fields.RESOURCE_LOADER + ".cache", "false");
		    ve.SetProperty("classpath." + RuntimeConstants_Fields.RESOURCE_LOADER + ".modificationCheckInterval", "2");
		}

		ve.Init();

		// Create the text generator.
		Generator generator = Generator.Instance;
		generator.LogPrefix = LogPrefix;
		generator.VelocityEngine = ve;
		generator.OutputPath = outputDirectory;
		generator.InputEncoding = inputEncoding;
		generator.OutputEncoding = outputEncoding;

		if (templatePath != null) {
		    generator.TemplatePath = templatePath;
		}

		// Make sure the output directory exists, if it doesn't
		// then create it.
		System.IO.FileInfo file = new System.IO.FileInfo(outputDirectory);
		bool tmpBool;
		if (System.IO.File.Exists(file.FullName))
		    tmpBool = true;
		else
		    tmpBool = System.IO.Directory.Exists(file.FullName);
		if (!tmpBool) {
		    System.IO.Directory.CreateDirectory(file.FullName);
		}

		System.String path = outputDirectory + System.IO.Path.DirectorySeparatorChar.ToString() + outputFile;
		Log.WriteLine(LogPrefix + "Generating to file " + path);
		System.IO.StreamWriter writer = generator.getWriter(path, outputEncoding);

		// The generator and the output path should
		// be placed in the init context here and
		// not in the generator class itself.
		IContext c = initControlContext();

		// Everything in the generator class should be
		// pulled out and placed in here. What the generator
		// class does can probably be added to the Velocity
		// class and the generator class can probably
		// be removed all together.
		populateInitialContext(c);
//.........这里部分代码省略.........
开发者ID:DF-thangld,项目名称:web_game,代码行数:101,代码来源:TexenTask.cs

示例3: NVelocityConfig

 static NVelocityConfig()
 {
     velocity = new VelocityEngine();
     velocity.AddProperty("assembly.resource.loader.assembly", new[] {"bdUnit.Core"});
     velocity.Init();
 }
开发者ID:lynchjames,项目名称:bdUnit,代码行数:6,代码来源:NVelocityConfig.cs


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