本文整理匯總了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);
}
示例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);
//.........這裏部分代碼省略.........
示例3: NVelocityConfig
static NVelocityConfig()
{
velocity = new VelocityEngine();
velocity.AddProperty("assembly.resource.loader.assembly", new[] {"bdUnit.Core"});
velocity.Init();
}