Skip to content

Commit

Permalink
8.1.2-beta.1
Browse files Browse the repository at this point in the history
rebase upstream/master for issue christopherrobinson#6 (christopherrobinson#7)
merge christopherrobinson#9
Nuget package support
  • Loading branch information
nvisage-gf committed Feb 26, 2022
1 parent 8ffd43d commit 9a2ec2d
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 41 deletions.
32 changes: 32 additions & 0 deletions .Nuget/Virtual-Nodes-for-Umbraco-8.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Virtual-Nodes-for-Umbraco-8</id>
<version>8.1.2-beta.1</version>
<title>Virtual-Nodes-for-Umbraco-8</title>
<authors>https://github.com/christopherrobinson/</authors>
<owners>https://github.com/christopherrobinson/Virtual-Nodes-for-Umbraco-8/</owners>
<description>A rewrite of Umbraco-VirtualNodes from Sotiris Filippidis to make it compatible with Umbraco 8.1+.</description>
<summary>This plugin lets you define document types that will be excluded from generated URLs., thus making them "invisible".</summary>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<language>en-GB</language>
<tags>Umbraco 8 Virtual Node URL ContentFinder</tags>
<projectUrl>https://github.com/nvisage-gf/Virtual-Nodes-for-Umbraco-8</projectUrl>
<readme>README.md</readme>
<license type="expression">MIT</license>
<dependencies>
<group targetFramework=".NETFramework4.7.2">
<dependency id="UmbracoCms.Core" version="[8.1,9)" />
<dependency id="UmbracoCms.Web" version="[8.1,9)" />
</group>
</dependencies>
</metadata>
<files>
<file src="..\README.md" target="" />
<file src="..\VirtualNodes\bin\Debug\VirtualNodes.dll" target="lib\net472" />
<file src="..\VirtualNodes\bin\Release\VirtualNodes.pdb" target="lib\net472" />
<file src="..\VirtualNodes\**\*.cs" target="src" />
<file src="web.config.install.xdt" target="content\web.config.install.xdt" />
<file src="web.config.uninstall.xdt" target="content\web.config.uninstall.xdt" />
</files>
</package>
6 changes: 6 additions & 0 deletions .Nuget/web.config.install.xdt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings xdt:Transform="InsertIfMissing">
<add key="VirtualNodes" value="virtual*" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
</appSettings>
</configuration>
6 changes: 6 additions & 0 deletions .Nuget/web.config.uninstall.xdt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="VirtualNodes" xdt:Transform="Remove" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,5 @@ healthchecksdb

# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

*.user
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Basically a rewrite of [Umbraco-VirtualNodes](https://github.com/sotirisf/Umbrac

This plugin lets you define document types that will be excluded from generated URLs., thus making them "invisible".

[myget](https://www.myget.org/F/nvisage-ltd/api/v3/index.json)

## Change Log

- 8.1.2-beta.1: VirtualNodesContentFinder update to ensure cached dictionary updated

## Usage
After you include this plugin you must have to add a single `appSettings` entry to your `web.config` file, e.g.

Expand Down Expand Up @@ -67,3 +73,14 @@ articles
## Known issues

To keep things simple the auto numbering of nodes only go one level up - if you have multiple virtual nodes under each other and multiple nodes with the same name in different levels then you will run into problems.

## Nuget Package

Update `.Nuget\\Virtual-Nodes-for-Umbraco-8.nuspec` manually for now.

Example pack command:

`
nuget pack Virtual-Nodes-for-Umbraco-8.nuspec -Build -Version 8.1.2 -Suffix beta.1 -Properties Configuration=Debug
`

13 changes: 11 additions & 2 deletions VirtualNodes.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.757
# Visual Studio Version 16
VisualStudioVersion = 16.0.32126.315
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualNodes", "VirtualNodes\VirtualNodes.csproj", "{3CEEA23B-3ECE-4CFF-B44A-551EDF7D2270}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FD069AC4-886E-42B1-A00F-C557BEDB6D55}"
ProjectSection(SolutionItems) = preProject
LICENSE.md = LICENSE.md
README.md = README.md
.Nuget\Virtual-Nodes-for-Umbraco-8.nuspec = .Nuget\Virtual-Nodes-for-Umbraco-8.nuspec
.Nuget\web.config.install.xdt = .Nuget\web.config.install.xdt
.Nuget\web.config.uninstall.xdt = .Nuget\web.config.uninstall.xdt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
9 changes: 6 additions & 3 deletions VirtualNodes/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<appSettings>
<add key="VirtualNodes" value="virtual*" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
33 changes: 33 additions & 0 deletions VirtualNodes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
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("VirtualNodes")]
[assembly: AssemblyDescription("This plugin lets you define document types that will be excluded from generated URLs., thus making them \"invisible\".")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("https://github.com/nvisage-gf/Virtual-Nodes-for-Umbraco-8/")]
[assembly: AssemblyProduct("VirtualNodes")]
[assembly: AssemblyCopyright("MIT")]
[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("0c46a457-7110-4ff4-a936-cfee9bd13668")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("8.1.2")]
[assembly: AssemblyFileVersion("8.1.2")]
[assembly: AssemblyInformationalVersion ("8.1.2-beta.1")]
8 changes: 6 additions & 2 deletions VirtualNodes/VirtualNodes.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -47,12 +47,16 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VirtualNodesComposer.cs" />
<Compile Include="VirtualNodesHelpers.cs" />
<Compile Include="VirtualNodesContentFinder.cs" />
<Compile Include="VirtualNodesEventHandler.cs" />
<Compile Include="VirtualNodesRuleManager.cs" />
<Compile Include="VirtualNodesUrlProvider.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
1 change: 1 addition & 0 deletions VirtualNodes/VirtualNodesComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public void Compose(Composition composition)
composition.ContentFinders().Insert<VirtualNodesContentFinder>();

