2017-07-20 11:21:28 +02:00
|
|
|
|
using System;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
2016-06-10 16:37:28 +02:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
2016-05-18 23:34:56 +02:00
|
|
|
|
using Umbraco.Core.Xml;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents an IDocumentProperty which is created based on an Xml structure.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
[XmlType(Namespace = "http://umbraco.org/webservices/")]
|
|
|
|
|
|
internal class XmlPublishedProperty : PublishedPropertyBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly string _sourceValue; // the raw, xml node value
|
2016-06-23 09:39:31 +02:00
|
|
|
|
|
2016-06-10 16:37:28 +02:00
|
|
|
|
// Xml cache not using XPath value... and as for the rest...
|
|
|
|
|
|
// we're single threaded here, keep it simple
|
2016-06-23 09:39:31 +02:00
|
|
|
|
private object _objectValue;
|
|
|
|
|
|
private bool _objectValueComputed;
|
|
|
|
|
|
private readonly bool _isPreviewing;
|
2017-07-21 17:19:00 +02:00
|
|
|
|
private readonly IPublishedContent _content;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the raw value of the property.
|
|
|
|
|
|
/// </summary>
|
2018-04-21 09:57:28 +02:00
|
|
|
|
public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
// in the Xml cache, everything is a string, and to have a value
|
2013-11-07 17:16:22 +01:00
|
|
|
|
// you want to have a non-null, non-empty string.
|
2018-04-21 09:57:28 +02:00
|
|
|
|
public override bool HasValue(string culture = null, string segment = null) => _sourceValue.Trim().Length > 0;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
2018-04-21 09:57:28 +02:00
|
|
|
|
public override object GetValue(string culture = null, string segment = null)
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
2017-12-06 11:51:35 +01:00
|
|
|
|
// NOT caching the source (intermediate) value since we'll never need it
|
|
|
|
|
|
// everything in Xml cache is per-request anyways
|
|
|
|
|
|
// also, properties should not be shared between requests and therefore
|
|
|
|
|
|
// are single threaded, so the following code should be safe & fast
|
|
|
|
|
|
|
|
|
|
|
|
if (_objectValueComputed) return _objectValue;
|
|
|
|
|
|
var inter = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
|
|
|
|
|
|
// initial reference cache level always is .Content
|
|
|
|
|
|
_objectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Element, inter, _isPreviewing);
|
|
|
|
|
|
_objectValueComputed = true;
|
|
|
|
|
|
return _objectValue;
|
2016-06-23 09:39:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-21 09:57:28 +02:00
|
|
|
|
public override object GetXPathValue(string culture = null, string segment = null) { throw new NotImplementedException(); }
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
2017-07-21 17:19:00 +02:00
|
|
|
|
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
|
|
|
|
|
|
: this(propertyType, content, isPreviewing)
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (propertyXmlData == null)
|
|
|
|
|
|
throw new ArgumentNullException(nameof(propertyXmlData), "Property xml source is null");
|
|
|
|
|
|
_sourceValue = XmlHelper.GetNodeValue(propertyXmlData);
|
2013-11-07 17:16:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-21 17:19:00 +02:00
|
|
|
|
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, string propertyData)
|
|
|
|
|
|
: this(propertyType, content, isPreviewing)
|
2013-11-07 17:16:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (propertyData == null)
|
2016-06-10 16:37:28 +02:00
|
|
|
|
throw new ArgumentNullException(nameof(propertyData));
|
|
|
|
|
|
_sourceValue = propertyData;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-21 17:19:00 +02:00
|
|
|
|
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing)
|
2016-06-10 16:37:28 +02:00
|
|
|
|
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
|
2013-11-07 17:16:22 +01:00
|
|
|
|
{
|
2016-06-10 16:37:28 +02:00
|
|
|
|
_sourceValue = string.Empty;
|
2017-07-21 17:19:00 +02:00
|
|
|
|
_content = content;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
_isPreviewing = isPreviewing;
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|