本文整理汇总了C#中RenderState.Render方法的典型用法代码示例。如果您正苦于以下问题:C# RenderState.Render方法的具体用法?C# RenderState.Render怎么用?C# RenderState.Render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RenderState
的用法示例。
在下文中一共展示了RenderState.Render方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: processImportTemplateElement
private async Task<Errorable> processImportTemplateElement(RenderState st)
{
// Imports content directly from another blob, addressable by a relative path or an absolute path.
// Relative path is always relative to the current blob's absolute path.
// In the case of nested imports, relative paths are relative to the absolute path of the importee's parent blob.
// <cms-import-template path="/template/main">
// <area id="head">
// <link rel="" />
// </area>
// <area id="body">
// <div>
// ...
// </div>
// </area>
// </cms-import-template>
// Absolute paths are canonicalized. An exception will be thrown if the path contains too many '..' references that
// bring the canonicalized path above the root of the tree (which is impossible).
// Recursively call RenderBlob on the imported blob and include the rendered HTMLFragment into this rendering.
var xr = st.Reader;
// st.Reader is pointing to "cms-import-template" Element.
if (!xr.HasAttributes || !xr.MoveToAttribute("path"))
{
st.Error("cms-import-template requires a 'path' attribute");
st.SkipElementAndChildren("cms-import-template");
return Errorable.NoErrors;
}
string ncpath = xr.Value;
st.Reader.MoveToElement();
TreePathStreamedBlob tmplBlob;
// Canonicalize the absolute or relative path relative to the current item's path:
var abspath = PathObjectModel.ParseBlobPath(ncpath);
CanonicalBlobPath path = abspath.Collapse(abs => abs, rel => (st.Item.TreeBlobPath.Path.Tree + rel)).Canonicalize();
// Fetch the Blob given the absolute path constructed:
TreeBlobPath tbp = new TreeBlobPath(st.Item.TreeBlobPath.RootTreeID, path);
var etmplBlob = await st.Engine.TreePathStreamedBlobs.GetBlobByTreePath(tbp).ConfigureAwait(continueOnCapturedContext: false);
if (etmplBlob.HasErrors)
{
st.SkipElementAndChildren("cms-import-template");
// Check if the error is a simple blob not found error:
bool notFound = etmplBlob.Errors.Any(er => er is BlobNotFoundByPathError);
if (notFound)
{
st.Error("cms-import-template could not find blob by path '{0}' off tree '{1}'", tbp.Path.ToString(), tbp.RootTreeID.ToString());
return Errorable.NoErrors;
}
// Error was more serious:
foreach (var err in etmplBlob.Errors.Errors)
{
st.Error(err.Message);
}
return etmplBlob.Errors;
}
else tmplBlob = etmplBlob.Value;
Debug.Assert(tmplBlob != null);
// This lambda processes the entire imported template:
Func<RenderState, Task<Errorable<bool>>> processElements = (Func<RenderState, Task<Errorable<bool>>>)(async sst =>
{
// Make sure cms-template is the first element from the imported template blob:
if (sst.Reader.LocalName != "cms-template")
{
sst.Error("cms-import-template expected cms-template as first element of imported template");
sst.SkipElementAndChildren(sst.Reader.LocalName);
st.SkipElementAndChildren("cms-import-template");
return false;
}
// Don't move the st.Reader yet until we know the cms-import-template has a cms-template-area in it:
string fillerAreaId = null;
bool isFirstArea = !st.Reader.IsEmptyElement;
// Create a new RenderState that reads from the parent blob and writes to the template's renderer:
var stWriter = new RenderState(st.Engine, st.Item, st.Reader, sst.Writer);
// This lambda is called recursively to handle cms-template-area elements found within parent cms-template-area elements in the template:
Func<RenderState, Task<Errorable<bool>>> processTemplateAreaElements = null;
processTemplateAreaElements = (Func<RenderState, Task<Errorable<bool>>>)(async tst =>
{
// Only process cms-template-area elements:
if (tst.Reader.LocalName != "cms-template-area")
{
// Use DefaultProcessElements to handle processing other cms- custom elements from the template:
return await RenderState.DefaultProcessElements(tst);
}
// Read the cms-template-area's id attribute:
if (!tst.Reader.MoveToAttribute("id"))
//.........这里部分代码省略.........
示例2: processImportElement
private async Task<Errorable> processImportElement(RenderState st)
{
// Imports content directly from another blob, addressable by a relative path or an absolute path.
// Relative path is always relative to the current blob's absolute path.
// In the case of nested imports, relative paths are relative to the absolute path of the importee's parent blob.
// <cms-import path="../templates/main" />
// <cms-import path="/templates/main" />
// Absolute paths are canonicalized. An exception will be thrown if the path contains too many '..' references that
// bring the canonicalized path above the root of the tree (which is impossible).
// Recursively call RenderBlob on the imported blob and include the rendered HTMLFragment into this rendering.
// st.Reader is pointing to "cms-import" Element.
if (!st.Reader.IsEmptyElement) st.Error("cms-import element must be empty");
if (st.Reader.HasAttributes && st.Reader.MoveToFirstAttribute())
{
string ncpath = st.Reader.GetAttribute("path");
string blob;
TreePathStreamedBlob tpsBlob;
// Fetch the TreePathStreamedBlob for the given path:
// Canonicalize the absolute or relative path relative to the current item's path:
var abspath = PathObjectModel.ParseBlobPath(ncpath);
CanonicalBlobPath path = abspath.Collapse(abs => abs, rel => (st.Item.TreeBlobPath.Path.Tree + rel)).Canonicalize();
// Fetch the Blob given the absolute path constructed:
TreeBlobPath tbp = new TreeBlobPath(st.Item.TreeBlobPath.RootTreeID, path);
var etpsBlob = await st.Engine.TreePathStreamedBlobs.GetBlobByTreePath(tbp).ConfigureAwait(continueOnCapturedContext: false);
if (etpsBlob.HasErrors)
{
st.SkipElementAndChildren("cms-import");
// Check if the error is a simple blob not found error:
bool notFound = etpsBlob.Errors.Any(er => er is BlobNotFoundByPathError);
if (notFound)
{
st.Error("cms-import could not find blob by path '{0]' off tree '{1}'", tbp.Path, tbp.RootTreeID);
return Errorable.NoErrors;
}
// Error was more serious:
foreach (var err in etpsBlob.Errors)
st.Error(err.Message);
return etpsBlob.Errors;
}
else tpsBlob = etpsBlob.Value;
Debug.Assert(tpsBlob != null);
// Fetch the contents for the given TreePathStreamedBlob:
// TODO: we could probably asynchronously load blobs and render their contents
// then at a final sync point go in and inject their contents into the proper
// places in each imported blob's parent StringBuilder.
// Render the blob inline:
RenderState rsInner = new RenderState(st.Engine, tpsBlob);
var einnerSb = await rsInner.Render().ConfigureAwait(continueOnCapturedContext: false);
if (einnerSb.HasErrors)
{
foreach (var err in einnerSb.Errors)
st.Error(err.Message);
return einnerSb.Errors;
}
blob = einnerSb.Value.ToString();
st.Writer.Append(blob);
// Move the reader back to the element node:
st.Reader.MoveToElement();
}
return Errorable.NoErrors;
}