2016-06-10 16:37:28 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache
|
|
|
|
|
|
{
|
2016-06-29 15:28:40 +02:00
|
|
|
|
// notes:
|
2017-07-21 17:04:14 +02:00
|
|
|
|
// a property set does NOT manage any tree-like elements, neither the
|
2016-06-29 15:28:40 +02:00
|
|
|
|
// original NestedContent (from Lee) nor the DetachedPublishedContent POC did.
|
2016-06-10 16:37:28 +02:00
|
|
|
|
//
|
2017-07-21 17:04:14 +02:00
|
|
|
|
// at the moment we do NOT support models for sets - that would require
|
2016-06-29 15:28:40 +02:00
|
|
|
|
// an entirely new models factory + not even sure it makes sense at all since
|
2017-07-21 17:04:14 +02:00
|
|
|
|
// sets are created manually
|
2016-06-10 16:37:28 +02:00
|
|
|
|
//
|
2017-09-25 08:59:32 +02:00
|
|
|
|
internal class PublishedElement : IPublishedElement
|
2016-06-10 16:37:28 +02:00
|
|
|
|
{
|
2017-09-25 08:59:32 +02:00
|
|
|
|
// initializes a new instance of the PublishedElement class
|
2016-06-29 15:28:40 +02:00
|
|
|
|
// within the context of a facade service (eg a published content property value)
|
2017-09-25 08:59:32 +02:00
|
|
|
|
public PublishedElement(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing,
|
2017-07-21 17:04:14 +02:00
|
|
|
|
IFacadeService facadeService, PropertyCacheLevel referenceCacheLevel)
|
2016-06-10 16:37:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
ContentType = contentType;
|
|
|
|
|
|
Key = key;
|
|
|
|
|
|
|
2016-06-29 15:28:40 +02:00
|
|
|
|
values = GetCaseInsensitiveValueDictionary(values);
|
2016-06-10 16:37:28 +02:00
|
|
|
|
|
|
|
|
|
|
_propertiesArray = contentType
|
|
|
|
|
|
.PropertyTypes
|
|
|
|
|
|
.Select(propertyType =>
|
|
|
|
|
|
{
|
2017-07-21 17:04:14 +02:00
|
|
|
|
values.TryGetValue(propertyType.PropertyTypeAlias, out object value);
|
2017-07-21 17:19:00 +02:00
|
|
|
|
return facadeService.CreateSetProperty(propertyType, this, previewing, referenceCacheLevel, value);
|
2016-06-10 16:37:28 +02:00
|
|
|
|
})
|
|
|
|
|
|
.ToArray();
|
2016-06-29 15:28:40 +02:00
|
|
|
|
}
|
2016-06-10 16:37:28 +02:00
|
|
|
|
|
2017-09-25 08:59:32 +02:00
|
|
|
|
// initializes a new instance of the PublishedElement class
|
2016-06-29 15:28:40 +02:00
|
|
|
|
// without any context, so it's purely 'standalone' and should NOT interfere with the facade service
|
2017-09-25 08:59:32 +02:00
|
|
|
|
public PublishedElement(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing)
|
2016-06-29 15:28:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
ContentType = contentType;
|
|
|
|
|
|
Key = key;
|
|
|
|
|
|
|
|
|
|
|
|
values = GetCaseInsensitiveValueDictionary(values);
|
|
|
|
|
|
|
2017-07-21 17:04:14 +02:00
|
|
|
|
// using an initial reference cache level of .None ensures that everything will be
|
|
|
|
|
|
// cached at .Content level - and that reference cache level will propagate to all
|
|
|
|
|
|
// properties
|
2016-06-29 15:28:40 +02:00
|
|
|
|
const PropertyCacheLevel cacheLevel = PropertyCacheLevel.None;
|
|
|
|
|
|
|
|
|
|
|
|
_propertiesArray = contentType
|
|
|
|
|
|
.PropertyTypes
|
|
|
|
|
|
.Select(propertyType =>
|
|
|
|
|
|
{
|
2017-07-21 17:04:14 +02:00
|
|
|
|
values.TryGetValue(propertyType.PropertyTypeAlias, out object value);
|
2017-09-25 08:59:32 +02:00
|
|
|
|
return (IPublishedProperty) new PublishedElementProperty(propertyType, this, previewing, cacheLevel, value);
|
2016-06-29 15:28:40 +02:00
|
|
|
|
})
|
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Dictionary<string, object> GetCaseInsensitiveValueDictionary(Dictionary<string, object> values)
|
|
|
|
|
|
{
|
|
|
|
|
|
// ensure we ignore case for property aliases
|
|
|
|
|
|
var comparer = values.Comparer;
|
2017-07-21 17:04:14 +02:00
|
|
|
|
var ignoreCase = Equals(comparer, StringComparer.OrdinalIgnoreCase) || Equals(comparer, StringComparer.InvariantCultureIgnoreCase) || Equals(comparer, StringComparer.CurrentCultureIgnoreCase);
|
2016-06-29 15:28:40 +02:00
|
|
|
|
return ignoreCase ? values : new Dictionary<string, object>(values, StringComparer.OrdinalIgnoreCase);
|
2016-06-10 16:37:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region ContentType
|
|
|
|
|
|
|
|
|
|
|
|
public PublishedContentType ContentType { get; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-09-25 08:59:32 +02:00
|
|
|
|
#region PublishedElement
|
2016-06-10 16:37:28 +02:00
|
|
|
|
|
|
|
|
|
|
public Guid Key { get; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IPublishedProperty[] _propertiesArray;
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<IPublishedProperty> Properties => _propertiesArray;
|
|
|
|
|
|
|
|
|
|
|
|
public IPublishedProperty GetProperty(string alias)
|
|
|
|
|
|
{
|
|
|
|
|
|
var index = ContentType.GetPropertyIndex(alias);
|
|
|
|
|
|
var property = index < 0 ? null : _propertiesArray[index];
|
|
|
|
|
|
return property;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|