Cleanup IPublishedContent

This commit is contained in:
Stephan
2018-04-28 16:34:43 +02:00
parent 27390afe86
commit ce8775b3e7
30 changed files with 855 additions and 540 deletions

View File

@@ -6,36 +6,119 @@ namespace Umbraco.Core.Models.PublishedContent
/// <inheritdoc />
/// <summary>
/// Represents a cached content.
/// Represents a published content item.
/// </summary>
/// <remarks>
/// <para>Can be a published document, media or member.</para>
/// </remarks>
public interface IPublishedContent : IPublishedElement
{
#region Content
// fixme - all these are colliding with models => ?
// or could we force them to be 'new' in models?
int Id { get; }
int TemplateId { get; }
int SortOrder { get; }
string Name { get; }
string UrlName { get; } // fixme rename
string DocumentTypeAlias { get; } // fixme obsolete
int DocumentTypeId { get; } // fixme obsolete
string WriterName { get; }
string CreatorName { get; }
int WriterId { get; }
int CreatorId { get; }
string Path { get; }
DateTime CreateDate { get; }
DateTime UpdateDate { get; }
int Level { get; }
string Url { get; }
IReadOnlyDictionary<string, PublishedCultureName> CultureNames { get; }
// todo - IPublishedContent properties colliding with models
// we need to find a way to remove as much clutter as possible from IPublishedContent,
// since this is preventing someone from creating a property named 'Path' and have it
// in a model, for instance. we could move them all under one unique property eg
// Infos, so we would do .Infos.SortOrder - just an idea - not going to do it in v8
/// <summary>
/// Gets a value indicating whether the content is a content (aka a document) or a media.
/// Gets the unique identifier of the content item.
/// </summary>
int Id { get; }
/// <summary>
/// Gets the name of the content item.
/// </summary>
/// <remarks>
/// <para>The value of this property is contextual. When the content type is multi-lingual,
/// this is the name for the 'current' culture.</para>
/// </remarks>
/// FIXME culture aware - returns the value for the 'current' culture whatever it is + see ?? for others
string Name { get; }
/// <summary>
/// Gets the url segment of the content item.
/// </summary>
/// <remarks>
/// <para>The value of this property is contextual. When the content type is multi-lingual,
/// this is the name for the 'current' culture.</para>
/// </remarks>
/// FIXME rename UrlSegment + culture aware
string UrlName { get; } // fixme rename, segment!
/// <summary>
/// Gets the sort order of the content item.
/// </summary>
int SortOrder { get; }
/// <summary>
/// Gets the tree level of the content item.
/// </summary>
int Level { get; }
/// <summary>
/// Gets the tree path of the content item.
/// </summary>
string Path { get; }
/// <summary>
/// Gets the identifier of the template to use to render the content item.
/// </summary>
int TemplateId { get; }
/// <summary>
/// Gets the identifier of the user who created the content item.
/// </summary>
int CreatorId { get; }
/// <summary>
/// Gets the name of the user who created the content item.
/// </summary>
string CreatorName { get; }
/// <summary>
/// Gets the date the content item was created.
/// </summary>
DateTime CreateDate { get; }
/// <summary>
/// Gets the identifier of the user who last updated the content item.
/// </summary>
int WriterId { get; }
/// <summary>
/// Gets the name of the user who last updated the content item.
/// </summary>
string WriterName { get; }
/// <summary>
/// Gets the date the content item was last updated.
/// </summary>
/// <remarks>
/// <para>For published content items, this is also the date the item was published.</para>
/// <para>This date is global to the content item, see FIXME for per-culture dates</para>
/// </remarks>
DateTime UpdateDate { get; }
/// <summary>
/// Gets the url of the content item.
/// </summary>
/// <remarks>
/// <para>The value of this property is contextual. It depends on the 'current' </para>
/// <para>In addition, when the content type is multi-lingual, this is the url for the
/// 'current' culture.</para>
/// </remarks>
/// FIXME explain what 'current' means here
string Url { get; }
// fixme document
//PublishedCultureInfos Culture(string culture = ".");
//string GetName(string culture = "."); // best naming? GetName? CultureName?
PublishedCultureInfos GetCulture(string culture = ".");
IReadOnlyDictionary<string, PublishedCultureInfos> Cultures { get; }
/// <summary>
/// Gets the type of the content item (document, media...).
/// </summary>
PublishedItemType ItemType { get; }
@@ -51,13 +134,13 @@ namespace Umbraco.Core.Models.PublishedContent
#region Tree
/// <summary>
/// Gets the parent of the content.
/// Gets the parent of the content item.
/// </summary>
/// <remarks>The parent of root content is <c>null</c>.</remarks>
IPublishedContent Parent { get; }
/// <summary>
/// Gets the children of the content.
/// Gets the children of the content item.
/// </summary>
/// <remarks>Children are sorted by their sortOrder.</remarks>
IEnumerable<IPublishedContent> Children { get; }

View File

@@ -20,7 +20,7 @@ namespace Umbraco.Core.Models.PublishedContent
#region PublishedElement
/// <summary>
/// Gets the unique key of the published snapshot item.
/// Gets the unique key of the published element.
/// </summary>
Guid Key { get; }

View File

@@ -39,72 +39,99 @@ namespace Umbraco.Core.Models.PublishedContent
public IPublishedContent Unwrap() => _content;
#region ContentType
/// <inheritdoc />
public virtual PublishedContentType ContentType => _content.ContentType;
#endregion
#region PublishedElement
#region Content
public virtual int Id => _content.Id;
/// <inheritdoc />
public Guid Key => _content.Key;
public virtual int TemplateId => _content.TemplateId;
#endregion
public virtual int SortOrder => _content.SortOrder;
#region PublishedContent
public virtual string Name => _content.Name;
public virtual IReadOnlyDictionary<string, PublishedCultureName> CultureNames => _content.CultureNames;
/// <inheritdoc />
public virtual int Id => _content.Id;
/// <inheritdoc />
public virtual string Name => _content.Name;
/// <inheritdoc />
public virtual string UrlName => _content.UrlName;
public virtual string DocumentTypeAlias => _content.DocumentTypeAlias;
public virtual int DocumentTypeId => _content.DocumentTypeId;
public virtual string WriterName => _content.WriterName;
public virtual string CreatorName => _content.CreatorName;
public virtual int WriterId => _content.WriterId;
public virtual int CreatorId => _content.CreatorId;
public virtual string Path => _content.Path;
public virtual DateTime CreateDate => _content.CreateDate;
public virtual DateTime UpdateDate => _content.UpdateDate;
/// <inheritdoc />
public virtual int SortOrder => _content.SortOrder;
/// <inheritdoc />
public virtual int Level => _content.Level;
/// <inheritdoc />
public virtual string Path => _content.Path;
/// <inheritdoc />
public virtual int TemplateId => _content.TemplateId;
/// <inheritdoc />
public virtual int CreatorId => _content.CreatorId;
/// <inheritdoc />
public virtual string CreatorName => _content.CreatorName;
/// <inheritdoc />
public virtual DateTime CreateDate => _content.CreateDate;
/// <inheritdoc />
public virtual int WriterId => _content.WriterId;
/// <inheritdoc />
public virtual string WriterName => _content.WriterName;
/// <inheritdoc />
public virtual DateTime UpdateDate => _content.UpdateDate;
/// <inheritdoc />
public virtual string Url => _content.Url;
/// <inheritdoc />
public PublishedCultureInfos GetCulture(string culture = ".") => _content.GetCulture(culture);
/// <inheritdoc />
public IReadOnlyDictionary<string, PublishedCultureInfos> Cultures => _content.Cultures;
/// <inheritdoc />
public virtual PublishedItemType ItemType => _content.ItemType;
/// <inheritdoc />
public virtual bool IsDraft => _content.IsDraft;
#endregion
#region Tree
/// <inheritdoc />
public virtual IPublishedContent Parent => _content.Parent;
/// <inheritdoc />
public virtual IEnumerable<IPublishedContent> Children => _content.Children;
#endregion
#region Properties
/// <inheritdoc cref="IPublishedElement.Properties"/>
public virtual IEnumerable<IPublishedProperty> Properties => _content.Properties;
/// <inheritdoc cref="IPublishedElement.GetProperty(string)"/>
public virtual IPublishedProperty GetProperty(string alias)
{
return _content.GetProperty(alias);
}
/// <inheritdoc cref="IPublishedContent.GetProperty(string, bool)"/>
public virtual IPublishedProperty GetProperty(string alias, bool recurse)
{
return _content.GetProperty(alias, recurse);

View File

@@ -1,4 +1,5 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models.PublishedContent
{
@@ -16,4 +17,54 @@ namespace Umbraco.Core.Models.PublishedContent
public string Name { get; }
public string UrlName { get; }
}
/// <summary>
/// Contains culture specific values for <see cref="IPublishedContent"/>.
/// </summary>
public class PublishedCultureInfos
{
/// <summary>
/// Initializes a new instance of the <see cref="PublishedCultureInfos"/> class.
/// </summary>
public PublishedCultureInfos(string culture, string name, bool published, DateTime publishedDate)
{
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentNullOrEmptyException(nameof(culture));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
Culture = culture;
Name = name;
UrlSegment = name.ToUrlSegment(culture);
Published = published;
PublishedDate = publishedDate;
}
/// <summary>
/// Gets the culture.
/// </summary>
public string Culture { get; }
/// <summary>
/// Gets the name of the item.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the url segment of the item.
/// </summary>
public string UrlSegment { get; }
/// <summary>
/// Gets a value indicating whether the culture is published.
/// </summary>
/// <remarks>
/// A published content item will only have published cultures, and therefore this
/// value will always be true. On the other hand, fixme drafts?
/// </remarks>
public bool Published { get; }
/// <summary>
/// Gets the date when fixme?
/// </summary>
public DateTime PublishedDate { get; } // fixme - model? model.UpdateDate - here?
}
}