Files
Umbraco-CMS/src/Umbraco.PublishedCache.NuCache/Navigable/NavigableContent.cs
Mole bf41c2eeaa Netcore: Align namespaces (#9801)
* Rename Umbraco.Core namespace to Umbraco.Cms.Core

* Move extension methods in core project to Umbraco.Extensions

* Move extension methods in core project to Umbraco.Extensions

* Rename Umbraco.Examine namespace to Umbraco.Cms.Examine

* Move examine extensions to Umbraco.Extensions namespace

* Reflect changed namespaces in Builder and fix unit tests

* Adjust namespace in Umbraco.ModelsBuilder.Embedded

* Adjust namespace in Umbraco.Persistence.SqlCe

* Adjust namespace in Umbraco.PublishedCache.NuCache

* Align namespaces in Umbraco.Web.BackOffice

* Align namespaces in Umbraco.Web.Common

* Ensure that SqlCeSupport is still enabled after changing the namespace

* Align namespaces in Umbraco.Web.Website

* Align namespaces in Umbraco.Web.UI.NetCore

* Align namespaces in Umbraco.Tests.Common

* Align namespaces in Umbraco.Tests.UnitTests

* Align namespaces in Umbraco.Tests.Integration

* Fix errors caused by changed namespaces

* Fix integration tests

* Undo the Umbraco.Examine.Lucene namespace change

This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows.

* Fix merge

* Fix Merge
2021-02-18 11:06:02 +01:00

80 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Xml.XPath;
namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
{
internal class NavigableContent : INavigableContent
{
private readonly PublishedContent _content;
private readonly string[] _builtInValues;
public NavigableContent(IPublishedContent content)
{
InnerContent = content;
_content = PublishedContent.UnwrapIPublishedContent(InnerContent);
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.UrlSegment),
XmlString(i, _content.IsDraft())
};
}
private string XmlString(int index, object value)
{
if (value == null) return string.Empty;
var field = Type.FieldTypes[index];
return field.XmlStringConverter == null ? value.ToString() : field.XmlStringConverter(value);
}
#region INavigableContent
public IPublishedContent InnerContent { get; }
public int Id => _content.Id;
public int ParentId => _content.ParentId;
public INavigableContentType Type => NavigableContentType.GetContentType(_content.ContentType);
// returns all child ids, will be filtered by the source
public IList<int> ChildIds => _content.ChildIds;
public object Value(int index)
{
if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index));
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)
throw new ArgumentOutOfRangeException(nameof(index));
// custom property, ie element
return properties[index].GetXPathValue();
}
#endregion
}
}