2013-03-19 17:51:55 -01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
2013-04-03 11:19:10 -02:00
|
|
|
|
using System.Xml.XPath;
|
2013-03-19 17:51:55 -01:00
|
|
|
|
using Umbraco.Core.Models;
|
2013-03-21 08:54:25 -01:00
|
|
|
|
using Umbraco.Core.Xml;
|
2013-03-19 17:51:55 -01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Provides access to cached contents in a specified context.
|
|
|
|
|
|
/// </summary>
|
2013-01-24 08:51:27 -01:00
|
|
|
|
public abstract class ContextualPublishedCache
|
2013-03-19 17:51:55 -01:00
|
|
|
|
{
|
|
|
|
|
|
protected readonly UmbracoContext UmbracoContext;
|
|
|
|
|
|
|
2013-03-31 18:44:29 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="ContextualPublishedCache"/> with a context.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="umbracoContext">The context.</param>
|
|
|
|
|
|
protected ContextualPublishedCache(UmbracoContext umbracoContext)
|
2013-03-19 17:51:55 -01:00
|
|
|
|
{
|
|
|
|
|
|
UmbracoContext = umbracoContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a content identified by its unique identifier.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="contentId">The content unique identifier.</param>
|
|
|
|
|
|
/// <returns>The content, or null.</returns>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <remarks>Considers published or unpublished content depending on context.</remarks>
|
|
|
|
|
|
public IPublishedContent GetById(int contentId)
|
2013-03-20 16:01:49 -01:00
|
|
|
|
{
|
2013-03-31 18:47:25 -02:00
|
|
|
|
return GetById(UmbracoContext.InPreviewMode, contentId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a content identified by its unique identifier.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
|
|
|
|
|
/// <param name="contentId">The content unique identifier.</param>
|
|
|
|
|
|
/// <returns>The content, or null.</returns>
|
|
|
|
|
|
public abstract IPublishedContent GetById(bool preview, int contentId);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets content at root.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>The contents.</returns>
|
|
|
|
|
|
/// <remarks>Considers published or unpublished content depending on context.</remarks>
|
|
|
|
|
|
public IEnumerable<IPublishedContent> GetAtRoot()
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetAtRoot(UmbracoContext.InPreviewMode);
|
2013-03-20 16:01:49 -01:00
|
|
|
|
}
|
2013-03-19 17:51:55 -01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets contents at root.
|
|
|
|
|
|
/// </summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
2013-03-19 17:51:55 -01:00
|
|
|
|
/// <returns>The contents.</returns>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
public abstract IEnumerable<IPublishedContent> GetAtRoot(bool preview);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a content resulting from an XPath query.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The content, or null.</returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
|
|
|
|
|
/// <para>Considers published or unpublished content depending on context.</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars)
|
2013-03-20 16:01:49 -01:00
|
|
|
|
{
|
2013-03-31 18:47:25 -02:00
|
|
|
|
return GetSingleByXPath(UmbracoContext.InPreviewMode, xpath, vars);
|
2013-03-20 16:01:49 -01:00
|
|
|
|
}
|
2013-03-19 17:51:55 -01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a content resulting from an XPath query.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The content, or null.</returns>
|
2013-03-21 08:54:25 -01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
2013-04-10 12:49:45 -02:00
|
|
|
|
/// <para>Considers published or unpublished content depending on context.</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public IPublishedContent GetSingleByXPath(XPathExpression xpath, params XPathVariable[] vars)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetSingleByXPath(UmbracoContext.InPreviewMode, xpath, vars);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-19 17:51:55 -01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a content resulting from an XPath query.
|
|
|
|
|
|
/// </summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
2013-03-19 17:51:55 -01:00
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The content, or null.</returns>
|
2013-03-21 08:54:25 -01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
|
|
|
|
|
/// </remarks>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
public abstract IPublishedContent GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars);
|
|
|
|
|
|
|
2013-04-10 12:49:45 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a content resulting from an XPath query.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
|
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The content, or null.</returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
2013-03-21 08:54:25 -01:00
|
|
|
|
/// </remarks>
|
2013-04-10 12:49:45 -02:00
|
|
|
|
public abstract IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars);
|
|
|
|
|
|
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets content resulting from an XPath query.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The contents.</returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
|
|
|
|
|
/// <para>Considers published or unpublished content depending on context.</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public IEnumerable<IPublishedContent> GetByXPath(string xpath, params XPathVariable[] vars)
|
2013-03-20 16:01:49 -01:00
|
|
|
|
{
|
2013-03-31 18:47:25 -02:00
|
|
|
|
return GetByXPath(UmbracoContext.InPreviewMode, xpath, vars);
|
2013-03-20 16:01:49 -01:00
|
|
|
|
}
|
2013-03-19 17:51:55 -01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-04-10 12:49:45 -02:00
|
|
|
|
/// Gets content resulting from an XPath query.
|
2013-03-19 17:51:55 -01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The contents.</returns>
|
2013-03-21 08:54:25 -01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
2013-04-10 12:49:45 -02:00
|
|
|
|
/// <para>Considers published or unpublished content depending on context.</para>
|
2013-03-21 08:54:25 -01:00
|
|
|
|
/// </remarks>
|
2013-04-10 12:49:45 -02:00
|
|
|
|
public IEnumerable<IPublishedContent> GetByXPath(XPathExpression xpath, params XPathVariable[] vars)
|
2013-03-20 16:01:49 -01:00
|
|
|
|
{
|
2013-04-10 12:49:45 -02:00
|
|
|
|
return GetByXPath(UmbracoContext.InPreviewMode, xpath, vars);
|
2013-03-20 16:01:49 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-03 11:19:10 -02:00
|
|
|
|
/// <summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// Gets content resulting from an XPath query.
|
2013-03-19 17:51:55 -01:00
|
|
|
|
/// </summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
2013-03-19 17:51:55 -01:00
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The contents.</returns>
|
2013-03-21 08:54:25 -01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
|
|
|
|
|
/// </remarks>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
public abstract IEnumerable<IPublishedContent> GetByXPath(bool preview, string xpath, params XPathVariable[] vars);
|
2013-03-20 16:01:49 -01:00
|
|
|
|
|
2013-04-10 12:49:45 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets content resulting from an XPath query.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
|
|
|
|
|
/// <param name="xpath">The XPath query.</param>
|
|
|
|
|
|
/// <param name="vars">Optional XPath variables.</param>
|
|
|
|
|
|
/// <returns>The contents.</returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If <param name="vars" /> is <c>null</c>, or is empty, or contains only one single
|
|
|
|
|
|
/// value which itself is <c>null</c>, then variables are ignored.</para>
|
|
|
|
|
|
/// <para>The XPath expression should reference variables as <c>$var</c>.</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public abstract IEnumerable<IPublishedContent> GetByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars);
|
|
|
|
|
|
|
2013-04-03 11:19:10 -02:00
|
|
|
|
/// <summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// Gets an XPath navigator that can be used to navigate content.
|
2013-04-03 11:19:10 -02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>The XPath navigator.</returns>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <remarks>Considers published or unpublished content depending on context.</remarks>
|
|
|
|
|
|
public XPathNavigator GetXPathNavigator()
|
2013-04-03 11:19:10 -02:00
|
|
|
|
{
|
2013-03-31 18:47:25 -02:00
|
|
|
|
return GetXPathNavigator(UmbracoContext.InPreviewMode);
|
2013-04-03 11:19:10 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-20 16:01:49 -01:00
|
|
|
|
/// <summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// Gets an XPath navigator that can be used to navigate content.
|
2013-03-20 16:01:49 -01:00
|
|
|
|
/// </summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
|
|
|
|
|
/// <returns>The XPath navigator.</returns>
|
|
|
|
|
|
public abstract XPathNavigator GetXPathNavigator(bool preview);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a value indicating whether the underlying non-contextual cache contains content.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>A value indicating whether the underlying non-contextual cache contains content.</returns>
|
|
|
|
|
|
/// <remarks>Considers published or unpublished content depending on context.</remarks>
|
|
|
|
|
|
public bool HasContent()
|
2013-03-20 16:01:49 -01:00
|
|
|
|
{
|
2013-03-31 18:47:25 -02:00
|
|
|
|
return HasContent(UmbracoContext.InPreviewMode);
|
2013-03-20 16:01:49 -01:00
|
|
|
|
}
|
2013-04-03 11:19:10 -02:00
|
|
|
|
|
2013-03-20 16:01:49 -01:00
|
|
|
|
/// <summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// Gets a value indicating whether the underlying non-contextual cache contains content.
|
2013-03-20 16:01:49 -01:00
|
|
|
|
/// </summary>
|
2013-03-31 18:47:25 -02:00
|
|
|
|
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
|
|
|
|
|
/// <returns>A value indicating whether the underlying non-contextual cache contains content.</returns>
|
|
|
|
|
|
public abstract bool HasContent(bool preview);
|
2013-03-19 17:51:55 -01:00
|
|
|
|
}
|
|
|
|
|
|
}
|