Skip to content

Commit 1429c3b

Browse files
committed
Migrated to .NET6 / Cofoundry v0.11
1 parent 8cb3ab4 commit 1429c3b

34 files changed

+503
-676
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ $RECYCLE.BIN/
150150
# Mac crap
151151
.DS_Store
152152

153-
src/.vs
153+
.vs
154154

155155
# Cake Build
156156
/tools

src/Cofoundry.Plugins.SiteMap.sln renamed to Cofoundry.Plugins.SiteMap.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26430.13
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cofoundry.Plugins.SiteMap", "Cofoundry.Plugins.SiteMap\Cofoundry.Plugins.SiteMap.csproj", "{EB0B3CB1-8AF1-41F9-97CA-5208BF17FA5A}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cofoundry.Plugins.SiteMap", "src\Cofoundry.Plugins.SiteMap\Cofoundry.Plugins.SiteMap.csproj", "{EB0B3CB1-8AF1-41F9-97CA-5208BF17FA5A}"
77
EndProject
8-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SitemapExample", "SitemapExample\SitemapExample.csproj", "{16753557-7C98-46B4-925A-F2E18F869974}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SitemapExample", "src\SitemapExample\SitemapExample.csproj", "{16753557-7C98-46B4-925A-F2E18F869974}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{2A5BFC8A-1F5F-414C-B67F-964364273F8A}"
1111
EndProject
File renamed without changes.

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version: '{build}'
2-
image: Visual Studio 2019
2+
image: Visual Studio 2022
33

44
build_script:
55
- cmd: PowerShell .\build.ps1 --PushPackages="true"

src/Cofoundry.Plugins.SiteMap/Cofoundry.Plugins.SiteMap.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
67
<PackageId>Cofoundry.Plugins.SiteMap</PackageId>
78
<Description>Adds dynamic sitemap functionality to a Cofoundry site.</Description>
89
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
910
<PackageTags>Cofoundry Plugin SiteMap</PackageTags>
1011
</PropertyGroup>
1112

1213
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
13-
<DocumentationFile>bin\Release\netcoreapp3.1\Cofoundry.Plugins.SiteMap.xml</DocumentationFile>
14+
<DocumentationFile>bin\Release\net6.0\Cofoundry.Plugins.SiteMap.xml</DocumentationFile>
1415
<NoWarn>1701;1702;1705;1591</NoWarn>
1516
</PropertyGroup>
1617

@@ -23,7 +24,7 @@
2324
</ItemGroup>
2425

2526
<ItemGroup>
26-
<PackageReference Include="Cofoundry.Domain" Version="0.10.0" />
27+
<PackageReference Include="Cofoundry.Domain" Version="0.11.1" />
2728
</ItemGroup>
2829

2930
</Project>
Lines changed: 75 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,101 @@
1-
using Cofoundry.Domain;
2-
using Cofoundry.Domain.CQS;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
1+
namespace Cofoundry.Plugins.SiteMap;
62

