本文整理汇总了C#中NVelocity.App.VelocityEngine.MergeTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# VelocityEngine.MergeTemplate方法的具体用法?C# VelocityEngine.MergeTemplate怎么用?C# VelocityEngine.MergeTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NVelocity.App.VelocityEngine
的用法示例。
在下文中一共展示了VelocityEngine.MergeTemplate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeTemplate
/// <summary>
/// Merge the specified Velocity template with the given model and write
/// the result to the given Writer.
/// </summary>
/// <param name="velocityEngine">VelocityEngine to work with</param>
/// <param name="templateLocation">the location of template, relative to Velocity's resource loader path</param>
/// <param name="encoding">encoding the encoding of the template file</param>
/// <param name="model">the Hashtable that contains model names as keys and model objects</param>
/// <param name="writer">writer the TextWriter to write the result to</param>
/// <exception cref="VelocityException">thrown if any exception is thrown by the velocity engine</exception>
public static void MergeTemplate(
VelocityEngine velocityEngine, string templateLocation, string encoding, Hashtable model, TextWriter writer) {
try {
VelocityContext velocityContext = new VelocityContext(model);
velocityEngine.MergeTemplate(templateLocation, encoding, velocityContext, writer);
} catch (VelocityException) {
throw;
} catch (Exception ex) {
throw new VelocityException(ex.ToString(), ex);
}
}
示例2: CreateSqlOutput
/// <summary>
/// Creates a velocity engine that is initiated. It loads up
/// templates from the 'Templates' folder.
/// </summary>
/// <returns></returns>
protected virtual string CreateSqlOutput(IEnumerable<Migration> migrations)
{
VelocityEngine velocityEngine = new VelocityEngine();
ExtendedProperties extendedProperties = new ExtendedProperties();
extendedProperties.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory + "\\Templates");
velocityEngine.Init(extendedProperties);
var context = new VelocityContext();
context.Put("migrations", migrations.OrderBy(migration => migration.MigrationDate));
var stringWriter = new StringWriter();
velocityEngine.MergeTemplate("deployment_tsql.vm", "ISO-8859-1", context, stringWriter);
return stringWriter.GetStringBuilder().ToString();
}
示例3: GetString
/// <summary>
/// 生成内容
/// </summary>
/// <returns></returns>
public string GetString()
{
VelocityEngine ve = new VelocityEngine();//模板引擎实例化
ExtendedProperties ep = new ExtendedProperties();//模板引擎参数实例化
ep.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)300); //缓存时间(秒)
ve.Init(ep);
VelocityContext vc = new VelocityContext(); //当前的数据信息载体集合
foreach (var item in Items)
{
vc.Put(item.Key, item.Value);
}
TextWriter writer = new StringWriter();
ve.MergeTemplate(TemplateName, "utf-8", vc, writer);
return writer.ToString();
}
示例4: RenderTemplate
public string RenderTemplate(string masterPage, string templateName, IDictionary<string, object> data)
{
if (string.IsNullOrEmpty(templateName))
{
throw new ArgumentException("The \"templateName\" parameter must be specified", "templateName");
}
var name = !string.IsNullOrEmpty(masterPage)
? masterPage : templateName;
var engine = new VelocityEngine();
var props = new ExtendedProperties();
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, _templatesPath);
engine.Init(props);
var template = engine.GetTemplate(name);
template.Encoding = Encoding.UTF8.BodyName;
var context = new VelocityContext();
var templateData = data ?? new Dictionary<string, object>();
foreach (var key in templateData.Keys)
{
context.Put(key, templateData[key]);
}
if (!string.IsNullOrEmpty(masterPage))
{
context.Put("childContent", templateName);
}
using (var writer = new StringWriter())
{
engine.MergeTemplate(name, context, writer);
return writer.GetStringBuilder().ToString();
}
}