Skip to content

Commit

Permalink
Merge pull request #529 from PiranhaCMS/v6.0/services
Browse files Browse the repository at this point in the history
V6.0/services
  • Loading branch information
tidyui authored Mar 3, 2019
2 parents a7dd66c + fb51897 commit 8ee1948
Show file tree
Hide file tree
Showing 241 changed files with 10,316 additions and 8,069 deletions.
17 changes: 16 additions & 1 deletion Piranha.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piranha.AttributeBuilder.Te
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".global", ".global", "{88054E40-5547-4EA5-B75E-D446E8E5A021}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand Down Expand Up @@ -66,6 +65,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piranha.AspNetCore.Identity
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcWeb", "examples\MvcWeb\MvcWeb.csproj", "{14F9CA8A-6532-40CC-81D6-9763351AFD91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piranha.Extensions.Sync", "core\Piranha.Extensions.Sync\Piranha.Extensions.Sync.csproj", "{D17485D2-371E-4F7C-952F-57B26606FC6A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{DCC52317-BC88-4F0A-923F-C9D9F6D952ED}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piranha.Data.EF", "data\Piranha.Data.EF\Piranha.Data.EF.csproj", "{4CCD6AF9-3A1D-41E3-B58F-80E9D6616CA3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -136,6 +141,14 @@ Global
{14F9CA8A-6532-40CC-81D6-9763351AFD91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14F9CA8A-6532-40CC-81D6-9763351AFD91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14F9CA8A-6532-40CC-81D6-9763351AFD91}.Release|Any CPU.Build.0 = Release|Any CPU
{D17485D2-371E-4F7C-952F-57B26606FC6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D17485D2-371E-4F7C-952F-57B26606FC6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D17485D2-371E-4F7C-952F-57B26606FC6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D17485D2-371E-4F7C-952F-57B26606FC6A}.Release|Any CPU.Build.0 = Release|Any CPU
{4CCD6AF9-3A1D-41E3-B58F-80E9D6616CA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CCD6AF9-3A1D-41E3-B58F-80E9D6616CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CCD6AF9-3A1D-41E3-B58F-80E9D6616CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CCD6AF9-3A1D-41E3-B58F-80E9D6616CA3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -157,6 +170,8 @@ Global
{CC742AA4-A544-46D4-901C-7A605B4F132B} = {42A64587-89B5-48F2-84D4-85B97F7847F1}
{BB0DADBE-987B-4DE6-8173-49BC8BA139BB} = {42A64587-89B5-48F2-84D4-85B97F7847F1}
{14F9CA8A-6532-40CC-81D6-9763351AFD91} = {A82A5922-BF05-4DD7-A2C1-DD22F1AD6A57}
{D17485D2-371E-4F7C-952F-57B26606FC6A} = {42A64587-89B5-48F2-84D4-85B97F7847F1}
{4CCD6AF9-3A1D-41E3-B58F-80E9D6616CA3} = {DCC52317-BC88-4F0A-923F-C9D9F6D952ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CF88AA05-D127-4707-8214-A230F0DA569B}
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ before_build:
build_script:
- dotnet build -c Debug /p:DebugType=full
test_script:
- ps: .\tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:".\script\tests.bat" -searchdirs:".\test\Piranha.Tests\bin\Debug\netcoreapp1.1;.\test\Piranha.AttributeBuilder.Tests\bin\Debug\netcoreapp1.1;.\test\Piranha.ImageSharp.Tests\bin\Debug\netcoreapp1.1" -oldstyle -output:coverage.xml -skipautoprops -returntargetcode -filter:"+[Piranha*]* -[*Tests]*" -excludebyattribute:"Piranha.NoCoverageAttribute"
- ps: .\tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -target:".\script\tests.bat" -searchdirs:".\test\Piranha.Tests\bin\Debug\netcoreapp2.1;.\test\Piranha.AttributeBuilder.Tests\bin\Debug\netcoreapp2.1;.\test\Piranha.ImageSharp.Tests\bin\Debug\netcoreapp2.1" -oldstyle -output:coverage.xml -skipautoprops -returntargetcode -filter:"+[Piranha*]* -[*Tests]*" -excludebyattribute:"Piranha.NoCoverageAttribute"
- ps: .\tools\coveralls.net.0.7.0\tools\csmacnz.coveralls.exe --opencover -i coverage.xml --repoToken $env:COVERALLS_REPO_TOKEN --useRelativePaths --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_BUILD_NUMBER --serviceName appveyor
8 changes: 4 additions & 4 deletions core/Piranha.AspNetCore/AliasMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (c) 2018 Håkan Edling
* Copyright (c) 2018-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -38,7 +38,7 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
{
var url = context.Request.Path.HasValue ? context.Request.Path.Value : "";

var response = AliasRouter.Invoke(api, url, service.Site.Id);
var response = await AliasRouter.InvokeAsync(api, url, service.Site.Id);
if (response != null)
{
_logger?.LogInformation($"Found alias\n Alias: {url}\n Redirect: {response.RedirectUrl}");
Expand Down
6 changes: 3 additions & 3 deletions core/Piranha.AspNetCore/ApplicationMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -37,7 +37,7 @@ public ApplicationMiddleware(RequestDelegate next, ILoggerFactory factory = null
/// <returns>An async task</returns>
public override async Task Invoke(HttpContext context, IApi api, IApplicationService service)
{
service.Init(context);
await service.InitAsync(context);

// Set culture if applicable
if (!string.IsNullOrEmpty(service.Site.Culture))
Expand Down
8 changes: 4 additions & 4 deletions core/Piranha.AspNetCore/ArchiveMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (c) 2016-2018 Håkan Edling
* Copyright (c) 2016-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -38,7 +38,7 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
var url = context.Request.Path.HasValue ? context.Request.Path.Value : "";
var siteId = service.Site.Id;

var response = ArchiveRouter.Invoke(api, url, siteId);
var response = await ArchiveRouter.InvokeAsync(api, url, siteId);
if (response != null)
{
_logger?.LogInformation($"Found archive\n Route: {response.Route}\n Params: {response.QueryString}");
Expand Down
8 changes: 4 additions & 4 deletions core/Piranha.AspNetCore/CoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -112,11 +112,11 @@ public static IApplicationBuilder UsePiranhaStartPage(this IApplicationBuilder b
/// </summary>
/// <param name="builder">The current application builder</param>
/// <returns>The builder</returns>
[Obsolete("Please replace UsePiranhaSites with UsePiranhaApplication.", false)]
[Obsolete("Please replace UsePiranhaSites with UsePiranhaApplication.", true)]
public static IApplicationBuilder UsePiranhaSites(this IApplicationBuilder builder)
{
return UsePiranhaApplication(builder);
}
}

/// <summary>
/// Uses the piranha sitemap generation middleware.
Expand Down
8 changes: 4 additions & 4 deletions core/Piranha.AspNetCore/PageMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (c) 2016-2018 Håkan Edling
* Copyright (c) 2016-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -41,7 +41,7 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
var siteId = service.Site.Id;
var authorized = true;

var response = PageRouter.Invoke(api, url, siteId);
var response = await PageRouter.InvokeAsync(api, url, siteId);
if (response != null)
{
_logger?.LogInformation($"Found page\n Route: {response.Route}\n Params: {response.QueryString}");
Expand Down
8 changes: 4 additions & 4 deletions core/Piranha.AspNetCore/PostMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (c) 2016-2018 Håkan Edling
* Copyright (c) 2016-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -41,7 +41,7 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
var siteId = service.Site.Id;
var authorized = true;

var response = PostRouter.Invoke(api, url, siteId);
var response = await PostRouter.InvokeAsync(api, url, siteId);
if (response != null)
{
_logger?.LogInformation($"Found post\n Route: {response.Route}\n Params: {response.QueryString}");
Expand Down
31 changes: 16 additions & 15 deletions core/Piranha.AspNetCore/Services/ApplicationService.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/*
* Copyright (c) 2018 Håkan Edling
* Copyright (c) 2018-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Http;
using System;
using System.Linq;
using Piranha.Data;
using System.Threading.Tasks;
using Piranha.Extend.Fields;
using Piranha.Models;
using Piranha.Services;

namespace Piranha.AspNetCore.Services
{
Expand Down Expand Up @@ -41,7 +42,7 @@ public class SiteHelper : ISiteHelper
/// <summary>
/// Default internal constructur.
/// </summary>
internal SiteHelper(IApi api)
internal SiteHelper(IApi api)
{
_api = api;
}
Expand All @@ -51,11 +52,11 @@ internal SiteHelper(IApi api)
/// </summary>
/// <typeparam name="T">The content type</typeparam>
/// <returns>The site content model</returns>
public T GetContent<T>() where T : SiteContent<T>
public Task<T> GetContentAsync<T>() where T : SiteContent<T>
{
if (Id != Guid.Empty)
{
return _api.Sites.GetContentById<T>(Id);
return _api.Sites.GetContentByIdAsync<T>(Id);
}
return null;
}
Expand All @@ -68,7 +69,7 @@ public class MediaHelper : IMediaHelper
/// <summary>
/// Default internal constructur.
/// </summary>
internal MediaHelper(IApi api)
internal MediaHelper(IApi api)
{
_api = api;
}
Expand Down Expand Up @@ -120,7 +121,7 @@ public string ResizeImage(Media image, int width, int? height = null)
/// Gets the media helper.
/// </summary>
public IMediaHelper Media { get; internal set; }

/// <summary>
/// Gets the currently requested URL.
/// </summary>
Expand All @@ -146,38 +147,38 @@ public ApplicationService(IApi api)
/// <summary>
/// Initializes the service.
/// </summary>
public void Init(HttpContext context)
public async Task InitAsync(HttpContext context)
{
// Gets the current site info
if (!context.Request.Path.Value.StartsWith("/manager/"))
{
Data.Site site = null;
Models.Site site = null;

// Try to get the requested site by hostname & prefix
var url = context.Request.Path.HasValue ? context.Request.Path.Value : "";
if (!string.IsNullOrEmpty(url) && url.Length > 1)
{
var segments = url.Substring(1).Split(new char[] { '/' });
site = Api.Sites.GetByHostname($"{context.Request.Host.Host}/{segments[0]}");
site = await Api.Sites.GetByHostnameAsync($"{context.Request.Host.Host}/{segments[0]}");

if (site != null)
context.Request.Path = "/" + string.Join("/", segments.Skip(1));
}

// Try to get the requested site by hostname
if (site == null)
site = Api.Sites.GetByHostname(context.Request.Host.Host);
site = await Api.Sites.GetByHostnameAsync(context.Request.Host.Host);

// If we didn't find the site, get the default site
if (site == null)
site = Api.Sites.GetDefault();
site = await Api.Sites.GetDefaultAsync();

// Store the current site id & get the sitemap
if (site != null)
{
Site.Id = site.Id;
Site.Culture = site.Culture;
Site.Sitemap = Api.Sites.GetSitemap(Site.Id);
Site.Sitemap = await Api.Sites.GetSitemapAsync(Site.Id);
}
}

Expand Down
11 changes: 6 additions & 5 deletions core/Piranha.AspNetCore/Services/IApplicationService.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*
* Copyright (c) 2018 Håkan Edling
* Copyright (c) 2018-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using Microsoft.AspNetCore.Http;
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Piranha.Models;

namespace Piranha.AspNetCore.Services
Expand Down Expand Up @@ -44,6 +45,6 @@ public interface IApplicationService
/// <summary>
/// Initializes the service.
/// </summary>
void Init(HttpContext context);
Task InitAsync(HttpContext context);
}
}
5 changes: 2 additions & 3 deletions core/Piranha.AspNetCore/Services/IMediaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using System;
using Piranha.Data;
using Piranha.Extend.Fields;
using Piranha.Models;

Expand Down
9 changes: 5 additions & 4 deletions core/Piranha.AspNetCore/Services/ISiteHelper.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* Copyright (c) 2018 Håkan Edling
* Copyright (c) 2018-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*
* https://github.com/piranhacms/piranha.core
*
*
*/

using System;
using System.Threading.Tasks;
using Piranha.Models;

namespace Piranha.AspNetCore.Services
Expand All @@ -35,6 +36,6 @@ public interface ISiteHelper
/// </summary>
/// <typeparam name="T">The content type</typeparam>
/// <returns>The site content model</returns>
T GetContent<T>() where T : SiteContent<T>;
Task<T> GetContentAsync<T>() where T : SiteContent<T>;
}
}
Loading

0 comments on commit 8ee1948

Please sign in to comment.