Skip to content

Commit

Permalink
removed NodeType enum, now using Umbraco.Core.Models.PublishedItemType
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendy committed Nov 27, 2018
1 parent 32409d3 commit 4b51e4b
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 84 deletions.
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ public class IndexingContext
/// <summary>
/// The IPublishedContent of the Content, Media or Member being indexed
/// </summary>
public IPublishedContent Node { get; }

/// <summary>
/// Enum to indicate whether the IPublishedContent is Content, Media or Member
/// </summary>
public NodeType NodeType { get; }
public IPublishedContent Item { get; }

/// <summary>
/// The name of the Examine indexer into which this node is being indexed
Expand All @@ -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;
Expand All @@ -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<Picker>("colours");
var picker = indexingContext.Item.GetPropertyValue<Picker>("colours");

return picker.PickedKeys.Select(x => new LookTag("colour", x)).ToArray();

Expand All @@ -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<Terratype.Models.Model>("location");
var terratype = indexingContext.Item.GetPropertyValue<Terratype.Models.Model>("location");
var terratypeLatLng = terratype.Position.ToWgs84();

return new Location(terratypeLatLng.Latitude, terratypeLatLng.Longitude);
Expand Down Expand Up @@ -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)
},
Expand Down Expand Up @@ -218,12 +213,7 @@ public class LookMatch
/// <summary>
/// Lazy evaluation of the associated IPublishedContent
/// </summary>
public IPublishedContent Node { get; }

/// <summary>
/// Enum flag to indicate if the IPublishedContent node is Content, Media or a Member
/// </summary>
public NodeType NodeType { get; }
public IPublishedContent Item { get; }

/// <summary>
/// The custom name field
Expand Down
128 changes: 128 additions & 0 deletions src/Our.Umbraco.Look.Tests/Our.Umbraco.Look.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,151 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="AutoMapper.Net4, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll</HintPath>
</Reference>
<Reference Include="businesslogic, Version=1.0.5556.26331, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\businesslogic.dll</HintPath>
</Reference>
<Reference Include="ClientDependency.Core, Version=1.9.7.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ClientDependency.1.9.7\lib\net45\ClientDependency.Core.dll</HintPath>
</Reference>
<Reference Include="ClientDependency.Core.Mvc, Version=1.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ClientDependency-Mvc.1.8.0.0\lib\net45\ClientDependency.Core.Mvc.dll</HintPath>
</Reference>
<Reference Include="cms, Version=1.0.5556.26331, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\cms.dll</HintPath>
</Reference>
<Reference Include="controls, Version=1.0.5556.26333, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\controls.dll</HintPath>
</Reference>
<Reference Include="CookComputing.XmlRpcV2, Version=2.5.0.0, Culture=neutral, PublicKeyToken=a7d6e17aa302004d, processorArchitecture=MSIL">
<HintPath>..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll</HintPath>
</Reference>
<Reference Include="Examine, Version=0.1.60.2941, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Examine.0.1.60.2941\lib\Examine.dll</HintPath>
</Reference>
<Reference Include="HtmlAgilityPack, Version=1.4.6.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="ImageProcessor, Version=1.9.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ImageProcessor.1.9.5.0\lib\ImageProcessor.dll</HintPath>
</Reference>
<Reference Include="ImageProcessor.Web, Version=3.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ImageProcessor.Web.3.3.1.0\lib\net45\ImageProcessor.Web.dll</HintPath>
</Reference>
<Reference Include="interfaces, Version=1.0.5556.26329, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\interfaces.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.11.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\log4net.dll</HintPath>
</Reference>
<Reference Include="Lucene.Net, Version=2.9.4.1, Culture=neutral, PublicKeyToken=85089178b9ac3181, processorArchitecture=MSIL">
<HintPath>..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ApplicationBlocks.Data, Version=1.0.1559.20655, Culture=neutral">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Mvc.FixedDisplayModes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll</HintPath>
</Reference>
<Reference Include="MiniProfiler, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3, processorArchitecture=MSIL">
<HintPath>..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SQLCE4Umbraco, Version=1.0.5556.26332, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\SQLCE4Umbraco.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\System.Data.SqlServerCe.dll</HintPath>
</Reference>
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\System.Data.SqlServerCe.Entity.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.30506.0\lib\net40\System.Web.Http.WebHost.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="TidyNet, Version=1.0.0.0, Culture=neutral">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\TidyNet.dll</HintPath>
</Reference>
<Reference Include="umbraco, Version=1.0.5556.26334, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.dll</HintPath>
</Reference>
<Reference Include="Umbraco.Core, Version=1.0.5556.26329, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\Umbraco.Core.dll</HintPath>
</Reference>
<Reference Include="umbraco.DataLayer, Version=1.0.5556.26331, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.DataLayer.dll</HintPath>
</Reference>
<Reference Include="umbraco.editorControls, Version=1.0.5556.26335, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.editorControls.dll</HintPath>
</Reference>
<Reference Include="umbraco.MacroEngines, Version=1.0.5556.26336, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.MacroEngines.dll</HintPath>
</Reference>
<Reference Include="umbraco.providers, Version=1.0.5556.26333, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\umbraco.providers.dll</HintPath>
</Reference>
<Reference Include="Umbraco.Web.UI, Version=1.0.5556.26336, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\Umbraco.Web.UI.dll</HintPath>
</Reference>
<Reference Include="UmbracoExamine, Version=0.7.0.26332, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\UmbracoExamine.dll</HintPath>
</Reference>
<Reference Include="UrlRewritingNet.UrlRewriter, Version=2.0.60829.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.2.3\lib\UrlRewritingNet.UrlRewriter.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DemoSiteTests\BaseDemoSiteTests.cs" />
Expand Down
22 changes: 22 additions & 0 deletions src/Our.Umbraco.Look.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.0.0" targetFramework="net45" />
<package id="ClientDependency" version="1.9.7" targetFramework="net45" />
<package id="ClientDependency-Mvc" version="1.8.0.0" targetFramework="net45" />
<package id="Examine" version="0.1.60.2941" targetFramework="net45" />
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net45" />
<package id="ImageProcessor" version="1.9.5.0" targetFramework="net45" />
<package id="ImageProcessor.Web" version="3.3.1.0" targetFramework="net45" />
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="MiniProfiler" version="2.1.0" targetFramework="net45" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net45" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net45" />
<package id="MySql.Data" version="6.6.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
<package id="UmbracoCms.Core" version="7.2.3" targetFramework="net45" />
<package id="xmlrpcnet" version="2.5.0" targetFramework="net45" />
</packages>
22 changes: 4 additions & 18 deletions src/Our.Umbraco.Look/Events/Indexing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 4 additions & 10 deletions src/Our.Umbraco.Look/Models/IndexingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
namespace Our.Umbraco.Look.Models
{
/// <summary>
/// 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
/// </summary>
public class IndexingContext
{
/// <summary>
/// The IPublishedContent representation of the Content, Media or Member being indexed
/// </summary>
public IPublishedContent Node { get; }

/// <summary>
/// Enum to indicate whether the IPublishedContent is Content, Media or Member
/// </summary>
public NodeType NodeType { get; }
public IPublishedContent Item { get; }

/// <summary>
/// The name of the Examine indexer into which this item is being indexed
Expand All @@ -28,10 +23,9 @@ public class IndexingContext
/// <param name="node"></param>
/// <param name="nodeType"></param>
/// <param name="indexerName"></param>
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;
}
}
Expand Down
Loading

0 comments on commit 4b51e4b

Please sign in to comment.