Refactor PublishedContentModelFactory
This commit is contained in:
@@ -51,7 +51,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
// a model, and then that model has to inherit from PublishedContentExtended,
|
||||
// => implements the internal IPublishedContentExtended.
|
||||
|
||||
var model = PublishedContentModelFactory.CreateModel(content);
|
||||
var model = content.CreateModel2();
|
||||
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
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides strongly typed published content models services.
|
||||
/// </summary>
|
||||
public static class PublishedContentModelFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a strongly typed published content model for an internal published content.
|
||||
/// </summary>
|
||||
/// <param name="content">The internal published content.</param>
|
||||
/// <returns>The strongly typed published content model.</returns>
|
||||
public static IPublishedContent CreateModel(IPublishedContent content)
|
||||
{
|
||||
return PublishedContentModelFactoryResolver.Current.HasValue
|
||||
? PublishedContentModelFactoryResolver.Current.Factory.CreateModel(content)
|
||||
: content;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides strongly typed published content models services.
|
||||
/// </summary>
|
||||
internal static class PublishedContentExtensionsForModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a strongly typed published content model for an internal published content.
|
||||
/// </summary>
|
||||
/// <param name="content">The internal published content.</param>
|
||||
/// <returns>The strongly typed published content model.</returns>
|
||||
public static IPublishedContent CreateModel(this IPublishedContent content)
|
||||
{
|
||||
return PublishedContentModelFactoryResolver.Current.HasValue
|
||||
? PublishedContentModelFactoryResolver.Current.Factory.CreateModel(content)
|
||||
: content;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -441,7 +441,7 @@
|
||||
<Compile Include="Models\Macro.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentExtended.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentModelAttribute.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentModelFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentExtensionsForModels.cs" />
|
||||
<Compile Include="Models\MacroProperty.cs" />
|
||||
<Compile Include="Models\MacroPropertyCollection.cs" />
|
||||
<Compile Include="Models\MacroPropertyTypeBaseTypes.cs" />
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
|
||||
public void Add(SolidPublishedContent content)
|
||||
{
|
||||
_content[content.Id] = PublishedContentModelFactory.CreateModel(content);
|
||||
_content[content.Id] = content.CreateModel2();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var doc = GetNode(1173);
|
||||
|
||||
var items = doc.Children
|
||||
.Select(PublishedContentModelFactory.CreateModel) // linq, returns IEnumerable<IPublishedContent>
|
||||
.Select(x => x.CreateModel2()) // linq, returns IEnumerable<IPublishedContent>
|
||||
|
||||
// only way around this is to make sure every IEnumerable<T> extension
|
||||
// explicitely returns a PublishedContentSet, not an IEnumerable<T>
|
||||
|
||||
@@ -242,13 +242,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
return xmlNode == null
|
||||
? null
|
||||
: PublishedContentModelFactory.CreateModel(new XmlPublishedContent(xmlNode, isPreviewing));
|
||||
: (new XmlPublishedContent(xmlNode, isPreviewing)).CreateModel2();
|
||||
}
|
||||
|
||||
private static IEnumerable<IPublishedContent> ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing)
|
||||
{
|
||||
return xmlNodes.Cast<XmlNode>()
|
||||
.Select(xmlNode => PublishedContentModelFactory.CreateModel(new XmlPublishedContent(xmlNode, isPreviewing)));
|
||||
.Select(xmlNode => (new XmlPublishedContent(xmlNode, isPreviewing)).CreateModel2());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -255,7 +255,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
d => GetChildrenMedia(d.Id),
|
||||
GetProperty,
|
||||
true);
|
||||
return PublishedContentModelFactory.CreateModel(content);
|
||||
return content.CreateModel2();
|
||||
}
|
||||
|
||||
internal IPublishedContent ConvertFromXPathNavigator(XPathNavigator xpath)
|
||||
@@ -314,7 +314,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
d => GetChildrenMedia(d.Id, xpath),
|
||||
GetProperty,
|
||||
false);
|
||||
return PublishedContentModelFactory.CreateModel(content);
|
||||
return content.CreateModel2();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -338,7 +338,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
if (parent == null) return;
|
||||
|
||||
if (parent.Name == "node" || (parent.Attributes != null && parent.Attributes.GetNamedItem("isDoc") != null))
|
||||
_parent = PublishedContentModelFactory.CreateModel(new XmlPublishedContent(parent, _isPreviewing, true));
|
||||
_parent = (new XmlPublishedContent(parent, _isPreviewing, true)).CreateModel2();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
@@ -439,8 +439,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
expr.AddSort("@sortOrder", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
|
||||
var iterator = nav.Select(expr);
|
||||
while (iterator.MoveNext())
|
||||
_children.Add(PublishedContentModelFactory.CreateModel(
|
||||
new XmlPublishedContent(((IHasXmlNode)iterator.Current).GetNode(), _isPreviewing, true)));
|
||||
_children.Add(
|
||||
(new XmlPublishedContent(((IHasXmlNode)iterator.Current).GetNode(), _isPreviewing, true)).CreateModel2());
|
||||
|
||||
// warn: this is not thread-safe
|
||||
_childrenInitialized = true;
|
||||
|
||||
Reference in New Issue
Block a user