PropertySet - rename and refactor
This commit is contained in:
@@ -4,9 +4,9 @@ using System.Collections.Generic;
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a facade fragment.
|
||||
/// Represents a facade property set.
|
||||
/// </summary>
|
||||
public interface IPublishedFragment
|
||||
public interface IPropertySet
|
||||
{
|
||||
#region ContentType
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
|
||||
#endregion
|
||||
|
||||
#region Content
|
||||
#region PropertySet
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique key of the facade item.
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the properties of the content.
|
||||
/// Gets the properties of the set.
|
||||
/// </summary>
|
||||
/// <remarks>Contains one <c>IPublishedProperty</c> for each property defined for the content type, including
|
||||
/// inherited properties. Some properties may have no value.</remarks>
|
||||
@@ -13,7 +13,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// cached preview (so, maybe unpublished) content. A better name would therefore be ICachedContent, as
|
||||
/// has been suggested. However, can't change now. Maybe in v7?</para>
|
||||
/// </remarks>
|
||||
public interface IPublishedContent : IPublishedFragment
|
||||
public interface IPublishedContent : IPropertySet
|
||||
{
|
||||
#region Content
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
return content;
|
||||
}
|
||||
|
||||
public T CreateModel<T>(IPublishedFragment content)
|
||||
public T CreateModel<T>(IPropertySet content)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
19
src/Umbraco.Core/Models/PublishedContent/PropertySetModel.cs
Normal file
19
src/Umbraco.Core/Models/PublishedContent/PropertySetModel.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a strongly-typed property set.
|
||||
/// </summary>
|
||||
/// <remarks>Every strongly-typed property set class should inherit from <c>PropertySetModel</c>
|
||||
/// (or inherit from a class that inherits from... etc.) so they are picked by the factory.</remarks>
|
||||
public class PropertySetModel : PropertySetWrapped
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PropertySetModel"/> class with
|
||||
/// an original <see cref="IPropertySet"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="content">The original content.</param>
|
||||
protected PropertySetModel(IPropertySet content)
|
||||
: base(content)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an abstract base class for <c>IPropertySet</c> implementations that
|
||||
/// wrap and extend another <c>IPropertySet</c>.
|
||||
/// </summary>
|
||||
public abstract class PropertySetWrapped : IPropertySet
|
||||
{
|
||||
protected readonly IPropertySet Content;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PropertySetWrapped"/> class
|
||||
/// with an <c>IPropertySet<c> instance to wrap.</c>
|
||||
/// </summary>
|
||||
/// <param name="content">The content to wrap.</param>
|
||||
protected PropertySetWrapped(IPropertySet content)
|
||||
{
|
||||
Content = content;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the wrapped content.
|
||||
/// </summary>
|
||||
/// <returns>The wrapped content, that was passed as an argument to the constructor.</returns>
|
||||
public IPropertySet Unwrap() => Content;
|
||||
|
||||
/// <inheritdoc />
|
||||
public PublishedContentType ContentType => Content.ContentType;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid Key => Content.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IPublishedProperty> Properties => Content.Properties;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IPublishedProperty GetProperty(string alias) => Content.GetProperty(alias);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
[TypeConverter(typeof(PublishedContentTypeConverter))]
|
||||
public class PublishedContentExtended : PublishedContentWrapped, IPublishedContentExtended
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
// protected for models, private for our static Extend method
|
||||
protected PublishedContentExtended(IPublishedContent content)
|
||||
: base(content)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Extend
|
||||
|
||||
private static IPublishedContent Unwrap(IPublishedContent content)
|
||||
{
|
||||
if (content == null) return null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var extended = content as PublishedContentExtended;
|
||||
if (extended != null)
|
||||
{
|
||||
if (((IPublishedContentExtended)extended).HasAddedProperties) return extended;
|
||||
content = extended.Unwrap();
|
||||
continue;
|
||||
}
|
||||
var wrapped = content as PublishedContentWrapped;
|
||||
if (wrapped != null)
|
||||
{
|
||||
content = wrapped.Unwrap();
|
||||
continue;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
internal static IPublishedContentExtended Extend(IPublishedContent content)
|
||||
{
|
||||
// first unwrap content down to the lowest possible level, ie either the deepest inner
|
||||
// IPublishedContent or the first extended that has added properties. this is to avoid
|
||||
// nesting extended objects as much as possible, so we try to re-extend that lowest
|
||||
// object. Then extend. But do NOT create a model, else we would not be able to add
|
||||
// properties. BEWARE means that whatever calls Extend MUST create the model.
|
||||
|
||||
return new PublishedContentExtended(Unwrap(content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPublishedContentExtended
|
||||
|
||||
void IPublishedContentExtended.AddProperty(IPublishedProperty property)
|
||||
{
|
||||
if (_properties == null)
|
||||
_properties = new Collection<IPublishedProperty>();
|
||||
_properties.Add(property);
|
||||
}
|
||||
|
||||
bool IPublishedContentExtended.HasAddedProperties => _properties != null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
private ICollection<IPublishedProperty> _properties;
|
||||
|
||||
public override IEnumerable<IPublishedProperty> Properties => _properties == null
|
||||
? Content.Properties
|
||||
: Content.Properties.Union(_properties).ToList();
|
||||
|
||||
public override IPublishedProperty GetProperty(string alias)
|
||||
{
|
||||
return _properties == null
|
||||
? Content.GetProperty(alias)
|
||||
: _properties.FirstOrDefault(prop => prop.PropertyTypeAlias.InvariantEquals(alias)) ?? Content.GetProperty(alias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Id.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
: content;
|
||||
}
|
||||
|
||||
public T CreateModel<T>(IPublishedFragment content)
|
||||
public T CreateModel<T>(IPropertySet content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ using System.Collections.Generic;
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
//
|
||||
// This class has two purposes.
|
||||
//
|
||||
// - First, we cannot implement strongly-typed content by inheriting from some sort
|
||||
// we cannot implement strongly-typed content by inheriting from some sort
|
||||
// of "master content" because that master content depends on the actual content cache
|
||||
// that is being used. It can be an XmlPublishedContent with the XmlPublishedCache,
|
||||
// or just anything else.
|
||||
@@ -15,11 +13,6 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
// returned by the content cache, and providing extra properties (mostly) or
|
||||
// methods or whatever. This class provides the base for such encapsulation.
|
||||
//
|
||||
// - Second, any time a content is used in a content set obtained from
|
||||
// IEnumerable<IPublishedContent>.ToContentSet(), it needs to be cloned and extended
|
||||
// in order to know about its position in the set. This class provides the base
|
||||
// for implementing such extension.
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base class for <c>IPublishedContent</c> implementations that
|
||||
@@ -31,9 +24,9 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new instance of the <see cref="PublishedContentWrapped"/> class
|
||||
/// with an <c>IPublishedContent</c> instance to wrap and extend.
|
||||
/// with an <c>IPublishedContent</c> instance to wrap.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to wrap and extend.</param>
|
||||
/// <param name="content">The content to wrap.</param>
|
||||
protected PublishedContentWrapped(IPublishedContent content)
|
||||
{
|
||||
Content = content;
|
||||
@@ -43,10 +36,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// Gets the wrapped content.
|
||||
/// </summary>
|
||||
/// <returns>The wrapped content, that was passed as an argument to the constructor.</returns>
|
||||
public IPublishedContent Unwrap()
|
||||
{
|
||||
return Content;
|
||||
}
|
||||
public IPublishedContent Unwrap() => Content;
|
||||
|
||||
#region ContentType
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
public class PublishedSearchResult
|
||||
{
|
||||
public PublishedSearchResult(IPublishedContent content, float score)
|
||||
{
|
||||
Content = content;
|
||||
Score = score;
|
||||
}
|
||||
|
||||
public IPublishedContent Content { get; }
|
||||
public float Score { get; }
|
||||
}
|
||||
}
|
||||
@@ -607,13 +607,14 @@
|
||||
<Compile Include="Models\PublishedContent\IPublishedContent.cs" />
|
||||
<Compile Include="Models\PublishedContent\IPublishedContentExtended.cs" />
|
||||
<Compile Include="Models\PublishedContent\IPublishedContentModelFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\IPublishedFragment.cs" />
|
||||
<Compile Include="Models\PublishedContent\IPropertySet.cs" />
|
||||
<Compile Include="Models\PublishedContent\IPublishedProperty.cs" />
|
||||
<Compile Include="Models\PublishedContent\NoopPublishedContentModelFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\PropertyResult.cs" />
|
||||
<Compile Include="Models\PublishedContent\PropertyResultType.cs" />
|
||||
<Compile Include="Models\PublishedContent\PropertySetModel.cs" />
|
||||
<Compile Include="Models\PublishedContent\PropertySetWrapped.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentEnumerable.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentExtended.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentExtensionsForModels.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentModel.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentModelAttribute.cs" />
|
||||
@@ -624,6 +625,7 @@
|
||||
<Compile Include="Models\PublishedContent\PublishedItemType.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedPropertyBase.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedPropertyType.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedSearchResult.cs" />
|
||||
<Compile Include="Models\PublishedState.cs" />
|
||||
<Compile Include="Models\Range.cs" />
|
||||
<Compile Include="Models\Rdbms\AccessDto.cs" />
|
||||
|
||||
@@ -556,7 +556,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
var pt = new PublishedPropertyType("detached", Constants.PropertyEditors.IntegerAlias);
|
||||
var ct = new PublishedContentType(0, "alias", new[] { pt });
|
||||
var prop = new PublishedFragmentProperty(pt, Guid.NewGuid(), false, PropertyCacheLevel.None, 5548);
|
||||
var prop = new PropertySetProperty(pt, Guid.NewGuid(), false, PropertyCacheLevel.None, 5548);
|
||||
Assert.IsInstanceOf<int>(prop.Value);
|
||||
Assert.AreEqual(5548, prop.Value);
|
||||
}
|
||||
@@ -565,7 +565,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
var type = ContentTypesCache.Get(PublishedItemType.Content, "detachedSomething");
|
||||
var values = new Dictionary<string, object>();
|
||||
var f = new PublishedFragment(type, Guid.NewGuid(), values, false);
|
||||
var f = new PropertySet(type, Guid.NewGuid(), values, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -593,7 +593,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Assert.AreEqual(val3, c.Size);
|
||||
}
|
||||
|
||||
class ImageWithLegendModel : PublishedFragment
|
||||
class ImageWithLegendModel : PropertySet
|
||||
{
|
||||
public ImageWithLegendModel(PublishedContentType contentType, Guid fragmentKey, Dictionary<string, object> values, bool previewing)
|
||||
: base(contentType, fragmentKey, values, previewing)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Examine;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
@@ -11,34 +12,16 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
public static class ExamineExtensions
|
||||
{
|
||||
public static IEnumerable<IPublishedContent> ConvertSearchResultToPublishedContent(this IEnumerable<SearchResult> results, IPublishedCache cache)
|
||||
public static IEnumerable<PublishedSearchResult> ToPublishedSearchResults(this IEnumerable<SearchResult> results, IPublishedCache cache)
|
||||
{
|
||||
// no need to think about creating the IPublishedContent from the Examine result
|
||||
// content cache is fast and optimized - use it!
|
||||
|
||||
var list = new List<IPublishedContent>();
|
||||
var list = new List<PublishedSearchResult>();
|
||||
|
||||
foreach (var result in results.OrderByDescending(x => x.Score))
|
||||
{
|
||||
var content = cache.GetById(result.Id);
|
||||
if (content == null) continue; // skip if this doesn't exist in the cache
|
||||
|
||||
// need to extend the content as we're going to add a property to it,
|
||||
// and we should not ever do it to the content we get from the cache,
|
||||
// precisely because it is cached and shared by all requests.
|
||||
|
||||
// but we cannot wrap it because we need to respect the type that was
|
||||
// returned by the cache, in case the cache can create real types.
|
||||
// so we have to ask it to please extend itself.
|
||||
|
||||
var extend = PublishedContentExtended.Extend(content);
|
||||
list.Add(extend.CreateModel()); // take care, must create the model!
|
||||
|
||||
var property = new PropertyResult("examineScore",
|
||||
result.Score,
|
||||
PropertyResultType.CustomProperty);
|
||||
|
||||
extend.AddProperty(property);
|
||||
list.Add(new PublishedSearchResult(content, result.Score));
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Web
|
||||
/// <param name="useWildCards"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<IPublishedContent> Search(string term, bool useWildCards = true, string searchProvider = null);
|
||||
IEnumerable<PublishedSearchResult> Search(string term, bool useWildCards = true, string searchProvider = null);
|
||||
|
||||
/// <summary>
|
||||
/// Searhes content
|
||||
@@ -41,6 +41,6 @@ namespace Umbraco.Web
|
||||
/// <param name="criteria"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<IPublishedContent> Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null);
|
||||
IEnumerable<PublishedSearchResult> Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Provides extension methods for <c>IPublishedItem</c>.
|
||||
/// </summary>
|
||||
public static class PublishedFragmentExtensions
|
||||
public static class PropertySetExtensions
|
||||
{
|
||||
#region IsComposedOf
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Umbraco.Web
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The content type alias.</param>
|
||||
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
|
||||
public static bool IsComposedOf(this IPublishedFragment content, string alias)
|
||||
public static bool IsComposedOf(this IPropertySet content, string alias)
|
||||
{
|
||||
return content.ContentType.CompositionAliases.Contains(alias);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace Umbraco.Web
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <returns>A value indicating whether the content has the property identified by the alias.</returns>
|
||||
/// <remarks>The content may have a property, and that property may not have a value.</remarks>
|
||||
public static bool HasProperty(this IPublishedFragment content, string alias)
|
||||
public static bool HasProperty(this IPropertySet content, string alias)
|
||||
{
|
||||
return content.ContentType.GetPropertyType(alias) != null;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ namespace Umbraco.Web
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <returns>A value indicating whether the content has a value for the property identified by the alias.</returns>
|
||||
/// <remarks>Returns true if <c>GetProperty(alias)</c> is not <c>null</c> and <c>GetProperty(alias).HasValue</c> is <c>true</c>.</remarks>
|
||||
public static bool HasValue(this IPublishedFragment content, string alias)
|
||||
public static bool HasValue(this IPropertySet content, string alias)
|
||||
{
|
||||
var prop = content.GetProperty(alias);
|
||||
return prop != null && prop.HasValue;
|
||||
@@ -66,7 +66,7 @@ namespace Umbraco.Web
|
||||
/// <param name="valueIfFalse">The value to return if the content has no value for the property.</param>
|
||||
/// <returns>Either <paramref name="valueIfTrue"/> or <paramref name="valueIfFalse"/> depending on whether the content
|
||||
/// has a value for the property identified by the alias.</returns>
|
||||
public static IHtmlString HasValue(this IPublishedFragment content, string alias,
|
||||
public static IHtmlString HasValue(this IPropertySet content, string alias,
|
||||
string valueIfTrue, string valueIfFalse = null)
|
||||
{
|
||||
return content.HasValue(alias)
|
||||
@@ -90,7 +90,7 @@ namespace Umbraco.Web
|
||||
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
public static object Value(this IPublishedFragment content, string alias)
|
||||
public static object Value(this IPropertySet content, string alias)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
return property?.Value;
|
||||
@@ -109,7 +109,7 @@ namespace Umbraco.Web
|
||||
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
public static object Value(this IPublishedFragment content, string alias, string defaultValue)
|
||||
public static object Value(this IPropertySet content, string alias, string defaultValue) // fixme - kill
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
return property == null || property.HasValue == false ? defaultValue : property.Value;
|
||||
@@ -128,7 +128,7 @@ namespace Umbraco.Web
|
||||
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
public static object Value(this IPublishedFragment content, string alias, object defaultValue)
|
||||
public static object Value(this IPropertySet content, string alias, object defaultValue)
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
return property == null || property.HasValue == false ? defaultValue : property.Value;
|
||||
@@ -151,7 +151,7 @@ namespace Umbraco.Web
|
||||
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
public static T Value<T>(this IPublishedFragment content, string alias)
|
||||
public static T Value<T>(this IPropertySet content, string alias)
|
||||
{
|
||||
return content.Value(alias, false, default(T));
|
||||
}
|
||||
@@ -170,12 +170,12 @@ namespace Umbraco.Web
|
||||
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
public static T Value<T>(this IPublishedFragment content, string alias, T defaultValue)
|
||||
public static T Value<T>(this IPropertySet content, string alias, T defaultValue)
|
||||
{
|
||||
return content.Value(alias, true, defaultValue);
|
||||
}
|
||||
|
||||
internal static T Value<T>(this IPublishedFragment content, string alias, bool withDefaultValue, T defaultValue)
|
||||
internal static T Value<T>(this IPropertySet content, string alias, bool withDefaultValue, T defaultValue) // fixme uh?
|
||||
{
|
||||
var property = content.GetProperty(alias);
|
||||
if (property == null) return defaultValue;
|
||||
@@ -205,7 +205,7 @@ namespace Umbraco.Web
|
||||
// TODO: strongly typed properties howto?
|
||||
// there is no strongly typed recurse, etc => needs to be in ModelsBuilder?
|
||||
|
||||
public static IHtmlString Value<T>(this IPublishedFragment content, string aliases, Func<T, string> format, string alt = "")
|
||||
public static IHtmlString Value<T>(this IPropertySet content, string aliases, Func<T, string> format, string alt = "")
|
||||
{
|
||||
if (format == null) format = x => x.ToString();
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace Umbraco.Web
|
||||
#region ToIndexedArray
|
||||
|
||||
public static IndexedArrayItem<TContent>[] ToIndexedArray<TContent>(this IEnumerable<TContent> source)
|
||||
where TContent : class, IPublishedFragment
|
||||
where TContent : class, IPropertySet
|
||||
{
|
||||
var set = source.Select((content, index) => new IndexedArrayItem<TContent>(content, index)).ToArray();
|
||||
foreach (var setItem in set) setItem.TotalCount = set.Length;
|
||||
@@ -253,7 +253,7 @@ namespace Umbraco.Web
|
||||
// the .OfType<T>() filter is nice when there's only one type
|
||||
// this is to support filtering with multiple types
|
||||
public static IEnumerable<T> OfTypes<T>(this IEnumerable<T> contents, params string[] types)
|
||||
where T : IPublishedFragment
|
||||
where T : IPropertySet
|
||||
{
|
||||
types = types.Select(x => x.ToLowerInvariant()).ToArray();
|
||||
return contents.Where(x => types.Contains(x.ContentType.Alias.ToLowerInvariant()));
|
||||
@@ -24,7 +24,12 @@ namespace Umbraco.Web.PublishedCache
|
||||
|
||||
public abstract bool EnsureEnvironment(out IEnumerable<string> errors);
|
||||
|
||||
public abstract IPublishedProperty CreateFragmentProperty(PublishedPropertyType propertyType, Guid itemKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
|
||||
public virtual IPropertySet CreateSet(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing, PropertyCacheLevel referenceCacheLevel)
|
||||
{
|
||||
return new PropertySet(contentType, key, values, previewing, this, referenceCacheLevel);
|
||||
}
|
||||
|
||||
public abstract IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, Guid setKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
|
||||
|
||||
public abstract string EnterPreview(IUser user, int contentId);
|
||||
public abstract void RefreshPreview(string previewToken, int contentId);
|
||||
|
||||
@@ -152,18 +152,29 @@ namespace Umbraco.Web.PublishedCache
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fragment
|
||||
#region Property Set
|
||||
|
||||
/// <summary>
|
||||
/// Creates a fragment property.
|
||||
/// Creates a property set.
|
||||
/// </summary>
|
||||
/// <param name="contentType">The content type.</param>
|
||||
/// <param name="key">The set key.</param>
|
||||
/// <param name="values">Raw values for properties.</param>
|
||||
/// <param name="previewing">A value indicating whether previewing.</param>
|
||||
/// <param name="referenceCacheLevel">The reference cache level.</param>
|
||||
/// <returns>A property set.</returns>
|
||||
IPropertySet CreateSet(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing, PropertyCacheLevel referenceCacheLevel);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a set property.
|
||||
/// </summary>
|
||||
/// <param name="propertyType">The property type.</param>
|
||||
/// <param name="itemKey">The fragment key.</param>
|
||||
/// <param name="setKey">The set key.</param>
|
||||
/// <param name="previewing">A value indicating whether previewing.</param>
|
||||
/// <param name="referenceCacheLevel">The reference cache level.</param>
|
||||
/// <param name="sourceValue">The source value.</param>
|
||||
/// <returns>A fragment property.</returns>
|
||||
IPublishedProperty CreateFragmentProperty(PublishedPropertyType propertyType, Guid itemKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
|
||||
/// <returns>A set property.</returns>
|
||||
IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, Guid setKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1534,11 +1534,11 @@ AND cmsContentNu.nodeId IS NULL
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fragments
|
||||
#region Property Set
|
||||
|
||||
public override IPublishedProperty CreateFragmentProperty(PublishedPropertyType propertyType, Guid itemKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
public override IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, Guid setKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
{
|
||||
return new PublishedFragmentProperty(FacadeAccessor, propertyType, itemKey, previewing, referenceCacheLevel, sourceValue);
|
||||
return new PropertySetProperty(FacadeAccessor, propertyType, setKey, previewing, referenceCacheLevel, sourceValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -5,13 +5,13 @@ using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache
|
||||
{
|
||||
internal class PublishedFragmentProperty : PublishedFragmentPropertyBase
|
||||
internal class PropertySetProperty : PropertySetPropertyBase
|
||||
{
|
||||
private readonly IFacadeAccessor _facadeAccessor;
|
||||
private string _valuesCacheKey;
|
||||
|
||||
// initializes a published item property
|
||||
public PublishedFragmentProperty(IFacadeAccessor facadeAccessor, PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
public PropertySetProperty(IFacadeAccessor facadeAccessor, PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
: base(propertyType, fragmentKey, previewing, referenceCacheLevel, sourceValue)
|
||||
{
|
||||
_facadeAccessor = facadeAccessor;
|
||||
@@ -7,21 +7,19 @@ using Umbraco.Core.PropertyEditors;
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
// notes:
|
||||
// a published fragment does NOT manage any tree-like elements, neither the
|
||||
// a property set does NOT manage any tree-like elements, neither the
|
||||
// original NestedContent (from Lee) nor the DetachedPublishedContent POC did.
|
||||
//
|
||||
// at the moment we do NOT support models for fragments - that would require
|
||||
// at the moment we do NOT support models for sets - that would require
|
||||
// an entirely new models factory + not even sure it makes sense at all since
|
||||
// fragments are created manually
|
||||
// sets are created manually
|
||||
//
|
||||
internal class PublishedFragment : IPublishedFragment
|
||||
internal class PropertySet : IPropertySet
|
||||
{
|
||||
// initializes a new instance of the PublishedFragment class
|
||||
// initializes a new instance of the PropertySet class
|
||||
// within the context of a facade service (eg a published content property value)
|
||||
public PublishedFragment(PublishedContentType contentType,
|
||||
IFacadeService facadeService, PropertyCacheLevel referenceCacheLevel,
|
||||
Guid key, Dictionary<string, object> values,
|
||||
bool previewing)
|
||||
public PropertySet(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing,
|
||||
IFacadeService facadeService, PropertyCacheLevel referenceCacheLevel)
|
||||
{
|
||||
ContentType = contentType;
|
||||
Key = key;
|
||||
@@ -32,34 +30,32 @@ namespace Umbraco.Web.PublishedCache
|
||||
.PropertyTypes
|
||||
.Select(propertyType =>
|
||||
{
|
||||
object value;
|
||||
values.TryGetValue(propertyType.PropertyTypeAlias, out value);
|
||||
return facadeService.CreateFragmentProperty(propertyType, Key, previewing, referenceCacheLevel, value);
|
||||
values.TryGetValue(propertyType.PropertyTypeAlias, out object value);
|
||||
return facadeService.CreateSetProperty(propertyType, Key, previewing, referenceCacheLevel, value);
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
// initializes a new instance of the PublishedFragment class
|
||||
// initializes a new instance of the PropertySet class
|
||||
// without any context, so it's purely 'standalone' and should NOT interfere with the facade service
|
||||
public PublishedFragment(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing)
|
||||
public PropertySet(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing)
|
||||
{
|
||||
ContentType = contentType;
|
||||
Key = key;
|
||||
|
||||
values = GetCaseInsensitiveValueDictionary(values);
|
||||
|
||||
// using an initial reference cache level of .None ensures that
|
||||
// everything will be cached at .Content level
|
||||
// that reference cache level will propagate to all properties
|
||||
// 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
|
||||
const PropertyCacheLevel cacheLevel = PropertyCacheLevel.None;
|
||||
|
||||
_propertiesArray = contentType
|
||||
.PropertyTypes
|
||||
.Select(propertyType =>
|
||||
{
|
||||
object value;
|
||||
values.TryGetValue(propertyType.PropertyTypeAlias, out value);
|
||||
return (IPublishedProperty) new PublishedFragmentProperty(propertyType, Key, previewing, cacheLevel, value);
|
||||
values.TryGetValue(propertyType.PropertyTypeAlias, out object value);
|
||||
return (IPublishedProperty) new PropertySetProperty(propertyType, Key, previewing, cacheLevel, value);
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
@@ -68,7 +64,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
// ensure we ignore case for property aliases
|
||||
var comparer = values.Comparer;
|
||||
var ignoreCase = comparer == StringComparer.OrdinalIgnoreCase || comparer == StringComparer.InvariantCultureIgnoreCase || comparer == StringComparer.CurrentCultureIgnoreCase;
|
||||
var ignoreCase = Equals(comparer, StringComparer.OrdinalIgnoreCase) || Equals(comparer, StringComparer.InvariantCultureIgnoreCase) || Equals(comparer, StringComparer.CurrentCultureIgnoreCase);
|
||||
return ignoreCase ? values : new Dictionary<string, object>(values, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
@@ -78,7 +74,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
|
||||
#endregion
|
||||
|
||||
#region Content
|
||||
#region PropertySet
|
||||
|
||||
public Guid Key { get; }
|
||||
|
||||
@@ -4,9 +4,9 @@ using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
class PublishedFragmentProperty : PublishedFragmentPropertyBase
|
||||
class PropertySetProperty : PropertySetPropertyBase
|
||||
{
|
||||
public PublishedFragmentProperty(PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel cacheLevel, object sourceValue = null)
|
||||
public PropertySetProperty(PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel cacheLevel, object sourceValue = null)
|
||||
: base(propertyType, fragmentKey, previewing, cacheLevel, sourceValue)
|
||||
{ }
|
||||
|
||||
@@ -4,7 +4,7 @@ using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
internal abstract class PublishedFragmentPropertyBase : PublishedPropertyBase
|
||||
internal abstract class PropertySetPropertyBase : PublishedPropertyBase
|
||||
{
|
||||
private readonly object _locko = new object();
|
||||
private readonly object _sourceValue;
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
private CacheValues _cacheValues;
|
||||
|
||||
// initializes a published item property
|
||||
protected PublishedFragmentPropertyBase(PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
protected PropertySetPropertyBase(PublishedPropertyType propertyType, Guid fragmentKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
: base(propertyType, referenceCacheLevel)
|
||||
{
|
||||
_sourceValue = sourceValue;
|
||||
@@ -238,9 +238,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fragments
|
||||
#region Property Set
|
||||
|
||||
public override IPublishedProperty CreateFragmentProperty(PublishedPropertyType propertyType, Guid itemKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
public override IPublishedProperty CreateSetProperty(PublishedPropertyType propertyType, Guid setKey, bool previewing, PropertyCacheLevel referenceCacheLevel, object sourceValue = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace Umbraco.Web
|
||||
|
||||
#region Search
|
||||
|
||||
public static IEnumerable<IPublishedContent> Search(this IPublishedContent content, string term, bool useWildCards = true, string searchProvider = null)
|
||||
public static IEnumerable<PublishedSearchResult> Search(this IPublishedContent content, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (string.IsNullOrEmpty(searchProvider) == false)
|
||||
@@ -235,12 +235,12 @@ namespace Umbraco.Web
|
||||
return content.Search(crit, searcher);
|
||||
}
|
||||
|
||||
public static IEnumerable<IPublishedContent> SearchDescendants(this IPublishedContent content, string term, bool useWildCards = true, string searchProvider = null)
|
||||
public static IEnumerable<PublishedSearchResult> SearchDescendants(this IPublishedContent content, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
return content.Search(term, useWildCards, searchProvider);
|
||||
}
|
||||
|
||||
public static IEnumerable<IPublishedContent> SearchChildren(this IPublishedContent content, string term, bool useWildCards = true, string searchProvider = null)
|
||||
public static IEnumerable<PublishedSearchResult> SearchChildren(this IPublishedContent content, string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
var searcher = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (string.IsNullOrEmpty(searchProvider) == false)
|
||||
@@ -256,14 +256,14 @@ namespace Umbraco.Web
|
||||
return content.Search(crit, searcher);
|
||||
}
|
||||
|
||||
public static IEnumerable<IPublishedContent> Search(this IPublishedContent content, Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
public static IEnumerable<PublishedSearchResult> Search(this IPublishedContent content, Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
var s = Examine.ExamineManager.Instance.DefaultSearchProvider;
|
||||
if (searchProvider != null)
|
||||
s = searchProvider;
|
||||
|
||||
var results = s.Search(criteria);
|
||||
return results.ConvertSearchResultToPublishedContent(UmbracoContext.Current.ContentCache);
|
||||
return results.ToPublishedSearchResults(UmbracoContext.Current.ContentCache);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace Umbraco.Web
|
||||
/// <param name="useWildCards"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IPublishedContent> Search(string term, bool useWildCards = true, string searchProvider = null)
|
||||
public IEnumerable<PublishedSearchResult> Search(string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
if (_query != null) return _query.Search(term, useWildCards, searchProvider);
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace Umbraco.Web
|
||||
searcher = Examine.ExamineManager.Instance.SearchProviderCollection[searchProvider];
|
||||
|
||||
var results = searcher.Search(term, useWildCards);
|
||||
return results.ConvertSearchResultToPublishedContent(_contentCache);
|
||||
return results.ToPublishedSearchResults(_contentCache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -224,7 +224,7 @@ namespace Umbraco.Web
|
||||
/// <param name="criteria"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IPublishedContent> Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
public IEnumerable<PublishedSearchResult> Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
if (_query != null) return _query.Search(criteria, searchProvider);
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace Umbraco.Web
|
||||
s = searchProvider;
|
||||
|
||||
var results = s.Search(criteria);
|
||||
return results.ConvertSearchResultToPublishedContent(_contentCache);
|
||||
return results.ToPublishedSearchResults(_contentCache);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -217,10 +217,10 @@
|
||||
<Compile Include="PropertyEditors\ValueConverters\MultiNodeTreePickerPropertyConverter.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\MultipleMediaPickerPropertyConverter.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\NuCacheComponent.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\PublishedFragmentProperty.cs" />
|
||||
<Compile Include="PublishedCache\PublishedFragment.cs" />
|
||||
<Compile Include="PublishedCache\PublishedFragmentProperty.cs" />
|
||||
<Compile Include="PublishedCache\PublishedFragmentPropertyBase.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\PropertySetProperty.cs" />
|
||||
<Compile Include="PublishedCache\PropertySet.cs" />
|
||||
<Compile Include="PublishedCache\PropertySetProperty.cs" />
|
||||
<Compile Include="PublishedCache\PropertySetPropertyBase.cs" />
|
||||
<Compile Include="Models\Trees\DisableUser.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\ContentPickerValueConverter.cs" />
|
||||
<Compile Include="PublishedCache\FacadeServiceBase.cs" />
|
||||
@@ -265,7 +265,7 @@
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\XmlCacheComponent.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\XmlStore.cs" />
|
||||
<Compile Include="PublishedCache\XmlPublishedCache\XmlStoreFilePersister.cs" />
|
||||
<Compile Include="PublishedFragmentExtensions.cs" />
|
||||
<Compile Include="PropertySetExtensions.cs" />
|
||||
<Compile Include="RelatedLinksTypeConverter.cs" />
|
||||
<Compile Include="Routing\ContentFinderCollection.cs" />
|
||||
<Compile Include="Routing\ContentFinderCollectionBuilder.cs" />
|
||||
|
||||
@@ -816,7 +816,7 @@ namespace Umbraco.Web
|
||||
/// <param name="useWildCards"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IPublishedContent> Search(string term, bool useWildCards = true, string searchProvider = null)
|
||||
public IEnumerable<PublishedSearchResult> Search(string term, bool useWildCards = true, string searchProvider = null)
|
||||
{
|
||||
return ContentQuery.Search(term, useWildCards, searchProvider);
|
||||
}
|
||||
@@ -827,7 +827,7 @@ namespace Umbraco.Web
|
||||
/// <param name="criteria"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IPublishedContent> Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
public IEnumerable<PublishedSearchResult> Search(Examine.SearchCriteria.ISearchCriteria criteria, Examine.Providers.BaseSearchProvider searchProvider = null)
|
||||
{
|
||||
return ContentQuery.Search(criteria, searchProvider);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user