using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.XPath; using Umbraco.Core.Models; using Umbraco.Core.Xml; namespace Umbraco.Web.PublishedCache { /// /// Provides access to cached contents in a specified context. /// public abstract class ContextualPublishedCache { protected readonly UmbracoContext UmbracoContext; /// /// Initializes a new instance of the with a context. /// /// The context. protected ContextualPublishedCache(UmbracoContext umbracoContext) { UmbracoContext = umbracoContext; } /// /// Informs the contextual cache that content has changed. /// /// The contextual cache may, although that is not mandatory, provide an immutable snapshot of /// the content over the duration of the context. If you make changes to the content and do want to have /// the cache update its snapshot, you have to explicitely ask it to do so by calling ContentHasChanged. public virtual void ContentHasChanged() { } /// /// Gets a content identified by its unique identifier. /// /// The content unique identifier. /// The content, or null. /// Considers published or unpublished content depending on context. public IPublishedContent GetById(int contentId) { return GetById(UmbracoContext.InPreviewMode, contentId); } /// /// Gets a content identified by its unique identifier. /// /// A value indicating whether to consider unpublished content. /// The content unique identifier. /// The content, or null. public abstract IPublishedContent GetById(bool preview, int contentId); /// /// Gets content at root. /// /// The contents. /// Considers published or unpublished content depending on context. public IEnumerable GetAtRoot() { return GetAtRoot(UmbracoContext.InPreviewMode); } /// /// Gets contents at root. /// /// A value indicating whether to consider unpublished content. /// The contents. public abstract IEnumerable GetAtRoot(bool preview); /// /// Gets a content resulting from an XPath query. /// /// The XPath query. /// Optional XPath variables. /// The content, or null. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// Considers published or unpublished content depending on context. /// public IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars) { return GetSingleByXPath(UmbracoContext.InPreviewMode, xpath, vars); } /// /// Gets a content resulting from an XPath query. /// /// The XPath query. /// Optional XPath variables. /// The content, or null. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// Considers published or unpublished content depending on context. /// public IPublishedContent GetSingleByXPath(XPathExpression xpath, params XPathVariable[] vars) { return GetSingleByXPath(UmbracoContext.InPreviewMode, xpath, vars); } /// /// Gets a content resulting from an XPath query. /// /// A value indicating whether to consider unpublished content. /// The XPath query. /// Optional XPath variables. /// The content, or null. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// public abstract IPublishedContent GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars); /// /// Gets a content resulting from an XPath query. /// /// A value indicating whether to consider unpublished content. /// The XPath query. /// Optional XPath variables. /// The content, or null. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// public abstract IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars); /// /// Gets content resulting from an XPath query. /// /// The XPath query. /// Optional XPath variables. /// The contents. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// Considers published or unpublished content depending on context. /// public IEnumerable GetByXPath(string xpath, params XPathVariable[] vars) { return GetByXPath(UmbracoContext.InPreviewMode, xpath, vars); } /// /// Gets content resulting from an XPath query. /// /// The XPath query. /// Optional XPath variables. /// The contents. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// Considers published or unpublished content depending on context. /// public IEnumerable GetByXPath(XPathExpression xpath, params XPathVariable[] vars) { return GetByXPath(UmbracoContext.InPreviewMode, xpath, vars); } /// /// Gets content resulting from an XPath query. /// /// A value indicating whether to consider unpublished content. /// The XPath query. /// Optional XPath variables. /// The contents. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// public abstract IEnumerable GetByXPath(bool preview, string xpath, params XPathVariable[] vars); /// /// Gets content resulting from an XPath query. /// /// A value indicating whether to consider unpublished content. /// The XPath query. /// Optional XPath variables. /// The contents. /// /// If is null, or is empty, or contains only one single /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// public abstract IEnumerable GetByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars); /// /// Gets an XPath navigator that can be used to navigate content. /// /// The XPath navigator. /// Considers published or unpublished content depending on context. public XPathNavigator GetXPathNavigator() { return GetXPathNavigator(UmbracoContext.InPreviewMode); } /// /// Gets an XPath navigator that can be used to navigate content. /// /// A value indicating whether to consider unpublished content. /// The XPath navigator. public abstract XPathNavigator GetXPathNavigator(bool preview); /// /// Gets a value indicating whether GetXPathNavigator returns an XPathNavigator /// and that navigator is a NavigableNavigator. /// public abstract bool XPathNavigatorIsNavigable { get; } /// /// Gets a value indicating whether the underlying non-contextual cache contains content. /// /// A value indicating whether the underlying non-contextual cache contains content. /// Considers published or unpublished content depending on context. public bool HasContent() { return HasContent(UmbracoContext.InPreviewMode); } /// /// Gets a value indicating whether the underlying non-contextual cache contains content. /// /// A value indicating whether to consider unpublished content. /// A value indicating whether the underlying non-contextual cache contains content. public abstract bool HasContent(bool preview); } }