Introduce IPublishedContentType

This commit is contained in:
Stephan
2019-04-15 13:04:14 +02:00
parent 747a8cba2e
commit 34ad8dfb8d
38 changed files with 183 additions and 140 deletions
@@ -66,24 +66,24 @@ namespace Umbraco.Core
/// <summary>
/// Determines whether the content type is invariant.
/// </summary>
public static bool VariesByNothing(this PublishedContentType contentType) => contentType.Variations.VariesByNothing();
public static bool VariesByNothing(this IPublishedContentType contentType) => contentType.Variations.VariesByNothing();
/// <summary>
/// Determines whether the content type varies by culture.
/// </summary>
/// <remarks>And then it could also vary by segment.</remarks>
public static bool VariesByCulture(this PublishedContentType contentType) => contentType.Variations.VariesByCulture();
public static bool VariesByCulture(this IPublishedContentType contentType) => contentType.Variations.VariesByCulture();
/// <summary>
/// Determines whether the content type varies by segment.
/// </summary>
/// <remarks>And then it could also vary by culture.</remarks>
public static bool VariesBySegment(this PublishedContentType contentType) => contentType.Variations.VariesBySegment();
public static bool VariesBySegment(this IPublishedContentType contentType) => contentType.Variations.VariesBySegment();
/// <summary>
/// Determines whether the content type varies by culture and segment.
/// </summary>
public static bool VariesByCultureAndSegment(this PublishedContentType contentType) => contentType.Variations.VariesByCultureAndSegment();
public static bool VariesByCultureAndSegment(this IPublishedContentType contentType) => contentType.Variations.VariesByCultureAndSegment();
/// <summary>
/// Determines whether the property type is invariant.
@@ -0,0 +1,63 @@
using System.Collections.Generic;
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Represents an <see cref="IPublishedElement"/> type.
/// </summary>
/// <remarks>Instances implementing the <see cref="IPublishedContentType"/> interface should be
/// immutable, ie if the content type changes, then a new instance needs to be created.</remarks>
public interface IPublishedContentType
{
/// <summary>
/// Gets the content type identifier.
/// </summary>
int Id { get; }
/// <summary>
/// Gets the content type alias.
/// </summary>
string Alias { get; }
/// <summary>
/// Gets the content item type.
/// </summary>
PublishedItemType ItemType { get; }
/// <summary>
/// Gets the aliases of the content types participating in the composition.
/// </summary>
HashSet<string> CompositionAliases { get; }
/// <summary>
/// Gets the content variations of the content type.
/// </summary>
ContentVariation Variations { get; }
/// <summary>
/// Gets a value indicating whether this content type is for an element.
/// </summary>
bool IsElement { get; }
/// <summary>
/// Gets the content type properties.
/// </summary>
IEnumerable<PublishedPropertyType> PropertyTypes { get; }
/// <summary>
/// Gets a property type index.
/// </summary>
/// <remarks>The alias is case-insensitive. This is the only place where alias strings are compared.</remarks>
int GetPropertyIndex(string alias);
/// <summary>
/// Gets a property type.
/// </summary>
PublishedPropertyType GetPropertyType(string alias);
/// <summary>
/// Gets a property type.
/// </summary>
PublishedPropertyType GetPropertyType(int index);
}
}
@@ -10,7 +10,7 @@
/// </summary>
/// <param name="contentType">An content type.</param>
/// <returns>A published content type corresponding to the item type and content type.</returns>
PublishedContentType CreateContentType(IContentTypeComposition contentType);
IPublishedContentType CreateContentType(IContentTypeComposition contentType);
/// <summary>
/// Creates a published property type.
@@ -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(PublishedContentType contentType, PropertyType propertyType);
PublishedPropertyType 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(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
PublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
/// <summary>
/// Gets a published datatype.
@@ -13,7 +13,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Gets the content type.
/// </summary>
PublishedContentType ContentType { get; }
IPublishedContentType ContentType { get; }
#endregion
@@ -5,11 +5,11 @@ using System.Linq;
namespace Umbraco.Core.Models.PublishedContent
{
/// <summary>
/// Represents an <see cref="IPublishedContent"/> type.
/// Represents an <see cref="IPublishedElement"/> type.
/// </summary>
/// <remarks>Instances of the <see cref="PublishedContentType"/> class are immutable, ie
/// if the content type changes, then a new class needs to be created.</remarks>
public class PublishedContentType
public class PublishedContentType : IPublishedContentType
{
private readonly PublishedPropertyType[] _propertyTypes;
@@ -103,44 +103,29 @@ namespace Umbraco.Core.Models.PublishedContent
#region Content type
/// <summary>
/// Gets the content type identifier.
/// </summary>
/// <inheritdoc />
public int Id { get; }
/// <summary>
/// Gets the content type alias.
/// </summary>
/// <inheritdoc />
public string Alias { get; }
/// <summary>
/// Gets the content item type.
/// </summary>
/// <inheritdoc />
public PublishedItemType ItemType { get; }
/// <summary>
/// Gets the aliases of the content types participating in the composition.
/// </summary>
/// <inheritdoc />
public HashSet<string> CompositionAliases { get; }
/// <summary>
/// Gets the content variations of the content type.
/// </summary>
/// <inheritdoc />
public ContentVariation Variations { get; }
#endregion
#region Properties
/// <summary>
/// Gets the content type properties.
/// </summary>
/// <inheritdoc />
public IEnumerable<PublishedPropertyType> PropertyTypes => _propertyTypes;
/// <summary>
/// Gets a property type index.
/// </summary>
/// <remarks>The alias is case-insensitive. This is the only place where alias strings are compared.</remarks>
/// <inheritdoc />
public int GetPropertyIndex(string alias)
{
if (_indexes.TryGetValue(alias, out var index)) return index; // fastest
@@ -150,9 +135,7 @@ namespace Umbraco.Core.Models.PublishedContent
// virtual for unit tests
// TODO: explain why
/// <summary>
/// Gets a property type.
/// </summary>
/// <inheritdoc />
public virtual PublishedPropertyType GetPropertyType(string alias)
{
var index = GetPropertyIndex(alias);
@@ -161,17 +144,13 @@ namespace Umbraco.Core.Models.PublishedContent
// virtual for unit tests
// TODO: explain why
/// <summary>
/// Gets a property type.
/// </summary>
/// <inheritdoc />
public virtual PublishedPropertyType GetPropertyType(int index)
{
return index >= 0 && index < _propertyTypes.Length ? _propertyTypes[index] : null;
}
/// <summary>
/// Gets a value indicating whether this content type is for an element.
/// </summary>
/// <inheritdoc />
public bool IsElement { get; }
#endregion
@@ -26,31 +26,31 @@ namespace Umbraco.Core.Models.PublishedContent
}
/// <inheritdoc />
public PublishedContentType CreateContentType(IContentTypeComposition contentType)
public IPublishedContentType CreateContentType(IContentTypeComposition contentType)
{
return new PublishedContentType(contentType, this);
}
// for tests
internal PublishedContentType CreateContentType(int id, string alias, IEnumerable<PublishedPropertyType> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
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);
}
// for tests
internal PublishedContentType CreateContentType(int id, string alias, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes, ContentVariation variations = ContentVariation.Nothing, bool isElement = false)
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);
}
/// <inheritdoc />
public PublishedPropertyType CreatePropertyType(PublishedContentType contentType, PropertyType propertyType)
public PublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType)
{
return new PublishedPropertyType(contentType, propertyType, _propertyValueConverters, _publishedModelFactory, this);
}
/// <inheritdoc />
public PublishedPropertyType CreatePropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations = ContentVariation.Nothing)
public PublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations = ContentVariation.Nothing)
{
return new PublishedPropertyType(contentType, propertyTypeAlias, dataTypeId, true, variations, _propertyValueConverters, _publishedModelFactory, this);
}
@@ -41,7 +41,7 @@ namespace Umbraco.Core.Models.PublishedContent
#region ContentType
/// <inheritdoc />
public virtual PublishedContentType ContentType => _content.ContentType;
public virtual IPublishedContentType ContentType => _content.ContentType;
#endregion
@@ -28,7 +28,7 @@ namespace Umbraco.Core.Models.PublishedContent
public IPublishedElement Unwrap() => _content;
/// <inheritdoc />
public PublishedContentType ContentType => _content.ContentType;
public IPublishedContentType ContentType => _content.ContentType;
/// <inheritdoc />
public Guid Key => _content.Key;
@@ -32,7 +32,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <remarks>
/// <para>The new published property type belongs to the published content type.</para>
/// </remarks>
public PublishedPropertyType(PublishedContentType contentType, PropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
public PublishedPropertyType(IPublishedContentType contentType, PropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
: this(propertyType.Alias, propertyType.DataTypeId, true, propertyType.Variations, propertyValueConverters, publishedModelFactory, factory)
{
ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
@@ -45,7 +45,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <para>Values are assumed to be consisted and are not checked.</para>
/// <para>The new published property type belongs to the published content type.</para>
/// </remarks>
public PublishedPropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
public PublishedPropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory)
: this(propertyTypeAlias, dataTypeId, isUserProperty, variations, propertyValueConverters, publishedModelFactory, factory)
{
ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
@@ -78,7 +78,7 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Gets the published content type containing the property type.
/// </summary>
public PublishedContentType ContentType { get; internal set; } // internally set by PublishedContentType constructor
public IPublishedContentType ContentType { get; internal set; } // internally set by PublishedContentType constructor
/// <summary>
/// Gets the data type.
+1
View File
@@ -221,6 +221,7 @@
<Compile Include="Mapping\UmbracoMapper.cs" />
<Compile Include="Models\CultureImpact.cs" />
<Compile Include="Models\PublishedContent\ILivePublishedModelFactory.cs" />
<Compile Include="Models\PublishedContent\IPublishedContentType.cs" />
<Compile Include="Persistence\Dtos\PropertyTypeCommonDto.cs" />
<Compile Include="Persistence\Repositories\Implement\ContentTypeCommonRepository.cs" />
<Compile Include="Persistence\Repositories\IContentTypeCommonRepository.cs" />
@@ -194,7 +194,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
return _getProperty(this, alias);
}
public override PublishedContentType ContentType => _contentType;
public override IPublishedContentType ContentType => _contentType;
private readonly List<string> _keysAdded = new List<string>();
private int _id;
@@ -215,7 +215,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
//private Guid _version;
private int _level;
private readonly ICollection<IPublishedProperty> _properties;
private readonly PublishedContentType _contentType;
private readonly IPublishedContentType _contentType;
private void ValidateAndSetProperty(IReadOnlyDictionary<string, string> valueDictionary, Action<string> setProperty, params string[] potentialKeys)
{
@@ -536,12 +536,12 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Content types
public override PublishedContentType GetContentType(int id)
public override IPublishedContentType GetContentType(int id)
{
return _contentTypeCache.Get(PublishedItemType.Content, id);
}
public override PublishedContentType GetContentType(string alias)
public override IPublishedContentType GetContentType(string alias)
{
return _contentTypeCache.Get(PublishedItemType.Content, alias);
}
@@ -609,17 +609,17 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Content types
public override PublishedContentType GetContentType(int id)
public override IPublishedContentType GetContentType(int id)
{
return _contentTypeCache.Get(PublishedItemType.Media, id);
}
public override PublishedContentType GetContentType(string alias)
public override IPublishedContentType GetContentType(string alias)
{
return _contentTypeCache.Get(PublishedItemType.Media, alias);
}
public override IEnumerable<IPublishedContent> GetByContentType(PublishedContentType contentType)
public override IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
{
throw new NotSupportedException();
}
@@ -138,12 +138,12 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Content types
public PublishedContentType GetContentType(int id)
public IPublishedContentType GetContentType(int id)
{
return _contentTypeCache.Get(PublishedItemType.Member, id);
}
public PublishedContentType GetContentType(string alias)
public IPublishedContentType GetContentType(string alias)
{
return _contentTypeCache.Get(PublishedItemType.Member, alias);
}
@@ -53,7 +53,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
private IEnumerable<IPublishedContent> _children = Enumerable.Empty<IPublishedContent>();
private IPublishedContent _parent;
private PublishedContentType _contentType;
private IPublishedContentType _contentType;
private Dictionary<string, IPublishedProperty> _properties;
private int _id;
@@ -254,7 +254,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
}
public override PublishedContentType ContentType
public override IPublishedContentType ContentType
{
get
{
@@ -308,8 +308,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
out PublishedContentType contentType, out Dictionary<string, IPublishedProperty> properties,
Func<PublishedItemType, string, PublishedContentType> getPublishedContentType)
out IPublishedContentType contentType, out Dictionary<string, IPublishedProperty> properties,
Func<PublishedItemType, string, IPublishedContentType> getPublishedContentType)
{
//initialize the out params with defaults:
writerName = null;
@@ -23,7 +23,7 @@ namespace Umbraco.Tests.Published
[TestFixture]
public class NestedContentTests
{
private (PublishedContentType, PublishedContentType) CreateContentTypes()
private (IPublishedContentType, IPublishedContentType) CreateContentTypes()
{
Current.Reset();
@@ -250,7 +250,7 @@ namespace Umbraco.Tests.Published
class TestPublishedContent : PublishedContentBase
{
public TestPublishedContent(PublishedContentType contentType, Guid key, IEnumerable<TestPublishedProperty> properties, IUmbracoContextAccessor umbracoContextAccessor): base(umbracoContextAccessor)
public TestPublishedContent(IPublishedContentType contentType, Guid key, IEnumerable<TestPublishedProperty> properties, IUmbracoContextAccessor umbracoContextAccessor): base(umbracoContextAccessor)
{
ContentType = contentType;
Key = key;
@@ -266,7 +266,7 @@ namespace Umbraco.Tests.Published
public override bool IsPublished(string culture = null) => true;
public override IPublishedContent Parent { get; }
public override IEnumerable<IPublishedContent> Children { get; }
public override PublishedContentType ContentType { get; }
public override IPublishedContentType ContentType { get; }
// ReSharper restore UnassignedGetOnlyAutoProperty
// ReSharper disable UnassignedGetOnlyAutoProperty
@@ -243,7 +243,7 @@ namespace Umbraco.Tests.PublishedContent
return property;
}
public PublishedContentType ContentType { get; set; }
public IPublishedContentType ContentType { get; set; }
}
}
}
@@ -930,7 +930,7 @@ namespace Umbraco.Tests.PublishedContent
class ImageWithLegendModel : PublishedElement
{
public ImageWithLegendModel(PublishedContentType contentType, Guid fragmentKey, Dictionary<string, object> values, bool previewing)
public ImageWithLegendModel(IPublishedContentType contentType, Guid fragmentKey, Dictionary<string, object> values, bool previewing)
: base(contentType, fragmentKey, values, previewing)
{ }
@@ -137,17 +137,17 @@ namespace Umbraco.Tests.PublishedContent
return _content.Count > 0;
}
public override PublishedContentType GetContentType(int id)
public override IPublishedContentType GetContentType(int id)
{
throw new NotImplementedException();
}
public override PublishedContentType GetContentType(string alias)
public override IPublishedContentType GetContentType(string alias)
{
throw new NotImplementedException();
}
public override IEnumerable<IPublishedContent> GetByContentType(PublishedContentType contentType)
public override IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
{
throw new NotImplementedException();
}
@@ -157,7 +157,7 @@ namespace Umbraco.Tests.PublishedContent
{
#region Constructor
public SolidPublishedContent(PublishedContentType contentType)
public SolidPublishedContent(IPublishedContentType contentType)
{
// initialize boring stuff
TemplateId = 0;
@@ -211,7 +211,7 @@ namespace Umbraco.Tests.PublishedContent
#region ContentType
public PublishedContentType ContentType { get; private set; }
public IPublishedContentType ContentType { get; private set; }
#endregion
@@ -7,7 +7,7 @@ namespace Umbraco.Tests.TestHelpers.Stubs
{
internal class TestPublishedContent : PublishedElement, IPublishedContent
{
public TestPublishedContent(PublishedContentType contentType, int id, Guid key, Dictionary<string, object> values, bool previewing, Dictionary<string, PublishedCultureInfo> cultures = null)
public TestPublishedContent(IPublishedContentType contentType, int id, Guid key, Dictionary<string, object> values, bool previewing, Dictionary<string, PublishedCultureInfo> cultures = null)
: base(contentType, key, values, previewing)
{
Id = id;
@@ -218,7 +218,7 @@ namespace Umbraco.Web.Macros
Parent = new PagePublishedContent(_inner.ParentId);
}
public PublishedContentType ContentType { get; }
public IPublishedContentType ContentType { get; }
public int Id { get; }
@@ -24,7 +24,7 @@ namespace Umbraco.Web.Models
#region ContentType
public abstract PublishedContentType ContentType { get; }
public abstract IPublishedContentType ContentType { get; }
#endregion
@@ -199,7 +199,7 @@ namespace Umbraco.Web.PublishedCache
/// </summary>
/// <param name="id">The content type unique identifier.</param>
/// <returns>The content type, or null.</returns>
PublishedContentType GetContentType(int id);
IPublishedContentType GetContentType(int id);
/// <summary>
/// Gets a content type identified by its alias.
@@ -207,13 +207,13 @@ namespace Umbraco.Web.PublishedCache
/// <param name="alias">The content type alias.</param>
/// <returns>The content type, or null.</returns>
/// <remarks>The alias is case-insensitive.</remarks>
PublishedContentType GetContentType(string alias);
IPublishedContentType GetContentType(string alias);
/// <summary>
/// Gets contents of a given content type.
/// </summary>
/// <param name="contentType">The content type.</param>
/// <returns>The contents.</returns>
IEnumerable<IPublishedContent> GetByContentType(PublishedContentType contentType);
IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType);
}
}
@@ -22,7 +22,7 @@ namespace Umbraco.Web.PublishedCache
/// </summary>
/// <param name="id">The content type unique identifier.</param>
/// <returns>The content type, or null.</returns>
PublishedContentType GetContentType(int id);
IPublishedContentType GetContentType(int id);
/// <summary>
/// Gets a content type identified by its alias.
@@ -30,6 +30,6 @@ namespace Umbraco.Web.PublishedCache
/// <param name="alias">The content type alias.</param>
/// <returns>The content type, or null.</returns>
/// <remarks>The alias is case-insensitive.</remarks>
PublishedContentType GetContentType(string alias);
IPublishedContentType GetContentType(string alias);
}
}
@@ -376,12 +376,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Content types
public override PublishedContentType GetContentType(int id)
public override IPublishedContentType GetContentType(int id)
{
return _snapshot.GetContentType(id);
}
public override PublishedContentType GetContentType(string alias)
public override IPublishedContentType GetContentType(string alias)
{
return _snapshot.GetContentType(alias);
}
@@ -10,7 +10,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
internal class ContentNode
{
// special ctor with no content data - for members
public ContentNode(int id, Guid uid, PublishedContentType contentType,
public ContentNode(int id, Guid uid, IPublishedContentType contentType,
int level, string path, int sortOrder,
int parentContentId,
DateTime createDate, int creatorId)
@@ -28,7 +28,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
ChildContentIds = new List<int>();
}
public ContentNode(int id, Guid uid, PublishedContentType contentType,
public ContentNode(int id, Guid uid, IPublishedContentType contentType,
int level, string path, int sortOrder,
int parentContentId,
DateTime createDate, int creatorId,
@@ -60,7 +60,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
// two-phase ctor, phase 2
public void SetContentTypeAndData(PublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor)
public void SetContentTypeAndData(IPublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor)
{
ContentType = contentType;
@@ -109,7 +109,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
// clone with new content type
public ContentNode(ContentNode origin, PublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor)
public ContentNode(ContentNode origin, IPublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor)
{
Id = origin.Id;
Uid = origin.Uid;
@@ -136,7 +136,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// keep this as small as possible
public readonly int Id;
public readonly Guid Uid;
public PublishedContentType ContentType;
public IPublishedContentType ContentType;
public readonly int Level;
public readonly string Path;
public readonly int SortOrder;
@@ -18,7 +18,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
public static ContentNodeKit Null { get; } = new ContentNodeKit { ContentTypeId = -1 };
public void Build(
PublishedContentType contentType,
IPublishedContentType contentType,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
bool canBePublished,
@@ -24,8 +24,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly ConcurrentDictionary<int, LinkedNode<ContentNode>> _contentNodes;
private readonly ConcurrentDictionary<int, LinkedNode<object>> _contentRootNodes;
private readonly ConcurrentDictionary<int, LinkedNode<PublishedContentType>> _contentTypesById;
private readonly ConcurrentDictionary<string, LinkedNode<PublishedContentType>> _contentTypesByAlias;
private readonly ConcurrentDictionary<int, LinkedNode<IPublishedContentType>> _contentTypesById;
private readonly ConcurrentDictionary<string, LinkedNode<IPublishedContentType>> _contentTypesByAlias;
private readonly ConcurrentDictionary<Guid, int> _xmap;
private readonly ILogger _logger;
@@ -61,8 +61,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
_contentNodes = new ConcurrentDictionary<int, LinkedNode<ContentNode>>();
_contentRootNodes = new ConcurrentDictionary<int, LinkedNode<object>>();
_contentTypesById = new ConcurrentDictionary<int, LinkedNode<PublishedContentType>>();
_contentTypesByAlias = new ConcurrentDictionary<string, LinkedNode<PublishedContentType>>(StringComparer.InvariantCultureIgnoreCase);
_contentTypesById = new ConcurrentDictionary<int, LinkedNode<IPublishedContentType>>();
_contentTypesByAlias = new ConcurrentDictionary<string, LinkedNode<IPublishedContentType>>(StringComparer.InvariantCultureIgnoreCase);
_xmap = new ConcurrentDictionary<Guid, int>();
_genObjs = new ConcurrentQueue<GenObj>();
@@ -249,7 +249,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Content types
public void NewContentTypes(IEnumerable<PublishedContentType> types)
public void NewContentTypes(IEnumerable<IPublishedContentType> types)
{
var lockInfo = new WriteLockInfo();
try
@@ -268,7 +268,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
public void UpdateContentTypes(IEnumerable<PublishedContentType> types)
public void UpdateContentTypes(IEnumerable<IPublishedContentType> types)
{
var lockInfo = new WriteLockInfo();
try
@@ -288,7 +288,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var node = link.Value;
if (node == null) continue;
var contentTypeId = node.ContentType.Id;
if (index.TryGetValue(contentTypeId, out PublishedContentType contentType) == false) continue;
if (index.TryGetValue(contentTypeId, out var contentType) == false) continue;
SetValueLocked(_contentNodes, node.Id, new ContentNode(node, contentType, _publishedSnapshotAccessor, _variationContextAccessor, _umbracoContextAccessor));
}
}
@@ -298,10 +298,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
public void UpdateContentTypes(IEnumerable<int> removedIds, IEnumerable<PublishedContentType> refreshedTypes, IEnumerable<ContentNodeKit> kits)
public void UpdateContentTypes(IEnumerable<int> removedIds, IEnumerable<IPublishedContentType> refreshedTypes, IEnumerable<ContentNodeKit> kits)
{
var removedIdsA = removedIds?.ToArray() ?? Array.Empty<int>();
var refreshedTypesA = refreshedTypes?.ToArray() ?? Array.Empty<PublishedContentType>();
var refreshedTypesA = refreshedTypes?.ToArray() ?? Array.Empty<IPublishedContentType>();
var refreshedIdsA = refreshedTypesA.Select(x => x.Id).ToArray();
kits = kits ?? Array.Empty<ContentNodeKit>();
@@ -377,7 +377,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
public void UpdateDataTypes(IEnumerable<int> dataTypeIds, Func<int, PublishedContentType> getContentType)
public void UpdateDataTypes(IEnumerable<int> dataTypeIds, Func<int, IPublishedContentType> getContentType)
{
var lockInfo = new WriteLockInfo();
try
@@ -434,7 +434,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
return false;
// unknown = bad
if (_contentTypesById.TryGetValue(kit.ContentTypeId, out LinkedNode<PublishedContentType> link) == false || link.Value == null)
if (_contentTypesById.TryGetValue(kit.ContentTypeId, out var link) == false || link.Value == null)
return false;
// check whether parent is published
@@ -830,12 +830,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
return has == false;
}
public PublishedContentType GetContentType(int id, long gen)
public IPublishedContentType GetContentType(int id, long gen)
{
return GetValue(_contentTypesById, id, gen);
}
public PublishedContentType GetContentType(string alias, long gen)
public IPublishedContentType GetContentType(string alias, long gen)
{
return GetValue(_contentTypesByAlias, alias, gen);
}
@@ -1151,14 +1151,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
return _store.GetAll(_gen);
}
public PublishedContentType GetContentType(int id)
public IPublishedContentType GetContentType(int id)
{
if (_gen < 0)
throw new ObjectDisposedException("snapshot" /*+ " (" + _thisCount + ")"*/);
return _store.GetContentType(id, _gen);
}
public PublishedContentType GetContentType(string alias)
public IPublishedContentType GetContentType(string alias)
{
if (_gen < 0)
throw new ObjectDisposedException("snapshot" /*+ " (" + _thisCount + ")"*/);
@@ -156,12 +156,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Content types
public override PublishedContentType GetContentType(int id)
public override IPublishedContentType GetContentType(int id)
{
return _snapshot.GetContentType(id);
}
public override PublishedContentType GetContentType(string alias)
public override IPublishedContentType GetContentType(string alias)
{
return _snapshot.GetContentType(alias);
}
@@ -151,12 +151,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Content types
public PublishedContentType GetContentType(int id)
public IPublishedContentType GetContentType(int id)
{
return _contentTypeCache.Get(PublishedItemType.Member, id);
}
public PublishedContentType GetContentType(string alias)
public IPublishedContentType GetContentType(string alias)
{
return _contentTypeCache.Get(PublishedItemType.Member, alias);
}
@@ -22,10 +22,10 @@ namespace Umbraco.Web.PublishedCache.NuCache.Navigable
// changes, but they are replaced by a new instance, so our map here will clean itself automatically and
// we don't have to manage cache - ConditionalWeakTable does not prevent keys from being GCed
private static readonly ConditionalWeakTable<PublishedContentType, NavigableContentType> TypesMap
= new ConditionalWeakTable<PublishedContentType,NavigableContentType>();
private static readonly ConditionalWeakTable<IPublishedContentType, NavigableContentType> TypesMap
= new ConditionalWeakTable<IPublishedContentType,NavigableContentType>();
public static NavigableContentType GetContentType(PublishedContentType contentType)
public static NavigableContentType GetContentType(IPublishedContentType contentType)
{
return TypesMap.GetOrCreateValue(contentType).EnsureInitialized(contentType);
}
@@ -49,7 +49,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.Navigable
};
}
private NavigableContentType EnsureInitialized(PublishedContentType contentType)
private NavigableContentType EnsureInitialized(IPublishedContentType contentType)
{
lock (_locko)
{
@@ -166,7 +166,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Content Type
/// <inheritdoc />
public override PublishedContentType ContentType => _contentNode.ContentType;
public override IPublishedContentType ContentType => _contentNode.ContentType;
#endregion
@@ -30,7 +30,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
public static IPublishedContent Create(
IMember member,
PublishedContentType contentType,
IPublishedContentType contentType,
bool previewing,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
@@ -53,7 +53,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
return new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor).CreateModel();
}
private static Dictionary<string, PropertyData[]> GetPropertyValues(PublishedContentType contentType, IMember member)
private static Dictionary<string, PropertyData[]> GetPropertyValues(IPublishedContentType contentType, IMember member)
{
// see node in PublishedSnapshotService
// we do not (want to) support ConvertDbToXml/String
@@ -91,7 +91,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
return properties;
}
private static void AddIf(PublishedContentType contentType, IDictionary<string, PropertyData[]> properties, string alias, object value)
private static void AddIf(IPublishedContentType contentType, IDictionary<string, PropertyData[]> properties, string alias, object value)
{
var propertyType = contentType.GetPropertyType(alias);
if (propertyType == null || propertyType.IsUserProperty) return;
@@ -898,11 +898,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Content Types
private IEnumerable<PublishedContentType> CreateContentTypes(PublishedItemType itemType, int[] ids)
private IEnumerable<IPublishedContentType> CreateContentTypes(PublishedItemType itemType, int[] ids)
{
// XxxTypeService.GetAll(empty) returns everything!
if (ids.Length == 0)
return Enumerable.Empty<PublishedContentType>();
return Enumerable.Empty<IPublishedContentType>();
IEnumerable<IContentTypeComposition> contentTypes;
switch (itemType)
@@ -925,7 +925,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
return contentTypes.Select(x => _publishedContentTypeFactory.CreateContentType(x));
}
private PublishedContentType CreateContentType(PublishedItemType itemType, int id)
private IPublishedContentType CreateContentType(PublishedItemType itemType, int id)
{
IContentTypeComposition contentType;
switch (itemType)
@@ -88,11 +88,11 @@ namespace Umbraco.Web.PublishedCache
return HasContent(PreviewDefault);
}
public abstract PublishedContentType GetContentType(int id);
public abstract IPublishedContentType GetContentType(int id);
public abstract PublishedContentType GetContentType(string alias);
public abstract IPublishedContentType GetContentType(string alias);
public virtual IEnumerable<IPublishedContent> GetByContentType(PublishedContentType contentType)
public virtual IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
{
// this is probably not super-efficient, but works
// some cache implementation may want to override it, though
@@ -15,8 +15,8 @@ namespace Umbraco.Web.PublishedCache
/// <remarks>This cache is not snapshotted, so it refreshes any time things change.</remarks>
public class PublishedContentTypeCache
{
private readonly Dictionary<string, PublishedContentType> _typesByAlias = new Dictionary<string, PublishedContentType>();
private readonly Dictionary<int, PublishedContentType> _typesById = new Dictionary<int, PublishedContentType>();
private readonly Dictionary<string, IPublishedContentType> _typesByAlias = new Dictionary<string, IPublishedContentType>();
private readonly Dictionary<int, IPublishedContentType> _typesById = new Dictionary<int, IPublishedContentType>();
private readonly IContentTypeService _contentTypeService;
private readonly IMediaTypeService _mediaTypeService;
private readonly IMemberTypeService _memberTypeService;
@@ -136,7 +136,7 @@ namespace Umbraco.Web.PublishedCache
/// <param name="itemType">An item type.</param>
/// <param name="alias">An alias.</param>
/// <returns>The published content type corresponding to the item type and alias.</returns>
public PublishedContentType Get(PublishedItemType itemType, string alias)
public IPublishedContentType Get(PublishedItemType itemType, string alias)
{
var aliasKey = GetAliasKey(itemType, alias);
@@ -174,7 +174,7 @@ namespace Umbraco.Web.PublishedCache
/// <param name="itemType">An item type.</param>
/// <param name="id">An identifier.</param>
/// <returns>The published content type corresponding to the item type and identifier.</returns>
public PublishedContentType Get(PublishedItemType itemType, int id)
public IPublishedContentType Get(PublishedItemType itemType, int id)
{
try
{
@@ -204,7 +204,7 @@ namespace Umbraco.Web.PublishedCache
}
}
private PublishedContentType CreatePublishedContentType(PublishedItemType itemType, string alias)
private IPublishedContentType CreatePublishedContentType(PublishedItemType itemType, string alias)
{
if (GetPublishedContentTypeByAlias != null)
return GetPublishedContentTypeByAlias(alias);
@@ -231,7 +231,7 @@ namespace Umbraco.Web.PublishedCache
return _publishedContentTypeFactory.CreateContentType(contentType);
}
private PublishedContentType CreatePublishedContentType(PublishedItemType itemType, int id)
private IPublishedContentType CreatePublishedContentType(PublishedItemType itemType, int id)
{
if (GetPublishedContentTypeById != null)
return GetPublishedContentTypeById(id);
@@ -259,8 +259,8 @@ namespace Umbraco.Web.PublishedCache
}
// for unit tests - changing the callback must reset the cache obviously
private Func<string, PublishedContentType> _getPublishedContentTypeByAlias;
internal Func<string, PublishedContentType> GetPublishedContentTypeByAlias
private Func<string, IPublishedContentType> _getPublishedContentTypeByAlias;
internal Func<string, IPublishedContentType> GetPublishedContentTypeByAlias
{
get => _getPublishedContentTypeByAlias;
set
@@ -282,8 +282,8 @@ namespace Umbraco.Web.PublishedCache
}
// for unit tests - changing the callback must reset the cache obviously
private Func<int, PublishedContentType> _getPublishedContentTypeById;
internal Func<int, PublishedContentType> GetPublishedContentTypeById
private Func<int, IPublishedContentType> _getPublishedContentTypeById;
internal Func<int, IPublishedContentType> GetPublishedContentTypeById
{
get => _getPublishedContentTypeById;
set
@@ -326,7 +326,7 @@ namespace Umbraco.Web.PublishedCache
return k + ":" + alias;
}
private static string GetAliasKey(PublishedContentType contentType)
private static string GetAliasKey(IPublishedContentType contentType)
{
return GetAliasKey(contentType.ItemType, contentType.Alias);
}
@@ -18,7 +18,7 @@ namespace Umbraco.Web.PublishedCache
{
// initializes a new instance of the PublishedElement class
// within the context of a published snapshot service (eg a published content property value)
public PublishedElement(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing,
public PublishedElement(IPublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing,
PropertyCacheLevel referenceCacheLevel, IPublishedSnapshotAccessor publishedSnapshotAccessor)
{
if (key == Guid.Empty) throw new ArgumentException("Empty guid.");
@@ -46,7 +46,7 @@ namespace Umbraco.Web.PublishedCache
// + 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
public PublishedElement(PublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing)
public PublishedElement(IPublishedContentType contentType, Guid key, Dictionary<string, object> values, bool previewing)
: this(contentType, key, values, previewing, PropertyCacheLevel.None, null)
{ }
@@ -60,7 +60,7 @@ namespace Umbraco.Web.PublishedCache
#region ContentType
public PublishedContentType ContentType { get; }
public IPublishedContentType ContentType { get; }
#endregion
@@ -17,11 +17,11 @@ namespace Umbraco.Web.PublishedCache
private readonly IMember _member;
private readonly IMembershipUser _membershipUser;
private readonly IPublishedProperty[] _properties;
private readonly PublishedContentType _publishedMemberType;
private readonly IPublishedContentType _publishedMemberType;
public PublishedMember(
IMember member,
PublishedContentType publishedMemberType,
IPublishedContentType publishedMemberType,
IUmbracoContextAccessor umbracoContextAccessor)
:base(umbracoContextAccessor)
{
@@ -126,7 +126,7 @@ namespace Umbraco.Web.PublishedCache
properties.Add(property);
}
public override PublishedContentType ContentType => _publishedMemberType;
public override IPublishedContentType ContentType => _publishedMemberType;
public override int Id => _member.Id;