Files
Umbraco-CMS/src/Umbraco.Web/PublishedCache/NuCache/Navigable/NavigableContent.cs

98 lines
3.4 KiB
C#
Raw Normal View History

2016-05-27 14:26:28 +02:00
using System;
using System.Collections.Generic;
using Umbraco.Core.Models.PublishedContent;
2016-05-27 14:26:28 +02:00
using Umbraco.Core.Xml.XPath;
namespace Umbraco.Web.PublishedCache.NuCache.Navigable
{
2017-07-12 14:09:31 +02:00
internal class NavigableContent : INavigableContent
2016-05-27 14:26:28 +02:00
{
private readonly IPublishedContent _icontent;
private readonly PublishedContent _content;
//private readonly object[] _builtInValues1;
private readonly string[] _builtInValues;
public NavigableContent(IPublishedContent content)
{
_icontent = content;
_content = PublishedContent.UnwrapIPublishedContent(_icontent);
// built-in properties (attributes)
//_builtInValues1 = new object[]
// {
// _content.Name,
// _content.ParentId,
// _content.CreateDate,
// _content.UpdateDate,
// true, // isDoc
// _content.SortOrder,
// _content.Level,
// _content.TemplateId,
// _content.WriterId,
// _content.CreatorId,
// _content.UrlName,
// _content.IsDraft
// };
var i = 0;
_builtInValues = new []
{
XmlString(i++, _content.Name),
XmlString(i++, _content.ParentId),
XmlString(i++, _content.CreateDate),
XmlString(i++, _content.UpdateDate),
XmlString(i++, true), // isDoc
XmlString(i++, _content.SortOrder),
XmlString(i++, _content.Level),
XmlString(i++, _content.TemplateId),
XmlString(i++, _content.WriterId),
XmlString(i++, _content.CreatorId),
XmlString(i++, _content.UrlName),
XmlString(i, _content.IsDraft)
};
}
private string XmlString(int index, object value)
{
var field = Type.FieldTypes[index];
return field.XmlStringConverter == null ? value.ToString() : field.XmlStringConverter(value);
}
#region INavigableContent
2017-07-12 14:09:31 +02:00
public IPublishedContent InnerContent => _icontent;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public int Id => _content.Id;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public int ParentId => _content.ParentId;
2016-05-27 14:26:28 +02:00
2017-07-12 14:09:31 +02:00
public INavigableContentType Type => NavigableContentType.GetContentType(_content.ContentType);
2016-05-27 14:26:28 +02:00
// returns all child ids, will be filtered by the source
2017-07-12 14:09:31 +02:00
public IList<int> ChildIds => _content.ChildIds;
2016-05-27 14:26:28 +02:00
public object Value(int index)
{
if (index < 0)
2017-07-12 14:09:31 +02:00
throw new ArgumentOutOfRangeException(nameof(index));
2016-05-27 14:26:28 +02:00
if (index < NavigableContentType.BuiltinProperties.Length)
{
// built-in field, ie attribute
//return XmlString(index, _builtInValues1[index]);
return _builtInValues[index];
}
index -= NavigableContentType.BuiltinProperties.Length;
var properties = _content.PropertiesArray;
if (index >= properties.Length)
2017-07-12 14:09:31 +02:00
throw new ArgumentOutOfRangeException(nameof(index));
2016-05-27 14:26:28 +02:00
// custom property, ie element
2017-12-06 11:51:35 +01:00
return properties[index].GetXPathValue();
2016-05-27 14:26:28 +02:00
}
#endregion
}
}