diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/publishedstatus.controller.js b/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/publishedstatus.controller.js
index 27c3e57ddf..ca4d5e1450 100644
--- a/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/publishedstatus.controller.js
+++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/settings/publishedstatus.controller.js
@@ -7,8 +7,6 @@
$http.get(umbRequestHelper.getApiUrl('publishedStatusBaseUrl', 'GetPublishedStatusUrl')),
'Failed to get published status url')
.then(function (result) {
-
- //result = 'views/dashboard/developer/nucache.html'
vm.includeUrl = result;
});
diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
index 55471dfffe..276eed8344 100644
--- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
+++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
@@ -124,6 +124,10 @@
{52ac0ba8-a60e-4e36-897b-e8b97a54ed1c}
Umbraco.ModelsBuilder.Embedded
+
+ {f6de8da0-07cc-4ef2-8a59-2bc81dbb3830}
+ Umbraco.PublishedCache.NuCache
+
{651e1350-91b6-44b7-bd60-7207006d7003}
Umbraco.Web
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Breadcrumb.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Breadcrumb.cshtml
index 263d4ae66e..335987f542 100755
--- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Breadcrumb.cshtml
+++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Breadcrumb.cshtml
@@ -1,4 +1,5 @@
-@using Umbraco.Web
+@using Umbraco.Core
+@using Umbraco.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListAncestorsFromCurrentPage.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListAncestorsFromCurrentPage.cshtml
index b654935558..e067ef6376 100755
--- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListAncestorsFromCurrentPage.cshtml
+++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListAncestorsFromCurrentPage.cshtml
@@ -1,3 +1,4 @@
+@using Umbraco.Core
@using Umbraco.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml
index 51fdbadb00..7a561cf94d 100755
--- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml
+++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/ListImagesFromMediaFolder.cshtml
@@ -1,3 +1,4 @@
+@using Umbraco.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
@@ -26,7 +27,7 @@
@foreach (var item in selection)
{
-
+
}
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml
index 1c01eeb855..363352c148 100755
--- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml
+++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Navigation.cshtml
@@ -1,3 +1,4 @@
+@using Umbraco.Core
@using Umbraco.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml
index 567ed5d07d..d6b12bbd78 100755
--- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml
+++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/SiteMap.cshtml
@@ -1,3 +1,4 @@
+@using Umbraco.Core
@using Umbraco.Core.Models.PublishedContent
@using Umbraco.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
diff --git a/src/Umbraco.Web/CompositionExtensions.cs b/src/Umbraco.Web/CompositionExtensions.cs
index 27a56afc1e..ae5a4f9773 100644
--- a/src/Umbraco.Web/CompositionExtensions.cs
+++ b/src/Umbraco.Web/CompositionExtensions.cs
@@ -169,37 +169,6 @@ namespace Umbraco.Web
composition.RegisterUnique(_ => finder);
}
- ///
- /// Sets the published snapshot service.
- ///
- /// The type of the published snapshot service.
- /// The composition.
- public static void SetPublishedSnapshotService(this Composition composition)
- where T : IPublishedSnapshotService
- {
- composition.RegisterUnique();
- }
-
- ///
- /// Sets the published snapshot service.
- ///
- /// The composition.
- /// A function creating a published snapshot service.
- public static void SetPublishedSnapshotService(this Composition composition, Func factory)
- {
- composition.RegisterUnique(factory);
- }
-
- ///
- /// Sets the published snapshot service.
- ///
- /// The composition.
- /// A published snapshot service.
- public static void SetPublishedSnapshotService(this Composition composition, IPublishedSnapshotService service)
- {
- composition.RegisterUnique(_ => service);
- }
-
///
/// Sets the site domain helper.
///
diff --git a/src/Umbraco.Web/Controllers/UmbLoginController.cs b/src/Umbraco.Web/Controllers/UmbLoginController.cs
index 2ff80e2668..88bc17abff 100644
--- a/src/Umbraco.Web/Controllers/UmbLoginController.cs
+++ b/src/Umbraco.Web/Controllers/UmbLoginController.cs
@@ -46,7 +46,7 @@ namespace Umbraco.Web.Controllers
// if it's not a local url we'll redirect to the root of the current site
return Redirect(Url.IsLocalUrl(model.RedirectUrl)
? model.RedirectUrl
- : CurrentPage.AncestorOrSelf(1).Url);
+ : CurrentPage.AncestorOrSelf(1).Url());
}
//redirect to current page by default
diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs
index b85bc1187e..8764590118 100644
--- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs
+++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs
@@ -286,7 +286,7 @@ namespace Umbraco.Web.Editors
controller => controller.DeleteById(int.MaxValue))
},
{
- "nuCacheStatusBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl(
+ "publishedSnapshotCacheStatusBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl(
controller => controller.GetStatus())
},
{
diff --git a/src/Umbraco.Web/Editors/NuCacheStatusController.cs b/src/Umbraco.Web/Editors/NuCacheStatusController.cs
deleted file mode 100644
index 86dbdd4e01..0000000000
--- a/src/Umbraco.Web/Editors/NuCacheStatusController.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using System;
-using System.Web.Http;
-using Umbraco.Web.Cache;
-using Umbraco.Web.Composing;
-using Umbraco.Web.PublishedCache;
-using Umbraco.Web.PublishedCache.NuCache;
-using Umbraco.Web.WebApi;
-
-namespace Umbraco.Web.Editors
-{
- public class NuCacheStatusController : UmbracoAuthorizedApiController
- {
- private readonly IPublishedSnapshotService _publishedSnapshotService;
-
- public NuCacheStatusController(IPublishedSnapshotService publishedSnapshotService)
- {
- _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
- }
-
- private PublishedSnapshotService PublishedSnapshotService
- {
- get
- {
- var svc = _publishedSnapshotService as PublishedSnapshotService;
- if (svc == null)
- throw new NotSupportedException("Not running NuCache.");
- return svc;
- }
- }
-
- [HttpPost]
- public string RebuildDbCache()
- {
- var service = PublishedSnapshotService;
- service.RebuildContentDbCache();
- service.RebuildMediaDbCache();
- service.RebuildMemberDbCache();
- return service.GetStatus();
- }
-
- [HttpGet]
- public string GetStatus()
- {
- var service = PublishedSnapshotService;
- return service.GetStatus();
- }
-
- [HttpGet]
- public string Collect()
- {
- var service = PublishedSnapshotService;
- GC.Collect();
- service.Collect();
- return service.GetStatus();
- }
-
- [HttpPost]
- public void ReloadCache()
- {
- Current.DistributedCache.RefreshAllPublishedSnapshot();
- }
- }
-}
diff --git a/src/Umbraco.Web/Editors/PublishedSnapshotCacheStatusController.cs b/src/Umbraco.Web/Editors/PublishedSnapshotCacheStatusController.cs
new file mode 100644
index 0000000000..6a701fdcfa
--- /dev/null
+++ b/src/Umbraco.Web/Editors/PublishedSnapshotCacheStatusController.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Web.Http;
+using Umbraco.Web.Cache;
+using Umbraco.Web.Composing;
+using Umbraco.Web.PublishedCache;
+using Umbraco.Web.WebApi;
+
+namespace Umbraco.Web.Editors
+{
+ public class PublishedSnapshotCacheStatusController : UmbracoAuthorizedApiController
+ {
+ private readonly IPublishedSnapshotService _publishedSnapshotService;
+
+ public PublishedSnapshotCacheStatusController(IPublishedSnapshotService publishedSnapshotService)
+ {
+ _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
+ }
+
+ [HttpPost]
+ public string RebuildDbCache()
+ {
+ _publishedSnapshotService.Rebuild();
+ return _publishedSnapshotService.GetStatus();
+ }
+
+ [HttpGet]
+ public string GetStatus()
+ {
+ return _publishedSnapshotService.GetStatus();
+ }
+
+ [HttpGet]
+ public string Collect()
+ {
+ GC.Collect();
+ _publishedSnapshotService.Collect();
+ return _publishedSnapshotService.GetStatus();
+ }
+
+ [HttpPost]
+ public void ReloadCache()
+ {
+ Current.DistributedCache.RefreshAllPublishedSnapshot();
+ }
+ }
+}
diff --git a/src/Umbraco.Web/Editors/PublishedStatusController.cs b/src/Umbraco.Web/Editors/PublishedStatusController.cs
index a6272108e9..5ed70c4811 100644
--- a/src/Umbraco.Web/Editors/PublishedStatusController.cs
+++ b/src/Umbraco.Web/Editors/PublishedStatusController.cs
@@ -17,11 +17,10 @@ namespace Umbraco.Web.Editors
[HttpGet]
public string GetPublishedStatusUrl()
{
- //if (service is PublishedCache.PublishedNoCache.PublishedSnapshotService)
- // return "views/dashboard/developer/nocache.html";
-
- if (_publishedSnapshotService is PublishedCache.NuCache.PublishedSnapshotService)
- return "views/dashboard/settings/nucache.html";
+ if (!string.IsNullOrWhiteSpace(_publishedSnapshotService.StatusUrl))
+ {
+ return _publishedSnapshotService.StatusUrl;
+ }
throw new NotSupportedException("Not supported: " + _publishedSnapshotService.GetType().FullName);
}
diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs
index 1b5f907205..d331dfc65f 100755
--- a/src/Umbraco.Web/Macros/MacroRenderer.cs
+++ b/src/Umbraco.Web/Macros/MacroRenderer.cs
@@ -26,8 +26,9 @@ namespace Umbraco.Web.Macros
private readonly ILocalizedTextService _textService;
private readonly AppCaches _appCaches;
private readonly IMacroService _macroService;
+ private readonly IUserService _userService;
- public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService)
+ public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService)
{
_plogger = plogger ?? throw new ArgumentNullException(nameof(plogger));
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
@@ -35,6 +36,7 @@ namespace Umbraco.Web.Macros
_textService = textService;
_appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches));
_macroService = macroService ?? throw new ArgumentNullException(nameof(macroService));
+ _userService = userService ?? throw new ArgumentNullException(nameof(userService));
}
#region MacroContent cache
@@ -201,7 +203,7 @@ namespace Umbraco.Web.Macros
if (m == null)
throw new InvalidOperationException("No macro found by alias " + macroAlias);
- var page = new PublishedContentHashtableConverter(content);
+ var page = new PublishedContentHashtableConverter(content, _userService);
var macro = new MacroModel(m);
diff --git a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs
index be284c1bb3..5e921eb7c2 100644
--- a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs
+++ b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs
@@ -25,19 +25,20 @@ namespace Umbraco.Web.Macros
/// Initializes a new instance of the class for a published document request.
///
/// The pointing to the document.
+ /// The .
///
/// The difference between creating the page with PublishedRequest vs an IPublishedContent item is
/// that the PublishedRequest takes into account how a template is assigned during the routing process whereas
/// with an IPublishedContent item, the template id is assigned purely based on the default.
///
- internal PublishedContentHashtableConverter(PublishedRequest frequest)
+ internal PublishedContentHashtableConverter(PublishedRequest frequest, IUserService userService)
{
if (!frequest.HasPublishedContent)
throw new ArgumentException("Document request has no node.", nameof(frequest));
PopulatePageData(frequest.PublishedContent.Id,
frequest.PublishedContent.Name, frequest.PublishedContent.ContentType.Id, frequest.PublishedContent.ContentType.Alias,
- frequest.PublishedContent.WriterName, frequest.PublishedContent.CreatorName, frequest.PublishedContent.CreateDate, frequest.PublishedContent.UpdateDate,
+ frequest.PublishedContent.GetWriterName(userService), frequest.PublishedContent.GetCreatorName(userService), frequest.PublishedContent.CreateDate, frequest.PublishedContent.UpdateDate,
frequest.PublishedContent.Path, frequest.PublishedContent.Parent?.Id ?? -1);
if (frequest.HasTemplate)
@@ -53,13 +54,13 @@ namespace Umbraco.Web.Macros
/// Initializes a new instance of the page for a published document
///
///
- internal PublishedContentHashtableConverter(IPublishedContent doc)
+ internal PublishedContentHashtableConverter(IPublishedContent doc, IUserService userService)
{
if (doc == null) throw new ArgumentNullException(nameof(doc));
PopulatePageData(doc.Id,
doc.Name, doc.ContentType.Id, doc.ContentType.Alias,
- doc.WriterName, doc.CreatorName, doc.CreateDate, doc.UpdateDate,
+ doc.GetWriterName(userService), doc.GetCreatorName(userService), doc.CreateDate, doc.UpdateDate,
doc.Path, doc.Parent?.Id ?? -1);
if (doc.TemplateId.HasValue)
@@ -78,7 +79,7 @@ namespace Umbraco.Web.Macros
///
/// This is for usage only.
internal PublishedContentHashtableConverter(IContent content, IVariationContextAccessor variationContextAccessor, IUserService userService, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IPublishedContentTypeFactory publishedContentTypeFactory, UrlSegmentProviderCollection urlSegmentProviders)
- : this(new PagePublishedContent(content, variationContextAccessor, userService, shortStringHelper, contentTypeBaseServiceProvider, publishedContentTypeFactory, urlSegmentProviders))
+ : this(new PagePublishedContent(content, variationContextAccessor, userService, shortStringHelper, contentTypeBaseServiceProvider, publishedContentTypeFactory, urlSegmentProviders), userService)
{ }
#endregion
diff --git a/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs b/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs
index 80c55e37d4..76e9d9742f 100644
--- a/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs
+++ b/src/Umbraco.Web/PropertyEditors/RichTextEditorPastedImages.cs
@@ -108,7 +108,7 @@ namespace Umbraco.Web.PropertyEditors
if (mediaTyped == null)
throw new PanicException($"Could not find media by id {udi.Guid} or there was no UmbracoContext available.");
- var location = mediaTyped.Url;
+ var location = mediaTyped.Url();
// Find the width & height attributes as we need to set the imageprocessor QueryString
var width = img.GetAttributeValue("width", int.MinValue);
diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs
index 5466c4a86e..11e8bd9f64 100644
--- a/src/Umbraco.Web/PublishedContentExtensions.cs
+++ b/src/Umbraco.Web/PublishedContentExtensions.cs
@@ -29,6 +29,7 @@ namespace Umbraco.Web
private static ISiteDomainHelper SiteDomainHelper => Current.Factory.GetInstance();
private static IVariationContextAccessor VariationContextAccessor => Current.VariationContextAccessor;
private static IExamineManager ExamineManager => Current.Factory.GetInstance();
+ private static IUserService UserService => Current.Services.UserService;
#region IsComposedOf
@@ -366,305 +367,6 @@ namespace Umbraco.Web
#endregion
- #region Axes: ancestors, ancestors-or-self
-
- // as per XPath 1.0 specs �2.2,
- // - the ancestor axis contains the ancestors of the context node; the ancestors of the context node consist
- // of the parent of context node and the parent's parent and so on; thus, the ancestor axis will always
- // include the root node, unless the context node is the root node.
- // - the ancestor-or-self axis contains the context node and the ancestors of the context node; thus,
- // the ancestor axis will always include the root node.
- //
- // as per XPath 2.0 specs �3.2.1.1,
- // - the ancestor axis is defined as the transitive closure of the parent axis; it contains the ancestors
- // of the context node (the parent, the parent of the parent, and so on) - The ancestor axis includes the
- // root node of the tree in which the context node is found, unless the context node is the root node.
- // - the ancestor-or-self axis contains the context node and the ancestors of the context node; thus,
- // the ancestor-or-self axis will always include the root node.
- //
- // the ancestor and ancestor-or-self axis are reverse axes ie they contain the context node or nodes that
- // are before the context node in document order.
- //
- // document order is defined by �2.4.1 as:
- // - the root node is the first node.
- // - every node occurs before all of its children and descendants.
- // - the relative order of siblings is the order in which they occur in the children property of their parent node.
- // - children and descendants occur before following siblings.
-
- ///
- /// Gets the ancestors of the content.
- ///
- /// The content.
- /// The ancestors of the content, in down-top order.
- /// Does not consider the content itself.
- public static IEnumerable Ancestors(this IPublishedContent content)
- {
- return content.AncestorsOrSelf(false, null);
- }
-
- ///
- /// Gets the ancestors of the content, at a level lesser or equal to a specified level.
- ///
- /// The content.
- /// The level.
- /// The ancestors of the content, at a level lesser or equal to the specified level, in down-top order.
- /// Does not consider the content itself. Only content that are "high enough" in the tree are returned.
- public static IEnumerable Ancestors(this IPublishedContent content, int maxLevel)
- {
- return content.AncestorsOrSelf(false, n => n.Level <= maxLevel);
- }
-
- ///
- /// Gets the ancestors of the content, of a specified content type.
- ///
- /// The content.
- /// The content type.
- /// The ancestors of the content, of the specified content type, in down-top order.
- /// Does not consider the content itself. Returns all ancestors, of the specified content type.
- public static IEnumerable Ancestors(this IPublishedContent content, string contentTypeAlias)
- {
- return content.AncestorsOrSelf(false, n => n.ContentType.Alias.InvariantEquals(contentTypeAlias));
- }
-
- ///
- /// Gets the ancestors of the content, of a specified content type.
- ///
- /// The content type.
- /// The content.
- /// The ancestors of the content, of the specified content type, in down-top order.
- /// Does not consider the content itself. Returns all ancestors, of the specified content type.
- public static IEnumerable Ancestors(this IPublishedContent content)
- where T : class, IPublishedContent
- {
- return content.Ancestors().OfType();
- }
-
- ///
- /// Gets the ancestors of the content, at a level lesser or equal to a specified level, and of a specified content type.
- ///
- /// The content type.
- /// The content.
- /// The level.
- /// The ancestors of the content, at a level lesser or equal to the specified level, and of the specified
- /// content type, in down-top order.
- /// Does not consider the content itself. Only content that are "high enough" in the trees, and of the
- /// specified content type, are returned.
- public static IEnumerable Ancestors(this IPublishedContent content, int maxLevel)
- where T : class, IPublishedContent
- {
- return content.Ancestors(maxLevel).OfType();
- }
-
- ///
- /// Gets the content and its ancestors.
- ///
- /// The content.
- /// The content and its ancestors, in down-top order.
- public static IEnumerable AncestorsOrSelf(this IPublishedContent content)
- {
- return content.AncestorsOrSelf(true, null);
- }
-
- ///
- /// Gets the content and its ancestors, at a level lesser or equal to a specified level.
- ///
- /// The content.
- /// The level.
- /// The content and its ancestors, at a level lesser or equal to the specified level,
- /// in down-top order.
- /// Only content that are "high enough" in the tree are returned. So it may or may not begin
- /// with the content itself, depending on its level.
- public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel)
- {
- return content.AncestorsOrSelf(true, n => n.Level <= maxLevel);
- }
-
- ///
- /// Gets the content and its ancestors, of a specified content type.
- ///
- /// The content.
- /// The content type.
- /// The content and its ancestors, of the specified content type, in down-top order.
- /// May or may not begin with the content itself, depending on its content type.
- public static IEnumerable AncestorsOrSelf(this IPublishedContent content, string contentTypeAlias)
- {
- return content.AncestorsOrSelf(true, n => n.ContentType.Alias.InvariantEquals(contentTypeAlias));
- }
-
- ///
- /// Gets the content and its ancestors, of a specified content type.
- ///
- /// The content type.
- /// The content.
- /// The content and its ancestors, of the specified content type, in down-top order.
- /// May or may not begin with the content itself, depending on its content type.
- public static IEnumerable AncestorsOrSelf(this IPublishedContent content)
- where T : class, IPublishedContent
- {
- return content.AncestorsOrSelf().OfType();
- }
-
- ///
- /// Gets the content and its ancestor, at a lever lesser or equal to a specified level, and of a specified content type.
- ///
- /// The content type.
- /// The content.
- /// The level.
- /// The content and its ancestors, at a level lesser or equal to the specified level, and of the specified
- /// content type, in down-top order.
- /// May or may not begin with the content itself, depending on its level and content type.
- public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel)
- where T : class, IPublishedContent
- {
- return content.AncestorsOrSelf(maxLevel).OfType();
- }
-
- ///
- /// Gets the ancestor of the content, ie its parent.
- ///
- /// The content.
- /// The ancestor of the content.
- /// This method is here for consistency purposes but does not make much sense.
- public static IPublishedContent Ancestor(this IPublishedContent content)
- {
- return content.Parent;
- }
-
- ///
- /// Gets the nearest ancestor of the content, at a lever lesser or equal to a specified level.
- ///
- /// The content.
- /// The level.
- /// The nearest (in down-top order) ancestor of the content, at a level lesser or equal to the specified level.
- /// Does not consider the content itself. May return null.
- public static IPublishedContent Ancestor(this IPublishedContent content, int maxLevel)
- {
- return content.EnumerateAncestors(false).FirstOrDefault(x => x.Level <= maxLevel);
- }
-
- ///
- /// Gets the nearest ancestor of the content, of a specified content type.
- ///
- /// The content.
- /// The content type alias.
- /// The nearest (in down-top order) ancestor of the content, of the specified content type.
- /// Does not consider the content itself. May return null.
- public static IPublishedContent Ancestor(this IPublishedContent content, string contentTypeAlias)
- {
- return content.EnumerateAncestors(false).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
- }
-
- ///
- /// Gets the nearest ancestor of the content, of a specified content type.
- ///
- /// The content type.
- /// The content.
- /// The nearest (in down-top order) ancestor of the content, of the specified content type.
- /// Does not consider the content itself. May return null.
- public static T Ancestor(this IPublishedContent content)
- where T : class, IPublishedContent
- {
- return content.Ancestors().FirstOrDefault();
- }
-
- ///
- /// Gets the nearest ancestor of the content, at the specified level and of the specified content type.
- ///
- /// The content type.
- /// The content.
- /// The level.
- /// The ancestor of the content, at the specified level and of the specified content type.
- /// Does not consider the content itself. If the ancestor at the specified level is
- /// not of the specified type, returns null.
- public static T Ancestor(this IPublishedContent content, int maxLevel)
- where T : class, IPublishedContent
- {
- return content.Ancestors(maxLevel).FirstOrDefault();
- }
-
- ///
- /// Gets the content or its nearest ancestor.
- ///
- /// The content.
- /// The content.
- /// This method is here for consistency purposes but does not make much sense.
- public static IPublishedContent AncestorOrSelf(this IPublishedContent content)
- {
- return content;
- }
-
- ///
- /// Gets the content or its nearest ancestor, at a lever lesser or equal to a specified level.
- ///
- /// The content.
- /// The level.
- /// The content or its nearest (in down-top order) ancestor, at a level lesser or equal to the specified level.
- /// May or may not return the content itself depending on its level. May return null.
- public static IPublishedContent AncestorOrSelf(this IPublishedContent content, int maxLevel)
- {
- return content.EnumerateAncestors(true).FirstOrDefault(x => x.Level <= maxLevel);
- }
-
- ///
- /// Gets the content or its nearest ancestor, of a specified content type.
- ///
- /// The content.
- /// The content type.
- /// The content or its nearest (in down-top order) ancestor, of the specified content type.
- /// May or may not return the content itself depending on its content type. May return null.
- public static IPublishedContent AncestorOrSelf(this IPublishedContent content, string contentTypeAlias)
- {
- return content.EnumerateAncestors(true).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
- }
-
- ///
- /// Gets the content or its nearest ancestor, of a specified content type.
- ///
- /// The content type.
- /// The content.
- /// The content or its nearest (in down-top order) ancestor, of the specified content type.
- /// May or may not return the content itself depending on its content type. May return null.
- public static T AncestorOrSelf(this IPublishedContent content)
- where T : class, IPublishedContent
- {
- return content.AncestorsOrSelf().FirstOrDefault();
- }
-
- ///
- /// Gets the content or its nearest ancestor, at a lever lesser or equal to a specified level, and of a specified content type.
- ///
- /// The content type.
- /// The content.
- /// The level.
- ///
- public static T AncestorOrSelf(this IPublishedContent content, int maxLevel)
- where T : class, IPublishedContent
- {
- return content.AncestorsOrSelf(maxLevel).FirstOrDefault();
- }
-
- public static IEnumerable AncestorsOrSelf(this IPublishedContent content, bool orSelf, Func func)
- {
- var ancestorsOrSelf = content.EnumerateAncestors(orSelf);
- return func == null ? ancestorsOrSelf : ancestorsOrSelf.Where(func);
- }
-
- ///
- /// Enumerates ancestors of the content, bottom-up.
- ///
- /// The content.
- /// Indicates whether the content should be included.
- /// Enumerates bottom-up ie walking up the tree (parent, grand-parent, etc).
- internal static IEnumerable EnumerateAncestors(this IPublishedContent content, bool orSelf)
- {
- if (content == null) throw new ArgumentNullException(nameof(content));
- if (orSelf) yield return content;
- while ((content = content.Parent) != null)
- yield return content;
- }
-
- #endregion
-
#region Axes: descendants, descendants-or-self
///
@@ -679,7 +381,7 @@ namespace Umbraco.Web
///
public static IEnumerable DescendantsOrSelfOfType(this IEnumerable parentNodes, string docTypeAlias, string culture = null)
{
- return parentNodes.SelectMany(x => x.DescendantsOrSelfOfType(docTypeAlias, culture));
+ return parentNodes.DescendantsOrSelfOfType(VariationContextAccessor, docTypeAlias, culture);
}
///
@@ -694,176 +396,110 @@ namespace Umbraco.Web
public static IEnumerable DescendantsOrSelf(this IEnumerable parentNodes, string culture = null)
where T : class, IPublishedContent
{
- return parentNodes.SelectMany(x => x.DescendantsOrSelf(culture));
+ return parentNodes.DescendantsOrSelf(VariationContextAccessor, culture);
}
-
-
- // as per XPath 1.0 specs �2.2,
- // - the descendant axis contains the descendants of the context node; a descendant is a child or a child of a child and so on; thus
- // the descendant axis never contains attribute or namespace nodes.
- // - the descendant-or-self axis contains the context node and the descendants of the context node.
- //
- // as per XPath 2.0 specs �3.2.1.1,
- // - the descendant axis is defined as the transitive closure of the child axis; it contains the descendants of the context node (the
- // children, the children of the children, and so on).
- // - the descendant-or-self axis contains the context node and the descendants of the context node.
- //
- // the descendant and descendant-or-self axis are forward axes ie they contain the context node or nodes that are after the context
- // node in document order.
- //
- // document order is defined by �2.4.1 as:
- // - the root node is the first node.
- // - every node occurs before all of its children and descendants.
- // - the relative order of siblings is the order in which they occur in the children property of their parent node.
- // - children and descendants occur before following siblings.
-
+
public static IEnumerable Descendants(this IPublishedContent content, string culture = null)
{
- return content.DescendantsOrSelf(false, null, culture);
+ return content.Descendants(VariationContextAccessor, culture);
}
public static IEnumerable Descendants(this IPublishedContent content, int level, string culture = null)
{
- return content.DescendantsOrSelf(false, p => p.Level >= level, culture);
+ return content.Descendants(VariationContextAccessor, level, culture);
}
public static IEnumerable DescendantsOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return content.DescendantsOrSelf(false, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture);
+ return content.DescendantsOfType(VariationContextAccessor, contentTypeAlias, culture);
}
public static IEnumerable Descendants(this IPublishedContent content, string culture = null)
where T : class, IPublishedContent
{
- return content.Descendants(culture).OfType();
+ return content.Descendants(VariationContextAccessor, culture);
}
public static IEnumerable Descendants(this IPublishedContent content, int level, string culture = null)
where T : class, IPublishedContent
{
- return content.Descendants(level, culture).OfType();
+ return content.Descendants(VariationContextAccessor, level, culture);
}
public static IEnumerable DescendantsOrSelf(this IPublishedContent content, string culture = null)
{
- return content.DescendantsOrSelf(true, null, culture);
+ return content.DescendantsOrSelf(VariationContextAccessor, culture);
}
public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string culture = null)
{
- return content.DescendantsOrSelf(true, p => p.Level >= level, culture);
+ return content.DescendantsOrSelf(VariationContextAccessor, level, culture);
}
public static IEnumerable DescendantsOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return content.DescendantsOrSelf(true, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture);
+ return content.DescendantsOrSelfOfType(VariationContextAccessor, contentTypeAlias, culture);
}
public static IEnumerable DescendantsOrSelf(this IPublishedContent content, string culture = null)
where T : class, IPublishedContent
{
- return content.DescendantsOrSelf(culture).OfType();
+ return content.DescendantsOrSelf(VariationContextAccessor, culture);
}
public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string culture = null)
where T : class, IPublishedContent
{
- return content.DescendantsOrSelf(level, culture).OfType();
+ return content.DescendantsOrSelf(VariationContextAccessor, level, culture);
}
public static IPublishedContent Descendant(this IPublishedContent content, string culture = null)
{
- return content.Children(VariationContextAccessor, culture).FirstOrDefault();
+ return content.Descendant(VariationContextAccessor, culture);
}
public static IPublishedContent Descendant(this IPublishedContent content, int level, string culture = null)
{
- return content.EnumerateDescendants(false, culture).FirstOrDefault(x => x.Level == level);
+ return content.Descendant(VariationContextAccessor, level, culture);
}
public static IPublishedContent DescendantOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return content.EnumerateDescendants(false, culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
+ return content.DescendantOfType(VariationContextAccessor, contentTypeAlias, culture);
}
public static T Descendant(this IPublishedContent content, string culture = null)
where T : class, IPublishedContent
{
- return content.EnumerateDescendants(false, culture).FirstOrDefault(x => x is T) as T;
+ return content.Descendant(VariationContextAccessor, culture);
}
public static T Descendant(this IPublishedContent content, int level, string culture = null)
where T : class, IPublishedContent
{
- return content.Descendant(level, culture) as T;
- }
-
- public static IPublishedContent DescendantOrSelf(this IPublishedContent content, string culture = null)
- {
- return content;
+ return content.Descendant(VariationContextAccessor, level, culture);
}
public static IPublishedContent DescendantOrSelf(this IPublishedContent content, int level, string culture = null)
{
- return content.EnumerateDescendants(true, culture).FirstOrDefault(x => x.Level == level);
+ return content.DescendantOrSelf(VariationContextAccessor, level, culture);
}
public static IPublishedContent DescendantOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return content.EnumerateDescendants(true, culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias));
+ return content.DescendantOrSelfOfType(VariationContextAccessor, contentTypeAlias, culture);
}
public static T DescendantOrSelf(this IPublishedContent content, string culture = null)
where T : class, IPublishedContent
{
- return content.EnumerateDescendants(true, culture).FirstOrDefault(x => x is T) as T;
+ return content.DescendantOrSelf(VariationContextAccessor, culture);
}
public static T DescendantOrSelf(this IPublishedContent content, int level, string culture = null)
where T : class, IPublishedContent
{
- return content.DescendantOrSelf(level, culture) as T;
- }
-
- internal static IEnumerable DescendantsOrSelf(this IPublishedContent content, bool orSelf, Func func, string culture = null)
- {
- return content.EnumerateDescendants(orSelf, culture).Where(x => func == null || func(x));
- }
-
- internal static IEnumerable EnumerateDescendants(this IPublishedContent content, bool orSelf, string culture = null)
- {
- if (content == null) throw new ArgumentNullException(nameof(content));
- if (orSelf) yield return content;
-
- foreach (var desc in content.Children(VariationContextAccessor, culture).SelectMany(x => x.EnumerateDescendants(culture)))
- yield return desc;
- }
-
- internal static IEnumerable EnumerateDescendants(this IPublishedContent content, string culture = null)
- {
- yield return content;
-
- foreach (var desc in content.Children(VariationContextAccessor, culture).SelectMany(x => x.EnumerateDescendants(culture)))
- yield return desc;
- }
-
- #endregion
-
- #region Axes: parent
-
- // Parent is native
-
- ///
- /// Gets the parent of the content, of a given content type.
- ///
- /// The content type.
- /// The content.
- /// The parent of content, of the given content type, else null.
- public static T Parent(this IPublishedContent content)
- where T : class, IPublishedContent
- {
- if (content == null) throw new ArgumentNullException(nameof(content));
- return content.Parent as T;
+ return content.DescendantOrSelf(VariationContextAccessor, level, culture);
}
#endregion
@@ -894,7 +530,7 @@ namespace Umbraco.Web
/// The children of the content, of any of the specified types.
public static IEnumerable ChildrenOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return content.Children(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias), culture);
+ return content.Children(VariationContextAccessor, x => x.ContentType.Alias.InvariantEquals(contentTypeAlias), culture);
}
///
@@ -923,29 +559,29 @@ namespace Umbraco.Web
///
public static IPublishedContent FirstChildOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return content.ChildrenOfType(contentTypeAlias, culture).FirstOrDefault();
+ return content.ChildrenOfType(VariationContextAccessor, contentTypeAlias, culture).FirstOrDefault();
}
public static IPublishedContent FirstChild(this IPublishedContent content, Func predicate, string culture = null)
{
- return content.Children(predicate, culture).FirstOrDefault();
+ return content.Children(VariationContextAccessor, predicate, culture).FirstOrDefault();
}
public static IPublishedContent FirstChild(this IPublishedContent content, Guid uniqueId, string culture = null)
{
- return content.Children(x=>x.Key == uniqueId, culture).FirstOrDefault();
+ return content.Children(VariationContextAccessor, x => x.Key == uniqueId, culture).FirstOrDefault();
}
public static T FirstChild(this IPublishedContent content, string culture = null)
where T : class, IPublishedContent
{
- return content.Children(culture).FirstOrDefault();
+ return content.Children(VariationContextAccessor, culture).FirstOrDefault();
}
public static T FirstChild(this IPublishedContent content, Func predicate, string culture = null)
where T : class, IPublishedContent
{
- return content.Children(culture).FirstOrDefault(predicate);
+ return content.Children(VariationContextAccessor, culture).FirstOrDefault(predicate);
}
///
@@ -1001,15 +637,15 @@ namespace Umbraco.Web
var standardVals = new Dictionary
{
- { "Id", n.Id },
- { "NodeName", n.Name(VariationContextAccessor) },
- { "NodeTypeAlias", n.ContentType.Alias },
- { "CreateDate", n.CreateDate },
- { "UpdateDate", n.UpdateDate },
- { "CreatorName", n.CreatorName },
- { "WriterName", n.WriterName },
- { "Url", n.Url() }
- };
+ { "Id", n.Id },
+ { "NodeName", n.Name(VariationContextAccessor) },
+ { "NodeTypeAlias", n.ContentType.Alias },
+ { "CreateDate", n.CreateDate },
+ { "UpdateDate", n.UpdateDate },
+ { "CreatorId", n.CreatorId},
+ { "WriterId", n.WriterId },
+ { "Url", n.Url() }
+ };
var userVals = new Dictionary();
foreach (var p in from IPublishedProperty p in n.Properties where p.GetSourceValue() != null select p)
@@ -1041,7 +677,7 @@ namespace Umbraco.Web
///
public static IEnumerable Siblings(this IPublishedContent content, string culture = null)
{
- return SiblingsAndSelf(content, culture).Where(x => x.Id != content.Id);
+ return content.Siblings(PublishedSnapshot, VariationContextAccessor, culture);
}
///
@@ -1056,7 +692,7 @@ namespace Umbraco.Web
///
public static IEnumerable SiblingsOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return SiblingsAndSelfOfType(content, contentTypeAlias, culture).Where(x => x.Id != content.Id);
+ return content.SiblingsOfType(PublishedSnapshot, VariationContextAccessor, contentTypeAlias, culture);
}
///
@@ -1072,7 +708,7 @@ namespace Umbraco.Web
public static IEnumerable Siblings(this IPublishedContent content, string culture = null)
where T : class, IPublishedContent
{
- return SiblingsAndSelf(content, culture).Where(x => x.Id != content.Id);
+ return content.Siblings(PublishedSnapshot, VariationContextAccessor, culture);
}
///
@@ -1083,9 +719,7 @@ namespace Umbraco.Web
/// The siblings of the content including the node itself.
public static IEnumerable SiblingsAndSelf(this IPublishedContent content, string culture = null)
{
- return content.Parent != null
- ? content.Parent.Children(VariationContextAccessor, culture)
- : PublishedSnapshot.Content.GetAtRoot().WhereIsInvariantOrHasCulture(VariationContextAccessor, culture);
+ return content.SiblingsAndSelf(PublishedSnapshot, VariationContextAccessor, culture);
}
///
@@ -1097,9 +731,7 @@ namespace Umbraco.Web
/// The siblings of the content including the node itself, of the given content type.
public static IEnumerable SiblingsAndSelfOfType(this IPublishedContent content, string contentTypeAlias, string culture = null)
{
- return content.Parent != null
- ? content.Parent.ChildrenOfType(contentTypeAlias, culture)
- : PublishedSnapshot.Content.GetAtRoot().OfTypes(contentTypeAlias).WhereIsInvariantOrHasCulture(VariationContextAccessor, culture);
+ return content.SiblingsAndSelfOfType(PublishedSnapshot, VariationContextAccessor, contentTypeAlias, culture);
}
///
@@ -1112,23 +744,7 @@ namespace Umbraco.Web
public static IEnumerable