本文整理汇总了C#中IDataStore.OpenSession方法的典型用法代码示例。如果您正苦于以下问题:C# IDataStore.OpenSession方法的具体用法?C# IDataStore.OpenSession怎么用?C# IDataStore.OpenSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataStore
的用法示例。
在下文中一共展示了IDataStore.OpenSession方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateStat
public void GenerateStat(IDataStore data)
{
Velocity.Init();
var menu = PageBuilders.Select(x => new
{
url = x.PageTemplate,
name = x.PageName
});
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
version = version.Substring(0, version.LastIndexOf('.'));
foreach (var builder in PageBuilders)
{
if (builder.TargetDir == null)
{
builder.TargetDir = TargetDir;
}
VelocityContext context = new VelocityContext();
context.Put("menu", menu);
context.Put("version", version);
using (var s = data.OpenSession())
{
foreach (var obj in builder.BuildData(s))
{
context.Put(obj.Key, obj.Value);
}
}
using (MemoryStream pageContent = new MemoryStream())
using (TextWriter writer = new StreamWriter(pageContent))
{
Velocity.MergeTemplate(
TemplateDir + "/" + builder.PageTemplate,
Encoding.UTF8.WebName,
context,
writer
);
writer.Flush();
pageContent.Seek(0, SeekOrigin.Begin);
context.Put("content", new StreamReader(pageContent).ReadToEnd());
using (TextWriter writer2 = new StreamWriter(OutputDir + "/" + builder.PageTemplate))
{
Velocity.MergeTemplate(
TemplateDir + "/" + SharedPageTemplate,
Encoding.UTF8.WebName,
context,
writer2
);
}
}
}
foreach (var fileToCopy in FilesToCopy)
{
File.Copy(TemplateDir + "/" + fileToCopy, OutputDir + "/" + fileToCopy, true);
}
}