diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentModelFactory.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentModelFactory.cs
index 3e8edd4b74..7eb8909878 100644
--- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentModelFactory.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentModelFactory.cs
@@ -1,25 +1,27 @@
-namespace Umbraco.Core.Models.PublishedContent
+using System;
+using System.Collections.Generic;
+
+namespace Umbraco.Core.Models.PublishedContent
{
///
/// Provides the model creation service.
///
- public interface IPublishedContentModelFactory
+ public interface IPublishedContentModelFactory // fixme rename IFacadeModelFactory
{
///
- /// Creates a strongly-typed model representing a published content.
+ /// Creates a strongly-typed model representing a property set.
///
- /// The original published content.
- /// The strongly-typed model representing the published content, or the published content
+ /// The original property set.
+ /// The strongly-typed model representing the property set, or the property set
/// itself it the factory has no model for that content type.
- IPublishedContent CreateModel(IPublishedContent content);
+ IPropertySet CreateModel(IPropertySet set);
- // temp - dont break MB
- //T CreateModel(IPublishedFragment content);
+ ///
+ /// Gets the model type map.
+ ///
+ Dictionary ModelTypeMap { get; }
// fixme
- // and we'd need a
- // PublishedContentModel = ContentModel : ContentWrapper
- // PublishedFragmentModel = FragmentModel : FragmentWrapper
//
// ModelFactory.Meta.Model("thing").ClrType (find the our post?)
//
diff --git a/src/Umbraco.Core/Models/PublishedContent/ModelType.cs b/src/Umbraco.Core/Models/PublishedContent/ModelType.cs
new file mode 100644
index 0000000000..93ba2e1788
--- /dev/null
+++ b/src/Umbraco.Core/Models/PublishedContent/ModelType.cs
@@ -0,0 +1,296 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Reflection;
+
+namespace Umbraco.Core.Models.PublishedContent
+{
+ // create a simple model type:
+ // ModelType.For("alias")
+ // use in a generic type:
+ // typeof (IEnumerable<>).MakeGenericType(ModelType.For("alias"))
+ // use in an array:
+ // ModelType.For("alias").MakeArrayType()
+
+ public class ModelType : Type
+ {
+ private ModelType(string contentTypeAlias)
+ {
+ ContentTypeAlias = contentTypeAlias;
+ Name = "{" + ContentTypeAlias + "}";
+ }
+
+ public string ContentTypeAlias { get; }
+
+ public override string ToString()
+ => Name;
+
+ public static ModelType For(string alias)
+ => new ModelType(alias);
+
+ public static Type Map(Type type, Dictionary modelTypes)
+ {
+ if (type is ModelType modelType)
+ {
+ if (modelTypes.TryGetValue(modelType.ContentTypeAlias, out Type actualType))
+ return actualType;
+ throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{modelType.ContentTypeAlias}\".");
+ }
+
+ if (type is ModelTypeArrayType arrayType)
+ {
+ if (modelTypes.TryGetValue(arrayType.ContentTypeAlias, out Type actualType))
+ return actualType.MakeArrayType();
+ throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{arrayType.ContentTypeAlias}\".");
+ }
+
+ if (type.IsGenericType == false)
+ return type;
+
+ var args = type.GetGenericArguments().Select(x => Map(x, modelTypes)).ToArray();
+
+ return type.GetGenericTypeDefinition().MakeGenericType(args);
+ }
+
+ public static bool Equals(Type t1, Type t2)
+ {
+ if (t1 == t2)
+ return true;
+
+ if (t1 is ModelType m1 && t2 is ModelType m2)
+ return m1.ContentTypeAlias == m2.ContentTypeAlias;
+
+ if (t1 is ModelTypeArrayType a1 && t2 is ModelTypeArrayType a2)
+ return a1.ContentTypeAlias == a2.ContentTypeAlias;
+
+ if (t1.IsGenericType == false || t2.IsGenericType == false)
+ return false;
+
+ var args1 = t1.GetGenericArguments();
+ var args2 = t2.GetGenericArguments();
+ if (args1.Length != args2.Length) return false;
+
+ for (var i = 0; i < args1.Length; i++)
+ {
+ // ReSharper disable once CheckForReferenceEqualityInstead.2
+ if (Equals(args1[i], args2[i]) == false) return false;
+ }
+
+ return true;
+ }
+
+ protected override TypeAttributes GetAttributeFlagsImpl()
+ => TypeAttributes.Class;
+
+ public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
+ => Array.Empty();
+
+ protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
+ => null;
+
+ public override Type[] GetInterfaces()
+ => Array.Empty();
+
+ public override Type GetInterface(string name, bool ignoreCase)
+ => null;
+
+ public override EventInfo[] GetEvents(BindingFlags bindingAttr)
+ => Array.Empty();
+
+ public override EventInfo GetEvent(string name, BindingFlags bindingAttr)
+ => null;
+
+ public override Type[] GetNestedTypes(BindingFlags bindingAttr)
+ => Array.Empty();
+
+ public override Type GetNestedType(string name, BindingFlags bindingAttr)
+ => null;
+
+ public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
+ => Array.Empty();
+
+ protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
+ => null;
+
+ public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
+ => Array.Empty();
+
+ protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
+ => null;
+
+ public override FieldInfo[] GetFields(BindingFlags bindingAttr)
+ => Array.Empty();
+
+ public override FieldInfo GetField(string name, BindingFlags bindingAttr)
+ => null;
+
+ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
+ => Array.Empty();
+
+ public override object[] GetCustomAttributes(Type attributeType, bool inherit)
+ => Array.Empty
public override bool IsConverter(PublishedPropertyType propertyType)
- {
- return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias)
- || propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinks2Alias);
- }
+ => propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias)
+ || propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinks2Alias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
- {
- return typeof (JArray);
- }
+ => typeof (JArray);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
- {
- return PropertyCacheLevel.Content;
- }
+ => PropertyCacheLevel.Content;
- public override object ConvertSourceToInter(PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToInter(IPropertySet owner, PublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -140,7 +134,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return link;
}
- public override object ConvertInterToXPath(PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertInterToXPath(IPropertySet owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (inter == null) return null;
var sourceString = inter.ToString();
diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs
index 32190d2c19..2041af92b9 100644
--- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs
+++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs
@@ -63,7 +63,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
}
- public override object ConvertSourceToInter(PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToInter(IPropertySet owner, PublishedPropertyType propertyType, object source, bool preview)
{
if (source == null)
{
diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs
index a7a9f433bf..c921930abd 100644
--- a/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs
+++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs
@@ -17,21 +17,15 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
};
public override bool IsConverter(PublishedPropertyType propertyType)
- {
- return PropertyTypeAliases.Contains(propertyType.PropertyEditorAlias);
- }
+ => PropertyTypeAliases.Contains(propertyType.PropertyEditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
- {
- return typeof (string);
- }
+ => typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
- {
- return PropertyCacheLevel.Facade;
- }
+ => PropertyCacheLevel.Facade;
- public override object ConvertSourceToInter(PublishedPropertyType propertyType, object source, bool preview)
+ public override object ConvertSourceToInter(IPropertySet owner, PublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -43,13 +37,13 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return sourceString;
}
- public override object ConvertInterToObject(PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertInterToObject(IPropertySet owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter ?? string.Empty;
}
- public override object ConvertInterToXPath(PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
+ public override object ConvertInterToXPath(IPropertySet owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter;
diff --git a/src/Umbraco.Web/PublishedCache/FacadeServiceBase.cs b/src/Umbraco.Web/PublishedCache/FacadeServiceBase.cs
index 17e3080edf..90d4fecced 100644
--- a/src/Umbraco.Web/PublishedCache/FacadeServiceBase.cs
+++ b/src/Umbraco.Web/PublishedCache/FacadeServiceBase.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using Umbraco.Core.Composing;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
@@ -26,10 +27,14 @@ namespace Umbraco.Web.PublishedCache
public virtual IPropertySet CreateSet(PublishedContentType contentType, Guid key, Dictionary values, bool previewing, PropertyCacheLevel referenceCacheLevel)
{
- return new PropertySet(contentType, key, values, previewing, this, referenceCacheLevel);
+ var set = new PropertySet(contentType, key, values, previewing, this, referenceCacheLevel);
+ var model = Current.PublishedContentModelFactory.CreateModel(set);
+ if (model == null)
+ throw new Exception("Factory returned null.");
+ return model;
}
- public abstract IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, Guid setKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
+ public abstract IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, IPropertySet set, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
public abstract string EnterPreview(IUser user, int contentId);
public abstract void RefreshPreview(string previewToken, int contentId);
diff --git a/src/Umbraco.Web/PublishedCache/IFacadeService.cs b/src/Umbraco.Web/PublishedCache/IFacadeService.cs
index b5ec511fc0..bb7acfa052 100644
--- a/src/Umbraco.Web/PublishedCache/IFacadeService.cs
+++ b/src/Umbraco.Web/PublishedCache/IFacadeService.cs
@@ -169,12 +169,12 @@ namespace Umbraco.Web.PublishedCache
/// Creates a set property.
///
/// The property type.
- /// The set key.
+ /// The set.
/// A value indicating whether previewing.
/// The reference cache level.
/// The source value.
/// A set property.
- IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, Guid setKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
+ IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, IPropertySet set, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
#endregion
}
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/FacadeService.cs b/src/Umbraco.Web/PublishedCache/NuCache/FacadeService.cs
index 0ae481c0a3..b08e885446 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/FacadeService.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/FacadeService.cs
@@ -1536,9 +1536,9 @@ AND cmsContentNu.nodeId IS NULL
#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)
{
- return new PropertySetProperty(FacadeAccessor, propertyType, setKey, previewing, referenceCacheLevel, sourceValue);
+ return new PropertySetProperty(FacadeAccessor, propertyType, set, previewing, referenceCacheLevel, sourceValue);
}
#endregion
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/Property.cs b/src/Umbraco.Web/PublishedCache/NuCache/Property.cs
index 12056fbc7b..2e7ee9275d 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/Property.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/Property.cs
@@ -15,6 +15,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private readonly Guid _contentUid;
private readonly bool _isPreviewing;
private readonly bool _isMember;
+ private readonly IPublishedContent _content;
private readonly object _locko = new object();
@@ -25,28 +26,29 @@ namespace Umbraco.Web.PublishedCache.NuCache
private string _recurseCacheKey;
// initializes a published content property with no value
- public Property(PublishedPropertyType propertyType, IPublishedContent content, IFacadeAccessor facadeAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Content)
+ public Property(PublishedPropertyType propertyType, PublishedContent content, IFacadeAccessor facadeAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Content)
: this(propertyType, content, null, facadeAccessor, referenceCacheLevel)
{ }
// initializes a published content property with a value
- public Property(PublishedPropertyType propertyType, IPublishedContent content, object sourceValue, IFacadeAccessor facadeAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Content)
+ public Property(PublishedPropertyType propertyType, PublishedContent content, object sourceValue, IFacadeAccessor facadeAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Content)
: base(propertyType, referenceCacheLevel)
{
_sourceValue = sourceValue;
_contentUid = content.Key;
- var inner = PublishedContent.UnwrapIPublishedContent(content);
- _isPreviewing = inner.IsPreviewing;
+ _content = content;
+ _isPreviewing = content.IsPreviewing;
_isMember = content.ContentType.ItemType == PublishedItemType.Member;
_facadeAccessor = facadeAccessor;
}
// clone for previewing as draft a published content that is published and has no draft
- public Property(Property origin)
+ public Property(Property origin, IPublishedContent content)
: base(origin.PropertyType, origin.ReferenceCacheLevel)
{
_sourceValue = origin._sourceValue;
_contentUid = origin._contentUid;
+ _content = content;
_isPreviewing = true;
_isMember = origin._isMember;
_facadeAccessor = origin._facadeAccessor;
@@ -122,7 +124,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
if (_interInitialized) return _interValue;
- _interValue = PropertyType.ConvertSourceToInter(_sourceValue, _isPreviewing);
+ _interValue = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
_interInitialized = true;
return _interValue;
}
@@ -139,7 +141,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (cacheValues.ObjectInitialized) return cacheValues.ObjectValue;
// initial reference cache level always is .Content
- cacheValues.ObjectValue = PropertyType.ConvertInterToObject(PropertyCacheLevel.Content, GetInterValue(), _isPreviewing);
+ cacheValues.ObjectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Content, GetInterValue(), _isPreviewing);
cacheValues.ObjectInitialized = true;
return cacheValues.ObjectValue;
}
@@ -156,7 +158,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (cacheValues.XPathInitialized) return cacheValues.XPathValue;
// initial reference cache level always is .Content
- cacheValues.XPathValue = PropertyType.ConvertInterToXPath(PropertyCacheLevel.Content, GetInterValue(), _isPreviewing);
+ cacheValues.XPathValue = PropertyType.ConvertInterToXPath(_content, PropertyCacheLevel.Content, GetInterValue(), _isPreviewing);
cacheValues.XPathInitialized = true;
return cacheValues.XPathValue;
}
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PropertySetProperty.cs b/src/Umbraco.Web/PublishedCache/NuCache/PropertySetProperty.cs
index cc4e9eaa90..eaad29a993 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/PropertySetProperty.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/PropertySetProperty.cs
@@ -11,15 +11,15 @@ namespace Umbraco.Web.PublishedCache.NuCache
private string _valuesCacheKey;
// initializes a published item property
- public PropertySetProperty(IFacadeAccessor facadeAccessor, PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
- : base(propertyType, fragmentKey, previewing, referenceCacheLevel, sourceValue)
+ public PropertySetProperty(IFacadeAccessor facadeAccessor, PublishedPropertyType propertyType, IPropertySet set, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
+ : base(propertyType, set, previewing, referenceCacheLevel, sourceValue)
{
_facadeAccessor = facadeAccessor;
}
// used to cache the CacheValues of this property
internal string ValuesCacheKey => _valuesCacheKey
- ?? (_valuesCacheKey = CacheKeys.PropertyCacheValues(FragmentKey, PropertyTypeAlias, IsPreviewing));
+ ?? (_valuesCacheKey = CacheKeys.PropertyCacheValues(Set.Key, PropertyTypeAlias, IsPreviewing));
protected override CacheValues GetSnapshotCacheValues()
{
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs
index e93b76221c..b06cc3927f 100644
--- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs
@@ -92,7 +92,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
IsPreviewing = true;
// clone properties so _isPreviewing is true
- PropertiesArray = origin.PropertiesArray.Select(x => (IPublishedProperty) new Property((Property) x)).ToArray();
+ PropertiesArray = origin.PropertiesArray.Select(x => (IPublishedProperty) new Property((Property) x, this)).ToArray();
}
#endregion
diff --git a/src/Umbraco.Web/PublishedCache/PropertySet.cs b/src/Umbraco.Web/PublishedCache/PropertySet.cs
index 98cd39c978..ae93c55a32 100644
--- a/src/Umbraco.Web/PublishedCache/PropertySet.cs
+++ b/src/Umbraco.Web/PublishedCache/PropertySet.cs
@@ -31,7 +31,7 @@ namespace Umbraco.Web.PublishedCache
.Select(propertyType =>
{
values.TryGetValue(propertyType.PropertyTypeAlias, out object value);
- return facadeService.CreateSetProperty(propertyType, Key, previewing, referenceCacheLevel, value);
+ return facadeService.CreateSetProperty(propertyType, this, previewing, referenceCacheLevel, value);
})
.ToArray();
}
@@ -55,7 +55,7 @@ namespace Umbraco.Web.PublishedCache
.Select(propertyType =>
{
values.TryGetValue(propertyType.PropertyTypeAlias, out object value);
- return (IPublishedProperty) new PropertySetProperty(propertyType, Key, previewing, cacheLevel, value);
+ return (IPublishedProperty) new PropertySetProperty(propertyType, this, previewing, cacheLevel, value);
})
.ToArray();
}
diff --git a/src/Umbraco.Web/PublishedCache/PropertySetProperty.cs b/src/Umbraco.Web/PublishedCache/PropertySetProperty.cs
index 4faa2090aa..784351115d 100644
--- a/src/Umbraco.Web/PublishedCache/PropertySetProperty.cs
+++ b/src/Umbraco.Web/PublishedCache/PropertySetProperty.cs
@@ -6,8 +6,8 @@ namespace Umbraco.Web.PublishedCache
{
class PropertySetProperty : PropertySetPropertyBase
{
- public PropertySetProperty(PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel cacheLevel, object sourceValue = null)
- : base(propertyType, fragmentKey, previewing, cacheLevel, sourceValue)
+ public PropertySetProperty(PublishedPropertyType propertyType, IPropertySet set, bool previewing, PropertyCacheLevel cacheLevel, object sourceValue = null)
+ : base(propertyType, set, previewing, cacheLevel, sourceValue)
{ }
protected override CacheValues GetSnapshotCacheValues()
diff --git a/src/Umbraco.Web/PublishedCache/PropertySetPropertyBase.cs b/src/Umbraco.Web/PublishedCache/PropertySetPropertyBase.cs
index d31a581987..f7d39c62fa 100644
--- a/src/Umbraco.Web/PublishedCache/PropertySetPropertyBase.cs
+++ b/src/Umbraco.Web/PublishedCache/PropertySetPropertyBase.cs
@@ -9,7 +9,7 @@ namespace Umbraco.Web.PublishedCache
private readonly object _locko = new object();
private readonly object _sourceValue;
- protected readonly Guid FragmentKey;
+ protected readonly IPropertySet Set;
protected readonly bool IsPreviewing;
protected readonly bool IsMember;
@@ -18,11 +18,11 @@ namespace Umbraco.Web.PublishedCache
private CacheValues _cacheValues;
// initializes a published item property
- protected PropertySetPropertyBase(PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
+ protected PropertySetPropertyBase(PublishedPropertyType propertyType, IPropertySet set, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
: base(propertyType, referenceCacheLevel)
{
_sourceValue = sourceValue;
- FragmentKey = fragmentKey;
+ Set = set;
IsPreviewing = previewing;
IsMember = propertyType.ContentType.ItemType == PublishedItemType.Member;
}
@@ -117,7 +117,7 @@ namespace Umbraco.Web.PublishedCache
{
if (_interInitialized) return _interValue;
- _interValue = PropertyType.ConvertSourceToInter(_sourceValue, IsPreviewing);
+ _interValue = PropertyType.ConvertSourceToInter(Set, _sourceValue, IsPreviewing);
_interInitialized = true;
return _interValue;
}
@@ -136,7 +136,7 @@ namespace Umbraco.Web.PublishedCache
var cacheValues = GetCacheValues(cacheLevel);
if (cacheValues.ObjectInitialized) return cacheValues.ObjectValue;
- cacheValues.ObjectValue = PropertyType.ConvertInterToObject(referenceCacheLevel, GetInterValue(), IsPreviewing);
+ cacheValues.ObjectValue = PropertyType.ConvertInterToObject(Set, referenceCacheLevel, GetInterValue(), IsPreviewing);
cacheValues.ObjectInitialized = true;
return cacheValues.ObjectValue;
}
@@ -155,7 +155,7 @@ namespace Umbraco.Web.PublishedCache
var cacheValues = GetCacheValues(cacheLevel);
if (cacheValues.XPathInitialized) return cacheValues.XPathValue;
- cacheValues.XPathValue = PropertyType.ConvertInterToXPath(referenceCacheLevel, GetInterValue(), IsPreviewing);
+ cacheValues.XPathValue = PropertyType.ConvertInterToXPath(Set, referenceCacheLevel, GetInterValue(), IsPreviewing);
cacheValues.XPathInitialized = true;
return cacheValues.XPathValue;
}
diff --git a/src/Umbraco.Web/PublishedCache/PublishedMember.cs b/src/Umbraco.Web/PublishedCache/PublishedMember.cs
index ecd6883fa0..cfc89a1fbd 100644
--- a/src/Umbraco.Web/PublishedCache/PublishedMember.cs
+++ b/src/Umbraco.Web/PublishedCache/PublishedMember.cs
@@ -21,15 +21,12 @@ namespace Umbraco.Web.PublishedCache
public PublishedMember(IMember member, PublishedContentType publishedMemberType)
{
- if (member == null) throw new ArgumentNullException(nameof(member));
- if (publishedMemberType == null) throw new ArgumentNullException(nameof(publishedMemberType));
-
- _member = member;
+ _member = member ?? throw new ArgumentNullException(nameof(member));
_membershipUser = member;
- _publishedMemberType = publishedMemberType;
+ _publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));
_properties = PublishedProperty.MapProperties(_publishedMemberType.PropertyTypes, _member.Properties,
- (t, v) => new RawValueProperty(t, v ?? string.Empty))
+ (t, v) => new RawValueProperty(t, this, v ?? string.Empty))
.ToArray();
}
diff --git a/src/Umbraco.Web/PublishedCache/RawValueProperty.cs b/src/Umbraco.Web/PublishedCache/RawValueProperty.cs
index 32322e42f7..c12d41faf9 100644
--- a/src/Umbraco.Web/PublishedCache/RawValueProperty.cs
+++ b/src/Umbraco.Web/PublishedCache/RawValueProperty.cs
@@ -12,10 +12,8 @@ namespace Umbraco.Web.PublishedCache
internal class RawValueProperty : PublishedPropertyBase
{
private readonly object _dbVal; //the value in the db
- private readonly Lazy _sourceValue;
private readonly Lazy _objectValue;
private readonly Lazy _xpathValue;
- private readonly bool _isPreviewing;
public override object SourceValue => _dbVal;
@@ -26,24 +24,22 @@ namespace Umbraco.Web.PublishedCache
public override object XPathValue => _xpathValue.Value;
// note: propertyData cannot be null
- public RawValueProperty(PublishedPropertyType propertyType, object propertyData, bool isPreviewing = false)
- : this(propertyType, isPreviewing)
+ public RawValueProperty(PublishedPropertyType propertyType, IPublishedContent content, object propertyData, bool isPreviewing = false)
+ : this(propertyType, content, isPreviewing)
{
- if (propertyData == null)
- throw new ArgumentNullException(nameof(propertyData));
- _dbVal = propertyData;
+ _dbVal = propertyData ?? throw new ArgumentNullException(nameof(propertyData));
}
// note: maintaining two ctors to make sure we understand what we do when calling them
- public RawValueProperty(PublishedPropertyType propertyType, bool isPreviewing = false)
+ public RawValueProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing = false)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
_dbVal = null;
- _isPreviewing = isPreviewing;
+ var isPreviewing1 = isPreviewing;
- _sourceValue = new Lazy(() => PropertyType.ConvertSourceToInter(_dbVal, _isPreviewing));
- _objectValue = new Lazy(() => PropertyType.ConvertInterToObject(PropertyCacheLevel.Unknown, _sourceValue.Value, _isPreviewing));
- _xpathValue = new Lazy(() => PropertyType.ConvertInterToXPath(PropertyCacheLevel.Unknown, _sourceValue.Value, _isPreviewing));
+ var sourceValue = new Lazy(() => PropertyType.ConvertSourceToInter(content, _dbVal, isPreviewing1));
+ _objectValue = new Lazy(() => PropertyType.ConvertInterToObject(content, PropertyCacheLevel.Unknown, sourceValue.Value, isPreviewing1));
+ _xpathValue = new Lazy(() => PropertyType.ConvertInterToXPath(content, PropertyCacheLevel.Unknown, sourceValue.Value, isPreviewing1));
}
}
}
diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs
index 073608c660..e7f314d730 100644
--- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs
+++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/FacadeService.cs
@@ -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();
}
diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
index 1cd1871f4d..30f989ffde 100644
--- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
+++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
@@ -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);
}
diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs
index b29642fcaa..535571007b 100644
--- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs
+++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs
@@ -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;
}
diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs
index 48f242b1ca..6e2b000a1e 100644
--- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs
+++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedProperty.cs
@@ -22,6 +22,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private object _objectValue;
private bool _objectValueComputed;
private readonly bool _isPreviewing;
+ private readonly IPublishedContent _content;
///
/// 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;
}
}
diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs
index 8e0aaf1fcc..1b99681be5 100644
--- a/src/Umbraco.Web/PublishedContentExtensions.cs
+++ b/src/Umbraco.Web/PublishedContentExtensions.cs
@@ -6,7 +6,6 @@ using System.Linq;
using System.Web;
using Examine.LuceneEngine.SearchCriteria;
using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Web.Models;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
diff --git a/src/Umbraco.Web/umbraco.presentation/page.cs b/src/Umbraco.Web/umbraco.presentation/page.cs
index 2826a1f6ed..8bfcd810e6 100644
--- a/src/Umbraco.Web/umbraco.presentation/page.cs
+++ b/src/Umbraco.Web/umbraco.presentation/page.cs
@@ -392,8 +392,8 @@ namespace umbraco
{
// isPreviewing is true here since we want to preview anyway...
const bool isPreviewing = true;
- var source = PropertyType.ConvertSourceToInter(_sourceValue, isPreviewing);
- return PropertyType.ConvertInterToObject(PropertyCacheLevel.Unknown, source, isPreviewing);
+ var source = PropertyType.ConvertSourceToInter(_content, _sourceValue, isPreviewing);
+ return PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Unknown, source, isPreviewing);
}
}