From bf81cbc7b706d3a87c5d02232bcdc53e0c5e8f88 Mon Sep 17 00:00:00 2001 From: Steve Temple Date: Thu, 8 Jul 2021 14:01:55 +0100 Subject: [PATCH] Umbraco v9 RC version --- .../DefaultNodeTypeFactory.cs | 27 ++ .../Filters/TemplateOrRedirectFilter.cs | 25 ++ .../Gibe.Navigation.Umbraco.V9.csproj | 19 ++ .../INavigationElementFactory.cs | 32 +++ .../INavigationFilter.cs | 23 ++ .../INodeTypeFactory.cs | 32 +++ .../IUmbracoNodeService.cs | 30 ++ .../Models/UmbracoNavigationElement.cs | 70 +++++ .../UmbracoNavigationRedirectElement.cs | 79 ++++++ .../NavigationElementFactory.cs | 33 +++ .../NodeTypes/AliasNodeType.cs | 22 ++ .../NodeTypes/HomeNodeType.cs | 26 ++ .../NodeTypes/INodeType.cs | 42 +++ .../NodeTypes/SettingsNodeType.cs | 33 +++ .../NodeTypes/UrlNodeType.cs | 25 ++ .../UmbracoNavigationProvider.cs | 88 ++++++ .../UmbracoNodeService.cs | 25 ++ Gibe.Navigation.sln | 13 +- Gibe.Navigation/DefaultNavigationService.cs | 4 +- Gibe.Navigation/Gibe.Navigation.csproj | 267 +++--------------- Gibe.Navigation/Gibe.Navigation.nuspec | 18 -- Gibe.Navigation/ICache.cs | 39 +++ Gibe.Navigation/Properties/AssemblyInfo.cs | 36 --- Gibe.Navigation/packages.config | 41 --- 24 files changed, 724 insertions(+), 325 deletions(-) create mode 100644 Gibe.Navigation.Umbraco.V9/DefaultNodeTypeFactory.cs create mode 100644 Gibe.Navigation.Umbraco.V9/Filters/TemplateOrRedirectFilter.cs create mode 100644 Gibe.Navigation.Umbraco.V9/Gibe.Navigation.Umbraco.V9.csproj create mode 100644 Gibe.Navigation.Umbraco.V9/INavigationElementFactory.cs create mode 100644 Gibe.Navigation.Umbraco.V9/INavigationFilter.cs create mode 100644 Gibe.Navigation.Umbraco.V9/INodeTypeFactory.cs create mode 100644 Gibe.Navigation.Umbraco.V9/IUmbracoNodeService.cs create mode 100644 Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationElement.cs create mode 100644 Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationRedirectElement.cs create mode 100644 Gibe.Navigation.Umbraco.V9/NavigationElementFactory.cs create mode 100644 Gibe.Navigation.Umbraco.V9/NodeTypes/AliasNodeType.cs create mode 100644 Gibe.Navigation.Umbraco.V9/NodeTypes/HomeNodeType.cs create mode 100644 Gibe.Navigation.Umbraco.V9/NodeTypes/INodeType.cs create mode 100644 Gibe.Navigation.Umbraco.V9/NodeTypes/SettingsNodeType.cs create mode 100644 Gibe.Navigation.Umbraco.V9/NodeTypes/UrlNodeType.cs create mode 100644 Gibe.Navigation.Umbraco.V9/UmbracoNavigationProvider.cs create mode 100644 Gibe.Navigation.Umbraco.V9/UmbracoNodeService.cs delete mode 100644 Gibe.Navigation/Gibe.Navigation.nuspec create mode 100644 Gibe.Navigation/ICache.cs delete mode 100644 Gibe.Navigation/Properties/AssemblyInfo.cs delete mode 100644 Gibe.Navigation/packages.config diff --git a/Gibe.Navigation.Umbraco.V9/DefaultNodeTypeFactory.cs b/Gibe.Navigation.Umbraco.V9/DefaultNodeTypeFactory.cs new file mode 100644 index 0000000..265564c --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/DefaultNodeTypeFactory.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Gibe.Navigation.Umbraco.NodeTypes; + +namespace Gibe.Navigation.Umbraco +{ + public class DefaultNodeTypeFactory : INodeTypeFactory + { + private readonly Dictionary _nodeTypes; + + public DefaultNodeTypeFactory(IEnumerable nodeTypes) + { + _nodeTypes = nodeTypes.ToDictionary(n => n.GetType(), n => n); + } + + public INodeType GetNodeType() where T : INodeType + { + return _nodeTypes[typeof(T)]; + } + + public INodeType GetNodeType(Type t) + { + return _nodeTypes[t]; + } + } +} \ No newline at end of file diff --git a/Gibe.Navigation.Umbraco.V9/Filters/TemplateOrRedirectFilter.cs b/Gibe.Navigation.Umbraco.V9/Filters/TemplateOrRedirectFilter.cs new file mode 100644 index 0000000..c4f302e --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/Filters/TemplateOrRedirectFilter.cs @@ -0,0 +1,25 @@ +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Gibe.Navigation.Umbraco.Filters +{ + public class TemplateOrRedirectFilter : INavigationFilter + { + + public bool IncludeInNavigation(IPublishedContent content) + { + return HasTemplate(content) || IsRedirect(content); + } + + private bool IsRedirect(IPublishedContent content) + { + return content.HasValue("gibeNavigationRedirect"); + } + + private bool HasTemplate(IPublishedContent content) + { + return content.TemplateId != 0; + } + } + +} diff --git a/Gibe.Navigation.Umbraco.V9/Gibe.Navigation.Umbraco.V9.csproj b/Gibe.Navigation.Umbraco.V9/Gibe.Navigation.Umbraco.V9.csproj new file mode 100644 index 0000000..30ab88f --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/Gibe.Navigation.Umbraco.V9.csproj @@ -0,0 +1,19 @@ + + + Gibe.Navigation.Umbraco.V9 + 9.0.0 + false + Gibe Navigation Umbraco + Gibe Digital Ltd + 9.0.0 + + + net5.0 + + + + + + + + diff --git a/Gibe.Navigation.Umbraco.V9/INavigationElementFactory.cs b/Gibe.Navigation.Umbraco.V9/INavigationElementFactory.cs new file mode 100644 index 0000000..661b9c4 --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/INavigationElementFactory.cs @@ -0,0 +1,32 @@ +using Gibe.Navigation.Models; +using Umbraco.Cms.Core.Models.PublishedContent; + +namespace Gibe.Navigation.Umbraco +{ + public interface INavigationElementFactory + { + INavigationElement Make(IPublishedContent content); + + INavigationElement HyrdateExtraProperties(IPublishedContent content, INavigationElement element); + } + + public class FakeNavigationElementFactory : INavigationElementFactory + { + private readonly INavigationElement _navigationElement; + + public FakeNavigationElementFactory(INavigationElement navigationElement) + { + _navigationElement = navigationElement; + } + + public INavigationElement Make(IPublishedContent content) + { + return _navigationElement; + } + + public INavigationElement HyrdateExtraProperties(IPublishedContent content, INavigationElement element) + { + return _navigationElement; + } + } +} diff --git a/Gibe.Navigation.Umbraco.V9/INavigationFilter.cs b/Gibe.Navigation.Umbraco.V9/INavigationFilter.cs new file mode 100644 index 0000000..c361cb2 --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/INavigationFilter.cs @@ -0,0 +1,23 @@ +using Umbraco.Cms.Core.Models.PublishedContent; + +namespace Gibe.Navigation.Umbraco +{ + public interface INavigationFilter + { + bool IncludeInNavigation(IPublishedContent content); + } + + public class FakeNavigationFilter : INavigationFilter + { + private readonly bool _includeInNavigation; + + public FakeNavigationFilter(bool includeInNavigation) + { + _includeInNavigation = includeInNavigation; + } + public bool IncludeInNavigation(IPublishedContent content) + { + return _includeInNavigation; + } + } +} diff --git a/Gibe.Navigation.Umbraco.V9/INodeTypeFactory.cs b/Gibe.Navigation.Umbraco.V9/INodeTypeFactory.cs new file mode 100644 index 0000000..bc39fbd --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/INodeTypeFactory.cs @@ -0,0 +1,32 @@ +using System; +using Gibe.Navigation.Umbraco.NodeTypes; + +namespace Gibe.Navigation.Umbraco +{ + public interface INodeTypeFactory + { + INodeType GetNodeType() where T : INodeType; + + INodeType GetNodeType(Type t); + } + + public class FakeNodeTypeFactory : INodeTypeFactory + { + private readonly INodeType _nodeType; + + public FakeNodeTypeFactory(INodeType nodeType) + { + _nodeType = nodeType; + } + + public INodeType GetNodeType() where T : INodeType + { + return _nodeType; + } + + public INodeType GetNodeType(Type t) + { + return _nodeType; + } + } +} diff --git a/Gibe.Navigation.Umbraco.V9/IUmbracoNodeService.cs b/Gibe.Navigation.Umbraco.V9/IUmbracoNodeService.cs new file mode 100644 index 0000000..df16d3b --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/IUmbracoNodeService.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using Gibe.Navigation.Umbraco.NodeTypes; +using Umbraco.Cms.Core.Models.PublishedContent; + +namespace Gibe.Navigation.Umbraco +{ + public interface IUmbracoNodeService + { + /// + /// Return the correct node for the given key. + /// + /// The type of node to find + /// The node represented by that key + IPublishedContent GetNode(INodeType nodeType); + } + + public class FakeUmbracoNodeService : IUmbracoNodeService + { + private readonly IDictionary _contentByNodeType; + + public FakeUmbracoNodeService(IDictionary contentByNodeType) + { + _contentByNodeType = contentByNodeType; + } + + public IPublishedContent GetNode(INodeType nodeKey) => _contentByNodeType[nodeKey]; + } + + +} diff --git a/Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationElement.cs b/Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationElement.cs new file mode 100644 index 0000000..68a6320 --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationElement.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +using System.Linq; +using Gibe.Navigation.Models; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Gibe.Navigation.Umbraco.Models +{ + public class UmbracoNavigationElement : PublishedContentModel, INavigationElement + { + public UmbracoNavigationElement(IPublishedContent content) : base(content, new NoopPublishedValueFallback()) + { + Items = new List(); + } + + public string Title => base.Name; + public string NavTitle => this.Value("NavTitle"); + public bool IsActive { get; set; } + public IEnumerable Items { get; set; } + public string Target => "_self"; + public bool IsVisible => !this.HasValue("umbracoNaviHide") || + !this.Value("umbracoNaviHide"); + public bool IsConcrete => true; + public bool HasVisibleChildren => Items.Any(x => x.IsVisible); + public string Url => this.Url(); + + public Dictionary ExtraProperties { get; set; } + + public object Clone() + { + return new UmbracoNavigationElement(this) + { + IsActive = IsActive, + Items = Items.Select(i => (INavigationElement)i.Clone()).ToList(), + ExtraProperties = ExtraProperties + }; + } + + public override bool Equals(object obj) + { + return obj is UmbracoNavigationElement && Equals((UmbracoNavigationElement)obj); + } + + protected bool Equals(UmbracoNavigationElement other) + { + return + string.Equals(Title, other.Title) && + string.Equals(NavTitle, other.NavTitle) && + string.Equals(Url, other.Url) && + IsActive == other.IsActive && + Items.SequenceEqual(other.Items) && + IsVisible == other.IsVisible; + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = Title?.GetHashCode() ?? 0; + hashCode = (hashCode * 397) ^ (NavTitle?.GetHashCode() ?? 0); + hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0); + hashCode = (hashCode * 397) ^ IsActive.GetHashCode(); + hashCode = (hashCode * 397) ^ (Items?.GetHashCode() ?? 0); + hashCode = (hashCode * 397) ^ IsVisible.GetHashCode(); + return hashCode; + } + } + } + +} \ No newline at end of file diff --git a/Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationRedirectElement.cs b/Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationRedirectElement.cs new file mode 100644 index 0000000..a33d44b --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/Models/UmbracoNavigationRedirectElement.cs @@ -0,0 +1,79 @@ +using System.Collections.Generic; +using System.Linq; +using Gibe.Navigation.Models; +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Gibe.Navigation.Umbraco.Models +{ + public class UmbracoNavigationRedirectElement : PublishedContentModel, INavigationElement + { + public UmbracoNavigationRedirectElement(IPublishedContent content) : base(content, new NoopPublishedValueFallback()) + { + + } + + public string Title => base.Name; + + public string NavTitle => this.Value("NavTitle"); + + private Link Redirect => this.Value("gibeNavigationRedirect"); + + public new string Url => Redirect?.Url; + + public bool IsActive { get; set; } + public IEnumerable Items { get; set; } + + public string Target => Redirect?.Target; + + public bool IsVisible => !this.HasValue("umbracoNaviHide") || + !this.Value("umbracoNaviHide"); + public bool IsConcrete => false; + public bool HasVisibleChildren => Items.Any(x => x.IsVisible); + + public Dictionary ExtraProperties { get; set; } + + public object Clone() + { + return new UmbracoNavigationRedirectElement(this) + { + IsActive = IsActive, + Items = Items.Select(i => (INavigationElement)i.Clone()).ToList(), + }; + } + + public override bool Equals(object obj) + { + return obj is UmbracoNavigationRedirectElement && Equals((UmbracoNavigationRedirectElement)obj); + } + + protected bool Equals(UmbracoNavigationRedirectElement other) + { + return + string.Equals(Title, other.Title) && + string.Equals(NavTitle, other.NavTitle) && + string.Equals(Redirect, other.Redirect) && + IsActive == other.IsActive && + Items.SequenceEqual(other.Items) && + IsVisible == other.IsVisible; + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = Title?.GetHashCode() ?? 0; + hashCode = (hashCode * 397) ^ (NavTitle?.GetHashCode() ?? 0); + hashCode = (hashCode * 397) ^ (Redirect?.GetHashCode() ?? 0); + hashCode = (hashCode * 397) ^ IsActive.GetHashCode(); + hashCode = (hashCode * 397) ^ (Items?.GetHashCode() ?? 0); + hashCode = (hashCode * 397) ^ IsVisible.GetHashCode(); + return hashCode; + } + } + + + } + +} diff --git a/Gibe.Navigation.Umbraco.V9/NavigationElementFactory.cs b/Gibe.Navigation.Umbraco.V9/NavigationElementFactory.cs new file mode 100644 index 0000000..2fb96b7 --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/NavigationElementFactory.cs @@ -0,0 +1,33 @@ +using Gibe.Navigation.Models; +using Gibe.Navigation.Umbraco.Models; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + + +namespace Gibe.Navigation.Umbraco +{ + public class NavigationElementFactory : INavigationElementFactory + { + public INavigationElement Make(IPublishedContent content) + { + var model = IsRedirect(content) + ? new UmbracoNavigationRedirectElement(content) + : (INavigationElement)new UmbracoNavigationElement(content); + + model = HyrdateExtraProperties(content, model); + + return model; + } + + private bool IsRedirect(IPublishedContent content) + { + return content.HasValue("gibeNavigationRedirect"); + } + + public virtual INavigationElement HyrdateExtraProperties(IPublishedContent content, INavigationElement element) + { + return element; + } + } + +} diff --git a/Gibe.Navigation.Umbraco.V9/NodeTypes/AliasNodeType.cs b/Gibe.Navigation.Umbraco.V9/NodeTypes/AliasNodeType.cs new file mode 100644 index 0000000..a83705e --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/NodeTypes/AliasNodeType.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Extensions; + +namespace Gibe.Navigation.Umbraco.NodeTypes +{ + public abstract class AliasNodeType : INodeType + { + private readonly string _alias; + + protected AliasNodeType(string alias) + { + _alias = alias; + } + + public IPublishedContent FindNode(IEnumerable rootNodes) + { + var settings = new SettingsNodeType().FindNode(rootNodes); + return settings.DescendantOrSelf(_alias); + } + } +} diff --git a/Gibe.Navigation.Umbraco.V9/NodeTypes/HomeNodeType.cs b/Gibe.Navigation.Umbraco.V9/NodeTypes/HomeNodeType.cs new file mode 100644 index 0000000..1a960fa --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/NodeTypes/HomeNodeType.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Extensions; + +namespace Gibe.Navigation.Umbraco.NodeTypes +{ + public class HomeNodeType : INodeType + { + private readonly IPublishedContentCache _publishedContentCache; + private readonly INodeTypeFactory _nodeTypeFactory; + + public HomeNodeType(IPublishedContentCache publishedContentCache, INodeTypeFactory nodeTypeFactory) + { + _publishedContentCache = publishedContentCache; + _nodeTypeFactory = nodeTypeFactory; + } + + public IPublishedContent FindNode(IEnumerable rootNodes) + { + var settings = _nodeTypeFactory.GetNodeType().FindNode(rootNodes); + var homeId = settings.Value("umbracoInternalRedirectId"); + return _publishedContentCache.GetById(homeId); + } + } +} diff --git a/Gibe.Navigation.Umbraco.V9/NodeTypes/INodeType.cs b/Gibe.Navigation.Umbraco.V9/NodeTypes/INodeType.cs new file mode 100644 index 0000000..6f87bb2 --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/NodeTypes/INodeType.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using Umbraco.Cms.Core.Models.PublishedContent; + +namespace Gibe.Navigation.Umbraco.NodeTypes +{ + public interface INodeType + { + IPublishedContent FindNode([NotNull]IEnumerable rootNodes); + } + + public class FakeNodeType : INodeType + { + private readonly IPublishedContent _contentToReturn; + + public FakeNodeType(IPublishedContent contentToReturn) + { + _contentToReturn = contentToReturn; + } + + public IPublishedContent FindNode(IEnumerable rootNodes) + { + return _contentToReturn; + } + } + + public class FakeRootNodeType : INodeType + { + private readonly string _rootDocumentTypeAlias; + + public FakeRootNodeType(string rootDocumentTypeAlias) + { + _rootDocumentTypeAlias = rootDocumentTypeAlias; + } + + public IPublishedContent FindNode(IEnumerable rootNodes) + { + return rootNodes.First(x => x.ContentType.Alias == _rootDocumentTypeAlias); + } + } +} \ No newline at end of file diff --git a/Gibe.Navigation.Umbraco.V9/NodeTypes/SettingsNodeType.cs b/Gibe.Navigation.Umbraco.V9/NodeTypes/SettingsNodeType.cs new file mode 100644 index 0000000..2e309da --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/NodeTypes/SettingsNodeType.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Cms.Core.Models.PublishedContent; + + +namespace Gibe.Navigation.Umbraco.NodeTypes +{ + public class SettingsNodeType : INodeType + { + private readonly string _docTypeAlias; + + public SettingsNodeType() : this("site") + { + + } + + public SettingsNodeType(string docTypeAlias) + { + _docTypeAlias = docTypeAlias; + } + + public IPublishedContent FindNode(IEnumerable rootNodes) + { + var settingsNodes = rootNodes.Where(r => r.ContentType.Alias == _docTypeAlias).ToList(); + if (settingsNodes.Count > 1) + { + throw new InvalidOperationException("More than one matching node"); + } + return settingsNodes.First(); + } + } +} diff --git a/Gibe.Navigation.Umbraco.V9/NodeTypes/UrlNodeType.cs b/Gibe.Navigation.Umbraco.V9/NodeTypes/UrlNodeType.cs new file mode 100644 index 0000000..3551e0b --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/NodeTypes/UrlNodeType.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.PublishedCache; + +namespace Gibe.Navigation.Umbraco.NodeTypes +{ + public class UrlNodeType : INodeType + { + private readonly IPublishedContentCache _publishedContentCache; + private readonly string _url; + + public UrlNodeType(IPublishedContentCache publishedContentCache, string url) + { + _publishedContentCache = publishedContentCache; + _url = url; + } + + public IPublishedContent FindNode(IEnumerable rootNodes) + { + + return _publishedContentCache.GetByRoute(_url); + + } + } +} diff --git a/Gibe.Navigation.Umbraco.V9/UmbracoNavigationProvider.cs b/Gibe.Navigation.Umbraco.V9/UmbracoNavigationProvider.cs new file mode 100644 index 0000000..0067a7f --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/UmbracoNavigationProvider.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Gibe.Navigation.Models; +using Gibe.Navigation.Umbraco.NodeTypes; +using Umbraco.Cms.Core.Models.PublishedContent; + +namespace Gibe.Navigation.Umbraco +{ + public class UmbracoNavigationProvider : INavigationProvider + { + private readonly INavigationElementFactory _navigationElementFactory; + private readonly INodeTypeFactory _nodeTypeFactory; + private readonly Type _rootNodeType; + private readonly IUmbracoNodeService _umbracoNodeService; + private readonly IEnumerable _filters; + + public UmbracoNavigationProvider( + IUmbracoNodeService umbracoNodeService, + INodeTypeFactory nodeTypeFactory, + INavigationElementFactory navigationElementFactory) + : + this(umbracoNodeService, nodeTypeFactory, navigationElementFactory, null, 1) + + { + + } + + public UmbracoNavigationProvider( + IUmbracoNodeService umbracoNodeService, + INodeTypeFactory nodeTypeFactory, + INavigationElementFactory navigationElementFactory, + IEnumerable filters = null, + int priority = 1) + : this( + umbracoNodeService, + nodeTypeFactory, + typeof(SettingsNodeType), + filters??Enumerable.Empty(), + navigationElementFactory, + priority) + { + } + + public UmbracoNavigationProvider( + IUmbracoNodeService umbracoNodeService, + INodeTypeFactory nodeTypeFactory, + Type rootNodeType, + IEnumerable filters, + INavigationElementFactory navigationElementFactory, + int priority = 1) + { + _umbracoNodeService = umbracoNodeService; + _nodeTypeFactory = nodeTypeFactory; + Priority = priority; + _rootNodeType = rootNodeType; + _filters = filters; + _navigationElementFactory = navigationElementFactory; + } + + public int Priority { get; } + + public IEnumerable NavigationElements() + { + var topLevel = _umbracoNodeService.GetNode(_nodeTypeFactory.GetNodeType(_rootNodeType)); + return NavigationElements(topLevel); + } + + public IEnumerable NavigationElements(IPublishedContent content) + { + var children = content.Children.Where(IncludeInNavigation); + var navItems = children.Select(ToNavigationElement); + return navItems.ToList(); + } + + private INavigationElement ToNavigationElement(IPublishedContent content) + { + var model = _navigationElementFactory.Make(content); + model.Items = NavigationElements(content).ToList(); + return model; + } + + private bool IncludeInNavigation(IPublishedContent content) + { + return _filters.All(filter => filter.IncludeInNavigation(content)); + } + } +} \ No newline at end of file diff --git a/Gibe.Navigation.Umbraco.V9/UmbracoNodeService.cs b/Gibe.Navigation.Umbraco.V9/UmbracoNodeService.cs new file mode 100644 index 0000000..3d24379 --- /dev/null +++ b/Gibe.Navigation.Umbraco.V9/UmbracoNodeService.cs @@ -0,0 +1,25 @@ +using System.Diagnostics.CodeAnalysis; +using Gibe.Navigation.Umbraco.NodeTypes; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.Web; + +namespace Gibe.Navigation.Umbraco +{ + public class UmbracoNodeService : IUmbracoNodeService + { + private readonly IUmbracoContextFactory _umbracoContextFactory; + + public UmbracoNodeService(IUmbracoContextFactory umbracoContextFactory) + { + _umbracoContextFactory = umbracoContextFactory; + } + + public IPublishedContent GetNode([NotNull]INodeType nodeType) + { + using (var context = _umbracoContextFactory.EnsureUmbracoContext()) + { + return nodeType.FindNode(context.UmbracoContext.Content.GetAtRoot()); + } + } + } +} diff --git a/Gibe.Navigation.sln b/Gibe.Navigation.sln index fea1d9c..d2f9c50 100644 --- a/Gibe.Navigation.sln +++ b/Gibe.Navigation.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31424.327 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gibe.Navigation", "Gibe.Navigation\Gibe.Navigation.csproj", "{F585D1E9-74D1-49FC-8700-DAE8C244BC25}" EndProject @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gibe.Navigation.GibeCommerce", "Gibe.Navigation.GibeCommerce\Gibe.Navigation.GibeCommerce.csproj", "{DFCA77AF-1331-47D8-969B-946B97C9CAFB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gibe.Navigation.Umbraco.V9", "Gibe.Navigation.Umbraco.V9\Gibe.Navigation.Umbraco.V9.csproj", "{86172156-D8C4-4927-BC99-239BE1CE4D57}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -32,8 +34,15 @@ Global {DFCA77AF-1331-47D8-969B-946B97C9CAFB}.Debug|Any CPU.Build.0 = Debug|Any CPU {DFCA77AF-1331-47D8-969B-946B97C9CAFB}.Release|Any CPU.ActiveCfg = Release|Any CPU {DFCA77AF-1331-47D8-969B-946B97C9CAFB}.Release|Any CPU.Build.0 = Release|Any CPU + {86172156-D8C4-4927-BC99-239BE1CE4D57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86172156-D8C4-4927-BC99-239BE1CE4D57}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86172156-D8C4-4927-BC99-239BE1CE4D57}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86172156-D8C4-4927-BC99-239BE1CE4D57}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {37ACB079-0BCD-4F47-B458-34ECF0F524CB} + EndGlobalSection EndGlobal diff --git a/Gibe.Navigation/DefaultNavigationService.cs b/Gibe.Navigation/DefaultNavigationService.cs index 55647ea..978960b 100644 --- a/Gibe.Navigation/DefaultNavigationService.cs +++ b/Gibe.Navigation/DefaultNavigationService.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using Gibe.Caching.Interfaces; using Gibe.Navigation.Models; +#if NET45 +using Gibe.Caching.Interfaces; +#endif namespace Gibe.Navigation { diff --git a/Gibe.Navigation/Gibe.Navigation.csproj b/Gibe.Navigation/Gibe.Navigation.csproj index b024f89..16e5421 100644 --- a/Gibe.Navigation/Gibe.Navigation.csproj +++ b/Gibe.Navigation/Gibe.Navigation.csproj @@ -1,230 +1,43 @@ - - - + + - Debug - AnyCPU - {F585D1E9-74D1-49FC-8700-DAE8C244BC25} - Library - Properties - Gibe.Navigation - Gibe.Navigation - v4.7.2 - 512 - + netcoreapp3.1;net45 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll - True - - - ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll - True - - - ..\packages\ClientDependency.1.8.4\lib\net45\ClientDependency.Core.dll - True - - - ..\packages\ClientDependency-Mvc5.1.8.0.0\lib\net45\ClientDependency.Core.Mvc.dll - True - - - ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll - True - - - ..\packages\Examine.0.1.68.0\lib\Examine.dll - True - - - ..\packages\Gibe.Caching.1.0.365\lib\Gibe.Caching.dll - - - ..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll - True - - - ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll - True - - - ..\packages\ImageProcessor.2.3.2.0\lib\net45\ImageProcessor.dll - True - - - ..\packages\ImageProcessor.Web.4.5.1.0\lib\net45\ImageProcessor.Web.dll - True - - - ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll - True - - - ..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll - True - - - ..\packages\Microsoft.AspNet.Identity.Owin.2.2.1\lib\net45\Microsoft.AspNet.Identity.Owin.dll - True - - - ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll - True - - - ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll - True - - - ..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll - True - - - ..\packages\Microsoft.Owin.Security.Cookies.3.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll - True - - - ..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll - True - - - ..\packages\Microsoft.AspNet.WebHelpers.3.2.3\lib\net45\Microsoft.Web.Helpers.dll - True - - - ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - True - - - ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll - True - - - ..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll - True - - - ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\Owin.1.0\lib\net40\Owin.dll - True - - - ..\packages\semver.1.1.2\lib\net451\Semver.dll - True - - - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll - True - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll - True - - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - True - - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll - True - - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll - True - - - ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - True - - - ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - True - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - True - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - True - - - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll - True - - - - - - - - - ..\packages\UrlRewritingNet.2.0.7\lib\UrlRewritingNet.UrlRewriter.dll - True - - - ..\packages\Microsoft.AspNet.WebPages.Data.3.2.3\lib\net45\WebMatrix.Data.dll - True - - - ..\packages\Microsoft.AspNet.WebPages.WebData.3.2.3\lib\net45\WebMatrix.WebData.dll - True - - - - - - - - - - - - - - - - - - - - - - - + + Gibe.Navigation + 9.0.0 + false + Gibe Navigation + Gibe Digital Ltd + 9.0.0 + + + + NETCORE;NETSTANDARD;NETSTANDARD2_0 + + + + NET45;NETFULL + + + + + + + + + + + + + ..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Configuration.dll + + + + + + 5.0.0 + + + \ No newline at end of file diff --git a/Gibe.Navigation/Gibe.Navigation.nuspec b/Gibe.Navigation/Gibe.Navigation.nuspec deleted file mode 100644 index a85e0e9..0000000 --- a/Gibe.Navigation/Gibe.Navigation.nuspec +++ /dev/null @@ -1,18 +0,0 @@ - - - - Gibe.Navigation - $version$ - Gibe Digital Ltd - false - - Base classes for navigation - - - - - - - - - \ No newline at end of file diff --git a/Gibe.Navigation/ICache.cs b/Gibe.Navigation/ICache.cs new file mode 100644 index 0000000..eaf8a2e --- /dev/null +++ b/Gibe.Navigation/ICache.cs @@ -0,0 +1,39 @@ +#if NETCORE +using System; +using Microsoft.Extensions.Caching.Memory; + +namespace Gibe.Navigation +{ + public interface ICache + { + T Get(string key); + void Add(string key, object value, TimeSpan timeSpan); + bool Exists(string key); + } + + public class MemoryCacheWrapper : ICache + { + private readonly IMemoryCache _memoryCache; + + public MemoryCacheWrapper(IMemoryCache memoryCache) + { + _memoryCache = memoryCache; + } + + public T Get(string key) + { + return _memoryCache.Get(key); + } + + public void Add(string key, object value, TimeSpan timeSpan) + { + _memoryCache.Set(key, value, timeSpan); + } + + public bool Exists(string key) + { + return _memoryCache.TryGetValue(key, out _); + } + } + } +#endif \ No newline at end of file diff --git a/Gibe.Navigation/Properties/AssemblyInfo.cs b/Gibe.Navigation/Properties/AssemblyInfo.cs deleted file mode 100644 index cb116fc..0000000 --- a/Gibe.Navigation/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Gibe.Navigation")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Gibe.Navigation")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("f585d1e9-74d1-49fc-8700-dae8c244bc25")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Gibe.Navigation/packages.config b/Gibe.Navigation/packages.config deleted file mode 100644 index aa4eff8..0000000 --- a/Gibe.Navigation/packages.config +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file