From 7848ea5ec0e7b80ce748791bf54fcc3953564d1e Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 31 Aug 2015 18:59:51 +0200 Subject: [PATCH] U4-7038 - IPublishedContentWithKey for contents, members --- .../Models/IPublishedContentWithKey.cs | 14 ++++++++++++++ .../PublishedContentExtended.cs | 17 ++++++++++++++--- .../PublishedContentWithKeyExtended.cs | 14 ++++++++++++++ .../PublishedContentWithKeyModel.cs | 13 +++++++++++++ .../PublishedContentWithKeyWrapped.cs | 17 +++++++++++++++++ .../Services/EntityXmlSerializer.cs | 1 + src/Umbraco.Core/Umbraco.Core.csproj | 4 ++++ src/Umbraco.Web.UI/config/log4net.config | 2 +- .../Models/PublishedContentWithKeyBase.cs | 15 +++++++++++++++ .../PublishedCache/MemberPublishedContent.cs | 7 ++++++- .../XmlPublishedCache/XmlPublishedContent.cs | 15 ++++++++++++++- src/Umbraco.Web/PublishedContentExtensions.cs | 12 +++++++++++- src/Umbraco.Web/Umbraco.Web.csproj | 1 + src/umbraco.cms/businesslogic/CMSNode.cs | 1 + src/umbraco.cms/businesslogic/Content.cs | 1 + src/umbraco.cms/businesslogic/web/Document.cs | 1 + 16 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 src/Umbraco.Core/Models/IPublishedContentWithKey.cs create mode 100644 src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyExtended.cs create mode 100644 src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyModel.cs create mode 100644 src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyWrapped.cs create mode 100644 src/Umbraco.Web/Models/PublishedContentWithKeyBase.cs diff --git a/src/Umbraco.Core/Models/IPublishedContentWithKey.cs b/src/Umbraco.Core/Models/IPublishedContentWithKey.cs new file mode 100644 index 0000000000..b0e71221b2 --- /dev/null +++ b/src/Umbraco.Core/Models/IPublishedContentWithKey.cs @@ -0,0 +1,14 @@ +using System; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a cached content with a GUID key. + /// + /// This is temporary, because we cannot add the Key property to IPublishedContent without + /// breaking backward compatibility. With v8, it will be merged into IPublishedContent. + public interface IPublishedContentWithKey : IPublishedContent + { + Guid Key { get; } + } +} diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs index 8c0eeef86f..fef066e0b1 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtended.cs @@ -62,9 +62,20 @@ namespace Umbraco.Core.Models.PublishedContent // model and therefore returned the original content unchanged. var model = content.CreateModel(); - var extended = model == content // == means the factory did not create a model - ? new PublishedContentExtended(content) // so we have to extend - : model; // else we can use what the factory returned + IPublishedContent extended; + if (model == content) // == means the factory did not create a model + { + // so we have to extend + var contentWithKey = content as IPublishedContentWithKey; + extended = contentWithKey == null + ? new PublishedContentExtended(content) + : new PublishedContentWithKeyExtended(contentWithKey); + } + else + { + // else we can use what the factory returned + extended = model; + } // so extended should always implement IPublishedContentExtended, however if // by mistake the factory returned a different object that does not implement diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyExtended.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyExtended.cs new file mode 100644 index 0000000000..492fd79796 --- /dev/null +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyExtended.cs @@ -0,0 +1,14 @@ +using System; + +namespace Umbraco.Core.Models.PublishedContent +{ + public class PublishedContentWithKeyExtended : PublishedContentExtended, IPublishedContentWithKey + { + // protected for models, internal for PublishedContentExtended static Extend method + protected internal PublishedContentWithKeyExtended(IPublishedContentWithKey content) + : base(content) + { } + + public Guid Key { get { return ((IPublishedContentWithKey) Content).Key; } } + } +} diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyModel.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyModel.cs new file mode 100644 index 0000000000..4761a52617 --- /dev/null +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace Umbraco.Core.Models.PublishedContent +{ + public abstract class PublishedContentWithKeyModel : PublishedContentModel, IPublishedContentWithKey + { + protected PublishedContentWithKeyModel(IPublishedContentWithKey content) + : base (content) + { } + + public Guid Key { get { return ((IPublishedContentWithKey) Content).Key; } } + } +} diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyWrapped.cs new file mode 100644 index 0000000000..35d7dd6f1f --- /dev/null +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWithKeyWrapped.cs @@ -0,0 +1,17 @@ +using System; + +namespace Umbraco.Core.Models.PublishedContent +{ + /// + /// Provides an abstract base class for IPublishedContentWithKey implementations that + /// wrap and extend another IPublishedContentWithKey. + /// + public class PublishedContentWithKeyWrapped : PublishedContentWrapped, IPublishedContentWithKey + { + protected PublishedContentWithKeyWrapped(IPublishedContentWithKey content) + : base(content) + { } + + public virtual Guid Key { get { return ((IPublishedContentWithKey) Content).Key; } } + } +} diff --git a/src/Umbraco.Core/Services/EntityXmlSerializer.cs b/src/Umbraco.Core/Services/EntityXmlSerializer.cs index 949b4e61c7..d0c89c32a0 100644 --- a/src/Umbraco.Core/Services/EntityXmlSerializer.cs +++ b/src/Umbraco.Core/Services/EntityXmlSerializer.cs @@ -440,6 +440,7 @@ namespace Umbraco.Core.Services var xml = new XElement(nodeName, new XAttribute("id", contentBase.Id), + new XAttribute("key", contentBase.Key), new XAttribute("parentID", contentBase.Level > 1 ? contentBase.ParentId : -1), new XAttribute("level", contentBase.Level), new XAttribute("creatorID", contentBase.CreatorId), diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f3e6cac1f1..b838db5441 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -364,10 +364,14 @@ + + + + diff --git a/src/Umbraco.Web.UI/config/log4net.config b/src/Umbraco.Web.UI/config/log4net.config index aa96f5a26a..497fd4471f 100644 --- a/src/Umbraco.Web.UI/config/log4net.config +++ b/src/Umbraco.Web.UI/config/log4net.config @@ -2,7 +2,7 @@ - + diff --git a/src/Umbraco.Web/Models/PublishedContentWithKeyBase.cs b/src/Umbraco.Web/Models/PublishedContentWithKeyBase.cs new file mode 100644 index 0000000000..52bd8b2f59 --- /dev/null +++ b/src/Umbraco.Web/Models/PublishedContentWithKeyBase.cs @@ -0,0 +1,15 @@ +using System; +using System.Diagnostics; +using Umbraco.Core.Models; + +namespace Umbraco.Web.Models +{ + /// + /// Provide an abstract base class for IPublishedContent implementations. + /// + [DebuggerDisplay("Content Id: {Id}, Name: {Name}")] + public abstract class PublishedContentWithKeyBase : PublishedContentBase, IPublishedContentWithKey + { + public abstract Guid Key { get; } + } +} diff --git a/src/Umbraco.Web/PublishedCache/MemberPublishedContent.cs b/src/Umbraco.Web/PublishedCache/MemberPublishedContent.cs index 5c0050c2a1..35b3d6ee62 100644 --- a/src/Umbraco.Web/PublishedCache/MemberPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/MemberPublishedContent.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web.PublishedCache /// /// Exposes a member object as IPublishedContent /// - public sealed class MemberPublishedContent : PublishedContentBase + public sealed class MemberPublishedContent : PublishedContentWithKeyBase { private readonly IMember _member; @@ -150,6 +150,11 @@ namespace Umbraco.Web.PublishedCache get { return _member.Id; } } + public override Guid Key + { + get { return _member.Key; } + } + public override int TemplateId { get { throw new NotSupportedException(); } diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs index 5450d4063f..4bc2f2388a 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache /// [Serializable] [XmlType(Namespace = "http://umbraco.org/webservices/")] - internal class XmlPublishedContent : PublishedContentBase + internal class XmlPublishedContent : PublishedContentWithKeyBase { /// /// Initializes a new instance of the XmlPublishedContent class with an Xml node. @@ -64,6 +64,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache private IPublishedContent _parent; private int _id; + private Guid _key; private int _template; private string _name; private string _docTypeAlias; @@ -150,6 +151,16 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache } } + public override Guid Key + { + get + { + if (_initialized == false) + Initialize(); + return _key; + } + } + public override int TemplateId { get @@ -348,6 +359,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache if (_xmlNode.Attributes != null) { _id = int.Parse(_xmlNode.Attributes.GetNamedItem("id").Value); + if (_xmlNode.Attributes.GetNamedItem("key") != null) // because, migration + _key = Guid.Parse(_xmlNode.Attributes.GetNamedItem("key").Value); if (_xmlNode.Attributes.GetNamedItem("template") != null) _template = int.Parse(_xmlNode.Attributes.GetNamedItem("template").Value); if (_xmlNode.Attributes.GetNamedItem("sortOrder") != null) diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 8f7dbc31df..d6cf3b3141 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -19,7 +19,17 @@ namespace Umbraco.Web /// Provides extension methods for IPublishedContent. /// public static class PublishedContentExtensions - { + { + #region Key + + public static Guid GetKey(this IPublishedContent content) + { + var contentWithKey = content as IPublishedContentWithKey; + return contentWithKey == null ? Guid.Empty : contentWithKey.Key; + } + + #endregion + #region Urls /// diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index b8ed24d5bb..1ad99b4315 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -303,6 +303,7 @@ + diff --git a/src/umbraco.cms/businesslogic/CMSNode.cs b/src/umbraco.cms/businesslogic/CMSNode.cs index 90091cc80e..661e620056 100644 --- a/src/umbraco.cms/businesslogic/CMSNode.cs +++ b/src/umbraco.cms/businesslogic/CMSNode.cs @@ -1181,6 +1181,7 @@ order by level,sortOrder"; { // attributes x.Attributes.Append(xmlHelper.addAttribute(xd, "id", this.Id.ToString())); + x.Attributes.Append(xmlHelper.addAttribute(xd, "key", this.UniqueId.ToString())); if (this.Level > 1) x.Attributes.Append(xmlHelper.addAttribute(xd, "parentID", this.Parent.Id.ToString())); else diff --git a/src/umbraco.cms/businesslogic/Content.cs b/src/umbraco.cms/businesslogic/Content.cs index f81ecce499..36eafb91a2 100644 --- a/src/umbraco.cms/businesslogic/Content.cs +++ b/src/umbraco.cms/businesslogic/Content.cs @@ -408,6 +408,7 @@ namespace umbraco.cms.businesslogic // attributes x.Attributes.Append(XmlHelper.AddAttribute(xd, "id", this.Id.ToString())); + x.Attributes.Append(XmlHelper.AddAttribute(xd, "key", this.UniqueId.ToString())); x.Attributes.Append(XmlHelper.AddAttribute(xd, "version", this.Version.ToString())); if (this.Level > 1) x.Attributes.Append(XmlHelper.AddAttribute(xd, "parentID", this.Parent.Id.ToString())); diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 1df6dd7c40..0c5f2c3025 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -1288,6 +1288,7 @@ namespace umbraco.cms.businesslogic.web // attributes x.Attributes.Append(addAttribute(xd, "id", Id.ToString())); + x.Attributes.Append(addAttribute(xd, "key", UniqueId.ToString())); // x.Attributes.Append(addAttribute(xd, "version", Version.ToString())); if (Level > 1) x.Attributes.Append(addAttribute(xd, "parentID", Parent.Id.ToString()));