PropertyValueConverter - refactoring WIP

This commit is contained in:
Stephan
2017-07-21 17:19:00 +02:00
parent 0e832d195a
commit 83f84f05b9
72 changed files with 1032 additions and 673 deletions

View File

@@ -240,7 +240,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
#region Property Set
public override IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, Guid setKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
public override IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, IPropertySet set, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
{
throw new NotImplementedException();
}

View File

@@ -683,8 +683,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
string value;
const bool isPreviewing = false; // false :: never preview a media
var property = valueDictionary.TryGetValue(alias, out value) == false || value == null
? new XmlPublishedProperty(propertyType, isPreviewing)
: new XmlPublishedProperty(propertyType, isPreviewing, value);
? new XmlPublishedProperty(propertyType, this, isPreviewing)
: new XmlPublishedProperty(propertyType, this, isPreviewing, value);
_properties.Add(property);
}

View File

@@ -301,7 +301,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private void InitializeNode()
{
InitializeNode(_xmlNode, _isPreviewing,
InitializeNode(this, _xmlNode, _isPreviewing,
out _id, out _key, out _template, out _sortOrder, out _name, out _writerName,
out _urlName, out _creatorName, out _creatorId, out _writerId, out _docTypeAlias, out _docTypeId, out _path,
out _version, out _createDate, out _updateDate, out _level, out _isDraft, out _contentType, out _properties,
@@ -311,7 +311,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
_nodeInitialized = true;
}
internal static void InitializeNode(XmlNode xmlNode, bool isPreviewing,
internal static void InitializeNode(XmlPublishedContent node, XmlNode xmlNode, bool isPreviewing,
out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
out Guid version, out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
@@ -405,8 +405,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
foreach (var propertyType in contentType.PropertyTypes)
{
var val = propertyNodes.TryGetValue(propertyType.PropertyTypeAlias.ToLowerInvariant(), out XmlNode n)
? new XmlPublishedProperty(propertyType, isPreviewing, n)
: new XmlPublishedProperty(propertyType, isPreviewing);
? new XmlPublishedProperty(propertyType, node, isPreviewing, n)
: new XmlPublishedProperty(propertyType, node, isPreviewing);
properties[propertyType.PropertyTypeAlias] = val;
}

View File

@@ -22,6 +22,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private object _objectValue;
private bool _objectValueComputed;
private readonly bool _isPreviewing;
private readonly IPublishedContent _content;
/// <summary>
/// Gets the raw value of the property.
@@ -42,9 +43,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
// are single threaded, so the following code should be safe & fast
if (_objectValueComputed) return _objectValue;
var inter = PropertyType.ConvertSourceToInter(_sourceValue, _isPreviewing);
var inter = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
// initial reference cache level always is .Content
_objectValue = PropertyType.ConvertInterToObject(PropertyCacheLevel.Content, inter, _isPreviewing);
_objectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Content, inter, _isPreviewing);
_objectValueComputed = true;
return _objectValue;
}
@@ -52,26 +53,27 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
public override object XPathValue { get { throw new NotImplementedException(); } }
public XmlPublishedProperty(PublishedPropertyType propertyType, bool isPreviewing, XmlNode propertyXmlData)
: this(propertyType, isPreviewing)
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
: this(propertyType, content, isPreviewing)
{
if (propertyXmlData == null)
throw new ArgumentNullException(nameof(propertyXmlData), "Property xml source is null");
_sourceValue = XmlHelper.GetNodeValue(propertyXmlData);
}
public XmlPublishedProperty(PublishedPropertyType propertyType, bool isPreviewing, string propertyData)
: this(propertyType, isPreviewing)
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, string propertyData)
: this(propertyType, content, isPreviewing)
{
if (propertyData == null)
throw new ArgumentNullException(nameof(propertyData));
_sourceValue = propertyData;
}
public XmlPublishedProperty(PublishedPropertyType propertyType, bool isPreviewing)
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
_sourceValue = string.Empty;
_content = content;
_isPreviewing = isPreviewing;
}
}