Introduce IPublishedPropertyType

This commit is contained in:
Stephan
2019-04-15 17:14:45 +02:00
parent 34ad8dfb8d
commit f039b00a44
60 changed files with 497 additions and 384 deletions
@@ -88,22 +88,22 @@ namespace Umbraco.Core
/// <summary>
/// Determines whether the property type is invariant.
/// </summary>
public static bool VariesByNothing(this PublishedPropertyType propertyType) => propertyType.Variations.VariesByNothing();
public static bool VariesByNothing(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesByNothing();
/// <summary>
/// Determines whether the property type varies by culture.
/// </summary>
public static bool VariesByCulture(this PublishedPropertyType propertyType) => propertyType.Variations.VariesByCulture();
public static bool VariesByCulture(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesByCulture();
/// <summary>
/// Determines whether the property type varies by segment.
/// </summary>
public static bool VariesBySegment(this PublishedPropertyType propertyType) => propertyType.Variations.VariesBySegment();
public static bool VariesBySegment(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesBySegment();
/// <summary>
/// Determines whether the property type varies by culture and segment.
/// </summary>
public static bool VariesByCultureAndSegment(this PublishedPropertyType propertyType) => propertyType.Variations.VariesByCultureAndSegment();
public static bool VariesByCultureAndSegment(this IPublishedPropertyType propertyType) => propertyType.Variations.VariesByCultureAndSegment();
/// <summary>
/// Determines whether a variation is invariant.
@@ -42,7 +42,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Gets the content type properties.
/// </summary>
IEnumerable<PublishedPropertyType> PropertyTypes { get; }
IEnumerable<IPublishedPropertyType> PropertyTypes { get; }
/// <summary>
/// Gets a property type index.
@@ -53,11 +53,11 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Gets a property type.
/// </summary>
PublishedPropertyType GetPropertyType(string alias);
IPublishedPropertyType GetPropertyType(string alias);
/// <summary>
/// Gets a property type.
/// </summary>
PublishedPropertyType GetPropertyType(int index);
IPublishedPropertyType GetPropertyType(int index);
}
}
@@ -18,7 +18,7 @@
/// <param name="contentType">The published content type owning the property.</param>
/// <param name="propertyType">A property type.</param>
/// <remarks>Is used by <see cref="PublishedContentType"/> constructor to create property types.</remarks>
PublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType);
IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType);
/// <summary>
/// Creates a published property type.
@@ -28,7 +28,7 @@
/// <param name="dataTypeId">The datatype identifier.</param>
/// <param name="variations">The variations.</param>
/// <remarks>Is used by <see cref="PublishedContentType"/> constructor to create special property types.</remarks>
PublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
/// <summary>
/// Gets a published datatype.
@@ -5,7 +5,7 @@
/// </summary>
public interface IPublishedProperty
{
PublishedPropertyType PropertyType { get; }
IPublishedPropertyType PropertyType { get; }
/// <summary>
/// Gets the alias of the property.
@@ -0,0 +1,108 @@
using System;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Represents a published property type.
/// </summary>
/// <remarks>Instances implementing the <see cref="PublishedPropertyType"/> interface should be
/// immutable, ie if the property type changes, then a new instance needs to be created.</remarks>
public interface IPublishedPropertyType
{
/// <summary>
/// Gets the published content type containing the property type.
/// </summary>
IPublishedContentType ContentType { get; }
/// <summary>
/// Gets the data type.
/// </summary>
PublishedDataType DataType { get; }
/// <summary>
/// Gets property type alias.
/// </summary>
string Alias { get; }
/// <summary>
/// Gets the property editor alias.
/// </summary>
string EditorAlias { get; }
/// <summary>
/// Gets a value indicating whether the property is a user content property.
/// </summary>
/// <remarks>A non-user content property is a property that has been added to a
/// published content type by Umbraco but does not corresponds to a user-defined
/// published property.</remarks>
bool IsUserProperty { get; }
/// <summary>
/// Gets the content variations of the property type.
/// </summary>
ContentVariation Variations { get; }
/// <summary>
/// Determines whether a value is an actual value, or not a value.
/// </summary>
/// <remarks>Used by property.HasValue and, for instance, in fallback scenarios.</remarks>
bool? IsValue(object value, PropertyValueLevel level);
/// <summary>
/// Gets the property cache level.
/// </summary>
PropertyCacheLevel CacheLevel { get; }
/// <summary>
/// Converts the source value into the intermediate value.
/// </summary>
/// <param name="owner">The published element owning the property.</param>
/// <param name="source">The source value.</param>
/// <param name="preview">A value indicating whether content should be considered draft.</param>
/// <returns>The intermediate value.</returns>
object ConvertSourceToInter(IPublishedElement owner, object source, bool preview);
/// <summary>
/// Converts the intermediate value into the object value.
/// </summary>
/// <param name="owner">The published element owning the property.</param>
/// <param name="referenceCacheLevel">The reference cache level.</param>
/// <param name="inter">The intermediate value.</param>
/// <param name="preview">A value indicating whether content should be considered draft.</param>
/// <returns>The object value.</returns>
object ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
/// <summary>
/// Converts the intermediate value into the XPath value.
/// </summary>
/// <param name="owner">The published element owning the property.</param>
/// <param name="referenceCacheLevel">The reference cache level.</param>
/// <param name="inter">The intermediate value.</param>
/// <param name="preview">A value indicating whether content should be considered draft.</param>
/// <returns>The XPath value.</returns>
/// <remarks>
/// <para>The XPath value can be either a string or an XPathNavigator.</para>
/// </remarks>
object ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
/// <summary>
/// Gets the property model CLR type.
/// </summary>
/// <remarks>
/// <para>The model CLR type may be a <see cref="ModelType"/> type, or may contain <see cref="ModelType"/> types.</para>
/// <para>For the actual CLR type, see <see cref="ClrType"/>.</para>
/// </remarks>
Type ModelClrType { get; }
/// <summary>
/// Gets the property CLR type.
/// </summary>
/// <remarks>
/// <para>Returns the actual CLR type which does not contain <see cref="ModelType"/> types.</para>
/// <para>Mapping from <see cref="ModelClrType"/> may throw if some <see cref="ModelType"/> instances
/// could not be mapped to actual CLR types.</para>
/// </remarks>
Type ClrType { get; }
}
}
@@ -11,7 +11,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// if the content type changes, then a new class needs to be created.</remarks>
public class PublishedContentType : IPublishedContentType
{
private readonly PublishedPropertyType[] _propertyTypes;
private readonly IPublishedPropertyType[] _propertyTypes;
// fast alias-to-index xref containing both the raw alias and its lowercase version
private readonly Dictionary<string, int> _indexes = new Dictionary<string, int>();
@@ -34,11 +34,11 @@ namespace Umbraco.Core.Models.PublishedContent
InitializeIndexes();
}
// fixme should be internal?
/// <summary>
/// Initializes a new instance of the <see cref="PublishedContentType"/> with specific values.
/// This constructor is for tests and is not intended to be used directly from application code.
/// </summary>
/// <remarks>
/// <para>This constructor is for tests and is not intended to be used directly from application code.</para>
/// <para>Values are assumed to be consisted and are not checked.</para>
/// </remarks>
public PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes, ContentVariation variations, bool isElement = false)
@@ -52,6 +52,15 @@ namespace Umbraco.Core.Models.PublishedContent
InitializeIndexes();
}
// fixme
public PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable<string> compositionAliases, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes, ContentVariation variations, bool isElement = false)
: this(id, alias, itemType, compositionAliases, variations, isElement)
{
_propertyTypes = propertyTypes(this).ToArray();
InitializeIndexes();
}
private PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable<string> compositionAliases, ContentVariation variations, bool isElement)
{
Id = id;
@@ -75,7 +84,7 @@ namespace Umbraco.Core.Models.PublishedContent
// Members have properties such as IMember LastLoginDate which are plain C# properties and not content
// properties; they are exposed as pseudo content properties, as long as a content property with the
// same alias does not exist already.
private void EnsureMemberProperties(List<PublishedPropertyType> propertyTypes, IPublishedContentTypeFactory factory)
private void EnsureMemberProperties(List<IPublishedPropertyType> propertyTypes, IPublishedContentTypeFactory factory)
{
var aliases = new HashSet<string>(propertyTypes.Select(x => x.Alias), StringComparer.OrdinalIgnoreCase);
@@ -123,7 +132,7 @@ namespace Umbraco.Core.Models.PublishedContent
#region Properties
/// <inheritdoc />
public IEnumerable<PublishedPropertyType> PropertyTypes => _propertyTypes;
public IEnumerable<IPublishedPropertyType> PropertyTypes => _propertyTypes;
/// <inheritdoc />
public int GetPropertyIndex(string alias)
@@ -136,7 +145,7 @@ namespace Umbraco.Core.Models.PublishedContent
// virtual for unit tests
// TODO: explain why
/// <inheritdoc />
public virtual PublishedPropertyType GetPropertyType(string alias)
public virtual IPublishedPropertyType GetPropertyType(string alias)
{
var index = GetPropertyIndex(alias);
return GetPropertyType(index);
@@ -145,7 +154,7 @@ namespace Umbraco.Core.Models.PublishedContent
// virtual for unit tests
// TODO: explain why
/// <inheritdoc />
public virtual PublishedPropertyType GetPropertyType(int index)
public virtual IPublishedPropertyType GetPropertyType(int index)
{
return index >= 0 && index < _propertyTypes.Length ? _propertyTypes[index] : null;
}
@@ -31,32 +31,43 @@ namespace Umbraco.Core.Models.PublishedContent
return new PublishedContentType(contentType, this);
}
// fixme kill
// for tests
internal IPublishedContentType CreateContentType(int id, string alias, IEnumerable<PublishedPropertyType> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
{
return new PublishedContentType(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, variations, isElement);
}
internal IPublishedContentType CreateContentType(int id, string alias, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
{
return new PublishedContentType(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, variations, isElement);
}
// fixme kill
// for tests
internal IPublishedContentType CreateContentType(int id, string alias, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
{
return new PublishedContentType(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, variations, isElement);
}
internal IPublishedContentType CreateContentType(int id, string alias, IEnumerable<string> compositionAliases, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
{
return new PublishedContentType(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, variations, isElement);
}
/// <inheritdoc />
public PublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType)
public IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType)
{
return new PublishedPropertyType(contentType, propertyType, _propertyValueConverters, _publishedModelFactory, this);
}
/// <inheritdoc />
public PublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations = ContentVariation.Nothing)
public IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations = ContentVariation.Nothing)
{
return new PublishedPropertyType(contentType, propertyTypeAlias, dataTypeId, true, variations, _propertyValueConverters, _publishedModelFactory, this);
}
// fixme kill
// for tests
internal PublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, bool umbraco = false, ContentVariation variations = ContentVariation.Nothing)
internal IPublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, bool umbraco = false, ContentVariation variations = ContentVariation.Nothing)
{
return new PublishedPropertyType(propertyTypeAlias, dataTypeId, umbraco, variations, _propertyValueConverters, _publishedModelFactory, this);
}
@@ -12,7 +12,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Initializes a new instance of the <see cref="PublishedPropertyBase"/> class.
/// </summary>
protected PublishedPropertyBase(PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel)
protected PublishedPropertyBase(IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel)
{
PropertyType = propertyType ?? throw new ArgumentNullException(nameof(propertyType));
ReferenceCacheLevel = referenceCacheLevel;
@@ -42,7 +42,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Gets the property type.
/// </summary>
public PublishedPropertyType PropertyType { get; }
public IPublishedPropertyType PropertyType { get; }
/// <summary>
/// Gets the property reference cache level.
@@ -10,10 +10,8 @@ namespace Umbraco.Core.Models.PublishedContent
/// </summary>
/// <remarks>Instances of the <see cref="PublishedPropertyType"/> class are immutable, ie
/// if the property type changes, then a new class needs to be created.</remarks>
public class PublishedPropertyType
public class PublishedPropertyType : IPublishedPropertyType
{
// TODO: API design review, should this be an interface?
private readonly IPublishedModelFactory _publishedModelFactory;
private readonly PropertyValueConverterCollection _propertyValueConverters;
private readonly object _locker = new object();
@@ -38,6 +36,7 @@ namespace Umbraco.Core.Models.PublishedContent
ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
}
// fixme should be internal?
/// <summary>
/// This constructor is for tests and is not intended to be used directly from application code.
/// </summary>
@@ -51,6 +50,7 @@ namespace Umbraco.Core.Models.PublishedContent
ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
}
// fixme should be internal?
/// <summary>
/// This constructor is for tests and is not intended to be used directly from application code.
/// </summary>
@@ -75,37 +75,22 @@ namespace Umbraco.Core.Models.PublishedContent
#region Property type
/// <summary>
/// Gets the published content type containing the property type.
/// </summary>
/// <inheritdoc />
public IPublishedContentType ContentType { get; internal set; } // internally set by PublishedContentType constructor
/// <summary>
/// Gets the data type.
/// </summary>
/// <inheritdoc />
public PublishedDataType DataType { get; }
/// <summary>
/// Gets property type alias.
/// </summary>
/// <inheritdoc />
public string Alias { get; }
/// <summary>
/// Gets the property editor alias.
/// </summary>
/// <inheritdoc />
public string EditorAlias => DataType.EditorAlias;
/// <summary>
/// Gets a value indicating whether the property is a user content property.
/// </summary>
/// <remarks>A non-user content property is a property that has been added to a
/// published content type by Umbraco but does not corresponds to a user-defined
/// published property.</remarks>
/// <inheritdoc />
public bool IsUserProperty { get; }
/// <summary>
/// Gets the content variations of the property type.
/// </summary>
/// <inheritdoc />
public ContentVariation Variations { get; }
#endregion
@@ -193,10 +178,7 @@ namespace Umbraco.Core.Models.PublishedContent
_modelClrType = _converter == null ? typeof (object) : _converter.GetPropertyValueType(this);
}
/// <summary>
/// Determines whether a value is an actual value, or not a value.
/// </summary>
/// <remarks>Used by property.HasValue and, for instance, in fallback scenarios.</remarks>
/// <inheritdoc />
public bool? IsValue(object value, PropertyValueLevel level)
{
if (!_initialized) Initialize();
@@ -209,9 +191,7 @@ namespace Umbraco.Core.Models.PublishedContent
return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
}
/// <summary>
/// Gets the property cache level.
/// </summary>
/// <inheritdoc />
public PropertyCacheLevel CacheLevel
{
get
@@ -221,13 +201,7 @@ namespace Umbraco.Core.Models.PublishedContent
}
}
/// <summary>
/// Converts the source value into the intermediate value.
/// </summary>
/// <param name="owner">The published element owning the property.</param>
/// <param name="source">The source value.</param>
/// <param name="preview">A value indicating whether content should be considered draft.</param>
/// <returns>The intermediate value.</returns>
/// <inheritdoc />
public object ConvertSourceToInter(IPublishedElement owner, object source, bool preview)
{
if (!_initialized) Initialize();
@@ -238,14 +212,7 @@ namespace Umbraco.Core.Models.PublishedContent
: source;
}
/// <summary>
/// Converts the intermediate value into the object value.
/// </summary>
/// <param name="owner">The published element owning the property.</param>
/// <param name="referenceCacheLevel">The reference cache level.</param>
/// <param name="inter">The intermediate value.</param>
/// <param name="preview">A value indicating whether content should be considered draft.</param>
/// <returns>The object value.</returns>
/// <inheritdoc />
public object ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (!_initialized) Initialize();
@@ -256,17 +223,7 @@ namespace Umbraco.Core.Models.PublishedContent
: inter;
}
/// <summary>
/// Converts the intermediate value into the XPath value.
/// </summary>
/// <param name="owner">The published element owning the property.</param>
/// <param name="referenceCacheLevel">The reference cache level.</param>
/// <param name="inter">The intermediate value.</param>
/// <param name="preview">A value indicating whether content should be considered draft.</param>
/// <returns>The XPath value.</returns>
/// <remarks>
/// <para>The XPath value can be either a string or an XPathNavigator.</para>
/// </remarks>
/// <inheritdoc />
public object ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (!_initialized) Initialize();
@@ -282,13 +239,7 @@ namespace Umbraco.Core.Models.PublishedContent
return inter.ToString().Trim();
}
/// <summary>
/// Gets the property model CLR type.
/// </summary>
/// <remarks>
/// <para>The model CLR type may be a <see cref="ModelType"/> type, or may contain <see cref="ModelType"/> types.</para>
/// <para>For the actual CLR type, see <see cref="ClrType"/>.</para>
/// </remarks>
/// <inheritdoc />
public Type ModelClrType
{
get
@@ -298,14 +249,7 @@ namespace Umbraco.Core.Models.PublishedContent
}
}
/// <summary>
/// Gets the property CLR type.
/// </summary>
/// <remarks>
/// <para>Returns the actual CLR type which does not contain <see cref="ModelType"/> types.</para>
/// <para>Mapping from <see cref="ModelClrType"/> may throw if some <see cref="ModelType"/> instances
/// could not be mapped to actual CLR types.</para>
/// </remarks>
/// <inheritdoc />
public Type ClrType
{
get
@@ -38,7 +38,7 @@ namespace Umbraco.Core.Models.PublishedContent
public override object GetXPathValue(string culture = null, string segment = null)
=> string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _xpathValue.Value : null;
public RawValueProperty(PublishedPropertyType propertyType, IPublishedElement content, object sourceValue, bool isPreviewing = false)
public RawValueProperty(IPublishedPropertyType propertyType, IPublishedElement content, object sourceValue, bool isPreviewing = false)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
if (propertyType.Variations != ContentVariation.Nothing)
@@ -15,7 +15,7 @@ namespace Umbraco.Core.PropertyEditors
/// </summary>
/// <param name="propertyType">The property type.</param>
/// <returns>A value indicating whether the converter supports a property type.</returns>
bool IsConverter(PublishedPropertyType propertyType);
bool IsConverter(IPublishedPropertyType propertyType);
/// <summary>
/// Determines whether a value is an actual value, or not a value.
@@ -36,14 +36,14 @@ namespace Umbraco.Core.PropertyEditors
/// <returns>The CLR type of values returned by the converter.</returns>
/// <remarks>Some of the CLR types may be generated, therefore this method cannot directly return
/// a Type object (which may not exist yet). In which case it needs to return a ModelType instance.</remarks>
Type GetPropertyValueType(PublishedPropertyType propertyType);
Type GetPropertyValueType(IPublishedPropertyType propertyType);
/// <summary>
/// Gets the property cache level.
/// </summary>
/// <param name="propertyType">The property type.</param>
/// <returns>The property cache level.</returns>
PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType);
PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType);
/// <summary>
/// Converts a property source value to an intermediate value.
@@ -64,7 +64,7 @@ namespace Umbraco.Core.PropertyEditors
/// strings, and xml-whitespace strings appropriately, ie it should know whether to preserve
/// white spaces.</para>
/// </remarks>
object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview);
object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview);
/// <summary>
/// Converts a property intermediate value to an Object value.
@@ -83,7 +83,7 @@ namespace Umbraco.Core.PropertyEditors
/// passed to eg a PublishedFragment constructor. It is used by the fragment and the properties to manage
/// the cache levels of property values. It is not meant to be used by the converter.</para>
/// </remarks>
object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
/// <summary>
/// Converts a property intermediate value to an XPath value.
@@ -107,6 +107,6 @@ namespace Umbraco.Core.PropertyEditors
/// passed to eg a PublishedFragment constructor. It is used by the fragment and the properties to manage
/// the cache levels of property values. It is not meant to be used by the converter.</para>
/// </remarks>
object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
}
}
@@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors
/// </summary>
public abstract class PropertyValueConverterBase : IPropertyValueConverter
{
public virtual bool IsConverter(PublishedPropertyType propertyType)
public virtual bool IsConverter(IPublishedPropertyType propertyType)
=> false;
public virtual bool? IsValue(object value, PropertyValueLevel level)
@@ -30,19 +30,19 @@ namespace Umbraco.Core.PropertyEditors
return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
}
public virtual Type GetPropertyValueType(PublishedPropertyType propertyType)
public virtual Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (object);
public virtual PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public virtual PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
public virtual object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public virtual object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
=> source;
public virtual object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public virtual object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> inter;
public virtual object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public virtual object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> inter?.ToString() ?? string.Empty;
}
}
@@ -9,16 +9,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class CheckboxListValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.CheckBoxList);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable<string>);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
var sourceString = source?.ToString() ?? string.Empty;
@@ -8,16 +8,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class ColorPickerValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.ColorPicker);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> UseLabel(propertyType) ? typeof(PickedColor) : typeof(string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var useLabel = UseLabel(propertyType);
@@ -39,7 +39,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return ssource;
}
private bool UseLabel(PublishedPropertyType propertyType)
private bool UseLabel(IPublishedPropertyType propertyType)
{
return ConfigurationEditor.ConfigurationAs<ColorPickerConfiguration>(propertyType.DataType.Configuration).UseLabel;
}
@@ -8,16 +8,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class DatePickerValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.DateTime);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (DateTime);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return DateTime.MinValue;
@@ -39,7 +39,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
// default ConvertSourceToObject just returns source ie a DateTime value
public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a DateTime already
return XmlConvert.ToString((DateTime) inter, XmlDateTimeSerializationMode.Unspecified);
@@ -7,16 +7,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class DecimalValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.Decimal.Equals(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (decimal);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null)
{
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class EmailAddressValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.EmailAddress);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
return source?.ToString() ?? string.Empty;
}
@@ -28,16 +28,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
_config = config;
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Grid);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (JToken);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -14,19 +14,19 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
public class ImageCropperValueConverter : PropertyValueConverterBase
{
/// <inheritdoc />
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.ImageCropper);
/// <inheritdoc />
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (ImageCropperValue);
/// <inheritdoc />
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
/// <inheritdoc />
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class IntegerValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.Integer.Equals(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (int);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source.TryConvertTo<int>().Result;
}
@@ -31,19 +31,19 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
/// </summary>
/// <param name="propertyType"></param>
/// <returns></returns>
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
{
return _propertyEditors.TryGet(propertyType.EditorAlias, out var editor)
&& editor.GetValueEditor().ValueType.InvariantEquals(ValueTypes.Json);
}
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (JToken);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -16,10 +16,10 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class LabelValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.Label.Equals(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
{
var valueType = ConfigurationEditor.ConfigurationAs<LabelConfiguration>(propertyType.DataType.Configuration);
switch (valueType.ValueType)
@@ -40,10 +40,10 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
}
}
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var valueType = ConfigurationEditor.ConfigurationAs<LabelConfiguration>(propertyType.DataType.Configuration);
switch (valueType.ValueType)
@@ -7,17 +7,17 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class MarkdownEditorValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.MarkdownEditor.Equals(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IHtmlString);
// PropertyCacheLevel.Content is ok here because that converter does not parse {locallink} nor executes macros
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a string is: string
// in the database a string is: string
@@ -25,13 +25,13 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return new HtmlString(inter == null ? string.Empty : (string) inter);
}
public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter?.ToString() ?? string.Empty;
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class MemberGroupPickerValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.MemberGroupPicker);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source?.ToString() ?? string.Empty;
}
@@ -9,18 +9,18 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class MultipleTextStringValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.MultipleTextstring.Equals(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable<string>);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
private static readonly string[] NewLineDelimiters = { "\r\n", "\r", "\n" };
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// data is (both in database and xml):
// <keyFeatureList>
@@ -58,7 +58,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
: values.ToArray();
}
public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
var d = new XmlDocument();
var e = d.CreateElement("values");
@@ -22,16 +22,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
Constants.PropertyEditors.Aliases.MultiNodeTreePicker
};
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> Aliases.Contains(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source?.ToString();
}
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class RadioButtonListValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.RadioButtonList);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var attempt = source.TryConvertTo<string>();
@@ -18,16 +18,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Slider);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> IsRangeDataType(propertyType.DataType.Id) ? typeof (Range<decimal>) : typeof (decimal);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
if (source == null)
return null;
@@ -19,16 +19,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
_dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService));
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Tags);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable<string>);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return Array.Empty<string>();
@@ -43,7 +43,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
return (string[]) source;
}
@@ -13,16 +13,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
Constants.PropertyEditors.Aliases.TextArea
};
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> PropertyTypeAliases.Contains(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a string is: string
// in the database a string is: string
@@ -30,13 +30,13 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType 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 ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter;
@@ -10,17 +10,17 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class TinyMceValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == Constants.PropertyEditors.Aliases.TinyMce;
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IHtmlString);
// PropertyCacheLevel.Content is ok here because that converter does not parse {locallink} nor executes macros
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a string is: string
// in the database a string is: string
@@ -28,13 +28,13 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
return source;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return new HtmlString(inter == null ? string.Empty : (string)inter);
}
public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter;
@@ -9,16 +9,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class UploadPropertyConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.UploadField);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
return source?.ToString() ?? "";
}
@@ -6,16 +6,16 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class YesNoValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == Constants.PropertyEditors.Aliases.Boolean;
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (bool);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
// in xml a boolean is: string
// in the database a boolean is: string "1" or "0" or empty
@@ -49,7 +49,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
// default ConvertSourceToObject just returns source ie a boolean value
public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a boolean already
return (bool)inter ? "1" : "0";
+1
View File
@@ -222,6 +222,7 @@
<Compile Include="Models\CultureImpact.cs" />
<Compile Include="Models\PublishedContent\ILivePublishedModelFactory.cs" />
<Compile Include="Models\PublishedContent\IPublishedContentType.cs" />
<Compile Include="Models\PublishedContent\IPublishedPropertyType.cs" />
<Compile Include="Persistence\Dtos\PropertyTypeCommonDto.cs" />
<Compile Include="Persistence\Repositories\Implement\ContentTypeCommonRepository.cs" />
<Compile Include="Persistence\Repositories\IContentTypeCommonRepository.cs" />
@@ -50,7 +50,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
public override object GetXPathValue(string culture = null, string segment = null) { throw new NotImplementedException(); }
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
public XmlPublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
: this(propertyType, content, isPreviewing)
{
if (propertyXmlData == null)
@@ -58,7 +58,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
_sourceValue = XmlHelper.GetNodeValue(propertyXmlData);
}
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, string propertyData)
public XmlPublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, string propertyData)
: this(propertyType, content, isPreviewing)
{
if (propertyData == null)
@@ -66,7 +66,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
_sourceValue = propertyData;
}
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing)
public XmlPublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
_sourceValue = string.Empty;
+37 -43
View File
@@ -37,10 +37,12 @@ namespace Umbraco.Tests.Published
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
contentTypeFactory.CreatePropertyType("prop1", 1),
});
yield return contentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
}
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", CreatePropertyTypes);
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "1234" } }, false);
@@ -70,22 +72,22 @@ namespace Umbraco.Tests.Published
}
}
public bool IsConverter(PublishedPropertyType propertyType)
public bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
public Type GetPropertyValueType(PublishedPropertyType propertyType)
public Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (int);
public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
public object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
=> int.TryParse(source as string, out int i) ? i : 0;
public object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> (int) inter;
public object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> ((int) inter).ToString();
}
@@ -115,10 +117,12 @@ namespace Umbraco.Tests.Published
var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
contentTypeFactory.CreatePropertyType("prop1", 1),
});
yield return contentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
}
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", CreatePropertyTypes);
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "1234" } }, false);
@@ -143,26 +147,26 @@ namespace Umbraco.Tests.Published
public bool? IsValue(object value, PropertyValueLevel level)
=> value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
public bool IsConverter(PublishedPropertyType propertyType)
public bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
public Type GetPropertyValueType(PublishedPropertyType propertyType)
public Type GetPropertyValueType(IPublishedPropertyType propertyType)
// the first version would be the "generic" version, but say we want to be more precise
// and return: whatever Clr type is generated for content type with alias "cnt1" -- which
// we cannot really typeof() at the moment because it has not been generated, hence ModelType.
// => typeof (IPublishedContent);
=> ModelType.For("cnt1");
public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> _cacheLevel;
public object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
=> int.TryParse(source as string, out int i) ? i : -1;
public object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById((int) inter);
public object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> ((int) inter).ToString();
}
@@ -208,25 +212,15 @@ namespace Umbraco.Tests.Published
var contentTypeFactory = new PublishedContentTypeFactory(factory, converters, dataTypeService);
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType, int i)
{
contentTypeFactory.CreatePropertyType("prop1", 1),
});
yield return contentTypeFactory.CreatePropertyType(contentType, "prop" + i, i);
}
var elementType2 = contentTypeFactory.CreateContentType(1001, "element2", new[]
{
contentTypeFactory.CreatePropertyType("prop2", 2),
});
var contentType1 = contentTypeFactory.CreateContentType(1002, "content1", new[]
{
contentTypeFactory.CreatePropertyType("prop1", 1),
});
var contentType2 = contentTypeFactory.CreateContentType(1003, "content2", new[]
{
contentTypeFactory.CreatePropertyType("prop2", 2),
});
var elementType1 = contentTypeFactory.CreateContentType(1000, "element1", t => CreatePropertyTypes(t, 1));
var elementType2 = contentTypeFactory.CreateContentType(1001, "element2", t => CreatePropertyTypes(t, 2));
var contentType1 = contentTypeFactory.CreateContentType(1002, "content1", t => CreatePropertyTypes(t, 1));
var contentType2 = contentTypeFactory.CreateContentType(1003, "content2", t => CreatePropertyTypes(t, 2));
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "val1" } }, false);
var element2 = new PublishedElement(elementType2, Guid.NewGuid(), new Dictionary<string, object> { { "prop2", "1003" } }, false);
@@ -267,13 +261,13 @@ namespace Umbraco.Tests.Published
public class SimpleConverter3A : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == "Umbraco.Void";
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
}
@@ -286,22 +280,22 @@ namespace Umbraco.Tests.Published
_publishedSnapshotAccessor = publishedSnapshotAccessor;
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == "Umbraco.Void.2";
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable<>).MakeGenericType(ModelType.For("content1"));
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Elements;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var s = source as string;
return s?.Split(',').Select(int.Parse).ToArray() ?? Array.Empty<int>();
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
return ((int[]) inter).Select(x => (PublishedSnapshotTestObjects.TestContentModel1) _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(x)).ToArray();
}
@@ -125,13 +125,24 @@ namespace Umbraco.Tests.Published
var factory = new PublishedContentTypeFactory(publishedModelFactory.Object, converters, dataTypeService);
var propertyType1 = factory.CreatePropertyType("property1", 1);
var propertyType2 = factory.CreatePropertyType("property2", 2);
var propertyTypeN1 = factory.CreatePropertyType("propertyN1", 3);
IEnumerable<IPublishedPropertyType> CreatePropertyTypes1(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "property1", 1);
}
var contentType1 = factory.CreateContentType(1, "content1", new[] { propertyType1 });
var contentType2 = factory.CreateContentType(2, "content2", new[] { propertyType2 });
var contentTypeN1 = factory.CreateContentType(2, "contentN1", new[] { propertyTypeN1 }, isElement: true);
IEnumerable<IPublishedPropertyType> CreatePropertyTypes2(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "property2", 2);
}
IEnumerable<IPublishedPropertyType> CreatePropertyTypesN1(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "propertyN1", 3);
}
var contentType1 = factory.CreateContentType(1, "content1", CreatePropertyTypes1);
var contentType2 = factory.CreateContentType(2, "content2", CreatePropertyTypes2);
var contentTypeN1 = factory.CreateContentType(2, "contentN1", CreatePropertyTypesN1, isElement: true);
// mocked content cache returns content types
contentCache
@@ -219,14 +230,14 @@ namespace Umbraco.Tests.Published
private readonly bool _hasValue;
private IPublishedElement _owner;
public TestPublishedProperty(PublishedPropertyType propertyType, object source)
public TestPublishedProperty(IPublishedPropertyType propertyType, object source)
: base(propertyType, PropertyCacheLevel.Element) // initial reference cache level always is .Content
{
_sourceValue = source;
_hasValue = source != null && (!(source is string ssource) || !string.IsNullOrWhiteSpace(ssource));
}
public TestPublishedProperty(PublishedPropertyType propertyType, IPublishedElement element, bool preview, PropertyCacheLevel referenceCacheLevel, object source)
public TestPublishedProperty(IPublishedPropertyType propertyType, IPublishedElement element, bool preview, PropertyCacheLevel referenceCacheLevel, object source)
: base(propertyType, referenceCacheLevel)
{
_sourceValue = source;
@@ -35,10 +35,13 @@ namespace Umbraco.Tests.Published
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
publishedContentTypeFactory.CreatePropertyType("prop1", 1),
});
yield return publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
}
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", CreatePropertyTypes);
// PublishedElementPropertyBase.GetCacheLevels:
//
@@ -113,10 +116,13 @@ namespace Umbraco.Tests.Published
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
publishedContentTypeFactory.CreatePropertyType("prop1", 1),
});
yield return publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
}
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", CreatePropertyTypes);
var elementsCache = new FastDictionaryAppCache();
var snapshotCache = new FastDictionaryAppCache();
@@ -187,10 +193,13 @@ namespace Umbraco.Tests.Published
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
publishedContentTypeFactory.CreatePropertyType("prop1", 1),
});
yield return publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", 1);
}
var setType1 = publishedContentTypeFactory.CreateContentType(1000, "set1", CreatePropertyTypes);
Assert.Throws<Exception>(() =>
{
@@ -213,28 +222,28 @@ namespace Umbraco.Tests.Published
public bool? IsValue(object value, PropertyValueLevel level)
=> value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false);
public bool IsConverter(PublishedPropertyType propertyType)
public bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.InvariantEquals("Umbraco.Void");
public Type GetPropertyValueType(PublishedPropertyType propertyType)
public Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof(int);
public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> _cacheLevel;
public object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
SourceConverts++;
return int.TryParse(source as string, out int i) ? i : 0;
}
public object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
InterConverts++;
return (int) inter;
}
public object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
=> ((int) inter).ToString();
}
}
@@ -65,17 +65,22 @@ namespace Umbraco.Tests.PublishedContent
var welcome2Type = factory.CreatePropertyType("welcomeText2", 1, variations: ContentVariation.Culture);
var nopropType = factory.CreatePropertyType("noprop", 1, variations: ContentVariation.Culture);
var props = new[]
{
prop1Type,
welcomeType,
welcome2Type,
nopropType
};
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), props);
IEnumerable<IPublishedPropertyType> CreatePropertyTypes1(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "prop1", 1, variations: ContentVariation.Culture);
yield return factory.CreatePropertyType(contentType, "welcomeText", 1, variations: ContentVariation.Culture);
yield return factory.CreatePropertyType(contentType, "welcomeText2", 1, variations: ContentVariation.Culture);
yield return factory.CreatePropertyType(contentType, "noprop", 1, variations: ContentVariation.Culture);
}
var prop3Type = factory.CreatePropertyType("prop3", 1, variations: ContentVariation.Culture);
var contentType2 = factory.CreateContentType(2, "contentType2", Enumerable.Empty<string>(), new[] { prop3Type });
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), CreatePropertyTypes1);
IEnumerable<IPublishedPropertyType> CreatePropertyTypes2(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "prop3", 1, variations: ContentVariation.Culture);
}
var contentType2 = factory.CreateContentType(2, "contentType2", Enumerable.Empty<string>(), CreatePropertyTypes2);
var prop1 = new SolidPublishedPropertyWithLanguageVariants
{
@@ -150,7 +155,7 @@ namespace Umbraco.Tests.PublishedContent
var prop4 = new SolidPublishedPropertyWithLanguageVariants
{
Alias = "prop3",
PropertyType = prop3Type
PropertyType = contentType2.GetPropertyType("prop3")
};
prop4.SetSourceValue("en-US", "Oxxo", true);
prop4.SetValue("en-US", "Oxxo", true);
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models.PublishedContent;
@@ -15,13 +16,14 @@ namespace Umbraco.Tests.PublishedContent
{
internal override void PopulateCache(PublishedContentTypeFactory factory, SolidPublishedContentCache cache)
{
var props = new[]
{
factory.CreatePropertyType("prop1", 1),
};
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), props);
var contentType2 = factory.CreateContentType(2, "ContentType2", Enumerable.Empty<string>(), props);
var contentType2Sub = factory.CreateContentType(3, "ContentType2Sub", Enumerable.Empty<string>(), props);
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "prop1", 1);
}
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), CreatePropertyTypes);
var contentType2 = factory.CreateContentType(2, "ContentType2", Enumerable.Empty<string>(), CreatePropertyTypes);
var contentType2Sub = factory.CreateContentType(3, "ContentType2Sub", Enumerable.Empty<string>(), CreatePropertyTypes);
cache.Add(new SolidPublishedContent(contentType1)
{
@@ -1,4 +1,5 @@
using Umbraco.Core;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.ValueConverters;
@@ -41,13 +42,12 @@ namespace Umbraco.Tests.PublishedContent
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
// need to specify a custom callback for unit tests
var propertyTypes = new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
// AutoPublishedContentType will auto-generate other properties
publishedContentTypeFactory.CreatePropertyType("content", 1),
};
var type = new AutoPublishedContentType(0, "anything", propertyTypes);
yield return publishedContentTypeFactory.CreatePropertyType(contentType, "content", 1);
}
var type = new AutoPublishedContentType(0, "anything", CreatePropertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = alias => type;
var umbracoContext = GetUmbracoContext("/test");
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
@@ -62,18 +63,19 @@ namespace Umbraco.Tests.PublishedContent
// when they are requested, but we must declare those that we
// explicitely want to be here...
var propertyTypes = new[]
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
// AutoPublishedContentType will auto-generate other properties
factory.CreatePropertyType("umbracoNaviHide", 1001),
factory.CreatePropertyType("selectedNodes", 1),
factory.CreatePropertyType("umbracoUrlAlias", 1),
factory.CreatePropertyType("content", 1002),
factory.CreatePropertyType("testRecursive", 1),
};
yield return factory.CreatePropertyType(contentType, "umbracoNaviHide", 1001);
yield return factory.CreatePropertyType(contentType, "selectedNodes", 1);
yield return factory.CreatePropertyType(contentType, "umbracoUrlAlias", 1);
yield return factory.CreatePropertyType(contentType, "content", 1002);
yield return factory.CreatePropertyType(contentType, "testRecursive", 1);
}
var compositionAliases = new[] { "MyCompositionAlias" };
var anythingType = new AutoPublishedContentType(0, "anything", compositionAliases, propertyTypes);
var homeType = new AutoPublishedContentType(0, "home", compositionAliases, propertyTypes);
var anythingType = new AutoPublishedContentType(0, "anything", compositionAliases, CreatePropertyTypes);
var homeType = new AutoPublishedContentType(0, "home", compositionAliases, CreatePropertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = alias => alias.InvariantEquals("home") ? homeType : anythingType;
}
@@ -887,8 +889,13 @@ namespace Umbraco.Tests.PublishedContent
{
var factory = Factory.GetInstance<IPublishedContentTypeFactory>() as PublishedContentTypeFactory;
var pt = factory.CreatePropertyType("detached", 1003);
var ct = factory.CreateContentType(0, "alias", new[] { pt });
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "detached", 1003);
}
var ct = factory.CreateContentType(0, "alias", CreatePropertyTypes);
var pt = ct.GetPropertyType("detached");
var prop = new PublishedElementPropertyBase(pt, null, false, PropertyCacheLevel.None, 5548);
Assert.IsInstanceOf<int>(prop.GetValue());
Assert.AreEqual(5548, prop.GetValue());
@@ -906,16 +913,20 @@ namespace Umbraco.Tests.PublishedContent
{
var factory = Factory.GetInstance<IPublishedContentTypeFactory>() as PublishedContentTypeFactory;
var pt1 = factory.CreatePropertyType("legend", 1004);
var pt2 = factory.CreatePropertyType("image", 1005);
var pt3 = factory.CreatePropertyType("size", 1003);
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
{
yield return factory.CreatePropertyType(contentType, "legend", 1004);
yield return factory.CreatePropertyType(contentType, "image", 1005);
yield return factory.CreatePropertyType(contentType, "size", 1003);
}
const string val1 = "boom bam";
const int val2 = 0;
const int val3 = 666;
var guid = Guid.NewGuid();
var ct = factory.CreateContentType(0, "alias", new[] { pt1, pt2, pt3 });
var ct = factory.CreateContentType(0, "alias", CreatePropertyTypes);
var c = new ImageWithLegendModel(ct, guid, new Dictionary<string, object>
{
@@ -253,7 +253,7 @@ namespace Umbraco.Tests.PublishedContent
internal class SolidPublishedProperty : IPublishedProperty
{
public PublishedPropertyType PropertyType { get; set; }
public IPublishedPropertyType PropertyType { get; set; }
public string Alias { get; set; }
public object SolidSourceValue { get; set; }
public object SolidValue { get; set; }
@@ -397,7 +397,7 @@ namespace Umbraco.Tests.PublishedContent
class AutoPublishedContentType : PublishedContentType
{
private static readonly PublishedPropertyType Default;
private static readonly IPublishedPropertyType Default;
static AutoPublishedContentType()
{
@@ -412,11 +412,19 @@ namespace Umbraco.Tests.PublishedContent
: base(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.Nothing)
{ }
public AutoPublishedContentType(int id, string alias, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes)
: base(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.Nothing)
{ }
public AutoPublishedContentType(int id, string alias, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes)
: base(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing)
{ }
public override PublishedPropertyType GetPropertyType(string alias)
public AutoPublishedContentType(int id, string alias, IEnumerable<string> compositionAliases, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes)
: base(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing)
{ }
public override IPublishedPropertyType GetPropertyType(string alias)
{
var propertyType = base.GetPropertyType(alias);
return propertyType ?? Default;
@@ -140,14 +140,14 @@ namespace Umbraco.Web.Macros
private readonly object _sourceValue;
private readonly IPublishedContent _content;
public PagePublishedProperty(PublishedPropertyType propertyType, IPublishedContent content)
public PagePublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
_sourceValue = null;
_content = content;
}
public PagePublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, Umbraco.Core.Models.Property property)
public PagePublishedProperty(IPublishedPropertyType propertyType, IPublishedContent content, Umbraco.Core.Models.Property property)
: base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored
{
_sourceValue = property.GetValue();
+2 -2
View File
@@ -19,8 +19,8 @@ namespace Umbraco.Web.Models
/// and taking values from the collection of Property.</returns>
/// <remarks>Ensures that all conversions took place correctly.</remarks>
internal static IEnumerable<IPublishedProperty> MapProperties(
IEnumerable<PublishedPropertyType> propertyTypes, IEnumerable<Property> properties,
Func<PublishedPropertyType, object, IPublishedProperty> map)
IEnumerable<IPublishedPropertyType> propertyTypes, IEnumerable<Property> properties,
Func<IPublishedPropertyType, object, IPublishedProperty> map)
{
var propertyEditors = Current.PropertyEditors;
var dataTypeService = Current.Services.DataTypeService;
@@ -23,16 +23,16 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
_publishedSnapshotAccessor = publishedSnapshotAccessor;
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.ContentPicker);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IPublishedContent);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Elements;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
@@ -45,7 +45,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return null;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (inter == null)
return null;
@@ -73,7 +73,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return inter;
}
public override object ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (inter == null) return null;
return inter.ToString();
@@ -11,12 +11,12 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class FlexibleDropdownPropertyValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
{
return propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.DropDownListFlexible);
}
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if(source == null) return Array.Empty<string>();
@@ -24,7 +24,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return JsonConvert.DeserializeObject<string[]>(source.ToString()) ?? Array.Empty<string>();
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (inter == null)
return null;
@@ -43,7 +43,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
: string.Empty;
}
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
{
return propertyType.DataType.ConfigurationAs<DropDownFlexibleConfiguration>().Multiple
? typeof(IEnumerable<string>)
@@ -28,13 +28,13 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
_macroRenderer = macroRenderer ?? throw new ArgumentNullException(nameof(macroRenderer));
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias == Constants.PropertyEditors.Aliases.MacroContainer;
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IHtmlString);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
// NOT thread-safe over a request because it modifies the
@@ -63,7 +63,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
}
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -12,16 +12,16 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
[DefaultPropertyValueConverter]
public class MarkdownEditorValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.PropertyEditors.Aliases.MarkdownEditor == propertyType.EditorAlias;
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IHtmlString);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -33,7 +33,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return sourceString;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// convert markup to HTML for frontend rendering.
// source should come from ConvertSource and be a string (or null) already
@@ -29,12 +29,12 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
_publishedModelFactory = publishedModelFactory;
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
{
return propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.MediaPicker);
}
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
{
var isMultiple = IsMultipleDataType(propertyType.DataType);
var isOnlyImages = IsOnlyImagesDataType(propertyType.DataType);
@@ -48,7 +48,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
: typeof(IPublishedContent);
}
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
private bool IsMultipleDataType(PublishedDataType dataType)
@@ -63,7 +63,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return config.OnlyImages;
}
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType,
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType,
object source, bool preview)
{
if (source == null) return null;
@@ -75,7 +75,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return nodeIds;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType,
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType,
PropertyCacheLevel cacheLevel, object source, bool preview)
{
var isMultiple = IsMultipleDataType(propertyType.DataType);
@@ -18,18 +18,18 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
_publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
{
return propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.MemberPicker);
}
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IPublishedContent);
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var attemptConvertInt = source.TryConvertTo<int>();
if (attemptConvertInt.Success)
@@ -40,7 +40,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return null;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
if (source == null)
return null;
@@ -34,18 +34,18 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
_publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
}
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
{
return propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.MultiNodeTreePicker);
}
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IEnumerable<IPublishedContent>);
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
@@ -60,7 +60,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return null;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview)
{
if (source == null)
{
@@ -23,20 +23,20 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
_proflog = proflog ?? throw new ArgumentNullException(nameof(proflog));
}
public override bool IsConverter(PublishedPropertyType propertyType) => Constants.PropertyEditors.Aliases.MultiUrlPicker.Equals(propertyType.EditorAlias);
public override bool IsConverter(IPublishedPropertyType propertyType) => Constants.PropertyEditors.Aliases.MultiUrlPicker.Equals(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType) =>
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) =>
propertyType.DataType.ConfigurationAs<MultiUrlPickerConfiguration>().MaxNumber == 1 ?
typeof(Link) :
typeof(IEnumerable<Link>);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot;
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot;
public override bool? IsValue(object value, PropertyValueLevel level) => value?.ToString() != "[]";
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview) => source?.ToString();
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview) => source?.ToString();
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
using (_proflog.DebugDuration<MultiUrlPickerValueConverter>($"ConvertPropertyToLinks ({propertyType.DataType.Id})"))
{
@@ -28,11 +28,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
/// <inheritdoc />
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> IsNestedMany(propertyType);
/// <inheritdoc />
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
{
var contentTypes = propertyType.DataType.ConfigurationAs<NestedContentConfiguration>().ContentTypes;
return contentTypes.Length > 1
@@ -41,19 +41,19 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
/// <inheritdoc />
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
/// <inheritdoc />
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source?.ToString();
}
/// <inheritdoc />
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
using (_proflog.DebugDuration<PublishedPropertyType>($"ConvertPropertyToNestedContent ({propertyType.DataType.Id})"))
using (_proflog.DebugDuration<NestedContentManyValueConverter>($"ConvertPropertyToNestedContent ({propertyType.DataType.Id})"))
{
var configuration = propertyType.DataType.ConfigurationAs<NestedContentConfiguration>();
var contentTypes = configuration.ContentTypes;
@@ -27,11 +27,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
/// <inheritdoc />
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> IsNestedSingle(propertyType);
/// <inheritdoc />
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
{
var contentTypes = propertyType.DataType.ConfigurationAs<NestedContentConfiguration>().ContentTypes;
return contentTypes.Length > 1
@@ -40,19 +40,19 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
/// <inheritdoc />
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Element;
/// <inheritdoc />
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
return source?.ToString();
}
/// <inheritdoc />
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
using (_proflog.DebugDuration<PublishedPropertyType>($"ConvertPropertyToNestedContent ({propertyType.DataType.Id})"))
using (_proflog.DebugDuration<NestedContentSingleValueConverter>($"ConvertPropertyToNestedContent ({propertyType.DataType.Id})"))
{
var value = (string) inter;
if (string.IsNullOrWhiteSpace(value)) return null;
@@ -20,12 +20,12 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
protected IPublishedModelFactory PublishedModelFactory { get; }
public static bool IsNested(PublishedPropertyType publishedProperty)
public static bool IsNested(IPublishedPropertyType publishedProperty)
{
return publishedProperty.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.NestedContent);
}
public static bool IsNestedSingle(PublishedPropertyType publishedProperty)
public static bool IsNestedSingle(IPublishedPropertyType publishedProperty)
{
if (!IsNested(publishedProperty))
return false;
@@ -34,7 +34,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return config.MinItems == 1 && config.MaxItems == 1;
}
public static bool IsNestedMany(PublishedPropertyType publishedProperty)
public static bool IsNestedMany(IPublishedPropertyType publishedProperty)
{
return IsNested(publishedProperty) && !IsNestedSingle(publishedProperty);
}
@@ -24,7 +24,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IMacroRenderer _macroRenderer;
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
{
// because that version of RTE converter parses {locallink} and executes macros, its value has
// to be cached at the published snapshot level, because we have no idea what the macros may depend on actually.
@@ -63,7 +63,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
}
}
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null)
{
@@ -17,16 +17,16 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
Constants.PropertyEditors.Aliases.TextArea
};
public override bool IsConverter(PublishedPropertyType propertyType)
public override bool IsConverter(IPublishedPropertyType propertyType)
=> PropertyTypeAliases.Contains(propertyType.EditorAlias);
public override Type GetPropertyValueType(PublishedPropertyType propertyType)
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (string);
public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType)
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Snapshot;
public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview)
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
@@ -38,13 +38,13 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
return sourceString;
}
public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType 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 ConvertIntermediateToXPath(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
public override object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
// source should come from ConvertSource and be a string (or null) already
return inter;
@@ -38,12 +38,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
private string _valuesCacheKey;
// initializes a published content property with no value
public Property(PublishedPropertyType propertyType, PublishedContent content, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
public Property(IPublishedPropertyType propertyType, PublishedContent content, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
: this(propertyType, content, null, publishedSnapshotAccessor, referenceCacheLevel)
{ }
// initializes a published content property with a value
public Property(PublishedPropertyType propertyType, PublishedContent content, PropertyData[] sourceValues, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
public Property(IPublishedPropertyType propertyType, PublishedContent content, PropertyData[] sourceValues, IPublishedSnapshotAccessor publishedSnapshotAccessor, PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
: base(propertyType, referenceCacheLevel)
{
if (sourceValues != null)
@@ -26,7 +26,7 @@ namespace Umbraco.Web.PublishedCache
// so making it configurable.
private const bool FullCacheWhenPreviewing = true;
public PublishedElementPropertyBase(PublishedPropertyType propertyType, IPublishedElement element, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null, IPublishedSnapshotAccessor publishedSnapshotAccessor = null)
public PublishedElementPropertyBase(IPublishedPropertyType propertyType, IPublishedElement element, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null, IPublishedSnapshotAccessor publishedSnapshotAccessor = null)
: base(propertyType, referenceCacheLevel)
{
_sourceValue = sourceValue;