7-
namespace Cofoundry.Plugins.SiteMap
3+
/// <summary>
4+
/// Registration for resources that should appear in the xml site map file.
5+
/// </summary>
6+
public class CofoundryContentSiteMapResourceRegistration : IAsyncSiteMapResourceRegistration
87
{
9-
/// <summary>
10-
/// Registration for resources that should appear in the xml site map file.
11-
/// </summary>
12-
public class CofoundryContentSiteMapResourceRegistration : IAsyncSiteMapResourceRegistration
8+
private readonly IQueryExecutor _queryExecutor;
9+
private readonly IPermissionValidationService _permissionValidationService;
10+
private readonly IUserContextService _userContextService;
11+
12+
public CofoundryContentSiteMapResourceRegistration(
13+
IQueryExecutor queryExecutor,
14+
IPermissionValidationService permissionValidationService,
15+
IUserContextService userContextService
16+
)
1317
{
14-
private readonly IQueryExecutor _queryExecutor;
15-
private readonly IPermissionValidationService _permissionValidationService;
16-
private readonly IUserContextService _userContextService;
17-
18-
public CofoundryContentSiteMapResourceRegistration(
19-
IQueryExecutor queryExecutor,
20-
IPermissionValidationService permissionValidationService,
21-
IUserContextService userContextService
22-
)
23-
{
24-
_queryExecutor = queryExecutor;
25-
_permissionValidationService = permissionValidationService;
26-
_userContextService = userContextService;
27-
}
18+
_queryExecutor = queryExecutor;
19+
_permissionValidationService = permissionValidationService;
20+
_userContextService = userContextService;
21+
}
2822

29-
public async Task<IEnumerable<ISiteMapResource>> GetResourcesAsync()
30-
{
31-
var userContext = await _userContextService.GetCurrentContextAsync();
32-
var resources = new List<SiteMapResource>();
33-
if (!_permissionValidationService.HasPermission<PageReadPermission>(userContext)) return resources;
23+
public async Task<IEnumerable<ISiteMapResource>> GetResourcesAsync()
24+
{
25+
var userContext = await _userContextService.GetCurrentContextAsync();
26+
var resources = new List<SiteMapResource>();
27+
if (!_permissionValidationService.HasPermission<PageReadPermission>(userContext)) return resources;
3428

35-
var pageRoutes = await _queryExecutor.ExecuteAsync(new GetAllPageRoutesQuery());
36-
var allRules = await _queryExecutor.ExecuteAsync(new GetAllCustomEntityRoutingRulesQuery());
29+
var pageRoutes = await _queryExecutor.ExecuteAsync(new GetAllPageRoutesQuery());
30+
var allRules = await _queryExecutor.ExecuteAsync(new GetAllCustomEntityRoutingRulesQuery());
3731

38-
foreach (var pageRoute in pageRoutes.Where(p => p.IsPublished() && p.ShowInSiteMap && p.CanAccess(userContext)))
32+
foreach (var pageRoute in pageRoutes.Where(p => p.IsPublished() && p.ShowInSiteMap && p.CanAccess(userContext)))
33+
{
34+
if (pageRoute.PageType == PageType.CustomEntityDetails)
3935
{
40-
if (pageRoute.PageType == PageType.CustomEntityDetails)
36+
if (_permissionValidationService.HasCustomEntityPermission<CustomEntityReadPermission>(pageRoute.CustomEntityDefinitionCode, userContext))
4137
{
42-
if (_permissionValidationService.HasCustomEntityPermission<CustomEntityReadPermission>(pageRoute.CustomEntityDefinitionCode, userContext))
43-
{
44-
var routesQuery = new GetCustomEntityRoutesByDefinitionCodeQuery(pageRoute.CustomEntityDefinitionCode);
45-
var allCustomEntityRoutes = await _queryExecutor.ExecuteAsync(routesQuery);
46-
var pageLocaleId = pageRoute.Locale != null ? pageRoute.Locale.LocaleId : (int?)null;
38+
var routesQuery = new GetCustomEntityRoutesByDefinitionCodeQuery(pageRoute.CustomEntityDefinitionCode);
39+
var allCustomEntityRoutes = await _queryExecutor.ExecuteAsync(routesQuery);
40+
var pageLocaleId = pageRoute.Locale != null ? pageRoute.Locale.LocaleId : (int?)null;
4741

48-
foreach (var customEntityRoute in allCustomEntityRoutes
49-
.Where(r => r.Locale == null ? !pageLocaleId.HasValue : r.Locale.LocaleId == pageLocaleId))
42+
foreach (var customEntityRoute in allCustomEntityRoutes
43+
.Where(r => r.Locale == null ? !pageLocaleId.HasValue : r.Locale.LocaleId == pageLocaleId))
44+
{
45+
var resource = MapCustomEntityResource(pageRoute, customEntityRoute, allRules);
46+
if (resource != null)
5047
{
51-
var resource = MapCustomEntityResource(pageRoute, customEntityRoute, allRules);
52-
if (resource != null)
53-
{
54-
resources.Add(resource);
55-
}
48+
resources.Add(resource);
5649
}
5750
}
5851
}
59-
else
60-
{
61-
resources.Add(MapPageResource(pageRoute));
62-
}
6352
}
64-
65-
return resources;
53+
else
54+
{
55+
resources.Add(MapPageResource(pageRoute));
56+
}
6657
}
6758

68-
private SiteMapResource MapCustomEntityResource(PageRoute pageRoute, CustomEntityRoute customEntityRoute, IEnumerable<ICustomEntityRoutingRule> allRules)
69-
{
70-
var version = customEntityRoute.Versions.GetVersionRouting(PublishStatusQuery.Published);
71-
if (version == null) return null;
59+
return resources;
60+
}
7261

73-
var rule = allRules.FirstOrDefault(r => r.RouteFormat == pageRoute.UrlPath);
74-
if (rule == null) return null;
62+
private SiteMapResource MapCustomEntityResource(PageRoute pageRoute, CustomEntityRoute customEntityRoute, IEnumerable<ICustomEntityRoutingRule> allRules)
63+
{
64+
var version = customEntityRoute.Versions.GetVersionRouting(PublishStatusQuery.Published);
65+
if (version == null) return null;
7566

76-
var resource = new SiteMapResource();
77-
resource.Url = rule.MakeUrl(pageRoute, customEntityRoute);
78-
resource.LastModifiedDate = customEntityRoute.LastPublishDate;
79-
resource.Priority = GetPriority(pageRoute);
67+
var rule = allRules.FirstOrDefault(r => r.RouteFormat == pageRoute.UrlPath);
68+
if (rule == null) return null;
8069

81-
return resource;
82-
}
70+
var resource = new SiteMapResource();
71+
resource.Url = rule.MakeUrl(pageRoute, customEntityRoute);
72+
resource.LastModifiedDate = customEntityRoute.LastPublishDate;
73+
resource.Priority = GetPriority(pageRoute);
8374

84-
private SiteMapResource MapPageResource(PageRoute pageRoute)
85-
{
86-
var resource = new SiteMapResource();
87-
resource.Url = pageRoute.FullUrlPath;
88-
resource.LastModifiedDate = pageRoute.LastPublishDate;
89-
resource.Priority = GetPriority(pageRoute);
75+
return resource;
76+
}
9077

91-
return resource;
92-
}
78+
private SiteMapResource MapPageResource(PageRoute pageRoute)
79+
{
80+
var resource = new SiteMapResource();
81+
resource.Url = pageRoute.FullUrlPath;
82+
resource.LastModifiedDate = pageRoute.LastPublishDate;
83+
resource.Priority = GetPriority(pageRoute);
9384

94-
private decimal GetPriority(PageRoute pageRoute)
95-
{
96-
var isDirectoryDefaultPage = pageRoute.IsDirectoryDefaultPage();
97-
var isInSiteRoot = pageRoute.PageDirectory.IsSiteRoot();
85+
return resource;
86+
}
9887

99-
// Site/Language root
100-
if (isInSiteRoot && isDirectoryDefaultPage) return 1;
101-
// Directory root
102-
if (isDirectoryDefaultPage) return 0.8m;
88+
private decimal GetPriority(PageRoute pageRoute)
89+
{
90+
var isDirectoryDefaultPage = pageRoute.IsDirectoryDefaultPage();
91+
var isInSiteRoot = pageRoute.PageDirectory.IsSiteRoot();
10392

104-
// Directory sub pages
105-
return 0.6m;
106-
}
93+
// Site/Language root
94+
if (isInSiteRoot && isDirectoryDefaultPage) return 1;
95+
// Directory root
96+
if (isDirectoryDefaultPage) return 0.8m;
97+
98+
// Directory sub pages
99+
return 0.6m;
107100
}
108101
}
Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Xml.Linq;
5-
using System.Text;
6-
using System.IO;
1+
using Microsoft.AspNetCore.Mvc;
72
using System.Reflection;
8-
using System.Threading.Tasks;
9-
using Cofoundry.Domain.CQS;
10-
using Microsoft.AspNetCore.Mvc;
3+
using System.Text;
114

12-
namespace Cofoundry.Plugins.SiteMap
13-
{
14-
public class SiteMapController : Controller
15-
{
16-
#region Constructors
5+
namespace Cofoundry.Plugins.SiteMap;
176

18-
private readonly ISiteMapRenderer _siteMapRenderer;
7+
public class SiteMapController : Controller
8+
{
9+
private readonly ISiteMapRenderer _siteMapRenderer;
1910

20-
public SiteMapController(
21-
IQueryExecutor queryExecutor,
22-
ISiteMapRenderer siteMapRenderer
23-
)
24-
{
25-
_siteMapRenderer = siteMapRenderer;
26-
}
11+
public SiteMapController(
12+
IQueryExecutor queryExecutor,
13+
ISiteMapRenderer siteMapRenderer
14+
)
15+
{
16+
_siteMapRenderer = siteMapRenderer;
17+
}
2718

28-
#endregion
19+
[Route("sitemap.xml")]
20+
public async Task<ContentResult> SitemapXml()
21+
{
22+
var siteMap = await _siteMapRenderer.RenderToUTF8StringAsync();
23+
return Content(siteMap, "application/xml", Encoding.UTF8);
24+
}
2925

30-
[Route("sitemap.xml")]
31-
public async Task<ContentResult> SitemapXml()
32-
{
33-
var siteMap = await _siteMapRenderer.RenderToUTF8StringAsync();
34-
return Content(siteMap, "application/xml", Encoding.UTF8);
35-
}
26+
[Route("sitemap.xsl")]
27+
public ContentResult SitemapXsl()
28+
{
29+
var assembly = typeof(SiteMapController).GetTypeInfo().Assembly;
3630

37-
[Route("sitemap.xsl")]
38-
public ContentResult SitemapXsl()
31+
using (var stream = assembly.GetManifestResourceStream("Cofoundry.Plugins.SiteMap.DefaultImplementation.sitemap.xsl"))
32+
using (var reader = new StreamReader(stream))
3933
{
40-
var assembly = typeof(SiteMapController).GetTypeInfo().Assembly;
41-
42-
using (var stream = assembly.GetManifestResourceStream("Cofoundry.Plugins.SiteMap.DefaultImplementation.sitemap.xsl"))
43-
using(var reader = new StreamReader(stream))
44-
{
45-
return Content(reader.ReadToEnd(), "application/xml", Encoding.UTF8);
46-
}
34+
return Content(reader.ReadToEnd(), "application/xml", Encoding.UTF8);
4735
}
4836
}
4937
}
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Cofoundry.Core.DependencyInjection;
1+
using Cofoundry.Core.DependencyInjection;
72

8-
namespace Cofoundry.Plugins.SiteMap
3+
namespace Cofoundry.Plugins.SiteMap;
4+
5+
public class DependencyRegistration : IDependencyRegistration
96
{
10-
public class DependencyRegistration : IDependencyRegistration
7+
public void Register(IContainerRegister container)
118
{
12-
public void Register(IContainerRegister container)
13-
{
14-
container
15-
.Register<ISiteMapBuilderFactory, SiteMapBuilderFactory>()
16-
.Register<ISiteMapRenderer, SiteMapRenderer>()
9+
container
10+
.Register<ISiteMapBuilderFactory, SiteMapBuilderFactory>()
11+
.Register<ISiteMapRenderer, SiteMapRenderer>()
1712

18-
.RegisterAll<ISiteMapResourceRegistration>()
19-
.RegisterAll<IAsyncSiteMapResourceRegistration>()
20-
;
21-
}
13+
.RegisterAll<ISiteMapResourceRegistration>()
14+
.RegisterAll<IAsyncSiteMapResourceRegistration>()
15+
;
2216
}
2317
}
Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Xml.Linq;
1+
using System.Xml.Linq;
72

8-
namespace Cofoundry.Plugins.SiteMap
3+
namespace Cofoundry.Plugins.SiteMap;
4+
5+
/// <summary>
6+
/// Builds a site map xml file from a set of resources. Call ToString()
7+
/// to render the xml file to a UTF8 string.
8+
/// </summary>
9+
public interface ISiteMapBuilder
910
{
1011
/// <summary>
11-
/// Builds a site map xml file from a set of resources. Call ToString()
12-
/// to render the xml file to a UTF8 string.
12+
/// The resources to include in the site map. These will be autiomatically
13+
/// ordered by priority when rendering.
1314
/// </summary>
14-
public interface ISiteMapBuilder
15-
{
16-
/// <summary>
17-
/// The resources to include in the site map. These will be autiomatically
18-
/// ordered by priority when rendering.
19-
/// </summary>
20-
List<ISiteMapResource> Resources { get; set; }
15+
List<ISiteMapResource> Resources { get; set; }
2116

22-
/// <summary>
23-
/// Creates the SiteMap xml document.
24-
/// </summary>
25-
XDocument ToXml();
26-
}
17+
/// <summary>
18+
/// Creates the SiteMap xml document.
19+
/// </summary>
20+
XDocument ToXml();
2721
}

0 commit comments

Comments
 (0)