U4-8720 - add dynamic support, UmbracoHelper methods

This commit is contained in:
Stephan
2016-07-19 16:13:46 +02:00
parent dc476dcb02
commit a0caab410e
4 changed files with 207 additions and 58 deletions

View File

@@ -113,7 +113,14 @@ namespace Umbraco.Web
? DocumentById(id, _contentCache, DynamicNull.Null)
: _dynamicContentQuery.Content(id);
}
public dynamic Content(Guid id)
{
return _dynamicContentQuery == null
? DocumentById(id, _contentCache, DynamicNull.Null)
: _dynamicContentQuery.Content(id);
}
public dynamic ContentSingleAtXPath(string xpath, params XPathVariable[] vars)
{
return _dynamicContentQuery == null
@@ -135,6 +142,13 @@ namespace Umbraco.Web
: _dynamicContentQuery.Content(ids);
}
public dynamic Content(IEnumerable<Guid> ids)
{
return _dynamicContentQuery == null
? DocumentByIds(_contentCache, ids.ToArray())
: _dynamicContentQuery.Content(ids);
}
public dynamic ContentAtXPath(string xpath, params XPathVariable[] vars)
{
return _dynamicContentQuery == null
@@ -270,6 +284,14 @@ namespace Umbraco.Web
: new DynamicPublishedContent(doc).AsDynamic();
}
private dynamic DocumentById(Guid id, ContextualPublishedCache cache, object ifNotFound)
{
var doc = TypedDocumentById(id, cache);
return doc == null
? ifNotFound
: new DynamicPublishedContent(doc).AsDynamic();
}
private dynamic DocumentByXPath(string xpath, XPathVariable[] vars, ContextualPublishedCache cache, object ifNotFound)
{
var doc = cache.GetSingleByXPath(xpath, vars);
@@ -295,6 +317,15 @@ namespace Umbraco.Web
return new DynamicPublishedContentList(nodes);
}
private dynamic DocumentByIds(ContextualPublishedCache cache, IEnumerable<Guid> ids)
{
var dNull = DynamicNull.Null;
var nodes = ids.Select(eachId => DocumentById(eachId, cache, dNull))
.Where(x => TypeHelper.IsTypeAssignableFrom<DynamicNull>(x) == false)
.Cast<DynamicPublishedContent>();
return new DynamicPublishedContentList(nodes);
}
private dynamic DocumentsByXPath(string xpath, XPathVariable[] vars, ContextualPublishedCache cache)
{
return new DynamicPublishedContentList(