composition.UrlProviders().Insert<VirtualNodesUrlProvider>();

}
}
}
13 changes: 7 additions & 6 deletions VirtualNodes/VirtualNodesContentFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ namespace VirtualNodes
{
public class VirtualNodesContentFinder : IContentFinder
{
public bool TryFindContent(PublishedRequest contentRequest)
public bool TryFindContent(PublishedRequest request)
{
var _runtimeCache = Current.AppCaches.RuntimeCache;
var _umbracoContext = contentRequest.UmbracoContext;
var _umbracoContext = request.UmbracoContext;
var cachedVirtualNodeUrls = _runtimeCache.GetCacheItem<Dictionary<string, int>>("CachedVirtualNodes");
var path = contentRequest.Uri.AbsolutePath;
var path = request.Uri.AbsolutePath;

// If found in the cached dictionary
if ((cachedVirtualNodeUrls != null) && cachedVirtualNodeUrls.ContainsKey(path))
{
var nodeId = cachedVirtualNodeUrls[path];

contentRequest.PublishedContent = _umbracoContext.Content.GetById(nodeId);
request.PublishedContent = _umbracoContext.Content.GetById(nodeId);

return true;
}

// If not found in the cached dictionary, traverse nodes and find the node that corresponds to the URL
var rootNodes = _umbracoContext.Content.GetAtRoot();
var item = rootNodes.DescendantsOrSelf<IPublishedContent>().Where(x => (x.Url == (path + "/") || (x.Url == path))).FirstOrDefault();
var item = rootNodes.DescendantsOrSelf<IPublishedContent>().FirstOrDefault(x => (x.Url == (path + "/") || (x.Url == path)));

// If item is found, return it after adding it to the cache so we don't have to go through the same process again.
if (cachedVirtualNodeUrls == null)
Expand All @@ -42,10 +42,11 @@ public bool TryFindContent(PublishedRequest contentRequest)
if (item != null)
{
// Update cache
cachedVirtualNodeUrls.Add(path, item.Id);
_runtimeCache.InsertCacheItem("CachedVirtualNodes", () => cachedVirtualNodeUrls, null, false, CacheItemPriority.High);

// That's all folks
contentRequest.PublishedContent = item;
request.PublishedContent = item;

return true;
}
Expand Down
39 changes: 26 additions & 13 deletions VirtualNodes/VirtualNodesEventHandler.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
using System;
using System;
using Umbraco.Core;
using Umbraco.Core.Composing;
#if DEBUG
using Umbraco.Core.Logging;
#endif
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Web;

namespace VirtualNodes
{
public class VirtualNodesComponent : IComponent
{
private readonly IContentService _contentService;
private readonly IUmbracoContextFactory _context;

public VirtualNodesComponent(IContentService contentService, IUmbracoContextFactory context)
#if DEBUG
private readonly ILogger _logger;
#endif
public VirtualNodesComponent(IUmbracoContextFactory context)
{
_contentService = contentService;
_context = context;
}

#if DEBUG
public VirtualNodesComponent(IUmbracoContextFactory context, ILogger logger) : this(context)
{
_logger = logger;
}
#endif

public void Initialize()
{
ContentService.Saving += (contentService, e) =>
Expand All @@ -28,7 +37,7 @@ public void Initialize()
{
var cache = cref.UmbracoContext.Content;

// Go through nodes being published
// Go through nodes being published
foreach (IContent node in e.SavedEntities)
{
// Name of node hasn't changed, so don't do anything
Expand Down Expand Up @@ -58,10 +67,13 @@ public void Initialize()
}
catch (Exception ex)
{
#if DEBUG
_logger.Error(typeof(VirtualNodesComponent), ex);
#endif
continue;
}

// Start the counter. This will count the nodes with the same name (taking numbering under consideration)
// Start the counter. This will count the nodes with the same name (taking numbering under consideration)
// that will be found under all the node's parent siblings that are virtual nodes.

int nodesFound = 0;
Expand Down Expand Up @@ -95,7 +107,7 @@ public void Initialize()
nodesFound++;
}
// If we find a node with the same name and numbering immediately after, increase counter by 1.
// Maxnumber will be the max number we found in node numbering, even if there are deleted node numbers in between.
// maxNumber will be the max number we found in node numbering, even if there are deleted node numbers in between.
// For example, if we have "aaa (1)" and "aaa(5)" only, maxNumber will be 5.
else if (VirtualNodesHelpers.MatchDuplicateName(p, y))
{
Expand All @@ -106,12 +118,12 @@ public void Initialize()
}

//Change the node's name to the appropriate number if duplicates were found.
//The number of nodes found will be the actual node number since we'll already have a node with
//no numbering. Meaning that if there is "aaa", "aaa (1)" and "aaa (2)" then
//The number of nodes found will be the actual node number since we'll already have a node with
//no numbering. Meaning that if there is "aaa", "aaa (1)" and "aaa (2)" then
//our new node (initially named "aaa") will be renamed to "aaa (3)" - that is 3 nodes found.
if (nodesFound > 0)
{
node.Name += " (" + (maxNumber + 1).ToString() + ")";
node.Name += $" ({maxNumber + 1})";
}
}
}
Expand All @@ -122,9 +134,10 @@ public void Initialize()
Current.AppCaches.RuntimeCache.ClearByKey("CachedVirtualNodes");
};
}

public void Terminate()
{
// do nothing
}
}
}
14 changes: 7 additions & 7 deletions VirtualNodes/VirtualNodesHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using Umbraco.Core.Models.PublishedContent;

