From 4b51e4bc95c6faa8ecc1a96a77cbfbeeacc3e1bd Mon Sep 17 00:00:00 2001 From: Hendy Racher Date: Tue, 27 Nov 2018 13:08:38 +0000 Subject: [PATCH] removed NodeType enum, now using Umbraco.Core.Models.PublishedItemType --- README.md | 26 ++-- .../Our.Umbraco.Look.Tests.csproj | 128 ++++++++++++++++++ src/Our.Umbraco.Look.Tests/packages.config | 22 +++ src/Our.Umbraco.Look/Events/Indexing.cs | 22 +-- .../Models/IndexingContext.cs | 14 +- src/Our.Umbraco.Look/Models/LookMatch.cs | 24 ++-- src/Our.Umbraco.Look/Models/NodeQuery.cs | 13 +- src/Our.Umbraco.Look/Models/NodeType.cs | 14 -- src/Our.Umbraco.Look/Our.Umbraco.Look.csproj | 1 - .../Services/LookService_GetLookMatches.cs | 2 +- .../Services/LookService_Index.cs | 2 +- 11 files changed, 184 insertions(+), 84 deletions(-) delete mode 100644 src/Our.Umbraco.Look/Models/NodeType.cs diff --git a/README.md b/README.md index 795e04c..a5757f5 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,7 @@ public class IndexingContext /// /// The IPublishedContent of the Content, Media or Member being indexed /// - public IPublishedContent Node { get; } - - /// - /// Enum to indicate whether the IPublishedContent is Content, Media or Member - /// - public NodeType NodeType { get; } + public IPublishedContent Item { get; } /// /// The name of the Examine indexer into which this node is being indexed @@ -73,14 +68,14 @@ public class ConfigureIndexing : ApplicationEventHandler protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { // return the Name of the IPublishedContent - LookService.SetNameIndexer(indexingContext => { return indexingContext.Node.Name; }); + LookService.SetNameIndexer(indexingContext => { return indexingContext.Item.Name; }); // return the UpdateDate of the IPublishedContent - LookService.SetDateIndexer(indexingContext => { return indexingContext.Node.UpdateDate; }); + LookService.SetDateIndexer(indexingContext => { return indexingContext.Item.UpdateDate; }); // return text string or null LookService.SetTextIndexer(indexingContext => { - if (indexingContext.NodeType == NodeType.Content) { + if (indexingContext.Item.ItemType == PublishedItemType.Content) { // eg. make web request and scrape markup to index } return null; @@ -89,7 +84,7 @@ public class ConfigureIndexing : ApplicationEventHandler // return an Our.Umbraco.Look.Models.LookTag[] or null (see tags section below) LookService.SetTagIndexer(indexingContext => { // eg a nuPicker - var picker = indexingContext.Node.GetPropertyValue("colours"); + var picker = indexingContext.Item.GetPropertyValue("colours"); return picker.PickedKeys.Select(x => new LookTag("colour", x)).ToArray(); @@ -99,7 +94,7 @@ public class ConfigureIndexing : ApplicationEventHandler // return an Our.Umbraco.Look.Model.Location or null LookService.SetLocationIndexer(indexingContext => { // eg. using Terratype - var terratype = indexingContext.Node.GetPropertyValue("location"); + var terratype = indexingContext.Item.GetPropertyValue("location"); var terratypeLatLng = terratype.Position.ToWgs84(); return new Location(terratypeLatLng.Latitude, terratypeLatLng.Longitude); @@ -134,7 +129,7 @@ var lookQuery = new LookQuery("InternalSearcher") RawQuery = "+path: 1059", NodeQuery = new NodeQuery() { - Types = new NodeType[] { NodeType.Content, NodeType.Media, NodeType.Member }, + Types = new PublishedItemType[] { PublishedItemType.Content, PublishedItemType.Media, PublishedItemType.Member }, Aliases = new string[] { "myDocTypeAlias", "myMediaTypeAlias" }, NotIds = new int[] { 123 } // (eg. exclude current page) }, @@ -218,12 +213,7 @@ public class LookMatch /// /// Lazy evaluation of the associated IPublishedContent /// - public IPublishedContent Node { get; } - - /// - /// Enum flag to indicate if the IPublishedContent node is Content, Media or a Member - /// - public NodeType NodeType { get; } + public IPublishedContent Item { get; } /// /// The custom name field diff --git a/src/Our.Umbraco.Look.Tests/Our.Umbraco.Look.Tests.csproj b/src/Our.Umbraco.Look.Tests/Our.Umbraco.Look.Tests.csproj index e2c679c..ba42868 100644 --- a/src/Our.Umbraco.Look.Tests/Our.Umbraco.Look.Tests.csproj +++ b/src/Our.Umbraco.Look.Tests/Our.Umbraco.Look.Tests.csproj @@ -39,12 +39,57 @@ 4 + + ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll + + + ..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\businesslogic.dll + + + ..\packages\ClientDependency.1.9.7\lib\net45\ClientDependency.Core.dll + + + ..\packages\ClientDependency-Mvc.1.8.0.0\lib\net45\ClientDependency.Core.Mvc.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\cms.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\controls.dll + + + ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll + + + ..\packages\Examine.0.1.60.2941\lib\Examine.dll + + + ..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll + ..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + + ..\packages\ImageProcessor.1.9.5.0\lib\ImageProcessor.dll + + + ..\packages\ImageProcessor.Web.3.3.1.0\lib\net45\ImageProcessor.Web.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\interfaces.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\log4net.dll + ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll + + ..\packages\UmbracoCms.Core.7.2.3\lib\Microsoft.ApplicationBlocks.Data.dll + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll @@ -52,10 +97,93 @@ ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + + ..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll + + + ..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll + + + ..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll + + + ..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\SQLCE4Umbraco.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\System.Data.SqlServerCe.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\System.Data.SqlServerCe.Entity.dll + + + + ..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll + + + + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll + + + ..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll + + + ..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.30506.0\lib\net40\System.Web.Http.WebHost.dll + + + ..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll + + + ..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll + + + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll + + + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll + + + ..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\TidyNet.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\Umbraco.Core.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.DataLayer.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.editorControls.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.MacroEngines.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.providers.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\Umbraco.Web.UI.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\UmbracoExamine.dll + + + ..\packages\UmbracoCms.Core.7.2.3\lib\UrlRewritingNet.UrlRewriter.dll + diff --git a/src/Our.Umbraco.Look.Tests/packages.config b/src/Our.Umbraco.Look.Tests/packages.config index 53e54a1..a72b161 100644 --- a/src/Our.Umbraco.Look.Tests/packages.config +++ b/src/Our.Umbraco.Look.Tests/packages.config @@ -1,7 +1,29 @@  + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Our.Umbraco.Look/Events/Indexing.cs b/src/Our.Umbraco.Look/Events/Indexing.cs index 86ba230..cb0359e 100644 --- a/src/Our.Umbraco.Look/Events/Indexing.cs +++ b/src/Our.Umbraco.Look/Events/Indexing.cs @@ -39,37 +39,23 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica private void Indexer_DocumentWriting(object sender, DocumentWritingEventArgs e, UmbracoHelper umbracoHelper, string indexerName) { IPublishedContent publishedContent = null; - NodeType? nodeType = null; publishedContent = umbracoHelper.TypedContent(e.NodeId); - if (publishedContent != null) - { - nodeType = NodeType.Content; - } - else // attempt to get as media + if (publishedContent == null) // attempt to get as media { publishedContent = umbracoHelper.TypedMedia(e.NodeId); - if (publishedContent != null) + if (publishedContent == null) // attempt to get as member { - nodeType = NodeType.Media; - } - else // attempt to get as member - { publishedContent = umbracoHelper.SafeTypedMember(e.NodeId); - - if (publishedContent != null) - { - nodeType = NodeType.Member; - } } } - if (publishedContent != null && nodeType.HasValue) + if (publishedContent != null) { this.EnsureUmbracoContext(); - var indexingContext = new IndexingContext(publishedContent, nodeType.Value, indexerName); + var indexingContext = new IndexingContext(publishedContent, indexerName); LookService.Index(indexingContext, e.Document); } diff --git a/src/Our.Umbraco.Look/Models/IndexingContext.cs b/src/Our.Umbraco.Look/Models/IndexingContext.cs index 5d722af..f2f6889 100644 --- a/src/Our.Umbraco.Look/Models/IndexingContext.cs +++ b/src/Our.Umbraco.Look/Models/IndexingContext.cs @@ -3,19 +3,14 @@ namespace Our.Umbraco.Look.Models { /// - /// Model passed into any custom cuonsumer indexing methods - supplies the data, as to what's being indexed, and to where it's being indexed + /// Model passed into any custom consumer indexing methods - supplies the data, as to what's being indexed, and to where it's being indexed /// public class IndexingContext { /// /// The IPublishedContent representation of the Content, Media or Member being indexed /// - public IPublishedContent Node { get; } - - /// - /// Enum to indicate whether the IPublishedContent is Content, Media or Member - /// - public NodeType NodeType { get; } + public IPublishedContent Item { get; } /// /// The name of the Examine indexer into which this item is being indexed @@ -28,10 +23,9 @@ public class IndexingContext /// /// /// - internal IndexingContext(IPublishedContent node, NodeType nodeType, string indexerName) + internal IndexingContext(IPublishedContent node, string indexerName) { - this.Node = node; - this.NodeType = nodeType; + this.Item = node; this.IndexerName = indexerName; } } diff --git a/src/Our.Umbraco.Look/Models/LookMatch.cs b/src/Our.Umbraco.Look/Models/LookMatch.cs index 1ace46b..77f627d 100644 --- a/src/Our.Umbraco.Look/Models/LookMatch.cs +++ b/src/Our.Umbraco.Look/Models/LookMatch.cs @@ -8,7 +8,7 @@ namespace Our.Umbraco.Look.Models { public class LookMatch { - private Lazy _node; + private Lazy _item; /// /// The Umbraco (content, media or member) Id of the matched item @@ -18,12 +18,7 @@ public class LookMatch /// /// Lazy evaluation of Item for IPublishedContent /// - public IPublishedContent Node => this._node.Value; - - /// - /// Enum flag to indicate if the IPublishedContent node is Content, Media or a Member - /// - public NodeType NodeType { get; } + public IPublishedContent Item => this._item.Value; /// /// Highlight text (containing search text) extracted from from the full text @@ -65,7 +60,7 @@ public class LookMatch /// /// /// - /// + /// /// /// /// @@ -76,7 +71,7 @@ public class LookMatch internal LookMatch( UmbracoHelper umbracoHelper, int id, - NodeType nodeType, + PublishedItemType publishedItemType, IHtmlString highlight, string text, LookTag[] tags, @@ -86,7 +81,6 @@ internal LookMatch( double? distance) { this.Id = id; - this.NodeType = nodeType; this.Highlight = highlight; this.Text = text; this.Tags = tags; @@ -95,15 +89,15 @@ internal LookMatch( this.Location = location; this.Distance = distance; - this._node = new Lazy(() => { + this._item = new Lazy(() => { if (umbracoHelper != null) // will be null for unit tests (as not initialized via Umbraco startup) { - switch (this.NodeType) + switch (publishedItemType) { - case NodeType.Content: return umbracoHelper.TypedContent(id); - case NodeType.Media: return umbracoHelper.TypedMedia(id); - case NodeType.Member: return umbracoHelper.SafeTypedMember(id); + case PublishedItemType.Content: return umbracoHelper.TypedContent(id); + case PublishedItemType.Media: return umbracoHelper.TypedMedia(id); + case PublishedItemType.Member: return umbracoHelper.SafeTypedMember(id); } } diff --git a/src/Our.Umbraco.Look/Models/NodeQuery.cs b/src/Our.Umbraco.Look/Models/NodeQuery.cs index 310a1a3..64c9c6e 100644 --- a/src/Our.Umbraco.Look/Models/NodeQuery.cs +++ b/src/Our.Umbraco.Look/Models/NodeQuery.cs @@ -1,4 +1,5 @@ using System.Linq; +using Umbraco.Core.Models; namespace Our.Umbraco.Look.Models { @@ -7,7 +8,7 @@ public class NodeQuery /// /// The types of node to find, eg. Content, Media, Members /// - public NodeType[] Types { get; set; } = null; + public PublishedItemType[] Types { get; set; } = null; /// /// The document type, media type or member type aliases @@ -29,10 +30,10 @@ public NodeQuery() /// /// Create new NodeQuery search criteria for nodes of a given type, eg content, media or members /// - /// The node type. eg. content, media or member - public NodeQuery(NodeType nodeType) + /// The node type. eg. content, media or member + public NodeQuery(PublishedItemType type) { - this.Types = new NodeType[] { nodeType }; + this.Types = new PublishedItemType[] { type }; } /// @@ -49,9 +50,9 @@ public NodeQuery(string alias) /// /// The node type. eg. content, media or member /// the alias of the content, media or member - public NodeQuery(NodeType nodeType, string alias) + public NodeQuery(PublishedItemType type, string alias) { - this.Types = new NodeType[] { nodeType }; + this.Types = new PublishedItemType[] { type }; this.Aliases = new string[] { alias }; } diff --git a/src/Our.Umbraco.Look/Models/NodeType.cs b/src/Our.Umbraco.Look/Models/NodeType.cs deleted file mode 100644 index deddc17..0000000 --- a/src/Our.Umbraco.Look/Models/NodeType.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Our.Umbraco.Look.Models -{ - /// - /// Indication of the node type - /// - public enum NodeType - { - Content, - - Media, - - Member - } -} diff --git a/src/Our.Umbraco.Look/Our.Umbraco.Look.csproj b/src/Our.Umbraco.Look/Our.Umbraco.Look.csproj index e174f68..7ff3c4c 100644 --- a/src/Our.Umbraco.Look/Our.Umbraco.Look.csproj +++ b/src/Our.Umbraco.Look/Our.Umbraco.Look.csproj @@ -225,7 +225,6 @@ - diff --git a/src/Our.Umbraco.Look/Services/LookService_GetLookMatches.cs b/src/Our.Umbraco.Look/Services/LookService_GetLookMatches.cs index ac0742d..f4b11e1 100644 --- a/src/Our.Umbraco.Look/Services/LookService_GetLookMatches.cs +++ b/src/Our.Umbraco.Look/Services/LookService_GetLookMatches.cs @@ -45,7 +45,7 @@ private static IEnumerable GetLookMatches( var mapFieldSelector = new MapFieldSelector(fields.ToArray()); // there should always be a valid node type value to parse - var getNodeType = new Func(x => { Enum.TryParse(x, out NodeType nodeType); return nodeType; }); + var getNodeType = new Func(x => { Enum.TryParse(x, out PublishedItemType type); return type; }); // if highlight func does not exist, then create one to always return null if (getHighlight == null) { getHighlight = x => null; } diff --git a/src/Our.Umbraco.Look/Services/LookService_Index.cs b/src/Our.Umbraco.Look/Services/LookService_Index.cs index 47cdadd..0a3f11e 100644 --- a/src/Our.Umbraco.Look/Services/LookService_Index.cs +++ b/src/Our.Umbraco.Look/Services/LookService_Index.cs @@ -18,7 +18,7 @@ internal static void Index(IndexingContext indexingContext, Document document) { var nodeTypeField = new Field( LookConstants.NodeTypeField, - indexingContext.NodeType.ToString(), + indexingContext.Item.ItemType.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO);