Updated the published content stores so that content doesn't inherit from media, instead there is a base
interface IPublishedDataStore. Simplified the interface structure and removed the GetDocumentProperty method as it is not needed and i think existed before we updated the codebase to not rely on xml.
This commit is contained in:
43
src/Umbraco.Core/DocumentExtensions.cs
Normal file
43
src/Umbraco.Core/DocumentExtensions.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
internal static class DocumentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the property as the specified type, if the property is not found or does not convert
|
||||
/// then the default value of type T is returned.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="prop"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <returns></returns>
|
||||
public static T GetPropertyValue<T>(this IDocument prop, string alias)
|
||||
{
|
||||
return prop.GetPropertyValue<T>(alias, default(T));
|
||||
}
|
||||
|
||||
public static T GetPropertyValue<T>(this IDocument prop, string alias, T ifCannotConvert)
|
||||
{
|
||||
var p = prop.GetProperty(alias);
|
||||
if (p == null)
|
||||
return default(T);
|
||||
var converted = p.TryConvertTo<T>();
|
||||
if (converted.Success)
|
||||
return converted.Result;
|
||||
return ifCannotConvert;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the property based on the case insensitive match of the alias
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <returns></returns>
|
||||
public static IDocumentProperty GetProperty(this IDocument d, string alias)
|
||||
{
|
||||
return d.Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
internal static class DocumentPropertyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the property as the specified type, if the property is not found or does not convert
|
||||
/// then the default value of type T is returned.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="prop"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <returns></returns>
|
||||
public static T GetProperty<T>(this IDocument prop, string alias)
|
||||
{
|
||||
var p = prop.GetProperty(alias);
|
||||
if (p == null)
|
||||
return default(T);
|
||||
var converted = p.TryConvertTo<T>();
|
||||
if (converted.Success)
|
||||
return converted.Result;
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for IDocument
|
||||
/// </summary>
|
||||
public static class DocumentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the property based on the case insensitive match of the alias
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <returns></returns>
|
||||
public static IDocumentProperty GetProperty(this IDocument d, string alias)
|
||||
{
|
||||
return d.Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@
|
||||
<Compile Include="DictionaryExtensions.cs" />
|
||||
<Compile Include="Dictionary\CultureDictionaryFactoryResolver.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionaryFactory.cs" />
|
||||
<Compile Include="DocumentPropertyExtensions.cs" />
|
||||
<Compile Include="DocumentExtensions.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionary.cs" />
|
||||
<Compile Include="Dynamics\ClassFactory.cs" />
|
||||
<Compile Include="Dynamics\DynamicBackingItem.cs" />
|
||||
@@ -90,7 +90,6 @@
|
||||
<Compile Include="IO\IFileSystemExtensions.cs" />
|
||||
<Compile Include="IO\IMediaFileSystem.cs" />
|
||||
<Compile Include="Macros\MacroTagParser.cs" />
|
||||
<Compile Include="Models\DocumentExtensions.cs" />
|
||||
<Compile Include="PropertyEditors\DatePickerPropertyEditorValueConverter.cs" />
|
||||
<Compile Include="PropertyEditors\IPropertyEditorValueConverter.cs" />
|
||||
<Compile Include="HtmlTagWrapper.cs" />
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<section name="umbraco.presentation.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
|
||||
|
||||
<section name="clientDependency" type="ClientDependency.Core.Config.ClientDependencySection, ClientDependency.Core" requirePermission="false"/>
|
||||
<section name="Examine" type="Examine.Config.ExamineSettings, Examine" requirePermission="false"/>
|
||||
<section name="ExamineLuceneIndexSets" type="UmbracoExamine.Config.ExamineLuceneIndexes, UmbracoExamine" requirePermission="false"/>
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// An IPublishedContentStore which uses the Xml cache system to return data
|
||||
/// </summary>
|
||||
internal class DefaultPublishedContentStore : DefaultPublishedMediaStore, IPublishedContentStore
|
||||
internal class DefaultPublishedContentStore : IPublishedContentStore
|
||||
{
|
||||
|
||||
private IDocument ConvertToDocument(XmlNode xmlNode)
|
||||
@@ -24,7 +24,7 @@ namespace Umbraco.Web
|
||||
return new Models.XmlDocument(xmlNode);
|
||||
}
|
||||
|
||||
public override IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId)
|
||||
public virtual IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId)
|
||||
{
|
||||
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
|
||||
|
||||
|
||||
@@ -21,32 +21,6 @@ namespace Umbraco.Web
|
||||
return GetUmbracoMedia(nodeId);
|
||||
}
|
||||
|
||||
public virtual string GetDocumentProperty(UmbracoContext umbracoContext, IDocument node, string propertyAlias)
|
||||
{
|
||||
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
|
||||
if (node == null) throw new ArgumentNullException("node");
|
||||
if (propertyAlias == null) throw new ArgumentNullException("propertyAlias");
|
||||
|
||||
if (propertyAlias.StartsWith("@"))
|
||||
{
|
||||
//if it starts with an @ then its a property of the object, not a user defined property
|
||||
var propName = propertyAlias.TrimStart('@');
|
||||
var prop = TypeHelper.GetProperty(typeof(IDocument), propName, true, false, false, false);
|
||||
if (prop == null)
|
||||
throw new ArgumentException("The property name " + propertyAlias + " was not found on type " + typeof(IDocument));
|
||||
var val = prop.GetValue(node, null);
|
||||
var valAsString = val == null ? "" : val.ToString();
|
||||
return valAsString;
|
||||
}
|
||||
else
|
||||
{
|
||||
var prop = node.GetProperty(propertyAlias);
|
||||
return prop == null ? null : Convert.ToString(prop.Value);
|
||||
//var propertyNode = node.SelectSingleNode("./" + propertyAlias);
|
||||
//return propertyNode == null ? null : propertyNode.InnerText;
|
||||
}
|
||||
}
|
||||
|
||||
private IDocument GetUmbracoMedia(int id)
|
||||
{
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Defines the methods to access published content
|
||||
/// </summary>
|
||||
internal interface IPublishedContentStore : IPublishedMediaStore
|
||||
internal interface IPublishedContentStore : IPublishedStore
|
||||
{
|
||||
IDocument GetDocumentByRoute(UmbracoContext umbracoContext, string route, bool? hideTopLevelNode = null);
|
||||
IDocument GetDocumentByUrlAlias(UmbracoContext umbracoContext, int rootNodeId, string alias);
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the methods to access published media
|
||||
/// </summary>
|
||||
internal interface IPublishedMediaStore
|
||||
internal interface IPublishedMediaStore : IPublishedStore
|
||||
{
|
||||
IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId);
|
||||
string GetDocumentProperty(UmbracoContext umbracoContext, IDocument node, string propertyAlias);
|
||||
}
|
||||
}
|
||||
12
src/Umbraco.Web/IPublishedStore.cs
Normal file
12
src/Umbraco.Web/IPublishedStore.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the methods for published documents
|
||||
/// </summary>
|
||||
internal interface IPublishedStore
|
||||
{
|
||||
IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId);
|
||||
}
|
||||
}
|
||||
@@ -238,8 +238,8 @@ namespace Umbraco.Web.Routing
|
||||
throw new InvalidOperationException("There is no node.");
|
||||
|
||||
bool redirect = false;
|
||||
string internalRedirect = _routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "umbracoInternalRedirectId");
|
||||
|
||||
var internalRedirect = _documentRequest.Document.GetPropertyValue<string>("umbracoInternalRedirectId");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(internalRedirect))
|
||||
{
|
||||
LogHelper.Debug<DocumentRequest>("{0}Found umbracoInternalRedirectId={1}", () => tracePrefix, () => internalRedirect);
|
||||
@@ -293,7 +293,7 @@ namespace Umbraco.Web.Routing
|
||||
if (_documentRequest.Document == null)
|
||||
throw new InvalidOperationException("There is no node.");
|
||||
|
||||
var path = _routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "@path");
|
||||
var path = _documentRequest.Document.Path;
|
||||
|
||||
if (Access.IsProtected(_documentRequest.DocumentId, path))
|
||||
{
|
||||
@@ -352,12 +352,9 @@ namespace Umbraco.Web.Routing
|
||||
// associated with it.
|
||||
//TODO: When we remove the need for a database for templates, then this id should be irrelavent, not sure how were going to do this nicely.
|
||||
|
||||
var templateIdAsString = _routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "@TemplateId");
|
||||
LogHelper.Debug<DocumentRequest>("{0}Look for template id={1}", () => tracePrefix, () => templateIdAsString);
|
||||
int templateId;
|
||||
if (!int.TryParse(templateIdAsString, out templateId))
|
||||
templateId = 0;
|
||||
|
||||
var templateId = _documentRequest.Document.TemplateId;
|
||||
LogHelper.Debug<DocumentRequest>("{0}Look for template id={1}", () => tracePrefix, () => templateId);
|
||||
|
||||
if (templateId > 0)
|
||||
{
|
||||
//NOTE: This will throw an exception if the template id doesn't exist, but that is ok to inform the front end.
|
||||
@@ -381,9 +378,8 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
if (_documentRequest.HasNode)
|
||||
{
|
||||
int redirectId;
|
||||
if (!int.TryParse(_routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "umbracoRedirect"), out redirectId))
|
||||
redirectId = -1;
|
||||
var redirectId = _documentRequest.Document.GetPropertyValue<int>("umbracoRedirect", -1);
|
||||
|
||||
string redirectUrl = "#";
|
||||
if (redirectId > 0)
|
||||
redirectUrl = _routingContext.NiceUrlProvider.GetNiceUrl(redirectId);
|
||||
|
||||
@@ -79,7 +79,8 @@ namespace Umbraco.Web.Routing
|
||||
domainUri = DomainUriAtNode(id, current);
|
||||
while (domainUri == null && id > 0)
|
||||
{
|
||||
pathParts.Add(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, UrlNameProperty));
|
||||
var urlName = node.GetPropertyValue<string>(UrlNameProperty);
|
||||
pathParts.Add(urlName);
|
||||
node = node.Parent; // set to parent node
|
||||
if (node == null)
|
||||
{
|
||||
@@ -87,7 +88,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
else
|
||||
{
|
||||
id = int.Parse(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, "@id")); // will be -1 or 1234
|
||||
id = node.Id;
|
||||
}
|
||||
domainUri = id > 0 ? DomainUriAtNode(id, current) : null;
|
||||
}
|
||||
@@ -145,9 +146,10 @@ namespace Umbraco.Web.Routing
|
||||
domainUris = DomainUrisAtNode(id, current);
|
||||
while (!domainUris.Any() && id > 0)
|
||||
{
|
||||
pathParts.Add(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, UrlNameProperty));
|
||||
var urlName = node.GetPropertyValue<string>(UrlNameProperty);
|
||||
pathParts.Add(urlName);
|
||||
node = node.Parent; //set to parent node
|
||||
id = int.Parse(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, "@id")); // will be -1 or 1234
|
||||
id = node.Id;
|
||||
domainUris = id > 0 ? DomainUrisAtNode(id, current) : new Uri[] { };
|
||||
}
|
||||
|
||||
|
||||
@@ -250,6 +250,7 @@
|
||||
</Compile>
|
||||
<Compile Include="HtmlHelperRenderExtensions.cs" />
|
||||
<Compile Include="IApplicationEventHandler.cs" />
|
||||
<Compile Include="IPublishedStore.cs" />
|
||||
<Compile Include="IPublishedMediaStore.cs" />
|
||||
<Compile Include="Media\EmbedProviders\AbstractOEmbedProvider.cs" />
|
||||
<Compile Include="Media\EmbedProviders\AbstractProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user