namespace VirtualNodes
Expand All @@ -9,23 +9,23 @@ public static class VirtualNodesHelpers
/// Checks a given node's name against a potential duplicate name. If the name is the same, followed by a space, a parenthesis and a number, then this is a duplicate name.
/// </summary>
/// <param name="potentialDuplicateName">The name to check against</param>
/// <param name="currNodeName">The given node's name</param>
/// <param name="currentNodeName">The given node's name</param>
/// <returns>True if the potential duplicate name is same with the current node's name followed by a parenthesis with a number</returns>
public static bool MatchDuplicateName(string potentialDuplicateName, string currNodeName)
public static bool MatchDuplicateName(string potentialDuplicateName, string currentNodeName)
{
var rgName = new Regex(@"^(.+)( \(\d+\))$");

return (rgName.IsMatch(potentialDuplicateName) && rgName.Replace(potentialDuplicateName, "$1").Equals(currNodeName));
return (rgName.IsMatch(potentialDuplicateName) && rgName.Replace(potentialDuplicateName, "$1").Equals(currentNodeName));
}

/// <summary>
/// Gets the largest same-name node number being used
/// </summary>
/// <param name="potentialDuplicateName">The name to check for duplicates</param>
/// <param name="currNodeName">The current node's name</param>
/// <param name="currentNodeName">The current node's name</param>
/// <param name="maxNumber">The current maximum number</param>
/// <returns>The new maximum number, if applicable, or the same maximum number if nothing has changed</returns>
public static int GetMaxNodeNameNumbering(string potentialDuplicateName, string currNodeName, int maxNumber)
public static int GetMaxNodeNameNumbering(string potentialDuplicateName, string currentNodeName, int maxNumber)
{
var rgName = new Regex(@"^.+ \((\d+)\)$");

Expand Down Expand Up @@ -60,7 +60,7 @@ public static bool IsVirtualNode(this IPublishedContent item)
}

/// <summary>
/// Checks rules from settings agains a given document type alias to see if it matches the rule
/// Checks rules from settings against a given document type alias to see if it matches the rule
/// </summary>
/// <param name="nodeContentTypeAlias">The given document type alias</param>
/// <param name="contentTypeAliasFromSettings">The rule from settings</param>
Expand Down
Loading

0 comments on commit 9a2ec2d

Please sign in to comment.