diff --git a/Piranha.sln b/Piranha.sln
index 8461c4da5..6d3f13210 100644
--- a/Piranha.sln
+++ b/Piranha.sln
@@ -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
@@ -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
@@ -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
@@ -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}
diff --git a/appveyor.yml b/appveyor.yml
index bf39c29cd..e12270d61 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -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
diff --git a/core/Piranha.AspNetCore/AliasMiddleware.cs b/core/Piranha.AspNetCore/AliasMiddleware.cs
index fb3b092e8..8b9c6dadd 100644
--- a/core/Piranha.AspNetCore/AliasMiddleware.cs
+++ b/core/Piranha.AspNetCore/AliasMiddleware.cs
@@ -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;
@@ -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}");
diff --git a/core/Piranha.AspNetCore/ApplicationMiddleware.cs b/core/Piranha.AspNetCore/ApplicationMiddleware.cs
index 2da542f7b..10d9a034a 100644
--- a/core/Piranha.AspNetCore/ApplicationMiddleware.cs
+++ b/core/Piranha.AspNetCore/ApplicationMiddleware.cs
@@ -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;
@@ -37,7 +37,7 @@ public ApplicationMiddleware(RequestDelegate next, ILoggerFactory factory = null
/// An async task
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))
diff --git a/core/Piranha.AspNetCore/ArchiveMiddleware.cs b/core/Piranha.AspNetCore/ArchiveMiddleware.cs
index 791ceb508..602714374 100644
--- a/core/Piranha.AspNetCore/ArchiveMiddleware.cs
+++ b/core/Piranha.AspNetCore/ArchiveMiddleware.cs
@@ -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;
@@ -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}");
diff --git a/core/Piranha.AspNetCore/CoreExtensions.cs b/core/Piranha.AspNetCore/CoreExtensions.cs
index 82af8085e..18b71a725 100644
--- a/core/Piranha.AspNetCore/CoreExtensions.cs
+++ b/core/Piranha.AspNetCore/CoreExtensions.cs
@@ -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;
@@ -112,11 +112,11 @@ public static IApplicationBuilder UsePiranhaStartPage(this IApplicationBuilder b
///
/// The current application builder
/// The builder
- [Obsolete("Please replace UsePiranhaSites with UsePiranhaApplication.", false)]
+ [Obsolete("Please replace UsePiranhaSites with UsePiranhaApplication.", true)]
public static IApplicationBuilder UsePiranhaSites(this IApplicationBuilder builder)
{
return UsePiranhaApplication(builder);
- }
+ }
///
/// Uses the piranha sitemap generation middleware.
diff --git a/core/Piranha.AspNetCore/PageMiddleware.cs b/core/Piranha.AspNetCore/PageMiddleware.cs
index a26f36f5f..46d1e950e 100644
--- a/core/Piranha.AspNetCore/PageMiddleware.cs
+++ b/core/Piranha.AspNetCore/PageMiddleware.cs
@@ -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;
@@ -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}");
diff --git a/core/Piranha.AspNetCore/PostMiddleware.cs b/core/Piranha.AspNetCore/PostMiddleware.cs
index 0bea2c7b9..eb4242155 100644
--- a/core/Piranha.AspNetCore/PostMiddleware.cs
+++ b/core/Piranha.AspNetCore/PostMiddleware.cs
@@ -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;
@@ -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}");
diff --git a/core/Piranha.AspNetCore/Services/ApplicationService.cs b/core/Piranha.AspNetCore/Services/ApplicationService.cs
index 42fbcb13b..8f397fd3a 100644
--- a/core/Piranha.AspNetCore/Services/ApplicationService.cs
+++ b/core/Piranha.AspNetCore/Services/ApplicationService.cs
@@ -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
{
@@ -41,7 +42,7 @@ public class SiteHelper : ISiteHelper
///
/// Default internal constructur.
///
- internal SiteHelper(IApi api)
+ internal SiteHelper(IApi api)
{
_api = api;
}
@@ -51,11 +52,11 @@ internal SiteHelper(IApi api)
///
/// The content type
/// The site content model
- public T GetContent() where T : SiteContent
+ public Task GetContentAsync() where T : SiteContent
{
if (Id != Guid.Empty)
{
- return _api.Sites.GetContentById(Id);
+ return _api.Sites.GetContentByIdAsync(Id);
}
return null;
}
@@ -68,7 +69,7 @@ public class MediaHelper : IMediaHelper
///
/// Default internal constructur.
///
- internal MediaHelper(IApi api)
+ internal MediaHelper(IApi api)
{
_api = api;
}
@@ -120,7 +121,7 @@ public string ResizeImage(Media image, int width, int? height = null)
/// Gets the media helper.
///
public IMediaHelper Media { get; internal set; }
-
+
///
/// Gets the currently requested URL.
///
@@ -146,19 +147,19 @@ public ApplicationService(IApi api)
///
/// Initializes the service.
///
- 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));
@@ -166,18 +167,18 @@ public void Init(HttpContext context)
// 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);
}
}
diff --git a/core/Piranha.AspNetCore/Services/IApplicationService.cs b/core/Piranha.AspNetCore/Services/IApplicationService.cs
index 78d8599a0..4f955e751 100644
--- a/core/Piranha.AspNetCore/Services/IApplicationService.cs
+++ b/core/Piranha.AspNetCore/Services/IApplicationService.cs
@@ -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
@@ -44,6 +45,6 @@ public interface IApplicationService
///
/// Initializes the service.
///
- void Init(HttpContext context);
+ Task InitAsync(HttpContext context);
}
}
diff --git a/core/Piranha.AspNetCore/Services/IMediaHelper.cs b/core/Piranha.AspNetCore/Services/IMediaHelper.cs
index e799d5c16..00f196f6d 100644
--- a/core/Piranha.AspNetCore/Services/IMediaHelper.cs
+++ b/core/Piranha.AspNetCore/Services/IMediaHelper.cs
@@ -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;
diff --git a/core/Piranha.AspNetCore/Services/ISiteHelper.cs b/core/Piranha.AspNetCore/Services/ISiteHelper.cs
index c2a6e89d9..8049b34a0 100644
--- a/core/Piranha.AspNetCore/Services/ISiteHelper.cs
+++ b/core/Piranha.AspNetCore/Services/ISiteHelper.cs
@@ -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
@@ -35,6 +36,6 @@ public interface ISiteHelper
///
/// The content type
/// The site content model
- T GetContent() where T : SiteContent;
+ Task GetContentAsync() where T : SiteContent;
}
}
\ No newline at end of file
diff --git a/core/Piranha.AspNetCore/SitemapMiddleware.cs b/core/Piranha.AspNetCore/SitemapMiddleware.cs
index 98651ded6..c16208318 100644
--- a/core/Piranha.AspNetCore/SitemapMiddleware.cs
+++ b/core/Piranha.AspNetCore/SitemapMiddleware.cs
@@ -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;
@@ -15,6 +15,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Piranha.AspNetCore.Services;
+using Piranha.Services;
using Piranha.Web;
using X.Web.Sitemap;
@@ -53,14 +54,14 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
var siteId = service.Site.Id;
// Get the sitemap for the site
- var pages = api.Sites.GetSitemap(siteId);
+ var pages = await api.Sites.GetSitemapAsync(siteId);
// Generate sitemap.xml
var sitemap = new Sitemap();
foreach (var page in pages)
{
- var urls = GetPageUrls(api, page, baseUrl);
+ var urls = await GetPageUrlsAsync(api, page, baseUrl);
if (urls.Count > 0)
sitemap.AddRange(urls);
@@ -73,7 +74,7 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
await _next.Invoke(context);
}
- private List GetPageUrls(IApi api, Models.SitemapItem item, string baseUrl)
+ private async Task> GetPageUrlsAsync(IApi api, Models.SitemapItem item, string baseUrl)
{
var urls = new List();
@@ -88,7 +89,7 @@ private List GetPageUrls(IApi api, Models.SitemapItem item, string baseUrl)
});
// Get all posts for the blog
- var posts = api.Posts.GetAll(item.Id);
+ var posts = await api.Posts.GetAllAsync(item.Id);
foreach (var post in posts)
{
if (post.Published.HasValue && post.Published.Value <= DateTime.Now)
@@ -105,7 +106,7 @@ private List GetPageUrls(IApi api, Models.SitemapItem item, string baseUrl)
foreach (var child in item.Items)
{
- var childUrls = GetPageUrls(api, child, baseUrl);
+ var childUrls = await GetPageUrlsAsync(api, child, baseUrl);
if (childUrls.Count > 0)
{
diff --git a/core/Piranha.AspNetCore/StartPageMiddleware.cs b/core/Piranha.AspNetCore/StartPageMiddleware.cs
index 0a5d3a123..25d958eeb 100644
--- a/core/Piranha.AspNetCore/StartPageMiddleware.cs
+++ b/core/Piranha.AspNetCore/StartPageMiddleware.cs
@@ -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;
@@ -41,7 +41,7 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
var siteId = service.Site.Id;
var authorized = true;
- var response = StartPageRouter.Invoke(api, url, siteId);
+ var response = await StartPageRouter.InvokeAsync(api, url, siteId);
if (response != null)
{
_logger?.LogInformation($"Found startpage\n Route: {response.Route}\n Params: {response.QueryString}");
@@ -58,7 +58,7 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
if (authorized)
{
service.PageId = response.PageId;
-
+
using (var config = new Config(api))
{
var headers = context.Response.GetTypedHeaders();
diff --git a/core/Piranha.AttributeBuilder/ContentTypeBuilder.cs b/core/Piranha.AttributeBuilder/ContentTypeBuilder.cs
index 60bceb3e8..09b5941c1 100644
--- a/core/Piranha.AttributeBuilder/ContentTypeBuilder.cs
+++ b/core/Piranha.AttributeBuilder/ContentTypeBuilder.cs
@@ -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 Piranha.Extend;
@@ -15,6 +15,7 @@
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
+using System.Threading.Tasks;
namespace Piranha.AttributeBuilder
{
@@ -37,7 +38,15 @@ public T AddType(Type type)
///
/// Builds the page types.
///
- public abstract T Build();
+ public virtual T Build()
+ {
+ return BuildAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Builds the page types.
+ ///
+ public abstract Task BuildAsync();
///
/// Gets the possible content type for the given type.
@@ -75,7 +84,7 @@ public T AddType(Type type)
if (descAttr != null)
{
regionType.Description = descAttr.Text;
- }
+ }
Type type = null;
diff --git a/core/Piranha.AttributeBuilder/PageTypeBuilder.cs b/core/Piranha.AttributeBuilder/PageTypeBuilder.cs
index b388f1234..760e59749 100644
--- a/core/Piranha.AttributeBuilder/PageTypeBuilder.cs
+++ b/core/Piranha.AttributeBuilder/PageTypeBuilder.cs
@@ -1,18 +1,20 @@
/*
- * 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 System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using System.Threading.Tasks;
using Piranha.Models;
+using Piranha.Services;
namespace Piranha.AttributeBuilder
{
@@ -23,7 +25,7 @@ public class PageTypeBuilder : ContentTypeBuilder
///
/// Default constructor.
///
- /// The current api
+ /// The current api
public PageTypeBuilder(IApi api)
{
_api = api;
@@ -32,7 +34,7 @@ public PageTypeBuilder(IApi api)
///
/// Builds the page types.
///
- public override PageTypeBuilder Build()
+ public override async Task BuildAsync()
{
foreach (var type in _types)
{
@@ -41,7 +43,7 @@ public override PageTypeBuilder Build()
if (pageType != null)
{
pageType.Ensure();
- _api.PageTypes.Save(pageType);
+ await _api.PageTypes.SaveAsync(pageType);
}
}
return this;
@@ -49,10 +51,20 @@ public override PageTypeBuilder Build()
///
/// Deletes all page types in the database that doesn't
- /// exist in the database,
+ /// exist in the database,
///
/// The builder
public PageTypeBuilder DeleteOrphans()
+ {
+ return DeleteOrphansAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes all page types in the database that doesn't
+ /// exist in the database,
+ ///
+ /// The builder
+ public async Task DeleteOrphansAsync()
{
var orphans = new List();
var importTypes = new List();
@@ -67,7 +79,7 @@ public PageTypeBuilder DeleteOrphans()
}
// Get all previously imported page types.
- foreach (var pageType in _api.PageTypes.GetAll())
+ foreach (var pageType in await _api.PageTypes.GetAllAsync())
{
if (!importTypes.Any(t => t.Id == pageType.Id))
orphans.Add(pageType);
@@ -76,7 +88,7 @@ public PageTypeBuilder DeleteOrphans()
// Delete all orphans.
foreach (var pageType in orphans)
{
- _api.PageTypes.Delete(pageType);
+ await _api.PageTypes.DeleteAsync(pageType);
}
return this;
}
diff --git a/core/Piranha.AttributeBuilder/PostTypeBuilder.cs b/core/Piranha.AttributeBuilder/PostTypeBuilder.cs
index c7e7a24fc..21442f79a 100644
--- a/core/Piranha.AttributeBuilder/PostTypeBuilder.cs
+++ b/core/Piranha.AttributeBuilder/PostTypeBuilder.cs
@@ -3,16 +3,18 @@
*
* 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.Collections.Generic;
using System.Linq;
using System.Reflection;
+using System.Threading.Tasks;
using Piranha.Models;
+using Piranha.Services;
namespace Piranha.AttributeBuilder
{
@@ -23,7 +25,7 @@ public class PostTypeBuilder : ContentTypeBuilder
///
/// Default constructor.
///
- /// The current api
+ /// The current api
public PostTypeBuilder(IApi api)
{
_api = api;
@@ -32,7 +34,7 @@ public PostTypeBuilder(IApi api)
///
/// Builds the page types.
///
- public override PostTypeBuilder Build()
+ public override async Task BuildAsync()
{
foreach (var type in _types)
{
@@ -41,18 +43,28 @@ public override PostTypeBuilder Build()
if (postType != null)
{
postType.Ensure();
- _api.PostTypes.Save(postType);
+ await _api.PostTypes.SaveAsync(postType);
}
}
return this;
}
///
- /// Deletes all page types in the database that doesn't
- /// exist in the database,
+ /// Deletes all post types in the database that doesn't
+ /// exist in the database,
///
/// The builder
public PostTypeBuilder DeleteOrphans()
+ {
+ return DeleteOrphansAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes all page types in the database that doesn't
+ /// exist in the database,
+ ///
+ /// The builder
+ public async Task DeleteOrphansAsync()
{
var orphans = new List();
var importTypes = new List();
@@ -67,7 +79,7 @@ public PostTypeBuilder DeleteOrphans()
}
// Get all previously imported page types.
- foreach (var postType in _api.PostTypes.GetAll())
+ foreach (var postType in await _api.PostTypes.GetAllAsync())
{
if (!importTypes.Any(t => t.Id == postType.Id))
orphans.Add(postType);
@@ -76,7 +88,7 @@ public PostTypeBuilder DeleteOrphans()
// Delete all orphans.
foreach (var postType in orphans)
{
- _api.PostTypes.Delete(postType);
+ await _api.PostTypes.DeleteAsync(postType);
}
return this;
}
diff --git a/core/Piranha.AttributeBuilder/SiteTypeBuilder.cs b/core/Piranha.AttributeBuilder/SiteTypeBuilder.cs
index b57cabe13..b4de79c15 100644
--- a/core/Piranha.AttributeBuilder/SiteTypeBuilder.cs
+++ b/core/Piranha.AttributeBuilder/SiteTypeBuilder.cs
@@ -3,16 +3,18 @@
*
* 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.Collections.Generic;
using System.Linq;
using System.Reflection;
+using System.Threading.Tasks;
using Piranha.Models;
+using Piranha.Services;
namespace Piranha.AttributeBuilder
{
@@ -23,7 +25,7 @@ public class SiteTypeBuilder : ContentTypeBuilder
///
/// Default constructor.
///
- /// The current api
+ /// The current api
public SiteTypeBuilder(IApi api)
{
_api = api;
@@ -32,7 +34,7 @@ public SiteTypeBuilder(IApi api)
///
/// Builds the site types.
///
- public override SiteTypeBuilder Build()
+ public override async Task BuildAsync()
{
foreach (var type in _types)
{
@@ -41,7 +43,7 @@ public override SiteTypeBuilder Build()
if (siteType != null)
{
siteType.Ensure();
- _api.SiteTypes.Save(siteType);
+ await _api.SiteTypes.SaveAsync(siteType);
}
}
return this;
@@ -49,10 +51,20 @@ public override SiteTypeBuilder Build()
///
/// Deletes all site types in the database that doesn't
- /// exist in the import,
+ /// exist in the database,
///
/// The builder
public SiteTypeBuilder DeleteOrphans()
+ {
+ return DeleteOrphansAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes all site types in the database that doesn't
+ /// exist in the import,
+ ///
+ /// The builder
+ public async Task DeleteOrphansAsync()
{
var orphans = new List();
var importTypes = new List();
@@ -67,7 +79,7 @@ public SiteTypeBuilder DeleteOrphans()
}
// Get all previously imported page types.
- foreach (var siteType in _api.SiteTypes.GetAll())
+ foreach (var siteType in await _api.SiteTypes.GetAllAsync())
{
if (!importTypes.Any(t => t.Id == siteType.Id))
orphans.Add(siteType);
@@ -76,7 +88,7 @@ public SiteTypeBuilder DeleteOrphans()
// Delete all orphans.
foreach (var siteType in orphans)
{
- _api.SiteTypes.Delete(siteType);
+ await _api.SiteTypes.DeleteAsync(siteType);
}
return this;
}
diff --git a/core/Piranha.Extensions.Sync/AliasServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/AliasServiceSyncExtensions.cs
new file mode 100644
index 000000000..fe54aba5f
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/AliasServiceSyncExtensions.cs
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class AliasServiceSyncExtensions
+ {
+ ///
+ /// Gets all available models for the specified site.
+ ///
+ /// The optional site id
+ /// The available models
+ public static IEnumerable GetAll(this AliasService service, Guid? siteId = null)
+ {
+ return service.GetAllAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the specified id.
+ ///
+ /// The unique id
+ /// The model, or null if it doesn't exist
+ public static Alias GetById(this AliasService service, Guid id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the given alias url.
+ ///
+ /// The unique url
+ /// The optional site id
+ /// The model
+ public static Alias GetByAliasUrl(this AliasService service, string url, Guid? siteId = null)
+ {
+ return service.GetByAliasUrlAsync(url, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the given redirect url.
+ ///
+ /// The unique url
+ /// The optional site id
+ /// The model
+ public static IEnumerable GetByRedirectUrl(this AliasService service, string url, Guid? siteId = null)
+ {
+ return service.GetByRedirectUrlAsync(url, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The model
+ public static void Save(this AliasService service, Alias model)
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this AliasService service, Guid id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this AliasService service, Alias model)
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/ArchiveServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/ArchiveServiceSyncExtensions.cs
new file mode 100644
index 000000000..c375886ac
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/ArchiveServiceSyncExtensions.cs
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class ArchiveServiceSyncExtensions
+ {
+ ///
+ /// Gets the specified post archive for the specified filter.
+ ///
+ /// The archive page id
+ /// The current page of the archive
+ /// The optional category id
+ /// The optional tag id
+ /// The optional year
+ /// The optional month
+ /// The optional page size
+ /// The archive model type
+ /// The archive model
+ public static T GetById(this ArchiveService service, Guid archiveId, int? currentPage = 1, Guid? categoryId = null,
+ Guid? tagId = null, int? year = null, int? month = null, int? pageSize = null) where T : ArchivePage
+ {
+ return service.GetByIdAsync(archiveId, currentPage, categoryId, tagId, year, month, pageSize)
+ .GetAwaiter()
+ .GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/MediaServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/MediaServiceSyncExtensions.cs
new file mode 100644
index 000000000..f23d4f618
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/MediaServiceSyncExtensions.cs
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class MediaServiceSyncExtensions
+ {
+ ///
+ /// Gets all media available in the specified folder.
+ ///
+ /// The optional folder id
+ /// The available media
+ public static IEnumerable GetAll(this MediaService service, Guid? folderId = null)
+ {
+ return service.GetAllAsync(folderId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets all media folders available in the specified
+ /// folder.
+ ///
+ /// The optional folder id
+ /// The available media folders
+ public static IEnumerable GetAllFolders(this MediaService service, Guid? folderId = null)
+ {
+ return service.GetAllFoldersAsync(folderId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the media with the given id.
+ ///
+ /// The unique id
+ /// The media
+ public static Media GetById(this MediaService service, Guid id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the media folder with the given id.
+ ///
+ /// The unique id
+ /// The media folder
+ public static MediaFolder GetFolderById(this MediaService service, Guid id)
+ {
+ return service.GetFolderByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the hierachical media structure.
+ ///
+ /// The media structure
+ public static Models.MediaStructure GetStructure(this MediaService service)
+ {
+ return service.GetStructureAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The content to save
+ public static void Save(this MediaService service, Models.MediaContent content)
+ {
+ service.SaveAsync(content).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The model
+ public static void SaveFolder(this MediaService service, MediaFolder model)
+ {
+ service.SaveFolderAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Moves the media to the folder with the specified id.
+ ///
+ /// The media
+ /// The folder id
+ public static void Move(this MediaService service, Media model, Guid? folderId)
+ {
+ service.MoveAsync(model, folderId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the media with the given id.
+ ///
+ /// The unique id
+ public static void Delete(this MediaService service, Guid id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The media
+ public static void Delete(this MediaService service, Media model)
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the media folder with the given id.
+ ///
+ /// The unique id
+ public static void DeleteFolder(this MediaService service, Guid id)
+ {
+ service.DeleteFolderAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The media
+ public static void DeleteFolder(this MediaService service, MediaFolder model)
+ {
+ service.DeleteFolderAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/PageServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/PageServiceSyncExtensions.cs
new file mode 100644
index 000000000..25b88747c
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/PageServiceSyncExtensions.cs
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class PageServiceSyncExtensions
+ {
+ ///
+ /// Detaches a copy and initializes it as a standalone page
+ ///
+ /// The standalone page
+ public static void Detach(this PageService service, T model) where T : PageBase
+ {
+ service.DetachAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets all available models.
+ ///
+ /// The available models
+ public static IEnumerable GetAll(this PageService service, Guid? siteId = null)
+ {
+ return service.GetAllAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets all available models.
+ ///
+ /// The available models
+ public static IEnumerable GetAll(this PageService service, Guid? siteId = null) where T : PageBase
+ {
+ return service.GetAllAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the available blog pages for the current site.
+ ///
+ /// The optional site id
+ /// The pages
+ public static IEnumerable GetAllBlogs(this PageService service, Guid? siteId = null)
+ {
+ return service.GetAllBlogsAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the available blog pages for the current site.
+ ///
+ /// The optional site id
+ /// The pages
+ public static IEnumerable GetAllBlogs(this PageService service, Guid? siteId = null) where T : PageBase
+ {
+ return service.GetAllBlogsAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the site startpage.
+ ///
+ /// The optional site id
+ /// The page model
+ public static DynamicPage GetStartpage(this PageService service, Guid? siteId = null)
+ {
+ return service.GetStartpageAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the site startpage.
+ ///
+ /// The model type
+ /// The optional site id
+ /// The page model
+ public static T GetStartpage(this PageService service, Guid? siteId = null) where T : PageBase
+ {
+ return service.GetStartpageAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the page model with the specified id.
+ ///
+ /// The unique id
+ /// The page model
+ public static DynamicPage GetById(this PageService service, Guid id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the specified id.
+ ///
+ /// The unique id
+ /// The model, or null if it doesn't exist
+ public static T GetById(this PageService service, Guid id) where T : PageBase
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the page model with the specified slug.
+ ///
+ /// The unique slug
+ /// The optional site id
+ /// The page model
+ public static DynamicPage GetBySlug(this PageService service, string slug, Guid? siteId = null)
+ {
+ return service.GetBySlugAsync(slug, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the page model with the specified slug.
+ ///
+ /// The model type
+ /// The unique slug
+ /// The optional site id
+ /// The page model
+ public static T GetBySlug(this PageService service, string slug, Guid? siteId = null) where T : PageBase
+ {
+ return service.GetBySlugAsync(slug, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the id for the page with the given slug.
+ ///
+ /// The unique slug
+ /// The optional page id
+ /// The id
+ public static Guid? GetIdBySlug(this PageService service, string slug, Guid? siteId = null)
+ {
+ return service.GetIdBySlugAsync(slug, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Moves the current page in the structure.
+ ///
+ /// The model type
+ /// The page to move
+ /// The new parent id
+ /// The new sort order
+ public static void Move(this PageService service, T model, Guid? parentId, int sortOrder) where T : PageBase
+ {
+ service.MoveAsync(model, parentId, sortOrder).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Saves the given page model
+ ///
+ /// The page model
+ public static void Save(this PageService service, T model) where T : PageBase
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this PageService service, Guid id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this PageService service, T model) where T : PageBase
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/PageTypeServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/PageTypeServiceSyncExtensions.cs
new file mode 100644
index 000000000..d74c2f1dd
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/PageTypeServiceSyncExtensions.cs
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class PageTypeServiceSyncExtensions
+ {
+ ///
+ /// Gets all available models.
+ ///
+ /// The available models
+ public static IEnumerable GetAll(this PageTypeService service)
+ {
+ return service.GetAllAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the specified id.
+ ///
+ /// The unique i
+ ///
+ public static Models.PageType GetById(this PageTypeService service, string id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The model
+ public static void Save(this PageTypeService service, PageType model)
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this PageTypeService service, string id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this PageTypeService service, PageType model)
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/ParamServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/ParamServiceSyncExtensions.cs
new file mode 100644
index 000000000..b6c0ecd7b
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/ParamServiceSyncExtensions.cs
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class ParamServiceSyncExtensions
+ {
+ ///
+ /// Gets all available models.
+ ///
+ /// The available models
+ public static IEnumerable GetAll(this ParamService service)
+ {
+ return service.GetAllAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the specified id.
+ ///
+ /// The unique id
+ /// The model, or null if it doesn't exist
+ public static Param GetById(this ParamService service, Guid id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the given key.
+ ///
+ /// The unique key
+ /// The model
+ public static Param GetByKey(this ParamService service, string key) {
+ return service.GetByKeyAsync(key).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The model
+ public static void Save(this ParamService service, Param model)
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this ParamService service, Guid id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this ParamService service, Param model)
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/Piranha.Extensions.Sync.csproj b/core/Piranha.Extensions.Sync/Piranha.Extensions.Sync.csproj
new file mode 100644
index 000000000..b22c547e0
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/Piranha.Extensions.Sync.csproj
@@ -0,0 +1,13 @@
+
+
+
+ netstandard2.0
+ 6.0.0-alpha1
+ Piranha CMS
+
+
+
+
+
+
+
diff --git a/core/Piranha.Extensions.Sync/PostServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/PostServiceSyncExtensions.cs
new file mode 100644
index 000000000..8efcc999e
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/PostServiceSyncExtensions.cs
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class PostServiceSyncExtensions
+ {
+ ///
+ /// Gets the available posts for the specified blog.
+ ///
+ /// The unique blog id
+ /// The posts
+ public static IEnumerable GetAll(this PostService service, Guid blogId)
+ {
+ return service.GetAllAsync(blogId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the available post items.
+ ///
+ /// The unique id
+ /// The posts
+ public static IEnumerable GetAll(this PostService service, Guid blogId) where T : PostBase
+ {
+ return service.GetAllAsync(blogId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the available posts for the specified blog.
+ ///
+ /// The optional site id
+ /// The posts
+ public static IEnumerable GetAllBySiteId(this PostService service, Guid? siteId = null)
+ {
+ return service.GetAllBySiteIdAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the available post items.
+ ///
+ /// The optional site id
+ /// The posts
+ public static IEnumerable GetAllBySiteId(this PostService service, Guid? siteId = null) where T : PostBase
+ {
+ return service.GetAllBySiteIdAsync(siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the available posts for the specified blog.
+ ///
+ /// The blog slug
+ /// The optional site id
+ /// The posts
+ public static IEnumerable GetAll(this PostService service, string slug, Guid? siteId = null)
+ {
+ return service.GetAllAsync(slug, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the available posts for the specified blog.
+ ///
+ /// The blog slug
+ /// The optional site id
+ /// The posts
+ public static IEnumerable GetAll(this PostService service, string slug, Guid? siteId = null) where T : PostBase
+ {
+ return service.GetAllAsync(slug, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets all available categories for the specified blog.
+ ///
+ /// The blog id
+ /// The available categories
+ public static IEnumerable GetAllCategories(this PostService service, Guid blogId)
+ {
+ return service.GetAllCategoriesAsync(blogId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets all available tags for the specified blog.
+ ///
+ /// The blog id
+ /// The available tags
+ public static IEnumerable GetAllTags(this PostService service, Guid blogId)
+ {
+ return service.GetAllTagsAsync(blogId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the post model with the specified id.
+ ///
+ /// The unique id
+ /// The post model
+ public static DynamicPost GetById(this PostService service, Guid id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the post model with the specified id.
+ ///
+ /// The model type
+ /// The unique id
+ /// The post model
+ public static T GetById(this PostService service, Guid id) where T : PostBase
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the post model with the specified slug.
+ ///
+ /// The unique blog slug
+ /// The unique slug
+ /// The optional site id
+ /// The post model
+ public static DynamicPost GetBySlug(this PostService service, string blog, string slug, Guid? siteId = null)
+ {
+ return service.GetBySlugAsync(blog, slug, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the post model with the specified slug.
+ ///
+ /// The model type
+ /// The unique blog slug
+ /// The unique slug
+ /// The optional site id
+ /// The post model
+ public static T GetBySlug(this PostService service, string blog, string slug, Guid? siteId = null) where T : PostBase
+ {
+ return service.GetBySlugAsync(blog, slug, siteId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the post model with the specified slug.
+ ///
+ /// The unique blog slug
+ /// The unique slug
+ /// The post model
+ public static DynamicPost GetBySlug(this PostService service, Guid blogId, string slug)
+ {
+ return service.GetBySlugAsync(blogId, slug).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the post model with the specified slug.
+ ///
+ /// The unique blog slug
+ /// The unique slug
+ /// The post model
+ public static T GetBySlug(this PostService service, Guid blogId, string slug) where T : PostBase
+ {
+ return service.GetBySlugAsync(blogId, slug).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the category with the given slug.
+ ///
+ /// The blog id
+ /// The unique slug
+ /// The model
+ public static Taxonomy GetCategoryBySlug(this PostService service, Guid blogId, string slug)
+ {
+ return service.GetCategoryBySlugAsync(blogId, slug).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the tag with the given slug.
+ ///
+ /// The blog id
+ /// The unique slug
+ /// The model
+ public static Taxonomy GetTagBySlug(this PostService service, Guid blogId, string slug)
+ {
+ return service.GetTagBySlugAsync(blogId, slug).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Saves the given post model
+ ///
+ /// The post model
+ public static void Save(this PostService service, T model) where T : PostBase
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this PostService service, Guid id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this PostService service, T model) where T : PostBase
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/PostTypeServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/PostTypeServiceSyncExtensions.cs
new file mode 100644
index 000000000..d7ced053f
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/PostTypeServiceSyncExtensions.cs
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class PostTypeServiceSyncExtensions
+ {
+ ///
+ /// Gets all available models.
+ ///
+ /// The available models
+ public static IEnumerable GetAll(this PostTypeService service)
+ {
+ return service.GetAllAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the specified id.
+ ///
+ /// The unique i
+ ///
+ public static PostType GetById(this PostTypeService service, string id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The model
+ public static void Save(this PostTypeService service, PostType model)
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this PostTypeService service, string id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this PostTypeService service, PostType model)
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/SiteServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/SiteServiceSyncExtensions.cs
new file mode 100644
index 000000000..9567a31b7
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/SiteServiceSyncExtensions.cs
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class SiteServiceSyncExtensions
+ {
+ ///
+ /// Gets all available models.
+ ///
+ /// The available models
+ public static IEnumerable GetAll(this SiteService service)
+ {
+ return service.GetAllAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the specified id.
+ ///
+ /// The unique id
+ /// The model, or null if it doesn't exist
+ public static Site GetById(this SiteService service, Guid id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the given internal id.
+ ///
+ /// The unique internal i
+ /// The model
+ public static Site GetByInternalId(this SiteService service, string internalId)
+ {
+ return service.GetByInternalIdAsync(internalId).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the given hostname.
+ ///
+ /// The hostname
+ /// The model
+ public static Site GetByHostname(this SiteService service, string hostname)
+ {
+ return service.GetByHostnameAsync(hostname).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the default side.
+ ///
+ /// The modell, or NULL if it doesnt exist
+ public static Site GetDefault(this SiteService service)
+ {
+ return service.GetDefaultAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the site content for given site id.
+ ///
+ /// Site id
+ /// The site content model
+ public static DynamicSiteContent GetContentById(this SiteService service, Guid id)
+ {
+ return service.GetContentByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the site content for given site id.
+ ///
+ /// Site id
+ /// The site model type
+ /// The site content model
+ public static T GetContentById(this SiteService service, Guid id) where T : SiteContent
+ {
+ return service.GetContentByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the hierachical sitemap structure.
+ ///
+ /// The optional site id
+ /// If only published items should be included
+ /// The sitemap
+ public static Sitemap GetSitemap(this SiteService service, Guid? id = null, bool onlyPublished = true)
+ {
+ return service.GetSitemapAsync(id, onlyPublished).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The model
+ public static void Save(this SiteService service, Site model)
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Saves the given site content to the site with the
+ /// given id.
+ ///
+ /// The site id
+ /// The site content model
+ /// The site content type
+ public static void SaveContent(this SiteService service, Guid siteId, T model) where T : SiteContent
+ {
+ service.SaveContentAsync(siteId, model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this SiteService service, Guid id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this SiteService service, Site model)
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Extensions.Sync/SiteTypeServiceSyncExtensions.cs b/core/Piranha.Extensions.Sync/SiteTypeServiceSyncExtensions.cs
new file mode 100644
index 000000000..bc7f3abe8
--- /dev/null
+++ b/core/Piranha.Extensions.Sync/SiteTypeServiceSyncExtensions.cs
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2018 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
+
+namespace Piranha.Services
+{
+ public static class SiteTypeServiceSyncExtensions
+ {
+ ///
+ /// Gets all available models.
+ ///
+ /// The available models
+ public static IEnumerable GetAll(this SiteTypeService service)
+ {
+ return service.GetAllAsync().GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Gets the model with the specified id.
+ ///
+ /// The unique i
+ ///
+ public static Models.SiteType GetById(this SiteTypeService service, string id)
+ {
+ return service.GetByIdAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Adds or updates the given model in the database
+ /// depending on its state.
+ ///
+ /// The model
+ public static void Save(this SiteTypeService service, SiteType model)
+ {
+ service.SaveAsync(model).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the model with the specified id.
+ ///
+ /// The unique id
+ public static void Delete(this SiteTypeService service, string id)
+ {
+ service.DeleteAsync(id).GetAwaiter().GetResult();
+ }
+
+ ///
+ /// Deletes the given model.
+ ///
+ /// The model
+ public static void Delete(this SiteTypeService service, SiteType model)
+ {
+ service.DeleteAsync(model).GetAwaiter().GetResult();
+ }
+ }
+}
diff --git a/core/Piranha.Manager/Areas/Manager/Controllers/AliasController.cs b/core/Piranha.Manager/Areas/Manager/Controllers/AliasController.cs
index 359ac13bb..241676e65 100644
--- a/core/Piranha.Manager/Areas/Manager/Controllers/AliasController.cs
+++ b/core/Piranha.Manager/Areas/Manager/Controllers/AliasController.cs
@@ -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 System;
@@ -13,6 +13,7 @@
using Microsoft.AspNetCore.Mvc;
using Piranha.Manager;
using Piranha.Models;
+using Piranha.Services;
namespace Piranha.Areas.Manager.Controllers
{
@@ -59,7 +60,7 @@ public IActionResult Add(Models.AliasEditModel model)
{
try
{
- _api.Aliases.Save(new Data.Alias
+ _api.Aliases.Save(new Alias
{
SiteId = model.SiteId,
AliasUrl = model.AliasUrl,
diff --git a/core/Piranha.Manager/Areas/Manager/Controllers/BlockController.cs b/core/Piranha.Manager/Areas/Manager/Controllers/BlockController.cs
index 1f5626b84..0c0ab6a10 100644
--- a/core/Piranha.Manager/Areas/Manager/Controllers/BlockController.cs
+++ b/core/Piranha.Manager/Areas/Manager/Controllers/BlockController.cs
@@ -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.Mvc;
@@ -16,18 +16,16 @@ namespace Piranha.Areas.Manager.Controllers
[Area("Manager")]
public class BlockController : ManagerAreaControllerBase
{
- private readonly IContentService _contentService;
+ private readonly IContentFactory _factory;
///
/// Default constructor.
///
/// The current api
- /// The content service factory
- public BlockController(IApi api, IContentServiceFactory factory) : base(api)
+ /// The content factory
+ public BlockController(IApi api, IContentFactory factory) : base(api)
{
- // Block transformation is not dependent on which content
- // type is actually selected, so let's create a page service.
- _contentService = factory.CreatePageService();
+ _factory = factory;
}
///
@@ -38,7 +36,7 @@ public BlockController(IApi api, IContentServiceFactory factory) : base(api)
[Route("manager/block/create")]
public IActionResult AddBlock([FromBody]Models.ContentBlockModel model)
{
- var block = (Extend.Block)_contentService.CreateBlock(model.TypeName);
+ var block = (Extend.Block)_factory.CreateBlock(model.TypeName);
if (block != null)
{
diff --git a/core/Piranha.Manager/Areas/Manager/Controllers/MediaController.cs b/core/Piranha.Manager/Areas/Manager/Controllers/MediaController.cs
index 35dfad594..8e7bc7996 100644
--- a/core/Piranha.Manager/Areas/Manager/Controllers/MediaController.cs
+++ b/core/Piranha.Manager/Areas/Manager/Controllers/MediaController.cs
@@ -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 System;
@@ -16,6 +16,7 @@
using Microsoft.AspNetCore.Mvc;
using Piranha.Manager;
using Piranha.Models;
+using Piranha.Services;
namespace Piranha.Areas.Manager.Controllers
{
@@ -158,7 +159,7 @@ public IActionResult AddFolder(Models.MediaFolderModel model)
{
if (!string.IsNullOrWhiteSpace(model.Name))
{
- _api.Media.SaveFolder(new Data.MediaFolder
+ _api.Media.SaveFolder(new MediaFolder
{
ParentId = model.ParentId,
Name = model.Name
diff --git a/core/Piranha.Manager/Areas/Manager/Controllers/PageController.cs b/core/Piranha.Manager/Areas/Manager/Controllers/PageController.cs
index a5792864c..ab3dcb75a 100644
--- a/core/Piranha.Manager/Areas/Manager/Controllers/PageController.cs
+++ b/core/Piranha.Manager/Areas/Manager/Controllers/PageController.cs
@@ -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 System;
@@ -26,7 +26,7 @@ public class PageController : ManagerAreaControllerBase
{
private const string COOKIE_SELECTEDSITE = "PiranhaManager_SelectedSite";
private readonly PageEditService _editService;
- private readonly IContentService _contentService;
+ private readonly IContentFactory _factory;
private readonly IHubContext _hub;
///
@@ -35,10 +35,10 @@ public class PageController : ManagerAreaControllerBase
/// The current api
/// The current page edit service
/// The content service factory
- public PageController(IApi api, PageEditService editService, IContentServiceFactory factory, IHubContext hub) : base(api)
- {
+ public PageController(IApi api, PageEditService editService, IContentFactory factory, IHubContext hub) : base(api)
+ {
_editService = editService;
- _contentService = factory.CreatePageService();
+ _factory = factory;
_hub = hub;
}
@@ -47,15 +47,15 @@ public PageController(IApi api, PageEditService editService, IContentServiceFact
///
[Route("manager/pages/{pageId?}")]
[Authorize(Policy = Permission.Pages)]
- public ViewResult List(string pageId = null)
+ public ViewResult List(string pageId = null)
{
// Get the currently selected site from the request cookies
var siteId = Request.Cookies[COOKIE_SELECTEDSITE];
Guid? site = null;
- if (!string.IsNullOrWhiteSpace(siteId))
- {
- site = new Guid(siteId);
+ if (!string.IsNullOrWhiteSpace(siteId))
+ {
+ site = new Guid(siteId);
}
return ListSite(site, pageId);
}
@@ -65,19 +65,19 @@ public ViewResult List(string pageId = null)
///
[Route("manager/pages/site/{siteId:Guid?}/{pageId?}")]
[Authorize(Policy = Permission.Pages)]
- public ViewResult ListSite(Guid? siteId, string pageId = null)
+ public ViewResult ListSite(Guid? siteId, string pageId = null)
{
var model = Models.PageListModel.Get(_api, siteId, pageId);
// Store a cookie on our currently selected site
- if (siteId.HasValue)
- {
- Response.Cookies.Append(COOKIE_SELECTEDSITE, siteId.ToString());
- }
- else
- {
- Response.Cookies.Delete(COOKIE_SELECTEDSITE);
- }
+ if (siteId.HasValue)
+ {
+ Response.Cookies.Append(COOKIE_SELECTEDSITE, siteId.ToString());
+ }
+ else
+ {
+ Response.Cookies.Delete(COOKIE_SELECTEDSITE);
+ }
return View("List", model);
}
@@ -87,7 +87,7 @@ public ViewResult ListSite(Guid? siteId, string pageId = null)
/// The page id
[Route("manager/page/{id:Guid}")]
[Authorize(Policy = Permission.PagesEdit)]
- public IActionResult Edit(Guid id)
+ public IActionResult Edit(Guid id)
{
return View(_editService.GetById(id));
}
@@ -99,7 +99,7 @@ public IActionResult Edit(Guid id)
/// The optional site id
[Route("manager/page/add/{type}/{siteId:Guid?}")]
[Authorize(Policy = Permission.PagesAdd)]
- public IActionResult Add(string type, Guid? siteId = null)
+ public IActionResult Add(string type, Guid? siteId = null)
{
var sitemap = _api.Sites.GetSitemap(siteId, onlyPublished: false);
var model = _editService.Create(type, siteId);
@@ -117,7 +117,7 @@ public IActionResult Add(string type, Guid? siteId = null)
/// The optional site id
[Route("manager/page/add/{type}/{sortOrder:int}/{parentId:Guid?}")]
[Authorize(Policy = Permission.PagesAdd)]
- public IActionResult AddAt(string type, int sortOrder, Guid? parentId = null)
+ public IActionResult AddAt(string type, int sortOrder, Guid? parentId = null)
{
return AddAt(Guid.Empty, type, sortOrder, parentId);
}
@@ -131,7 +131,7 @@ public IActionResult AddAt(string type, int sortOrder, Guid? parentId = null)
/// The optional site id
[Route("manager/page/add/site/{siteId:Guid}/{type}/{sortOrder:int}/{parentId:Guid?}")]
[Authorize(Policy = Permission.PagesAdd)]
- public IActionResult AddAt(Guid siteId, string type, int sortOrder, Guid? parentId = null)
+ public IActionResult AddAt(Guid siteId, string type, int sortOrder, Guid? parentId = null)
{
var model = _editService.Create(type, siteId != Guid.Empty ? siteId : (Guid?)null);
@@ -139,8 +139,8 @@ public IActionResult AddAt(Guid siteId, string type, int sortOrder, Guid? parent
model.SortOrder = sortOrder;
return View("Edit", model);
- }
-
+ }
+
///
/// Adds a new copy of the specified page.
///
@@ -148,9 +148,9 @@ public IActionResult AddAt(Guid siteId, string type, int sortOrder, Guid? parent
/// The optional site id
[Route("manager/page/copy/{originalId:Guid}/{siteId:Guid?}")]
[Authorize(Policy = Permission.PagesAdd)]
- public IActionResult AddCopy(Guid originalId, Guid? siteId = null)
+ public IActionResult AddCopy(Guid originalId, Guid? siteId = null)
{
- if (!siteId.HasValue)
+ if (!siteId.HasValue)
{
var site = _api.Sites.GetDefault();
siteId = site.Id;
@@ -159,7 +159,7 @@ public IActionResult AddCopy(Guid originalId, Guid? siteId = null)
var sitemap = _api.Sites.GetSitemap(siteId, onlyPublished: false);
var model = _editService.GetById(originalId);
- if (model.OriginalPageId.HasValue)
+ if (model.OriginalPageId.HasValue)
{
ErrorMessage("Can't create a copy from a copied page.");
return RedirectToAction("List", new { siteId = siteId.Value });
@@ -169,7 +169,7 @@ public IActionResult AddCopy(Guid originalId, Guid? siteId = null)
model.Id = Guid.NewGuid();
model.SiteId = siteId.Value;
model.ParentId = null;
- model.SortOrder = sitemap.Count;
+ model.SortOrder = sitemap.Count;
model.Title = "Copy of " + model.Title;
model.NavigationTitle = "";
model.Created = model.LastModified = DateTime.MinValue;
@@ -181,14 +181,14 @@ public IActionResult AddCopy(Guid originalId, Guid? siteId = null)
[Route("manager/page/preview/{id:Guid}")]
[Authorize(Policy = Permission.PagesEdit)]
- public IActionResult Preview(Guid id)
+ public IActionResult Preview(Guid id)
{
var page = _api.Pages.GetById(id);
- if (page != null)
- {
- return View("_Preview", new Models.PreviewModel { Id = id, Permalink = page.Permalink });
- }
+ if (page != null)
+ {
+ return View("_Preview", new Models.PreviewModel { Id = id, Permalink = page.Permalink });
+ }
return NotFound();
}
@@ -198,21 +198,21 @@ public IActionResult Preview(Guid id)
/// The page id
[Route("manager/page/detach/{id:Guid}")]
[Authorize(Policy = Permission.PagesSave)]
- public IActionResult Detach(Guid id)
+ public IActionResult Detach(Guid id)
{
var page = _api.Pages.GetById(id);
- if (page != null && page.OriginalPageId.HasValue)
+ if (page != null && page.OriginalPageId.HasValue)
{
_api.Pages.Detach(page);
SuccessMessage("The page has been detached from its original.");
return RedirectToAction("Edit", new { id });
- }
- else
+ }
+ else
{
ErrorMessage("The page could not be be detached.");
- return RedirectToAction("Edit", new { id });
+ return RedirectToAction("Edit", new { id });
}
}
@@ -223,10 +223,10 @@ public IActionResult Detach(Guid id)
[HttpPost]
[Route("manager/page/save")]
[Authorize(Policy = Permission.PagesSave)]
- public async Task Save(Models.PageEditModel model)
+ public async Task Save(Models.PageEditModel model)
{
// Validate
- if (string.IsNullOrWhiteSpace(model.Title))
+ if (string.IsNullOrWhiteSpace(model.Title))
{
return BadRequest();
}
@@ -234,13 +234,13 @@ public async Task Save(Models.PageEditModel model)
var ret = _editService.Save(model, out var alias);
// Save
- if (ret)
+ if (ret)
{
if (_hub != null)
await _hub.Clients.All.SendAsync("Update", model.Id);
- if (!string.IsNullOrWhiteSpace(alias))
- {
+ if (!string.IsNullOrWhiteSpace(alias))
+ {
return Json(new
{
Location = Url.Action("Edit", new { id = model.Id }),
@@ -251,14 +251,14 @@ public async Task Save(Models.PageEditModel model)
SiteId = model.SiteId,
PageId = model.Id
}
- });
- }
- else
- {
- return Json(new { Location = Url.Action("Edit", new { id = model.Id }) });
- }
- }
- else
+ });
+ }
+ else
+ {
+ return Json(new { Location = Url.Action("Edit", new { id = model.Id }) });
+ }
+ }
+ else
{
return StatusCode(500);
}
@@ -271,24 +271,24 @@ public async Task Save(Models.PageEditModel model)
[HttpPost]
[Route("manager/page/publish")]
[Authorize(Policy = Permission.PagesPublish)]
- public IActionResult Publish(Models.PageEditModel model)
+ public IActionResult Publish(Models.PageEditModel model)
{
// Validate
- if (string.IsNullOrWhiteSpace(model.Title))
+ if (string.IsNullOrWhiteSpace(model.Title))
{
return BadRequest();
}
// Save
- if (_editService.Save(model, out var alias, true))
+ if (_editService.Save(model, out var alias, true))
{
return Json(new
{
Published = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
Location = Url.Action("Edit", new { id = model.Id })
});
- }
- else
+ }
+ else
{
return StatusCode(500);
}
@@ -301,17 +301,17 @@ public IActionResult Publish(Models.PageEditModel model)
[HttpPost]
[Route("manager/page/unpublish")]
[Authorize(Policy = Permission.PagesPublish)]
- public IActionResult UnPublish(Models.PageEditModel model)
+ public IActionResult UnPublish(Models.PageEditModel model)
{
- if (_editService.Save(model, out var alias, false))
+ if (_editService.Save(model, out var alias, false))
{
return Json(new
{
Unpublished = true,
Location = Url.Action("Edit", new { id = model.Id })
});
- }
- else
+ }
+ else
{
return StatusCode(500);
}
@@ -324,7 +324,7 @@ public IActionResult UnPublish(Models.PageEditModel model)
[HttpPost]
[Route("manager/pages/move")]
[Authorize(Policy = Permission.PagesEdit)]
- public IActionResult Move([FromBody]Models.PageStructureModel structure)
+ public IActionResult Move([FromBody]Models.PageStructureModel structure)
{
Guid? siteId = null;
@@ -332,22 +332,22 @@ public IActionResult Move([FromBody]Models.PageStructureModel structure)
{
var page = _api.Pages.GetById(new Guid(structure.Items[0].Id));
- if (page != null)
- {
+ if (page != null)
+ {
siteId = page.SiteId;
- }
+ }
}
- for (var n = 0; n < structure.Items.Count; n++)
+ for (var n = 0; n < structure.Items.Count; n++)
{
- if (MovePage(structure.Items[n], n))
- {
- break;
+ if (MovePage(structure.Items[n], n))
+ {
+ break;
}
}
- using (var config = new Config(_api))
+ using (var config = new Config(_api))
{
- return View("Partial/_Sitemap", new Models.SitemapModel
+ return View("Partial/_Sitemap", new Models.SitemapModel
{
Sitemap = _api.Sites.GetSitemap(siteId, onlyPublished: false),
ExpandedLevels = config.ManagerExpandedSitemapLevels
@@ -361,7 +361,7 @@ public IActionResult Move([FromBody]Models.PageStructureModel structure)
/// The unique id
[Route("manager/page/delete/{id:Guid}")]
[Authorize(Policy = Permission.PagesDelete)]
- public IActionResult Delete(Guid id)
+ public IActionResult Delete(Guid id)
{
_api.Pages.Delete(id);
SuccessMessage("The page has been deleted");
@@ -375,19 +375,19 @@ public IActionResult Delete(Guid id)
[HttpPost]
[Route("manager/page/region")]
[Authorize(Policy = Permission.Pages)]
- public IActionResult AddRegion([FromBody]Models.PageRegionModel model)
+ public IActionResult AddRegion([FromBody]Models.PageRegionModel model)
{
var pageType = _api.PageTypes.GetById(model.PageTypeId);
- if (pageType != null)
+ if (pageType != null)
{
var regionType = pageType.Regions.SingleOrDefault(r => r.Id == model.RegionTypeId);
- if (regionType != null)
+ if (regionType != null)
{
- var region = _contentService.CreateDynamicRegion(pageType, model.RegionTypeId);
+ var region = _factory.CreateDynamicRegion(pageType, model.RegionTypeId);
- var editModel = (Models.PageEditRegionCollection)_editService.CreateRegion(regionType,
+ var editModel = (Models.PageEditRegionCollection)_editService.CreateRegion(regionType,
new List
private Cache.CacheLevel _cacheLevel = Cache.CacheLevel.Full;
+ ///
+ /// The application markdown converter.
+ ///
+ private IMarkdown _markdown;
+
+ ///
+ /// The currently available page types.
+ ///
+ private readonly ContentTypeList _pageTypes;
+
+ ///
+ /// The currently available post types.
+ ///
+ private readonly ContentTypeList _postTypes;
+
+ ///
+ /// The currently available post types.
+ ///
+ private readonly ContentTypeList _siteTypes;
+
///
/// Gets the currently registered block types.
///
@@ -114,11 +125,6 @@ public sealed class App
///
public static MediaManager MediaTypes => Instance._mediaTypes;
- ///
- /// Gets the application object mapper.
- ///
- public static IMapper Mapper => Instance._mapper;
-
///
/// Gets the markdown converter.
///
@@ -160,6 +166,93 @@ public static Cache.CacheLevel CacheLevel
set { Instance._cacheLevel = value; }
}
+ ///
+ /// Gets the currently available page types.
+ ///
+ public static ContentTypeList PageTypes => Instance._pageTypes;
+
+ ///
+ /// Gets the currently available page types.
+ ///
+ public static ContentTypeList PostTypes => Instance._postTypes;
+
+ ///
+ /// Gets the currently available page types.
+ ///
+ public static ContentTypeList SiteTypes => Instance._siteTypes;
+
+ ///
+ /// Static constructor. Called once every application
+ /// lifecycle.
+ ///
+ static App()
+ {
+ Instance = new App();
+
+ // Setup media types
+ Instance._mediaTypes.Documents.Add(".pdf", "application/pdf");
+ Instance._mediaTypes.Images.Add(".jpg", "image/jpeg");
+ Instance._mediaTypes.Images.Add(".jpeg", "image/jpeg");
+ Instance._mediaTypes.Images.Add(".png", "image/png");
+ Instance._mediaTypes.Videos.Add(".mp4", "video/mp4");
+
+ // Compose content types
+ Instance._contentTypes.Register("Page", "Page");
+ Instance._contentTypes.Register("Blog", "Archive", true);
+
+ // Compose field types
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+ Instance._fields.Register();
+
+ // Compose block types
+ Instance._blocks.Register();
+ Instance._blocks.Register();
+ Instance._blocks.Register();
+ Instance._blocks.Register();
+ Instance._blocks.Register();
+
+ // Compose serializers
+ Instance._serializers.Register(new CheckBoxFieldSerializer());
+ Instance._serializers.Register(new DateFieldSerializer());
+ Instance._serializers.Register(new DocumentFieldSerializer());
+ Instance._serializers.Register(new StringFieldSerializer());
+ Instance._serializers.Register(new StringFieldSerializer());
+ Instance._serializers.Register(new MediaFieldSerializer());
+ Instance._serializers.Register(new IntegerFieldSerializer());
+ Instance._serializers.Register(new PageFieldSerializer());
+ Instance._serializers.Register(new PostFieldSerializer());
+ Instance._serializers.Register(new StringFieldSerializer());
+ Instance._serializers.Register(new StringFieldSerializer());
+ Instance._serializers.Register(new ImageFieldSerializer());
+ Instance._serializers.Register(new VideoFieldSerializer());
+
+ // Create markdown converter
+ Instance._markdown = new DefaultMarkdown();
+
+ // Register permissions
+ Instance._permissions["Core"].Add(new PermissionItem
+ {
+ Name = Permission.PagePreview,
+ Title = "Page Preview"
+ });
+ Instance._permissions["Core"].Add(new PermissionItem
+ {
+ Name = Permission.PostPreview,
+ Title = "Post Preview"
+ });
+ }
+
///
/// Default private constructor.
///
@@ -173,23 +266,17 @@ private App()
_contentTypes = new ContentTypeManager();
_hooks = new HookManager();
_permissions = new PermissionManager();
+ _pageTypes = new ContentTypeList();
+ _postTypes = new ContentTypeList();
+ _siteTypes = new ContentTypeList();
}
///
- /// Initializes the application object.
- ///
- public static void Init()
- {
- Instance.Initialize();
- }
-
- ///
- /// Initializes the application object.
+ /// Initializes the application.
///
- [Obsolete("Please refer to App.Init()")]
public static void Init(IApi api)
{
- Instance.Initialize();
+ Instance.InitApp(api);
}
///
@@ -226,7 +313,7 @@ public static object DeserializeObject(string value, Type type)
/// Initializes the application object.
///
/// The current api
- private void Initialize()
+ private void InitApp(IApi api)
{
if (!_isInitialized)
{
@@ -234,144 +321,10 @@ private void Initialize()
{
if (!_isInitialized)
{
- // Configure object mapper
- var mapperConfig = new MapperConfiguration(cfg =>
- {
- cfg.CreateMap()
- .ForMember(a => a.Id, o => o.Ignore())
- .ForMember(a => a.Created, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(c => c.Id, o => o.Ignore())
- .ForMember(c => c.Created, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(f => f.Id, o => o.Ignore())
- .ForMember(f => f.Created, o => o.Ignore())
- .ForMember(f => f.Media, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(f => f.Level, o => o.Ignore())
- .ForMember(f => f.Items, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PageTypeId))
- .ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Slug))
- .ForMember(p => p.Blocks, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(p => p.PageTypeId, o => o.MapFrom(m => m.TypeId))
- .ForMember(p => p.Blocks, o => o.Ignore())
- .ForMember(p => p.Fields, o => o.Ignore())
- .ForMember(p => p.Created, o => o.Ignore())
- .ForMember(p => p.LastModified, o => o.Ignore())
- .ForMember(p => p.PageType, o => o.Ignore())
- .ForMember(p => p.Site, o => o.Ignore())
- .ForMember(p => p.Parent, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(p => p.MenuTitle, o => o.Ignore())
- .ForMember(p => p.Level, o => o.Ignore())
- .ForMember(p => p.Items, o => o.Ignore())
- .ForMember(p => p.PageTypeName, o => o.Ignore())
- .ForMember(p => p.Permalink, o => o.MapFrom(d => !d.ParentId.HasValue && d.SortOrder == 0 ? "/" : "/" + d.Slug));
- cfg.CreateMap()
- .ForMember(p => p.Id, o => o.Ignore())
- .ForMember(p => p.Created, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(p => p.TypeId, o => o.MapFrom(m => m.PostTypeId))
- .ForMember(p => p.Permalink, o => o.MapFrom(m => "/" + m.Blog.Slug + "/" + m.Slug))
- .ForMember(p => p.Blocks, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(p => p.PostTypeId, o => o.MapFrom(m => m.TypeId))
- .ForMember(p => p.CategoryId, o => o.MapFrom(m => m.Category.Id))
- .ForMember(p => p.Blocks, o => o.Ignore())
- .ForMember(p => p.Fields, o => o.Ignore())
- .ForMember(p => p.Created, o => o.Ignore())
- .ForMember(p => p.LastModified, o => o.Ignore())
- .ForMember(p => p.PostType, o => o.Ignore())
- .ForMember(p => p.Blog, o => o.Ignore())
- .ForMember(p => p.Category, o => o.Ignore())
- .ForMember(p => p.Tags, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(s => s.Id, o => o.Ignore())
- .ForMember(s => s.Created, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(s => s.TypeId, o => o.MapFrom(m => m.SiteTypeId));
- cfg.CreateMap()
- .ForMember(s => s.SiteTypeId, o => o.Ignore())
- .ForMember(s => s.InternalId, o => o.Ignore())
- .ForMember(s => s.Description, o => o.Ignore())
- .ForMember(s => s.Hostnames, o => o.Ignore())
- .ForMember(s => s.IsDefault, o => o.Ignore())
- .ForMember(s => s.Culture, o => o.Ignore())
- .ForMember(s => s.Fields, o => o.Ignore())
- .ForMember(s => s.Created, o => o.Ignore())
- .ForMember(s => s.LastModified, o => o.Ignore())
- .ForMember(s => s.ContentLastModified, o => o.Ignore());
- cfg.CreateMap()
- .ForMember(t => t.Id, o => o.Ignore())
- .ForMember(t => t.Created, o => o.Ignore());
- });
- mapperConfig.AssertConfigurationIsValid();
- _mapper = mapperConfig.CreateMapper();
-
- // Setup media types
- _mediaTypes.Documents.Add(".pdf", "application/pdf");
- _mediaTypes.Images.Add(".jpg", "image/jpeg");
- _mediaTypes.Images.Add(".jpeg", "image/jpeg");
- _mediaTypes.Images.Add(".png", "image/png");
- _mediaTypes.Videos.Add(".mp4", "video/mp4");
-
- // Compose content types
- _contentTypes.Register("Page", "Page");
- _contentTypes.Register("Blog", "Archive", true);
-
- // Compose field types
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
- _fields.Register();
-
- // Compose block types
- _blocks.Register();
- _blocks.Register();
- _blocks.Register();
- _blocks.Register();
- _blocks.Register();
-
- // Compose serializers
- _serializers.Register(new CheckBoxFieldSerializer());
- _serializers.Register(new DateFieldSerializer());
- _serializers.Register(new DocumentFieldSerializer());
- _serializers.Register(new StringFieldSerializer());
- _serializers.Register(new StringFieldSerializer());
- _serializers.Register(new MediaFieldSerializer());
- _serializers.Register(new IntegerFieldSerializer());
- _serializers.Register(new PageFieldSerializer());
- _serializers.Register(new PostFieldSerializer());
- _serializers.Register(new StringFieldSerializer());
- _serializers.Register(new StringFieldSerializer());
- _serializers.Register(new ImageFieldSerializer());
- _serializers.Register(new VideoFieldSerializer());
-
- // Create markdown converter
- _markdown = new DefaultMarkdown();
-
- // Register permissions
- _permissions["Core"].Add(new PermissionItem
- {
- Name = Permission.PagePreview,
- Title = "Page Preview"
- });
- _permissions["Core"].Add(new PermissionItem
- {
- Name = Permission.PostPreview,
- Title = "Post Preview"
- });
+ // Initialize content types
+ _pageTypes.Init(api.PageTypes.GetAllAsync().GetAwaiter().GetResult());
+ _postTypes.Init(api.PostTypes.GetAllAsync().GetAwaiter().GetResult());
+ _siteTypes.Init(api.SiteTypes.GetAllAsync().GetAwaiter().GetResult());
// Initialize all modules
foreach (var module in _modules)
diff --git a/core/Piranha/Cache/MemoryCache.cs b/core/Piranha/Cache/MemoryCache.cs
index d0d90ca82..d860e0329 100644
--- a/core/Piranha/Cache/MemoryCache.cs
+++ b/core/Piranha/Cache/MemoryCache.cs
@@ -3,9 +3,9 @@
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using Microsoft.Extensions.Caching.Memory;
@@ -39,7 +39,7 @@ public MemoryCache(IMemoryCache cache)
/// The cached model, null it wasn't found
public T Get(string key)
{
- return _cache.Get(key);
+ return Utils.DeepClone(_cache.Get(key));
}
///
diff --git a/core/Piranha/Cache/SimpleCache.cs b/core/Piranha/Cache/SimpleCache.cs
index f084b68c6..7a0efb53f 100644
--- a/core/Piranha/Cache/SimpleCache.cs
+++ b/core/Piranha/Cache/SimpleCache.cs
@@ -3,9 +3,9 @@
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
@@ -38,7 +38,7 @@ public T Get(string key)
if (_cache.TryGetValue(key, out value))
{
- return (T)value;
+ return Utils.DeepClone((T)value);
}
return default(T);
}
diff --git a/core/Piranha/Config.cs b/core/Piranha/Config.cs
index 9d5661736..f13cd3cb9 100644
--- a/core/Piranha/Config.cs
+++ b/core/Piranha/Config.cs
@@ -1,14 +1,16 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-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 Piranha.Models;
+using Piranha.Services;
namespace Piranha
{
@@ -18,9 +20,9 @@ namespace Piranha
public sealed class Config : IDisposable
{
///
- /// The private api.
+ /// The private param service.
///
- private readonly IApi _api;
+ private readonly ParamService _service;
///
/// The system config keys.
@@ -37,22 +39,22 @@ public sealed class Config : IDisposable
///
public int ArchivePageSize {
get {
- var param = _api.Params.GetByKey(ARCHIVE_PAGE_SIZE);
+ var param = _service.GetByKeyAsync(ARCHIVE_PAGE_SIZE).GetAwaiter().GetResult();
if (param != null)
return Convert.ToInt32(param.Value);
return 0;
}
set {
- var param = _api.Params.GetByKey(ARCHIVE_PAGE_SIZE);
+ var param = _service.GetByKeyAsync(ARCHIVE_PAGE_SIZE).GetAwaiter().GetResult();
if (param == null)
{
- param = new Data.Param
+ param = new Param
{
Key = ARCHIVE_PAGE_SIZE
};
}
param.Value = value.ToString();
- _api.Params.Save(param);
+ _service.SaveAsync(param).GetAwaiter().GetResult();
}
}
@@ -62,22 +64,22 @@ public int ArchivePageSize {
///
public int CacheExpiresPages {
get {
- var param = _api.Params.GetByKey(CACHE_EXPIRES_PAGES);
+ var param = _service.GetByKeyAsync(CACHE_EXPIRES_PAGES).GetAwaiter().GetResult();
if (param != null)
return Convert.ToInt32(param.Value);
return 0;
}
set {
- var param = _api.Params.GetByKey(CACHE_EXPIRES_PAGES);
+ var param = _service.GetByKeyAsync(CACHE_EXPIRES_PAGES).GetAwaiter().GetResult();
if (param == null)
{
- param = new Data.Param
+ param = new Param
{
Key = CACHE_EXPIRES_PAGES
};
}
param.Value = value.ToString();
- _api.Params.Save(param);
+ _service.SaveAsync(param).GetAwaiter().GetResult();
}
}
@@ -87,22 +89,22 @@ public int CacheExpiresPages {
///
public int CacheExpiresPosts {
get {
- var param = _api.Params.GetByKey(CACHE_EXPIRES_POSTS);
+ var param = _service.GetByKeyAsync(CACHE_EXPIRES_POSTS).GetAwaiter().GetResult();
if (param != null)
return Convert.ToInt32(param.Value);
return 0;
}
set {
- var param = _api.Params.GetByKey(CACHE_EXPIRES_POSTS);
+ var param = _service.GetByKeyAsync(CACHE_EXPIRES_POSTS).GetAwaiter().GetResult();
if (param == null)
{
- param = new Data.Param
+ param = new Param
{
Key = CACHE_EXPIRES_POSTS
};
}
param.Value = value.ToString();
- _api.Params.Save(param);
+ _service.SaveAsync(param).GetAwaiter().GetResult();
}
}
@@ -112,22 +114,22 @@ public int CacheExpiresPosts {
///
public bool HierarchicalPageSlugs {
get {
- var param = _api.Params.GetByKey(PAGES_HIERARCHICAL_SLUGS);
+ var param = _service.GetByKeyAsync(PAGES_HIERARCHICAL_SLUGS).GetAwaiter().GetResult();
if (param != null)
return Convert.ToBoolean(param.Value);
return true;
}
set {
- var param = _api.Params.GetByKey(PAGES_HIERARCHICAL_SLUGS);
+ var param = _service.GetByKeyAsync(PAGES_HIERARCHICAL_SLUGS).GetAwaiter().GetResult();
if (param == null)
{
- param = new Data.Param
+ param = new Param
{
Key = PAGES_HIERARCHICAL_SLUGS
};
}
param.Value = value.ToString();
- _api.Params.Save(param);
+ _service.SaveAsync(param).GetAwaiter().GetResult();
}
}
@@ -137,22 +139,22 @@ public bool HierarchicalPageSlugs {
///
public int ManagerExpandedSitemapLevels {
get {
- var param = _api.Params.GetByKey(MANAGER_EXPANDED_SITEMAP_LEVELS);
+ var param = _service.GetByKeyAsync(MANAGER_EXPANDED_SITEMAP_LEVELS).GetAwaiter().GetResult();
if (param != null)
return Convert.ToInt32(param.Value);
return 0;
}
set {
- var param = _api.Params.GetByKey(MANAGER_EXPANDED_SITEMAP_LEVELS);
+ var param = _service.GetByKeyAsync(MANAGER_EXPANDED_SITEMAP_LEVELS).GetAwaiter().GetResult();
if (param == null)
{
- param = new Data.Param
+ param = new Param
{
Key = MANAGER_EXPANDED_SITEMAP_LEVELS
};
}
param.Value = value.ToString();
- _api.Params.Save(param);
+ _service.SaveAsync(param).GetAwaiter().GetResult();
}
}
@@ -162,16 +164,16 @@ public int ManagerExpandedSitemapLevels {
///
public string MediaCDN {
get {
- var param = _api.Params.GetByKey(MEDIA_CDN_URL);
+ var param = _service.GetByKeyAsync(MEDIA_CDN_URL).GetAwaiter().GetResult();
if (param != null)
return param.Value;
return null;
}
set {
- var param = _api.Params.GetByKey(MEDIA_CDN_URL);
+ var param = _service.GetByKeyAsync(MEDIA_CDN_URL).GetAwaiter().GetResult();
if (param == null)
{
- param = new Data.Param
+ param = new Param
{
Key = MEDIA_CDN_URL
};
@@ -182,17 +184,26 @@ public string MediaCDN {
value = value + "/";
param.Value = value;
- _api.Params.Save(param);
+ _service.SaveAsync(param).GetAwaiter().GetResult();
}
}
+ ///
+ /// Default constructor.
+ ///
+ /// The current param service
+ public Config(ParamService paramService)
+ {
+ _service = paramService;
+ }
+
///
/// Default constructor.
///
/// The current api
public Config(IApi api)
{
- _api = api;
+ _service = api.Params;
}
///
diff --git a/core/Piranha/Data/ICreated.cs b/core/Piranha/Data/ICreated.cs
deleted file mode 100644
index b75d65c0a..000000000
--- a/core/Piranha/Data/ICreated.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2017 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-
-namespace Piranha.Data
-{
- ///
- /// Interface for models tracking created date.
- ///
- public interface ICreated
- {
- ///
- /// Gets/sets the created date.
- ///
- DateTime Created { get; set; }
- }
-}
diff --git a/core/Piranha/Data/IModified.cs b/core/Piranha/Data/IModified.cs
deleted file mode 100644
index 879592678..000000000
--- a/core/Piranha/Data/IModified.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2017 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-
-namespace Piranha.Data
-{
- ///
- /// Interface for models tracking last modification date.
- ///
- public interface IModified
- {
- ///
- /// Gets/sets the last modification date.
- ///
- DateTime LastModified { get; set; }
- }
-}
diff --git a/core/Piranha/Data/PageContentType.cs b/core/Piranha/Data/PageContentType.cs
deleted file mode 100644
index d365cd020..000000000
--- a/core/Piranha/Data/PageContentType.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (c) 2017 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
- *
- */
-
-namespace Piranha.Data
-{
- public enum PageContentType
- {
- Page,
- Blog
- }
-}
\ No newline at end of file
diff --git a/core/Piranha/Extend/Fields/DocumentField.cs b/core/Piranha/Extend/Fields/DocumentField.cs
index 2ed6606ae..c0d956119 100644
--- a/core/Piranha/Extend/Fields/DocumentField.cs
+++ b/core/Piranha/Extend/Fields/DocumentField.cs
@@ -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 Piranha.Models;
namespace Piranha.Extend.Fields
{
@@ -28,7 +29,7 @@ public static implicit operator DocumentField(Guid guid)
/// Implicit operator for converting a media object to a field.
///
/// The media object
- public static implicit operator DocumentField(Data.Media media)
+ public static implicit operator DocumentField(Media media)
{
return new DocumentField { Id = media.Id };
}
diff --git a/core/Piranha/Extend/Fields/ImageField.cs b/core/Piranha/Extend/Fields/ImageField.cs
index 6e50e1da6..906903e7d 100644
--- a/core/Piranha/Extend/Fields/ImageField.cs
+++ b/core/Piranha/Extend/Fields/ImageField.cs
@@ -1,14 +1,15 @@
/*
- * Copyright (c) 2017-2018 Håkan Edling
+ * Copyright (c) 2017-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 Piranha.Models;
namespace Piranha.Extend.Fields
{
@@ -28,7 +29,7 @@ public static implicit operator ImageField(Guid guid)
/// Implicit operator for converting a media object to a field.
///
/// The media object
- public static implicit operator ImageField(Data.Media media)
+ public static implicit operator ImageField(Media media)
{
return new ImageField { Id = media.Id };
}
diff --git a/core/Piranha/Extend/Fields/MediaField.cs b/core/Piranha/Extend/Fields/MediaField.cs
index 8d0cf4364..f7623abb7 100644
--- a/core/Piranha/Extend/Fields/MediaField.cs
+++ b/core/Piranha/Extend/Fields/MediaField.cs
@@ -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 Piranha.Models;
namespace Piranha.Extend.Fields
{
@@ -28,7 +29,7 @@ public static implicit operator MediaField(Guid guid)
/// Implicit operator for converting a media object to a field.
///
/// The media object
- public static implicit operator MediaField(Data.Media media)
+ public static implicit operator MediaField(Media media)
{
return new MediaField { Id = media.Id };
}
diff --git a/core/Piranha/Extend/Fields/MediaFieldBase.cs b/core/Piranha/Extend/Fields/MediaFieldBase.cs
index 6c807ca90..f6d2d11ca 100644
--- a/core/Piranha/Extend/Fields/MediaFieldBase.cs
+++ b/core/Piranha/Extend/Fields/MediaFieldBase.cs
@@ -3,13 +3,14 @@
*
* 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 Newtonsoft.Json;
using System;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
namespace Piranha.Extend.Fields
{
@@ -38,7 +39,7 @@ public virtual string GetTitle()
/// Gets/sets the related media object.
///
[JsonIgnore]
- public Data.Media Media { get; private set; }
+ public Models.Media Media { get; private set; }
///
/// Gets if the field has a media object available.
@@ -49,11 +50,11 @@ public virtual string GetTitle()
/// Initializes the field for client use.
///
/// The current api
- public virtual void Init(IApi api)
+ public virtual async Task Init(IApi api)
{
if (Id.HasValue)
{
- Media = api.Media.GetById(Id.Value);
+ Media = await api.Media.GetByIdAsync(Id.Value);
if (Media == null)
{
diff --git a/core/Piranha/Extend/Fields/PageField.cs b/core/Piranha/Extend/Fields/PageField.cs
index c3f9adb53..0905c9809 100644
--- a/core/Piranha/Extend/Fields/PageField.cs
+++ b/core/Piranha/Extend/Fields/PageField.cs
@@ -3,13 +3,15 @@
*
* 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 Newtonsoft.Json;
using System;
+using System.Threading.Tasks;
+using Piranha.Services;
namespace Piranha.Extend.Fields
{
@@ -48,11 +50,11 @@ public virtual string GetTitle()
/// Initializes the field for client use.
///
/// The current api
- public virtual void Init(IApi api)
+ public virtual async Task Init(IApi api)
{
if (Id.HasValue)
{
- Page = api.Pages.GetById(Id.Value);
+ Page = await api.Pages.GetByIdAsync(Id.Value);
if (Page == null)
{
@@ -68,10 +70,10 @@ public virtual void Init(IApi api)
///
/// The current api
/// The referenced page
- public virtual T GetPage(IApi api) where T : Models.GenericPage
+ public virtual Task GetPageAsync(IApi api) where T : Models.GenericPage
{
if (Id.HasValue)
- return api.Pages.GetById(Id.Value);
+ return api.Pages.GetByIdAsync(Id.Value);
return null;
}
diff --git a/core/Piranha/Extend/Fields/PostField.cs b/core/Piranha/Extend/Fields/PostField.cs
index 3ca158952..4d92f26e0 100644
--- a/core/Piranha/Extend/Fields/PostField.cs
+++ b/core/Piranha/Extend/Fields/PostField.cs
@@ -1,15 +1,17 @@
/*
- * 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 Newtonsoft.Json;
using System;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+using Piranha.Services;
namespace Piranha.Extend.Fields
{
@@ -46,11 +48,11 @@ public virtual string GetTitle()
/// Initializes the field for client use.
///
/// The current api
- public virtual void Init(IApi api)
+ public virtual async Task Init(IApi api)
{
if (Id.HasValue)
{
- Post = api.Posts.GetById(Id.Value);
+ Post = await api.Posts.GetByIdAsync(Id.Value);
if (Post == null)
{
@@ -66,11 +68,11 @@ public virtual void Init(IApi api)
///
/// The current api
/// The referenced post
- public virtual T GetPost(IApi api) where T : Models.Post
+ public virtual Task GetPostAsync(IApi api) where T : Models.Post
{
if (Id.HasValue)
{
- return api.Posts.GetById(Id.Value);
+ return api.Posts.GetByIdAsync(Id.Value);
}
return null;
}
@@ -81,9 +83,9 @@ public virtual T GetPost(IApi api) where T : Models.Post
/// The string value
public static implicit operator PostField(Guid guid)
{
- return new PostField
- {
- Id = guid
+ return new PostField
+ {
+ Id = guid
};
}
@@ -93,9 +95,9 @@ public static implicit operator PostField(Guid guid)
/// The post object
public static implicit operator PostField(Models.PostBase post)
{
- return new PostField
- {
- Id = post.Id
+ return new PostField
+ {
+ Id = post.Id
};
}
diff --git a/core/Piranha/Extend/Fields/VideoField.cs b/core/Piranha/Extend/Fields/VideoField.cs
index 7a0c2ac9a..7bddb2956 100644
--- a/core/Piranha/Extend/Fields/VideoField.cs
+++ b/core/Piranha/Extend/Fields/VideoField.cs
@@ -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 Piranha.Models;
namespace Piranha.Extend.Fields
{
@@ -28,7 +29,7 @@ public static implicit operator VideoField(Guid guid)
/// Implicit operator for converting a media object to a field.
///
/// The media object
- public static implicit operator VideoField(Data.Media media)
+ public static implicit operator VideoField(Media media)
{
return new VideoField { Id = media.Id };
}
diff --git a/core/Piranha/IApi.cs b/core/Piranha/IApi.cs
index 0442985fd..59aadf07f 100644
--- a/core/Piranha/IApi.cs
+++ b/core/Piranha/IApi.cs
@@ -1,16 +1,16 @@
/*
- * Copyright (c) 2017-2018 Håkan Edling
+ * Copyright (c) 2017-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
-using Piranha.Data;
-using Piranha.Repositories;
using System;
+using Piranha.Repositories;
+using Piranha.Services;
namespace Piranha
{
@@ -22,61 +22,51 @@ public interface IApi : IDisposable
///
/// Gets/sets the alias repository.
///
- IAliasRepository Aliases { get; }
-
- ///
- /// Gets/sets the archive repository.
- ///
- IArchiveRepository Archives { get; }
+ AliasService Aliases { get; }
///
- /// Gets the category repository.
+ /// Gets/sets the archive service.
///
- ICategoryRepository Categories { get; }
+ ArchiveService Archives { get; }
///
- /// Gets the media repository.
+ /// Gets the media service.
///
- IMediaRepository Media { get; }
+ MediaService Media { get; }
///
/// Gets the page repository.
///
- IPageRepository Pages { get; }
-
- ///
- /// Gets the page type repository.
- ///
- IPageTypeRepository PageTypes { get; }
+ PageService Pages { get; }
///
- /// Gets the param repository.
+ /// Gets the page type service.
///
- IParamRepository Params { get; }
+ PageTypeService PageTypes { get; }
///
- /// Gets the post repository.
+ /// Gets the param service.
///
- IPostRepository Posts { get; }
+ ParamService Params { get; }
///
- /// Gets the post type repository.
+ /// Gets the post service.
///
- IPostTypeRepository PostTypes { get; }
+ PostService Posts { get; }
///
- /// Gets the site repository.
+ /// Gets the post type service.
///
- ISiteRepository Sites { get; }
+ PostTypeService PostTypes { get; }
///
- /// Gets the site type repository.
+ /// Gets the site service.
///
- ISiteTypeRepository SiteTypes { get; }
+ SiteService Sites { get; }
///
- /// Gets the tag repository.
+ /// Gets the site type service.
///
- ITagRepository Tags { get; }
+ SiteTypeService SiteTypes { get; }
}
}
diff --git a/core/Piranha/Data/Alias.cs b/core/Piranha/Models/Alias.cs
similarity index 69%
rename from core/Piranha/Data/Alias.cs
rename to core/Piranha/Models/Alias.cs
index 99d2ff8b0..ca4ce4ade 100644
--- a/core/Piranha/Data/Alias.cs
+++ b/core/Piranha/Models/Alias.cs
@@ -1,45 +1,53 @@
/*
- * 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.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
+using System.ComponentModel.DataAnnotations;
-namespace Piranha.Data
+namespace Piranha.Models
{
[Serializable]
- public sealed class Alias : IModel
+ public sealed class Alias : Alias { }
+
+ [Serializable]
+ public abstract class Alias
{
///
/// Gets/sets the unique id.
///
- public Guid Id { get; set; }
+ public TKey Id { get; set; }
///
/// Gets/sets the id of the site this alias is for.
///
- public Guid SiteId { get; set; }
+ public TKey SiteId { get; set; }
///
/// Gets/sets the alias url.
///
+ [Required]
+ [StringLength(256)]
public string AliasUrl { get; set; }
///
/// Gets/sets the url of the redirect.
///
+ [Required]
+ [StringLength(256)]
public string RedirectUrl { get; set; }
///
/// Gets/sets if this is a permanent or temporary
/// redirect.
///
- public Models.RedirectType Type { get; set; } = Models.RedirectType.Temporary;
+ public RedirectType Type { get; set; } = RedirectType.Temporary;
///
/// Gets/sets the created date.
@@ -50,11 +58,5 @@ public sealed class Alias : IModel
/// Gets/sets the last modification date.
///
public DateTime LastModified { get; set; }
-
- ///
- /// Gets/sets the site this alias is for.
- ///
- ///
- public Site Site { get; set; }
}
}
\ No newline at end of file
diff --git a/core/Piranha/Models/ArchivePage.cs b/core/Piranha/Models/ArchivePage.cs
index 942e71819..7dee56c85 100644
--- a/core/Piranha/Models/ArchivePage.cs
+++ b/core/Piranha/Models/ArchivePage.cs
@@ -12,7 +12,7 @@
namespace Piranha.Models
{
- [Obsolete("BlogPage has been renamed to ArchivePage, please update your code.", false)]
+ [Obsolete("BlogPage has been renamed to ArchivePage, please update your code.", true)]
public class BlogPage : ArchivePage where T : BlogPage { }
///
diff --git a/core/Piranha/Models/Content.cs b/core/Piranha/Models/Content.cs
index f8a9ba737..582fb82a7 100644
--- a/core/Piranha/Models/Content.cs
+++ b/core/Piranha/Models/Content.cs
@@ -1,14 +1,15 @@
/*
- * Copyright (c) 2016 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 System;
+using System.ComponentModel.DataAnnotations;
namespace Piranha.Models
{
@@ -25,11 +26,15 @@ public abstract class Content
///
/// Gets/sets the content type id.
///
+ //[Required]
+ [StringLength(64)]
public string TypeId { get; set; }
///
/// Gets/sets the title.
///
+ //[Required]
+ [StringLength(128)]
public string Title { get; set; }
///
diff --git a/core/Piranha/Models/ContentType.cs b/core/Piranha/Models/ContentType.cs
index c49a8bc7c..7c21048bd 100644
--- a/core/Piranha/Models/ContentType.cs
+++ b/core/Piranha/Models/ContentType.cs
@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
namespace Piranha.Models
{
@@ -22,11 +23,14 @@ public abstract class ContentType
///
/// Gets/sets the unique id.
///
+ [Required]
+ [StringLength(64)]
public string Id { get; set; }
///
/// Gets/sets the CLR type of the content model.
///
+ [StringLength(255)]
public string CLRType { get; set; }
///
diff --git a/core/Piranha/Models/GenericPage.cs b/core/Piranha/Models/GenericPage.cs
index 06cf6a884..3d3c55f68 100644
--- a/core/Piranha/Models/GenericPage.cs
+++ b/core/Piranha/Models/GenericPage.cs
@@ -3,11 +3,13 @@
*
* 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 Piranha.Services;
+
namespace Piranha.Models
{
///
diff --git a/core/Piranha/Models/IBlockModel.cs b/core/Piranha/Models/IBlockModel.cs
new file mode 100644
index 000000000..6bb73c831
--- /dev/null
+++ b/core/Piranha/Models/IBlockModel.cs
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 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.Collections.Generic;
+
+namespace Piranha.Models
+{
+ public interface IBlockModel
+ {
+ ///
+ /// Gets/sets the blocks.
+ ///
+ IList Blocks { get; set; }
+ }
+}
diff --git a/core/Piranha/Data/Media.cs b/core/Piranha/Models/Media.cs
similarity index 83%
rename from core/Piranha/Data/Media.cs
rename to core/Piranha/Models/Media.cs
index 263aa76b6..5cc431107 100644
--- a/core/Piranha/Data/Media.cs
+++ b/core/Piranha/Models/Media.cs
@@ -1,35 +1,42 @@
/*
- * Copyright (c) 2017-2018 Håkan Edling
+ * Copyright (c) 2017-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
using System.Collections.Generic;
-namespace Piranha.Data
+namespace Piranha.Models
{
- [Serializable]
- public sealed class Media : IModel, ICreated, IModified
+ public sealed class Media : Media
{
///
- /// Gets/sets the unique id.
+ /// Gets/sets the optional folder id.
///
- public Guid Id { get; set; }
+ public Guid? FolderId { get; set; }
///
- /// Gets/sets the optional folder id.
+ /// Gets/sets the available versions.
///
- public Guid? FolderId { get; set; }
+ public IList Versions { get; set; } = new List();
+ }
+
+ public abstract class Media
+ {
+ ///
+ /// Gets/sets the unique id.
+ ///
+ public TKey Id { get; set; }
///
/// Gets/sets the media type.
///
- public Models.MediaType Type { get; set; }
+ public MediaType Type { get; set; }
///
/// Gets/sets the filename.
@@ -73,15 +80,5 @@ public sealed class Media : IModel, ICreated, IModified
/// Gets/sets the last modification date.
///
public DateTime LastModified { get; set; }
-
- ///
- /// Gets/sets the optional folder.
- ///
- public MediaFolder Folder { get; set; }
-
- ///
- /// Gets/sets the available versions.
- ///
- public IList Versions { get; set; } = new List();
}
}
\ No newline at end of file
diff --git a/core/Piranha/Data/MediaFolder.cs b/core/Piranha/Models/MediaFolder.cs
similarity index 64%
rename from core/Piranha/Data/MediaFolder.cs
rename to core/Piranha/Models/MediaFolder.cs
index ddad52d44..59de34287 100644
--- a/core/Piranha/Data/MediaFolder.cs
+++ b/core/Piranha/Models/MediaFolder.cs
@@ -1,44 +1,43 @@
/*
- * Copyright (c) 2017-2018 Håkan Edling
+ * Copyright (c) 2017-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
-using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
-namespace Piranha.Data
+namespace Piranha.Models
{
- [Serializable]
- public sealed class MediaFolder : IModel, ICreated
+ public sealed class MediaFolder : MediaFolder
{
///
- /// Gets/sets the unique id.
+ /// Gets/sets the optional parent id.
///
- public Guid Id { get; set; }
+ public Guid? ParentId { get; set; }
+ }
+ public abstract class MediaFolder
+ {
///
- /// Gets/sets the optional parent id.
+ /// Gets/sets the unique id.
///
- public Guid? ParentId { get; set; }
+ public TKey Id { get; set; }
///
/// Gets/sets the folder name.
///
+ [Required]
+ [StringLength(128)]
public string Name { get; set; }
///
/// Gets/sets the created date.
///
public DateTime Created { get; set; }
-
- ///
- /// Gets/sets the available media.
- ///
- public IList Media { get; set; } = new List();
}
}
\ No newline at end of file
diff --git a/core/Piranha/Models/MediaStructureItem.cs b/core/Piranha/Models/MediaStructureItem.cs
index b47327511..b3300f1da 100644
--- a/core/Piranha/Models/MediaStructureItem.cs
+++ b/core/Piranha/Models/MediaStructureItem.cs
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-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;
@@ -13,7 +13,7 @@
namespace Piranha.Models
{
[Serializable]
- public class MediaStructureItem : StructureItem
+ public class MediaStructureItem : StructureItem
{
///
/// Gets/sets the folder name.
@@ -24,5 +24,13 @@ public class MediaStructureItem : StructureItem
/// Gets/sets the created date.
///
public DateTime Created { get; set; }
+
+ ///
+ /// Default constructor.
+ ///
+ public MediaStructureItem()
+ {
+ Items = new MediaStructure();
+ }
}
}
\ No newline at end of file
diff --git a/core/Piranha/Data/MediaVersion.cs b/core/Piranha/Models/MediaVersion.cs
similarity index 63%
rename from core/Piranha/Data/MediaVersion.cs
rename to core/Piranha/Models/MediaVersion.cs
index 151ac844b..d8093fa5b 100644
--- a/core/Piranha/Data/MediaVersion.cs
+++ b/core/Piranha/Models/MediaVersion.cs
@@ -1,30 +1,25 @@
/*
- * 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.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
-namespace Piranha.Data
+namespace Piranha.Models
{
- [Serializable]
- public sealed class MediaVersion : IModel
+ public sealed class MediaVersion : MediaVersion { }
+
+ public abstract class MediaVersion
{
///
/// Gets/sets the unique id.
///
- public Guid Id { get; set; }
-
- ///
- /// Gets/sets the id of the media this is
- /// a version of.
- ///
- public Guid MediaId { get; set; }
+ public TKey Id { get; set; }
///
/// Gets/sets the file size in bytes.
@@ -45,10 +40,5 @@ public sealed class MediaVersion : IModel
/// Gets/sets the file extension of the generated version.
///
public string FileExtension { get; set; }
-
- ///
- /// Gets/sets the media this is a version of.
- ///
- public Media Media { get; set; }
}
}
\ No newline at end of file
diff --git a/core/Piranha/Models/PageBase.cs b/core/Piranha/Models/PageBase.cs
index 09e7f91c6..6bf27f43d 100644
--- a/core/Piranha/Models/PageBase.cs
+++ b/core/Piranha/Models/PageBase.cs
@@ -1,22 +1,23 @@
/*
- * 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 System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
namespace Piranha.Models
{
///
/// Base class for page models.
///
- public abstract class PageBase : RoutedContent, IMeta
+ public abstract class PageBase : RoutedContent, IBlockModel, IMeta
{
///
/// Gets/sets the site id.
@@ -26,6 +27,7 @@ public abstract class PageBase : RoutedContent, IMeta
///
/// Gets/sets the page content type.
///
+ [StringLength(256)]
public string ContentType { get; set; }
///
@@ -41,6 +43,7 @@ public abstract class PageBase : RoutedContent, IMeta
///
/// Gets/sets the navigation title.
///
+ [StringLength(128)]
public string NavigationTitle { get; set; }
///
@@ -51,7 +54,7 @@ public abstract class PageBase : RoutedContent, IMeta
///
/// Gets/sets the optional redirect.
///
- ///
+ [StringLength(256)]
public string RedirectUrl { get; set; }
///
diff --git a/core/Piranha/Data/Param.cs b/core/Piranha/Models/Param.cs
similarity index 75%
rename from core/Piranha/Data/Param.cs
rename to core/Piranha/Models/Param.cs
index b92cf346c..a018edd1a 100644
--- a/core/Piranha/Data/Param.cs
+++ b/core/Piranha/Models/Param.cs
@@ -1,51 +1,58 @@
-/*
- * Copyright (c) 2017-2018 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-
-namespace Piranha.Data
-{
- [Serializable]
- ///
- /// String parameter.
- ///
- public sealed class Param : IModel, ICreated, IModified
- {
- ///
- /// Gets/sets the unique id.
- ///
- public Guid Id { get; set; }
-
- ///
- /// Gets/sets the unique key.
- ///
- public string Key { get; set; }
-
- ///
- /// Gets/sets the value.
- ///
- public string Value { get; set; }
-
- ///
- /// Gets/sets the optional description.
- ///
- public string Description { get; set; }
-
- ///
- /// Gets/sets the created date.
- ///
- public DateTime Created { get; set; }
-
- ///
- /// Gets/sets the last modification date.
- ///
- public DateTime LastModified { get; set; }
- }
-}
+/*
+ * Copyright (c) 2018 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace Piranha.Models
+{
+ [Serializable]
+ public sealed class Param : Param { }
+
+ [Serializable]
+ ///
+ /// String parameter.
+ ///
+ public abstract class Param
+ {
+ ///
+ /// Gets/sets the unique id.
+ ///
+ public TKey Id { get; set; }
+
+ ///
+ /// Gets/sets the unique key.
+ ///
+ [Required]
+ [StringLength(64)]
+ public string Key { get; set; }
+
+ ///
+ /// Gets/sets the value.
+ ///
+ public string Value { get; set; }
+
+ ///
+ /// Gets/sets the optional description.
+ ///
+ [StringLength(255)]
+ public string Description { get; set; }
+
+ ///
+ /// Gets/sets the created date.
+ ///
+ public DateTime Created { get; set; }
+
+ ///
+ /// Gets/sets the last modification date.
+ ///
+ public DateTime LastModified { get; set; }
+ }
+}
diff --git a/core/Piranha/Models/PostBase.cs b/core/Piranha/Models/PostBase.cs
index c68a56e0b..8bc5c260f 100644
--- a/core/Piranha/Models/PostBase.cs
+++ b/core/Piranha/Models/PostBase.cs
@@ -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 System;
@@ -16,7 +16,7 @@ namespace Piranha.Models
///
/// Base class for post models.
///
- public abstract class PostBase : RoutedContent, IMeta
+ public abstract class PostBase : RoutedContent, IBlockModel, IMeta
{
///
/// Gets/sets the blog page id.
diff --git a/core/Piranha/Models/RoutedContent.cs b/core/Piranha/Models/RoutedContent.cs
index 500c65c6a..3eb887625 100644
--- a/core/Piranha/Models/RoutedContent.cs
+++ b/core/Piranha/Models/RoutedContent.cs
@@ -1,14 +1,15 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-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.ComponentModel.DataAnnotations;
namespace Piranha.Models
{
@@ -20,6 +21,7 @@ public abstract class RoutedContent : Content
///
/// Gets/sets the unique slug.
///
+ [StringLength(128)]
public string Slug { get; set; }
///
@@ -30,16 +32,19 @@ public abstract class RoutedContent : Content
///
/// Gets/sets the optional meta keywords.
///
+ [StringLength(128)]
public string MetaKeywords { get; set; }
///
/// Gets/sets the optional meta description.
///
+ [StringLength(256)]
public string MetaDescription { get; set; }
///
/// Gets/sets the optional route used by the middleware.
///
+ [StringLength(256)]
public string Route { get; set; }
///
diff --git a/core/Piranha/Models/Site.cs b/core/Piranha/Models/Site.cs
new file mode 100644
index 000000000..c090bef38
--- /dev/null
+++ b/core/Piranha/Models/Site.cs
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2017-2019 Håkan Edling
+ *
+ * This software may be modified and distributed under the terms
+ * of the MIT license. See the LICENSE file for details.
+ *
+ * http://github.com/piranhacms/piranha
+ *
+ */
+
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace Piranha.Models
+{
+ [Serializable]
+ public sealed class Site
+ {
+ ///
+ /// Gets/sets the unique id.
+ ///
+ public Guid Id { get; set; }
+
+ ///
+ /// Gets/sets the optional site type id.
+ ///
+ [StringLength(64)]
+ public string SiteTypeId { get; set; }
+
+ ///
+ /// Gets/sets the main title.
+ ///
+ [Required]
+ [StringLength(128)]
+ public string Title { get; set; }
+
+ ///
+ /// Gets/sets the internal textual id.
+ ///
+ [StringLength(64)]
+ public string InternalId { get; set; }
+
+ ///
+ /// Gets/sets the optional description.
+ ///
+ [StringLength(256)]
+ public string Description { get; set; }
+
+ ///
+ /// Gets/sets the optional hostnames to bind this site for.
+ ///
+ [StringLength(256)]
+ public string Hostnames { get; set; }
+
+ ///
+ /// Gets/sets if this is the default site.
+ ///
+ public bool IsDefault { get; set; }
+
+ ///
+ /// Gets/sets the optional culture for the site.
+ ///
+ [StringLength(6)]
+ public string Culture { get; set; }
+
+ ///
+ /// Gets/sets the global last modification date
+ /// of the site's content.
+ ///
+ public DateTime? ContentLastModified { get; set; }
+
+ ///
+ /// Gets/sets the created date.
+ ///
+ public DateTime Created { get; set; }
+
+ ///
+ /// Gets/sets the last modification date.
+ ///
+ public DateTime LastModified { get; set; }
+ }
+}
diff --git a/core/Piranha/Models/SitemapItem.cs b/core/Piranha/Models/SitemapItem.cs
index 804c65c1f..da76aa473 100644
--- a/core/Piranha/Models/SitemapItem.cs
+++ b/core/Piranha/Models/SitemapItem.cs
@@ -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 System;
@@ -13,7 +13,7 @@
namespace Piranha.Models
{
[Serializable]
- public class SitemapItem : StructureItem
+ public class SitemapItem : StructureItem
{
///
/// Gets/sets the optional original id.
@@ -44,9 +44,9 @@ public class SitemapItem : StructureItem
/// Gets the menu title for the item. The menu title returns
/// the navigation title if set, otherwise the main title.
///
- public string MenuTitle
+ public string MenuTitle
{
- get
+ get
{
if (!string.IsNullOrWhiteSpace(NavigationTitle))
{
@@ -74,7 +74,7 @@ public string MenuTitle
///
/// Gets/sets the published date.
- ///
+ ///
public DateTime? Published { get; set; }
///
diff --git a/core/Piranha/Models/Structure.cs b/core/Piranha/Models/Structure.cs
index 9ded5edc4..5ad039bbc 100644
--- a/core/Piranha/Models/Structure.cs
+++ b/core/Piranha/Models/Structure.cs
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2017-2018 Håkan Edling
+ * Copyright (c) 2017-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;
@@ -16,8 +16,8 @@ namespace Piranha.Models
///
/// Abstract class for building a hierarchical structure.
///
- [Serializable]
- public abstract class Structure : List where T : StructureItem where TThis : Structure
+ [Serializable]
+ public abstract class Structure : List where T : StructureItem where TThis : Structure
{
///
/// Gets the partial structure with the items positioned
diff --git a/core/Piranha/Models/StructureItem.cs b/core/Piranha/Models/StructureItem.cs
index d40cefd25..014bd0b24 100644
--- a/core/Piranha/Models/StructureItem.cs
+++ b/core/Piranha/Models/StructureItem.cs
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2017-2018 Håkan Edling
+ * Copyright (c) 2017-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;
@@ -17,7 +17,9 @@ namespace Piranha.Models
/// Abstract class for an hierarchical item in a structure.
///
[Serializable]
- public abstract class StructureItem where T : StructureItem
+ public abstract class StructureItem
+ where T : StructureItem
+ where TStructure : Structure
{
///
/// Gets/sets the unique id.
@@ -32,6 +34,6 @@ public abstract class StructureItem where T : StructureItem
///
/// Gets/sets the child items.
///
- public IList Items { get; set; } = new List();
+ public TStructure Items { get; set; }
}
}
\ No newline at end of file
diff --git a/core/Piranha/Models/Taxonomy.cs b/core/Piranha/Models/Taxonomy.cs
index 622248cdd..9b5e9734e 100644
--- a/core/Piranha/Models/Taxonomy.cs
+++ b/core/Piranha/Models/Taxonomy.cs
@@ -1,14 +1,15 @@
/*
- * Copyright (c) 2017-2018 Håkan Edling
+ * Copyright (c) 2017-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.ComponentModel.DataAnnotations;
namespace Piranha.Models
{
@@ -22,11 +23,13 @@ public class Taxonomy
///
/// Gets/sets the title.
///
+ [StringLength(128)]
public string Title { get; set; }
///
/// Gets/sets the slug.
///
+ [StringLength(128)]
public string Slug { get; set; }
///
@@ -40,39 +43,5 @@ public static implicit operator Taxonomy(string str)
Title = str
};
}
-
- ///
- /// Operator for type casting a category to a taxonomy.
- ///
- /// The category
- public static implicit operator Taxonomy(Data.Category category)
- {
- if (category != null)
- {
- return new Taxonomy
- {
- Id = category.Id,
- Title = category.Title,
- Slug = category.Slug
- };
- }
- return null;
- }
-
- ///
- /// Operator for type casting a tag to a taxonomy.
- ///
- /// The tag
- public static implicit operator Taxonomy(Data.Tag tag)
- {
- if (tag != null)
- return new Taxonomy
- {
- Id = tag.Id,
- Title = tag.Title,
- Slug = tag.Slug
- };
- return null;
- }
}
}
diff --git a/core/Piranha/Piranha.csproj b/core/Piranha/Piranha.csproj
index f795cf9a4..4780e820a 100644
--- a/core/Piranha/Piranha.csproj
+++ b/core/Piranha/Piranha.csproj
@@ -6,10 +6,11 @@
Piranha
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/core/Piranha/PiranhaExtensions.cs b/core/Piranha/PiranhaExtensions.cs
new file mode 100644
index 000000000..d986dc4f6
--- /dev/null
+++ b/core/Piranha/PiranhaExtensions.cs
@@ -0,0 +1,64 @@
+/*
+ * 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 Microsoft.Extensions.DependencyInjection;
+using Piranha;
+using Piranha.Cache;
+using Piranha.Services;
+
+public static class PiranhaExtensions
+{
+ public static IServiceCollection AddPiranha(this IServiceCollection services)
+ {
+ return services.AddSingleton();
+ }
+
+ ///
+ /// Adds the memory cache service for repository caching.
+ ///
+ /// The current service collection
+ /// The updated service collection
+ [Obsolete("Please use AddPiranhaSimpleCache instead", true)]
+ public static IServiceCollection AddPiranhaMemCache(this IServiceCollection services)
+ {
+ return services;
+ }
+
+ ///
+ /// Adds the distributed cache service for repository caching.
+ ///
+ /// The current service collection
+ /// The updated service collection
+ public static IServiceCollection AddPiranhaDistributedCache(this IServiceCollection services)
+ {
+ return services.AddSingleton();
+ }
+
+ ///
+ /// Adds the memory cache service for repository caching.
+ ///
+ /// The current service collection
+ /// The updated service collection
+ public static IServiceCollection AddPiranhaMemoryCache(this IServiceCollection services)
+ {
+ return services.AddSingleton();
+ }
+
+ ///
+ /// Adds the simple cache service for repository caching.
+ ///
+ /// The current service collection
+ /// The updated service collection
+ public static IServiceCollection AddPiranhaSimpleCache(this IServiceCollection services)
+ {
+ return services.AddSingleton();
+ }
+}
diff --git a/core/Piranha/Repositories/AliasRepository.cs b/core/Piranha/Repositories/AliasRepository.cs
deleted file mode 100644
index 65923dd12..000000000
--- a/core/Piranha/Repositories/AliasRepository.cs
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright (c) 2018 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.EntityFrameworkCore;
-using Piranha.Data;
-
-namespace Piranha.Repositories
-{
- public class AliasRepository : BaseRepository, IAliasRepository
- {
- private readonly Api _api;
-
- ///
- /// Default constructor.
- ///
- /// The current db context
- /// The optional model cache
- public AliasRepository(Api api, IDb db, ICache cache = null)
- : base(db, cache)
- {
- _api = api;
- }
-
- ///
- /// Gets all available models for the specified site.
- ///
- /// The optional site id
- /// The available models
- public IEnumerable GetAll(Guid? siteId)
- {
- var models = new List();
-
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
- if (site != null)
- siteId = site.Id;
- }
-
- var aliases = db.Aliases
- .AsNoTracking()
- .Where(a => a.SiteId == siteId)
- .OrderBy(a => a.AliasUrl)
- .ThenBy(a => a.RedirectUrl)
- .Select(a => a.Id);
-
- foreach (var a in aliases)
- {
- var model = GetById(a);
- if (model != null)
- models.Add(model);
- }
- return models;
- }
-
- ///
- /// Gets the model with the given alias url.
- ///
- /// The unique url
- /// The optional site id
- /// The model
- public Alias GetByAliasUrl(string url, Guid? siteId = null)
- {
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
- if (site != null)
- siteId = site.Id;
- }
-
- var id = cache?.Get($"AliasId_{siteId}_{url}");
- Alias model = null;
-
- if (id.HasValue)
- {
- model = GetById(id.Value);
- }
- else
- {
- id = db.Aliases
- .AsNoTracking()
- .Where(a => a.SiteId == siteId && a.AliasUrl == url)
- .Select(a => a.Id)
- .FirstOrDefault();
-
- if (id != Guid.Empty)
- model = GetById(id.Value);
- }
- return model;
- }
-
- ///
- /// Gets the model with the given redirect url.
- ///
- /// The unique url
- /// The optional site id
- /// The model
- public IEnumerable GetByRedirectUrl(string url, Guid? siteId = null)
- {
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
- if (site != null)
- siteId = site.Id;
- }
-
- var models = new List();
-
- var aliases = db.Aliases
- .AsNoTracking()
- .Where(a => a.SiteId == siteId && a.RedirectUrl == url)
- .Select(a => a.Id)
- .ToList();
-
- foreach (var id in aliases)
- {
- models.Add(GetById(id));
- }
- return models;
- }
-
- ///
- /// Adds a new model to the database.
- ///
- /// The model
- protected override void Add(Alias model)
- {
- PrepareInsert(model);
-
- // Check for alias url
- if (string.IsNullOrWhiteSpace(model.AliasUrl))
- throw new ArgumentException("Alias Url cannot be empty");
-
- // Check for redirect url
- if (string.IsNullOrWhiteSpace(model.RedirectUrl))
- throw new ArgumentException("Redirect Url cannot be empty");
-
- // Fix urls
- if (!model.AliasUrl.StartsWith("/"))
- {
- model.AliasUrl = "/" + model.AliasUrl;
- }
- if (!model.RedirectUrl.StartsWith("/") && !model.RedirectUrl.StartsWith("http://") && !model.RedirectUrl.StartsWith("https://"))
- {
- model.RedirectUrl = "/" + model.RedirectUrl;
- }
-
- db.Aliases.Add(model);
- }
-
- ///
- /// Updates the given model in the database.
- ///
- /// The model
- protected override void Update(Alias model)
- {
- PrepareUpdate(model);
-
- // Check for alias url
- if (string.IsNullOrWhiteSpace(model.AliasUrl))
- throw new ArgumentException("Alias Url cannot be empty");
-
- // Check for redirect url
- if (string.IsNullOrWhiteSpace(model.RedirectUrl))
- throw new ArgumentException("Redirect Url cannot be empty");
-
- // Fix urls
- if (!model.AliasUrl.StartsWith("/"))
- {
- model.AliasUrl = "/" + model.AliasUrl;
- }
- if (!model.RedirectUrl.StartsWith("/") && !model.RedirectUrl.StartsWith("http://") && !model.RedirectUrl.StartsWith("https://"))
- {
- model.RedirectUrl = "/" + model.RedirectUrl;
- }
-
- var alias = db.Aliases.FirstOrDefault(s => s.Id == model.Id);
- if (alias != null)
- {
- App.Mapper.Map(model, alias);
- }
- }
-
- ///
- /// Adds the given model to cache.
- ///
- /// The model
- protected override void AddToCache(Alias model)
- {
- cache.Set(model.Id.ToString(), model);
- cache.Set($"AliasId_{model.SiteId}_{model.AliasUrl}", model.Id);
- }
-
- ///
- /// Removes the given model from cache.
- ///
- /// The model
- protected override void RemoveFromCache(Alias model)
- {
- cache.Remove($"AliasId_{model.SiteId}_{model.AliasUrl}");
-
- base.RemoveFromCache(model);
- }
- }
-}
diff --git a/core/Piranha/Repositories/ArchiveRepository.cs b/core/Piranha/Repositories/ArchiveRepository.cs
deleted file mode 100644
index 4d36746a1..000000000
--- a/core/Piranha/Repositories/ArchiveRepository.cs
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2016 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.Linq;
-
-namespace Piranha.Repositories
-{
- public class ArchiveRepository : IArchiveRepository
- {
- ///
- /// The current api.
- ///
- private readonly Api _api;
-
- ///
- /// The current db context.
- ///
- private readonly IDb _db;
-
- ///
- /// Default internal constructor.
- ///
- /// The current db context
- internal ArchiveRepository(Api api, IDb db)
- {
- _api = api;
- _db = db;
- }
-
- ///
- /// Gets the post archive for the blog with the given id.
- ///
- /// The unique blog id
- /// The optional page
- /// The optional category id
- /// The optional year
- /// The optional month
- /// The optional page size
- /// The archive model
- public T GetById(Guid id, int? page = 1, Guid? categoryId = null, int? year = null, int? month = null, int? pageSize = null) where T : Models.ArchivePage
- {
- return Get(id, page, categoryId, null, year, month, pageSize);
- }
-
- ///
- /// Gets the post archive for the specified blog and tag.
- ///
- /// The unique blog id
- /// The optional page
- /// The optional year
- /// The optional month
- /// The optional page size
- /// The archive model
- public T GetById(Guid id, int? page = 1, int? year = null, int? month = null, int? pageSize = null) where T : Models.ArchivePage
- {
- return Get(id, page, null, null, year, month, pageSize);
- }
-
- ///
- /// Gets the post archive for the specified blog and tag.
- ///
- /// The unique blog id
- /// The unique category id
- /// The optional page
- /// The optional year
- /// The optional month
- /// The optional page size
- /// The archive model
- public T GetByCategoryId(Guid id, Guid categoryId, int? page = 1, int? year = null, int? month = null, int? pageSize = null) where T : Models.ArchivePage
- {
- return Get(id, page, categoryId, null, year, month, pageSize);
- }
-
- ///
- /// Gets the post archive for the specified blog and tag.
- ///
- /// The unique blog id
- /// The unique tag id
- /// The optional page
- /// The optional year
- /// The optional month
- /// The optional page size
- /// The archive model
- public T GetByTagId(Guid id, Guid tagId, int? page = 1, int? year = null, int? month = null, int? pageSize = null) where T : Models.ArchivePage
- {
- return Get(id, page, null, tagId, year, month, pageSize);
- }
-
- private T Get(Guid id, int? page = 1, Guid? categoryId = null, Guid? tagId = null, int? year = null, int? month = null, int? pageSize = null) where T : Models.ArchivePage
- {
- // Get the requested blog page
- var model = _api.Pages.GetById(id);
-
- if (model != null)
- {
- // Set basic fields
- model.Archive = new Models.PostArchive();
-
- model.Route = model.Route ?? "/archive";
- model.Archive.Year = year;
- model.Archive.Month = month;
- model.Archive.CurrentPage = Math.Max(1, page.HasValue ? page.Value : 1);
-
- // Build the query.
- var now = DateTime.Now;
- var query = _db.Posts
- .Where(p => p.BlogId == id && p.Published <= now);
-
- if (categoryId.HasValue)
- {
- model.Archive.Category = _api.Categories.GetById(categoryId.Value);
-
- query = query.Where(p => p.CategoryId == categoryId.Value);
- }
- if (tagId.HasValue)
- {
- model.Archive.Tag = _api.Tags.GetById(tagId.Value);
-
- query = query.Where(p => p.Tags.Any(t => t.TagId == tagId.Value));
- }
-
- if (year.HasValue)
- {
- DateTime from;
- DateTime to;
-
- if (month.HasValue)
- {
- from = new DateTime(year.Value, month.Value, 1);
- to = from.AddMonths(1);
- }
- else
- {
- from = new DateTime(year.Value, 1, 1);
- to = from.AddYears(1);
- }
- query = query.Where(p => p.Published >= from && p.Published < to);
- }
-
- // Get requested page size
- if (!pageSize.HasValue)
- {
- using (var config = new Config(_api))
- {
- pageSize = config.ArchivePageSize;
-
- if (!pageSize.HasValue || pageSize == 0)
- pageSize = 5;
- }
- }
-
- // Get the total page count for the archive
- model.Archive.TotalPosts = query.Count();
- model.Archive.TotalPages = Math.Max(Convert.ToInt32(Math.Ceiling((double)model.Archive.TotalPosts / pageSize.Value)), 1);
- model.Archive.CurrentPage = Math.Min(model.Archive.CurrentPage, model.Archive.TotalPages);
-
- // Get the posts
- var posts = query
- .OrderByDescending(p => p.Published)
- .Skip((model.Archive.CurrentPage - 1) * pageSize.Value)
- .Take(pageSize.Value)
- .Select(p => p.Id);
-
- // Map & add the posts within the requested page
- foreach (var post in posts)
- {
- model.Archive.Posts.Add(_api.Posts.GetById(post));
- }
- return model;
- }
- return null;
- }
- }
-}
diff --git a/core/Piranha/Repositories/BaseRepository.cs b/core/Piranha/Repositories/BaseRepository.cs
deleted file mode 100644
index 4813977ff..000000000
--- a/core/Piranha/Repositories/BaseRepository.cs
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (c) 2017-2018 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Linq;
-using Microsoft.EntityFrameworkCore;
-using Piranha.Data;
-
-namespace Piranha.Repositories
-{
- ///
- /// Abstract base repository.
- ///
- /// The model type
- public abstract class BaseRepository where T : class, IModel
- {
- protected static readonly bool isCreated = typeof(ICreated).IsAssignableFrom(typeof(T));
- protected static readonly bool isModified = typeof(IModified).IsAssignableFrom(typeof(T));
- protected readonly IDb db;
- protected readonly ICache cache;
-
- ///
- /// Default constructor.
- ///
- /// The current db connection
- /// The optional model cache
- protected BaseRepository(IDb db, ICache cache = null)
- {
- this.db = db;
- this.cache = cache;
- }
-
- ///
- /// Gets the model with the specified id.
- ///
- /// The unique id
- /// The model, or null if it doesn't exist
- public virtual T GetById(Guid id)
- {
- T model = cache != null ? cache.Get(id.ToString()) : null;
-
- if (model == null)
- {
- model = db.Set()
- .AsNoTracking()
- .FirstOrDefault(m => m.Id == id);
-
- if (model != null)
- App.Hooks.OnLoad(model);
-
- if (cache != null && model != null)
- AddToCache(model);
- }
- return model;
- }
-
- ///
- /// Adds or updates the given model in the database
- /// depending on its state.
- ///
- /// The model
- public virtual void Save(T model)
- {
- App.Hooks.OnBeforeSave(model);
-
- if (db.Set().Count(m => m.Id == model.Id) == 0)
- Add(model);
- else Update(model);
-
- db.SaveChanges();
-
- App.Hooks.OnAfterSave(model);
-
- if (cache != null)
- cache.Remove(model.Id.ToString());
- }
-
- ///
- /// Deletes the model with the specified id.
- ///
- /// The unique id
- public virtual void Delete(Guid id)
- {
- var model = db.Set().FirstOrDefault(m => m.Id == id);
- if (model != null)
- {
- App.Hooks.OnBeforeDelete(model);
-
- db.Set().Remove(model);
- db.SaveChanges();
-
- App.Hooks.OnAfterDelete(model);
- }
-
- if (cache != null)
- cache.Remove(id.ToString());
- }
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- public virtual void Delete(T model)
- {
- Delete(model.Id);
- }
-
- #region Protected methods
- ///
- /// Adds a new model to the database.
- ///
- /// The model
- protected abstract void Add(T model);
-
- ///
- /// Updates the given model in the database.
- ///
- /// The model
- protected abstract void Update(T model);
-
- ///
- /// Prepares the model for an insert.
- ///
- /// The model
- protected virtual void PrepareInsert(T model)
- {
- // Prepare id
- model.Id = model.Id != Guid.Empty ? model.Id : Guid.NewGuid();
-
- // Prepare created date
- if (isCreated)
- ((ICreated)model).Created = DateTime.Now;
-
- // Prepare last modified date
- if (isModified)
- ((IModified)model).LastModified = DateTime.Now;
- }
-
- ///
- /// Perpares the model for an update.
- ///
- /// The model
- protected virtual void PrepareUpdate(T model)
- {
- // Prepare last modified date
- if (isModified)
- ((IModified)model).LastModified = DateTime.Now;
- }
-
- ///
- /// Adds the given model to cache.
- ///
- /// The model
- protected virtual void AddToCache(T model)
- {
- cache.Set(model.Id.ToString(), model);
- }
-
- ///
- /// Removes the given model from cache.
- ///
- /// The model
- protected virtual void RemoveFromCache(T model)
- {
- cache.Remove(model.Id.ToString());
- }
- #endregion
- }
-}
diff --git a/core/Piranha/Repositories/BaseRepositoryWithAll.cs b/core/Piranha/Repositories/BaseRepositoryWithAll.cs
deleted file mode 100644
index 304984e9c..000000000
--- a/core/Piranha/Repositories/BaseRepositoryWithAll.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2017-2018 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.EntityFrameworkCore;
-using Piranha.Data;
-
-namespace Piranha.Repositories
-{
- ///
- /// Abstract base repository.
- ///
- /// The model type
- public abstract class BaseRepositoryWithAll : BaseRepository where T : class, IModel
- {
- ///
- /// Default constructor.
- ///
- /// The current db connection
- /// The optional model cache
- protected BaseRepositoryWithAll(IDb db, ICache cache = null) : base(db, cache) { }
-
- ///
- /// Gets all available models.
- ///
- /// The available models
- public virtual IEnumerable GetAll()
- {
- var models = new List();
- var ids = db.Set()
- .AsNoTracking()
- .Select(m => m.Id);
-
- foreach (var id in ids)
- {
- var model = GetById(id);
- if (model != null)
- models.Add(model);
- }
- return models;
- }
- }
-}
diff --git a/core/Piranha/Repositories/CategoryRepository.cs b/core/Piranha/Repositories/CategoryRepository.cs
deleted file mode 100644
index 230c3671e..000000000
--- a/core/Piranha/Repositories/CategoryRepository.cs
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2017-2018 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.EntityFrameworkCore;
-using Piranha.Data;
-
-namespace Piranha.Repositories
-{
- public class CategoryRepository : BaseRepository, ICategoryRepository
- {
- private readonly Api api;
-
- ///
- /// Default constructor.
- ///
- /// The current api
- /// The current db context
- /// The optional model cache
- public CategoryRepository(Api api, IDb db, ICache cache = null)
- : base(db, cache)
- {
- this.api = api;
- }
-
- ///
- /// Gets all available models for the specified blog.
- ///
- /// The blog id
- /// The available models
- public IEnumerable GetAll(Guid blogId)
- {
- var models = new List();
- var categories = db.Categories
- .AsNoTracking()
- .Where(c => c.BlogId == blogId)
- .Select(c => c.Id);
-
- foreach (var c in categories)
- {
- var model = GetById(c);
- if (model != null)
- models.Add(model);
- }
- return models;
- }
-
- ///
- /// Gets the model with the given slug.
- ///
- /// The blog id
- /// The unique slug
- /// The model
- public Category GetBySlug(Guid blogId, string slug)
- {
- var id = cache != null ? cache.Get($"Category_{blogId}_{slug}") : null;
- Category model = null;
-
- if (id.HasValue)
- {
- model = GetById(id.Value);
- }
- else
- {
- id = db.Categories
- .AsNoTracking()
- .Where(c => c.BlogId == blogId && c.Slug == slug)
- .Select(c => c.Id)
- .FirstOrDefault();
-
- if (id.HasValue && id != Guid.Empty)
- model = GetById(id.Value);
- }
- return model;
- }
-
- ///
- /// Gets the model with the given title
- ///
- /// The blog id
- /// The unique title
- /// The model
- public Category GetByTitle(Guid blogId, string title)
- {
- var id = db.Categories
- .AsNoTracking()
- .Where(c => c.BlogId == blogId && c.Title == title)
- .Select(c => c.Id)
- .FirstOrDefault();
-
- if (id != Guid.Empty)
- return GetById(id);
- return null;
- }
-
- ///
- /// Deletes all unused categories for the specified blog.
- ///
- /// The blog id
- public void DeleteUnused(Guid blogId)
- {
- var used = db.Posts
- .Where(p => p.BlogId == blogId)
- .Select(p => p.CategoryId)
- .Distinct()
- .ToArray();
-
- var unused = db.Categories
- .Where(c => c.BlogId == blogId && !used.Contains(c.Id))
- .ToList();
-
- if (unused.Count > 0)
- {
- db.Categories.RemoveRange(unused);
- db.SaveChanges();
- }
- }
-
- #region Protected methods
- ///
- /// Adds a new model to the database.
- ///
- /// The model
- protected override void Add(Category model)
- {
- PrepareInsert(model);
-
- // Check required
- if (string.IsNullOrWhiteSpace(model.Title))
- throw new ArgumentException("Title is required for Category");
-
- // Ensure slug
- if (string.IsNullOrWhiteSpace(model.Slug))
- model.Slug = Utils.GenerateSlug(model.Title, false);
- else model.Slug = Utils.GenerateSlug(model.Slug, false);
-
- db.Categories.Add(model);
- }
-
- ///
- /// Updates the given model in the database.
- ///
- /// The model
- protected override void Update(Category model)
- {
- PrepareUpdate(model);
-
- // Check required
- if (string.IsNullOrWhiteSpace(model.Title))
- throw new ArgumentException("Title is required for Category");
-
- // Ensure slug
- if (string.IsNullOrWhiteSpace(model.Slug))
- model.Slug = Utils.GenerateSlug(model.Title);
- else model.Slug = Utils.GenerateSlug(model.Slug);
-
- var category = db.Categories.FirstOrDefault(c => c.Id == model.Id);
- if (category != null)
- {
- App.Mapper.Map(model, category);
- }
- }
-
- ///
- /// Adds the given model to cache.
- ///
- /// The model
- protected override void AddToCache(Category model)
- {
- cache.Set(model.Id.ToString(), model);
- cache.Set($"Category_{model.BlogId}_{model.Slug}", model.Id);
- }
-
- ///
- /// Removes the given model from cache.
- ///
- /// The model
- protected override void RemoveFromCache(Category model)
- {
- cache.Remove(model.Id.ToString());
- cache.Remove($"Category_{model.BlogId}_{model.Slug}");
- }
- #endregion
- }
-}
diff --git a/core/Piranha/Repositories/IAliasRepository.cs b/core/Piranha/Repositories/IAliasRepository.cs
index 7e4d0fd0a..52eac1e38 100644
--- a/core/Piranha/Repositories/IAliasRepository.cs
+++ b/core/Piranha/Repositories/IAliasRepository.cs
@@ -1,16 +1,17 @@
/*
- * 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.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
using System.Collections.Generic;
-using Piranha.Data;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
@@ -21,48 +22,42 @@ public interface IAliasRepository
///
/// The optional site id
/// The available models
- IEnumerable GetAll(Guid? siteId = null);
+ Task> GetAll(Guid siteId);
///
/// Gets the model with the specified id.
///
/// The unique id
/// The model, or NULL if it doesn't exist
- Alias GetById(Guid id);
+ Task GetById(Guid id);
///
/// Gets the model with the given alias url.
///
/// The unique url
- /// The optional site id
+ /// The site id
/// The model
- Alias GetByAliasUrl(string url, Guid? siteId = null);
+ Task GetByAliasUrl(string url, Guid siteId);
///
/// Gets the models with the given redirect url.
///
/// The unique url
- /// The optional site id
+ /// The site id
/// The models
- IEnumerable GetByRedirectUrl(string url, Guid? siteId = null);
+ Task> GetByRedirectUrl(string url, Guid siteId);
///
/// Adds or updates the given model in the database
/// depending on its state.
///
/// The model
- void Save(Alias model);
+ Task Save(Alias model);
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Alias model);
+ Task Delete(Guid id);
}
}
diff --git a/core/Piranha/Repositories/IArchiveRepository.cs b/core/Piranha/Repositories/IArchiveRepository.cs
index 7effd733a..c53f075d9 100644
--- a/core/Piranha/Repositories/IArchiveRepository.cs
+++ b/core/Piranha/Repositories/IArchiveRepository.cs
@@ -1,14 +1,16 @@
/*
- * Copyright (c) 2016-2017 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 System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
using Piranha.Models;
namespace Piranha.Repositories
@@ -16,51 +18,29 @@ namespace Piranha.Repositories
public interface IArchiveRepository
{
///
- /// Gets the post archive for the blog with the given id.
+ /// Gets the total post count for the specified archive
+ /// and filter.
///
- /// The unique blog id
- /// The optional page
+ /// The archive id
/// The optional category id
+ /// The optional tag id
/// The optional year
/// The optional month
- /// The optional page size
- /// The archive model
- [Obsolete("Please update your code to use the new GetById, GetByCategoryId & GetByTagId", true)]
- T GetById(Guid id, int? page = 1, Guid? categoryId = null, int? year = null, int? month = null, int? pageSize = null) where T : ArchivePage;
-
- ///
- /// Gets the post archive for the blog with the given id.
- ///
- /// The unique blog id
- /// The optional page
- /// The optional year
- /// The optional month
- /// The optional page size
- /// The archive model
- T GetById(Guid id, int? page = 1, int? year = null, int? month = null, int? pageSize = null) where T : ArchivePage;
+ /// The total post count
+ Task GetPostCount(Guid archiveId, Guid? categoryId = null, Guid? tagId = null, int? year = null, int? month = null);
///
- /// Gets the post archive for the blog with the given id.
+ /// Gets the id of the posts in the current archive
+ /// matching the specified filter.
///
- /// The unique blog id
- /// The unique category id
- /// The optional page
- /// The optional year
- /// The optional month
- /// The optional page size
- /// The archive model
- T GetByCategoryId(Guid id, Guid categoryId, int? page = 1, int? year = null, int? month = null, int? pageSize = null) where T : ArchivePage;
-
- ///
- /// Gets the post archive for the blog with the given id.
- ///
- /// The unique blog id
- /// The unique tag id
- /// The optional page
+ /// The archive id
+ /// The page size
+ /// The current page
+ /// The optional category id
+ /// The optional tag id
/// The optional year
/// The optional month
- /// The optional page size
- /// The archive model
- T GetByTagId(Guid id, Guid tagId, int? page = 1, int? year = null, int? month = null, int? pageSize = null) where T : ArchivePage;
+ /// The matching posts
+ Task> GetPosts(Guid archiveId, int pageSize, int currentPage, Guid? categoryId = null, Guid? tagId = null, int? year = null, int? month = null);
}
}
diff --git a/core/Piranha/Repositories/ICategoryRepository.cs b/core/Piranha/Repositories/ICategoryRepository.cs
deleted file mode 100644
index 46db623d9..000000000
--- a/core/Piranha/Repositories/ICategoryRepository.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2017 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Collections.Generic;
-using Piranha.Data;
-
-namespace Piranha.Repositories
-{
- public interface ICategoryRepository
- {
- ///
- /// Gets all available models.
- ///
- /// The blog id
- /// The available models
- IEnumerable GetAll(Guid blogId);
-
- ///
- /// Gets the model with the specified id.
- ///
- /// The unique id
- /// The model, or NULL if it doesn't exist
- Category GetById(Guid id);
-
- ///
- /// Gets the model with the given slug
- ///
- /// The blog id
- /// The unique slug
- /// The model
- Category GetBySlug(Guid blogId, string slug);
-
- ///
- /// Gets the model with the given title
- ///
- /// The blog id
- /// The unique title
- /// The model
- Category GetByTitle(Guid blogId, string title);
-
- ///
- /// Adds or updates the given model in the database
- /// depending on its state.
- ///
- /// The model
- void Save(Category model);
-
- ///
- /// Deletes the model with the specified id.
- ///
- /// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Category model);
-
- ///
- /// Deletes all unused categories for the specified blog.
- ///
- /// The blog id
- void DeleteUnused(Guid blogId);
- }
-}
diff --git a/core/Piranha/Repositories/IMediaRepository.cs b/core/Piranha/Repositories/IMediaRepository.cs
index 26c293749..b25ffa98c 100644
--- a/core/Piranha/Repositories/IMediaRepository.cs
+++ b/core/Piranha/Repositories/IMediaRepository.cs
@@ -1,17 +1,17 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-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.Collections.Generic;
using System.Threading.Tasks;
-using Piranha.Data;
+using Piranha.Models;
namespace Piranha.Repositories
{
@@ -22,7 +22,7 @@ public interface IMediaRepository
///
/// The optional folder id
/// The available media
- IEnumerable GetAll(Guid? folderId = null);
+ Task> GetAll(Guid? folderId = null);
///
/// Gets all media folders available in the specified
@@ -30,114 +30,59 @@ public interface IMediaRepository
///
/// The optional folder id
/// The available media folders
- IEnumerable GetAllFolders(Guid? folderId = null);
+ Task> GetAllFolders(Guid? folderId = null);
///
/// Gets the media with the given id.
///
/// The unique id
/// The media
- Media GetById(Guid id);
+ Task GetById(Guid id);
///
/// Gets the media folder with the given id.
///
/// The unique id
/// The media folder
- MediaFolder GetFolderById(Guid id);
+ Task GetFolderById(Guid id);
///
/// Gets the hierachical media structure.
///
/// The media structure
- Models.MediaStructure GetStructure();
+ Task GetStructure();
///
- /// Adds or updates the given model in the database depending on its state.
- /// Please note that this method is not really synchronous, it's just a
- /// wrapper for the async version.
+ /// Adds or updates the given model in the database.
///
- /// The content to save
- void Save(Models.MediaContent content);
-
- ///
- /// Adds or updates the given model in the database
- /// depending on its state.
- ///
- /// The content to save
- Task SaveAsync(Models.MediaContent content);
+ /// The model
+ Task Save(Media model);
///
/// Adds or updates the given model in the database
/// depending on its state.
///
/// The model
- void SaveFolder(MediaFolder model);
+ Task SaveFolder(MediaFolder model);
///
/// Moves the media to the folder with the specified id.
///
/// The media
/// The folder id
- void Move(Media model, Guid? folderId);
-
- ///
- /// Ensures that the image version with the given size exsists
- /// and returns its public URL. Please note that this method is
- /// not really synchronous, it's just a wrapper for the async version.
- ///
- /// The unique id
- /// The requested width
- /// The optionally requested height
- /// The public URL
- string EnsureVersion(Guid id, int width, int? height = null);
-
- ///
- /// Ensures that the image version with the given size exsists
- /// and returns its public URL.
- ///
- /// The unique id
- /// The requested width
- /// The optionally requested height
- /// The public URL
- Task EnsureVersionAsync(Guid id, int width, int? height = null);
+ Task Move(Media model, Guid? folderId);
///
/// Deletes the media with the given id. Please note that this method
/// is not really synchronous, it's just a wrapper for the async version.
///
/// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the media with the given id.
- ///
- /// The unique id
- Task DeleteAsync(Guid id);
-
- ///
- /// Deletes the given model. Please note that this method
- /// is not really synchronous, it's just a wrapper for the async version.
- ///
- /// The media
- void Delete(Media model);
-
- ///
- /// Deletes the given model.
- ///
- /// The media
- Task DeleteAsync(Media model);
+ Task Delete(Guid id);
///
/// Deletes the media folder with the given id.
///
/// The unique id
- void DeleteFolder(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The media
- void DeleteFolder(MediaFolder model);
+ Task DeleteFolder(Guid id);
}
}
\ No newline at end of file
diff --git a/core/Piranha/Repositories/IPageRepository.cs b/core/Piranha/Repositories/IPageRepository.cs
index 9668895ce..1c30afc7f 100644
--- a/core/Piranha/Repositories/IPageRepository.cs
+++ b/core/Piranha/Repositories/IPageRepository.cs
@@ -1,87 +1,43 @@
/*
- * 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 System;
using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
public interface IPageRepository
{
- ///
- /// Creates and initializes a new page of the specified type.
- ///
- /// The created page
- T Create(string typeId = null) where T : Models.PageBase;
-
- ///
- /// Creates and initializes a copy of the given page.
- ///
- /// The created copy
- T Copy(T originalPage) where T : Models.PageBase;
-
- ///
- /// Detaches a copy and initializes it as a standalone page
- ///
- /// The standalone page
- void Detach(T originalPage) where T : Models.PageBase;
-
///
/// Gets all of the available pages for the current site.
///
- /// The optional site id
+ /// The site id
/// The pages
- IEnumerable GetAll(Guid? siteId = null);
-
- ///
- /// Gets all of the available pages for the current site.
- ///
- /// The optional site id
- /// The pages
- IEnumerable GetAll(Guid? siteId = null) where T : Models.PageBase;
+ Task> GetAll(Guid siteId);
///
/// Gets the available blog pages for the current site.
///
- /// The optional site id
+ /// The site id
/// The pages
- IEnumerable GetAllBlogs(Guid? siteId = null);
-
- ///
- /// Gets the available blog pages for the current site.
- ///
- /// The optional site id
- /// The pages
- IEnumerable GetAllBlogs(Guid? siteId = null) where T : Models.PageBase;
-
- ///
- /// Gets the site startpage.
- ///
- /// The optional site id
- /// The page model
- Models.DynamicPage GetStartpage(Guid? siteId = null);
+ Task> GetAllBlogs(Guid siteId);
///
/// Gets the site startpage.
///
/// The model type
- /// The optional site id
+ /// The site id
/// The page model
- T GetStartpage(Guid? siteId = null) where T : Models.PageBase;
-
- ///
- /// Gets the page model with the specified id.
- ///
- /// The unique id
- /// The page model
- Models.DynamicPage GetById(Guid id);
+ Task GetStartpage(Guid siteId) where T : PageBase;
///
/// Gets the page model with the specified id.
@@ -89,32 +45,16 @@ public interface IPageRepository
/// The model type
/// The unique id
/// The page model
- T GetById(Guid id) where T : Models.PageBase;
-
- ///
- /// Gets the page model with the specified slug.
- ///
- /// The unique slug
- /// The optional site id
- /// The page model
- Models.DynamicPage GetBySlug(string slug, Guid? siteId = null);
+ Task GetById(Guid id) where T : PageBase;
///
/// Gets the page model with the specified slug.
///
/// The model type
/// The unique slug
- /// The optional site id
+ /// The site id
/// The page model
- T GetBySlug(string slug, Guid? siteId = null) where T : Models.PageBase;
-
- ///
- /// Gets the id for the page with the given slug.
- ///
- /// The unique slug
- /// The optional page id
- /// The id
- Guid? GetIdBySlug(string slug, Guid? siteId = null);
+ Task GetBySlug(string slug, Guid siteId) where T : PageBase;
///
/// Moves the current page in the structure.
@@ -123,24 +63,21 @@ public interface IPageRepository
/// The page to move
/// The new parent id
/// The new sort order
- void Move(T model, Guid? parentId, int sortOrder) where T : Models.PageBase;
+ /// The other pages that were affected by the move
+ Task> Move(T model, Guid? parentId, int sortOrder) where T : PageBase;
///
/// Saves the given page model
///
/// The page model
- void Save(T model) where T : Models.PageBase;
+ /// The other pages that were affected by the move
+ Task> Save(T model) where T : PageBase;
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(T model) where T : Models.PageBase;
+ /// The other pages that were affected by the move
+ Task> Delete(Guid id);
}
}
diff --git a/core/Piranha/Repositories/IPageTypeRepository.cs b/core/Piranha/Repositories/IPageTypeRepository.cs
index 3d97491bd..30441f9a2 100644
--- a/core/Piranha/Repositories/IPageTypeRepository.cs
+++ b/core/Piranha/Repositories/IPageTypeRepository.cs
@@ -1,14 +1,16 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
@@ -18,32 +20,26 @@ public interface IPageTypeRepository
/// Gets all available models.
///
/// The available models
- IEnumerable GetAll();
+ Task> GetAll();
///
/// Gets the model with the specified id.
///
/// The unique i
///
- Models.PageType GetById(string id);
+ Task GetById(string id);
///
/// Adds or updates the given model in the database
/// depending on its state.
///
/// The model
- void Save(Models.PageType model);
+ Task Save(PageType model);
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(string id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Models.PageType model);
+ Task Delete(string id);
}
}
diff --git a/core/Piranha/Repositories/IParamRepository.cs b/core/Piranha/Repositories/IParamRepository.cs
index 46625454d..292df1887 100644
--- a/core/Piranha/Repositories/IParamRepository.cs
+++ b/core/Piranha/Repositories/IParamRepository.cs
@@ -1,16 +1,17 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
using System.Collections.Generic;
-using Piranha.Data;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
@@ -20,39 +21,33 @@ public interface IParamRepository
/// Gets all available models.
///
/// The available models
- IEnumerable GetAll();
+ Task> GetAll();
///
/// Gets the model with the specified id.
///
/// The unique id
/// The model, or NULL if it doesn't exist
- Param GetById(Guid id);
+ Task GetById(Guid id);
///
/// Gets the model with the given internal id.
///
/// The unique key
/// The model
- Param GetByKey(string key);
+ Task GetByKey(string key);
///
/// Adds or updates the given model in the database
/// depending on its state.
///
/// The model
- void Save(Param model);
+ Task Save(Param model);
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Param model);
+ Task Delete(Guid id);
}
}
diff --git a/core/Piranha/Repositories/IPostRepository.cs b/core/Piranha/Repositories/IPostRepository.cs
index 483d11842..818868214 100644
--- a/core/Piranha/Repositories/IPostRepository.cs
+++ b/core/Piranha/Repositories/IPostRepository.cs
@@ -1,74 +1,49 @@
/*
- * 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 System;
using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
public interface IPostRepository
{
///
- /// Creates and initializes a new post of the specified type.
- ///
- /// The created post
- T Create(string typeId = null) where T : Models.PostBase;
-
- ///
- /// Gets the available post items.
- ///
- /// The posts
- IEnumerable GetAll();
-
- ///
- /// Gets the available post items.
- ///
- /// The posts
- IEnumerable GetAll() where T : Models.PostBase;
-
- ///
- /// Gets the available post items.
+ /// Gets the available posts for the specified blog.
///
/// The unique id
/// The posts
- IEnumerable GetAll(Guid blogId);
+ Task> GetAll(Guid blogId);
///
- /// Gets the available post items.
+ /// Gets the available posts for the specified site.
///
- /// The unique id
+ /// The site id
/// The posts
- IEnumerable GetAll(Guid blogId) where T : Models.PostBase;
+ Task> GetAllBySiteId(Guid siteId);
///
- /// Gets the available posts for the specified blog.
+ /// Gets all available categories for the specified blog.
///
- /// The blog slug
- /// The optional site id
- /// The posts
- IEnumerable GetAll(string slug, Guid? siteId = null);
+ /// The blog id
+ /// The available categories
+ Task> GetAllCategories(Guid blogId);
///
- /// Gets the available posts for the specified blog.
+ /// Gets all available tags for the specified blog.
///
- /// The blog slug
- /// The optional site id
- /// The posts
- IEnumerable GetAll(string slug, Guid? siteId = null) where T : Models.PostBase;
-
- ///
- /// Gets the post model with the specified id.
- ///
- /// The unique id
- /// The post model
- Models.DynamicPost GetById(Guid id);
+ /// The blog id
+ /// The available tags
+ Task> GetAllTags(Guid blogId);
///
/// Gets the post model with the specified id.
@@ -76,60 +51,43 @@ public interface IPostRepository
/// The model type
/// The unique id
/// The post model
- T GetById(Guid id) where T : Models.PostBase;
-
- ///
- /// Gets the post model with the specified slug.
- ///
- /// The unique blog slug
- /// The unique slug
- /// The post model
- Models.DynamicPost GetBySlug(Guid blogId, string slug);
+ Task GetById(Guid id) where T : PostBase;
///
/// Gets the post model with the specified slug.
///
/// The model type
- /// The unique blog slug
+ /// The blog id
/// The unique slug
/// The post model
- T GetBySlug(Guid blogId, string slug) where T : Models.PostBase;
+ Task GetBySlug(Guid blogId, string slug) where T : PostBase;
///
- /// Gets the post model with the specified slug.
+ /// Gets the category with the given slug.
///
- /// The unique blog slug
+ /// The blog id
/// The unique slug
- /// The optional site id
- /// The post model
- Models.DynamicPost GetBySlug(string blog, string slug, Guid? siteId = null);
+ /// The category
+ Task GetCategoryBySlug(Guid blogId, string slug);
///
- /// Gets the post model with the specified slug.
+ /// Gets the tag with the given slug.
///
- /// The model type
- /// The unique blog slug
+ /// The blog id
/// The unique slug
- /// The optional site id
- /// The post model
- T GetBySlug(string blog, string slug, Guid? siteId = null) where T : Models.PostBase;
+ /// The tag
+ Task GetTagBySlug(Guid blogId, string slug);
///
/// Saves the given post model
///
/// The post model
- void Save(T model) where T : Models.PostBase;
+ Task Save(T model) where T : PostBase;
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(T model) where T : Models.PostBase;
+ Task Delete(Guid id);
}
}
diff --git a/core/Piranha/Repositories/IPostTypeRepository.cs b/core/Piranha/Repositories/IPostTypeRepository.cs
index d74074df4..0abb426f6 100644
--- a/core/Piranha/Repositories/IPostTypeRepository.cs
+++ b/core/Piranha/Repositories/IPostTypeRepository.cs
@@ -1,14 +1,16 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
@@ -18,32 +20,26 @@ public interface IPostTypeRepository
/// Gets all available models.
///
/// The available models
- IEnumerable GetAll();
+ Task> GetAll();
///
/// Gets the model with the specified id.
///
/// The unique i
///
- Models.PostType GetById(string id);
+ Task GetById(string id);
///
/// Adds or updates the given model in the database
/// depending on its state.
///
/// The model
- void Save(Models.PostType model);
+ Task Save(PostType model);
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(string id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Models.PostType model);
+ Task Delete(string id);
}
}
diff --git a/core/Piranha/Repositories/ISiteRepository.cs b/core/Piranha/Repositories/ISiteRepository.cs
index f8f50286f..34674a362 100644
--- a/core/Piranha/Repositories/ISiteRepository.cs
+++ b/core/Piranha/Repositories/ISiteRepository.cs
@@ -1,16 +1,17 @@
/*
- * Copyright (c) 2017 Håkan Edling
+ * Copyright (c) 2017-2019 Håkan Edling
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System;
using System.Collections.Generic;
-using Piranha.Data;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
@@ -20,41 +21,34 @@ public interface ISiteRepository
/// Gets all available models.
///
/// The available models
- IEnumerable GetAll();
+ Task> GetAll();
///
/// Gets the model with the specified id.
///
/// The unique id
/// The model, or NULL if it doesn't exist
- Site GetById(Guid id);
+ Task GetById(Guid id);
///
/// Gets the model with the given internal id.
///
/// The unique internal i
/// The model
- Site GetByInternalId(string internalId);
-
- ///
- /// Gets the model with the given hostname.
- ///
- /// The hostname
- /// The model
- Site GetByHostname(string hostname);
+ Task GetByInternalId(string internalId);
///
/// Gets the default side.
///
/// The modell, or NULL if it doesnt exist
- Site GetDefault();
+ Task GetDefault();
///
/// Gets the site content for given site id.
///
/// Site id
/// The site content model
- Models.DynamicSiteContent GetContentById(Guid id);
+ Task GetContentById(Guid id);
///
/// Gets the site content for given site id.
@@ -62,55 +56,36 @@ public interface ISiteRepository
/// Site id
/// The site model type
/// The site content model
- T GetContentById(Guid id) where T : Models.SiteContent;
+ Task GetContentById(Guid id) where T : SiteContent;
///
/// Gets the hierachical sitemap structure.
///
- /// The optional site id
+ /// The site id
/// If only published items should be included
/// The sitemap
- Models.Sitemap GetSitemap(Guid? id = null, bool onlyPublished = true);
+ Task GetSitemap(Guid id, bool onlyPublished = true);
///
/// Adds or updates the given model in the database
/// depending on its state.
///
/// The model
- void Save(Site model);
+ Task Save(Site model);
///
- /// Saves the given site content to the site with the
+ /// Saves the given site content to the site with the
/// given id.
///
/// The site id
/// The site content
/// The site content type
- void SaveContent(Guid siteId, T content) where T : Models.SiteContent;
+ Task SaveContent(Guid siteId, T content) where T : SiteContent;
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Site model);
-
- ///
- /// Creates and initializes a new site content model of the specified type.
- ///
- /// The created site content
- T CreateContent(string typeId = null) where T : Models.SiteContentBase;
-
- ///
- /// Invalidates the cached version of the sitemap with the
- /// given id, if caching is enabled.
- ///
- /// The site id
- void InvalidateSitemap(Guid id);
+ Task Delete(Guid id);
}
}
diff --git a/core/Piranha/Repositories/ISiteTypeRepository.cs b/core/Piranha/Repositories/ISiteTypeRepository.cs
index 9fba56fd3..9159f2237 100644
--- a/core/Piranha/Repositories/ISiteTypeRepository.cs
+++ b/core/Piranha/Repositories/ISiteTypeRepository.cs
@@ -1,14 +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.
- *
+ *
* http://github.com/piranhacms/piranha
- *
+ *
*/
using System.Collections.Generic;
+using System.Threading.Tasks;
+using Piranha.Models;
namespace Piranha.Repositories
{
@@ -18,32 +20,26 @@ public interface ISiteTypeRepository
/// Gets all available models.
///
/// The available models
- IEnumerable GetAll();
+ Task> GetAll();
///
/// Gets the model with the specified id.
///
/// The unique i
///
- Models.SiteType GetById(string id);
+ Task GetById(string id);
///
/// Adds or updates the given model in the database
/// depending on its state.
///
/// The model
- void Save(Models.SiteType model);
+ Task Save(SiteType model);
///
/// Deletes the model with the specified id.
///
/// The unique id
- void Delete(string id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Models.SiteType model);
+ Task Delete(string id);
}
}
diff --git a/core/Piranha/Repositories/ITagRepository.cs b/core/Piranha/Repositories/ITagRepository.cs
deleted file mode 100644
index 4014b550c..000000000
--- a/core/Piranha/Repositories/ITagRepository.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2017 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Collections.Generic;
-using Piranha.Data;
-
-namespace Piranha.Repositories
-{
- public interface ITagRepository
- {
- ///
- /// Gets all available models.
- ///
- /// The blog id
- /// The available models
- IEnumerable GetAll(Guid blogId);
-
- ///
- /// Gets the models for the post with the given id.
- ///
- /// The post id
- /// The model
- IEnumerable GetByPostId(Guid postId);
-
- ///
- /// Gets the model with the specified id.
- ///
- /// The unique id
- /// The model, or NULL if it doesn't exist
- Tag GetById(Guid id);
-
- ///
- /// Gets the model with the given slug
- ///
- /// The blog id
- /// The unique slug
- /// The model
- Tag GetBySlug(Guid blogId, string slug);
-
- ///
- /// Gets the model with the given title
- ///
- /// The blog id
- /// The unique title
- /// The model
- Tag GetByTitle(Guid blogId, string title);
-
- ///
- /// Adds or updates the given model in the database
- /// depending on its state.
- ///
- /// The model
- void Save(Tag model);
-
- ///
- /// Deletes the model with the specified id.
- ///
- /// The unique id
- void Delete(Guid id);
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- void Delete(Tag model);
-
- ///
- /// Deletes all unused tags for the specified blog.
- ///
- /// The blog id
- void DeleteUnused(Guid blogId);
- }
-}
diff --git a/core/Piranha/Repositories/PageRepository.cs b/core/Piranha/Repositories/PageRepository.cs
deleted file mode 100644
index 467b7038b..000000000
--- a/core/Piranha/Repositories/PageRepository.cs
+++ /dev/null
@@ -1,961 +0,0 @@
-/*
- * Copyright (c) 2016-2018 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.Collections.Generic;
-using System.Linq;
-using Microsoft.EntityFrameworkCore;
-using Piranha.Data;
-using Piranha.Services;
-
-namespace Piranha.Repositories
-{
- public class PageRepository : IPageRepository
- {
- private readonly IDb _db;
- private readonly IApi _api;
- private readonly IContentService _contentService;
- private readonly ICache _cache;
-
- ///
- /// Default constructor.
- ///
- /// The current api
- /// The current db context
- /// The content service factory
- /// The optional model cache
- public PageRepository(IApi api, IDb db, IContentServiceFactory factory, ICache cache = null)
- {
- _api = api;
- _db = db;
- _contentService = factory.CreatePageService();
- _cache = cache;
- }
-
- ///
- /// Creates and initializes a new page of the specified type.
- ///
- /// The created page
- public T Create(string typeId = null) where T : Models.PageBase
- {
- if (string.IsNullOrWhiteSpace(typeId))
- {
- typeId = typeof(T).Name;
- }
- return _contentService.Create(_api.PageTypes.GetById(typeId));
- }
-
- ///
- /// Creates and initializes a copy of the given page.
- ///
- /// The created copy
- public T Copy(T originalPage) where T : Models.PageBase
- {
- var model = _contentService.Create(_api.PageTypes.GetById(originalPage.TypeId));
- model.OriginalPageId = originalPage.Id;
- model.Slug = null;
- return model;
- }
-
- ///
- /// Detaches a copy and initializes it as a standalone page
- ///
- /// The standalone page
- public void Detach(T page) where T : Models.PageBase
- {
- if (!page.OriginalPageId.HasValue)
- {
- throw new InvalidOperationException("Page is not an copy");
- }
-
- var model = GetById(page.Id);
- model.OriginalPageId = null;
-
- foreach (var pageBlock in model.Blocks)
- {
- pageBlock.Id = Guid.Empty;
- }
-
- Save(model);
- }
-
- ///
- /// Gets all of the available pages for the current site.
- ///
- /// The optional site id
- /// The pages
- public IEnumerable GetAll(Guid? siteId = null)
- {
- return GetAll(siteId);
- }
-
- ///
- /// Gets all of the available pages for the current site.
- ///
- /// The optional site id
- /// The pages
- public IEnumerable GetAll(Guid? siteId = null) where T : Models.PageBase
- {
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
-
- if (site != null)
- {
- siteId = site.Id;
- }
- }
-
- var pages = _db.Pages
- .AsNoTracking()
- .Where(p => p.SiteId == siteId)
- .OrderBy(p => p.ParentId)
- .ThenBy(p => p.SortOrder)
- .Select(p => p.Id);
-
- var models = new List();
-
- foreach (var page in pages)
- {
- var model = GetById(page);
-
- if (model != null)
- {
- models.Add(model);
- }
- }
- return models;
- }
-
- ///
- /// Gets the available blog pages for the current site.
- ///
- /// The optional site id
- /// The pages
- public IEnumerable GetAllBlogs(Guid? siteId = null)
- {
- return GetAllBlogs(siteId);
- }
-
- ///
- /// Gets the available blog pages for the current site.
- ///
- /// The optional site id
- /// The pages
- public IEnumerable GetAllBlogs(Guid? siteId = null) where T : Models.PageBase
- {
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
-
- if (site != null)
- {
- siteId = site.Id;
- }
- }
-
- var pages = _db.Pages
- .AsNoTracking()
- .Where(p => p.SiteId == siteId && p.ContentType == "Blog")
- .OrderBy(p => p.ParentId)
- .ThenBy(p => p.SortOrder)
- .Select(p => p.Id);
-
- var models = new List();
-
- foreach (var page in pages)
- {
- var model = GetById(page);
-
- if (model != null)
- {
- models.Add(model);
- }
- }
- return models;
- }
-
- ///
- /// Gets the site startpage.
- ///
- /// The optional site id
- /// The page model
- public Models.DynamicPage GetStartpage(Guid? siteId = null)
- {
- return GetStartpage(siteId);
- }
-
- ///
- /// Gets the site startpage.
- ///
- /// The model type
- /// The optional site id
- /// The page model
- public T GetStartpage(Guid? siteId = null) where T : Models.PageBase
- {
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
- if (site != null)
- {
- siteId = site.Id;
- }
- }
-
- var page = _cache?.Get($"Page_{siteId}");
-
- if (page == null)
- {
- page = GetQuery(out var fullQuery)
- .FirstOrDefault(p => p.SiteId == siteId && p.ParentId == null && p.SortOrder == 0);
-
- if (page != null)
- {
- if (_cache != null && fullQuery)
- {
- AddToCache(page);
- }
- }
- }
-
- if (page != null)
- {
- if (page.OriginalPageId.HasValue)
- {
- return MapOriginalPage(page);
- }
- return _contentService.Transform(page, _api.PageTypes.GetById(page.PageTypeId), Process);
- }
- return null;
- }
-
- ///
- /// Gets the page model with the specified id.
- ///
- /// The unique id
- /// The page model
- public Models.DynamicPage GetById(Guid id)
- {
- return GetById(id);
- }
-
- ///
- /// Gets the page model with the specified id.
- ///
- /// The model type
- /// The unique id
- /// The page model
- public T GetById(Guid id) where T : Models.PageBase
- {
- var page = _cache?.Get(id.ToString());
-
- if (page == null)
- {
- page = GetQuery(out var fullQuery)
- .FirstOrDefault(p => p.Id == id);
-
- if (page != null)
- {
- if (_cache != null && fullQuery)
- {
- AddToCache(page);
- }
- }
- }
-
- if (page != null)
- {
- if (page.OriginalPageId.HasValue)
- {
- return MapOriginalPage(page);
- }
- return _contentService.Transform(page, _api.PageTypes.GetById(page.PageTypeId), Process);
- }
- return null;
- }
-
- ///
- /// Gets the page model with the specified slug.
- ///
- /// The unique slug
- /// The optional site id
- /// The page model
- public Models.DynamicPage GetBySlug(string slug, Guid? siteId = null)
- {
- return GetBySlug(slug, siteId);
- }
-
- ///
- /// Gets the page model with the specified slug.
- ///
- /// The model type
- /// The unique slug
- /// The optional site id
- /// The page model
- public T GetBySlug(string slug, Guid? siteId = null) where T : Models.PageBase
- {
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
- if (site != null)
- {
- siteId = site.Id;
- }
- }
-
- // See if we can get the page id for the slug from cache.
- var pageId = _cache?.Get($"PageId_{siteId}_{slug}");
-
- if (pageId.HasValue)
- {
- // Load the page by id instead
- return GetById(pageId.Value);
- }
- else
- {
- // No cache found, load from database
- var page = GetQuery(out var fullQuery)
- .FirstOrDefault(p => p.SiteId == siteId && p.Slug == slug);
-
- if (page != null)
- {
- if (_cache != null && fullQuery)
- {
- AddToCache(page);
- }
-
- if (page.OriginalPageId.HasValue)
- {
- return MapOriginalPage(page);
- }
-
- return _contentService.Transform(page, _api.PageTypes.GetById(page.PageTypeId), Process);
- }
- return null;
- }
- }
-
- ///
- /// Gets the id for the page with the given slug.
- ///
- /// The unique slug
- /// The optional page id
- /// The id
- public Guid? GetIdBySlug(string slug, Guid? siteId = null)
- {
- if (!siteId.HasValue)
- {
- var site = _api.Sites.GetDefault();
- if (site != null)
- {
- siteId = site.Id;
- }
- }
-
- // See if we can get the page id for the slug from cache.
- var pageId = _cache != null ? _cache.Get($"PageId_{siteId}_{slug}") : (Guid?)null;
-
- if (pageId.HasValue)
- {
- return pageId;
- }
- else
- {
- // No cache found, load from database
- var page = _db.Pages
- .AsNoTracking()
- .FirstOrDefault(p => p.SiteId == siteId && p.Slug == slug);
-
- if (page != null)
- {
- return page.Id;
- }
- return null;
- }
- }
-
- ///
- /// Moves the current page in the structure.
- ///
- /// The model type
- /// The page to move
- /// The new parent id
- /// The new sort order
- public void Move(T model, Guid? parentId, int sortOrder) where T : Models.PageBase
- {
- IEnumerable oldSiblings = null;
- IEnumerable newSiblings = null;
-
- // Only get siblings if we need to invalidate from cache
- if (_cache != null)
- {
- oldSiblings = _db.Pages
- .Where(p => p.ParentId == model.ParentId && p.Id != model.Id)
- .ToList();
- newSiblings = _db.Pages
- .Where(p => p.ParentId == parentId)
- .ToList();
- }
-
- // Remove the old position for the page
- MovePages(model.Id, model.SiteId, model.ParentId, model.SortOrder + 1, false);
- // Add room for the new position of the page
- MovePages(model.Id, model.SiteId, parentId, sortOrder, true);
-
- // Update the position of the current page
- var page = _db.Pages
- .FirstOrDefault(p => p.Id == model.Id);
- var site = _db.Sites
- .FirstOrDefault(s => s.Id == page.SiteId);
- page.ParentId = parentId;
- page.SortOrder = sortOrder;
- site.ContentLastModified = DateTime.Now;
-
- _db.SaveChanges();
-
- // Remove all siblings from cache
- if (_cache != null)
- {
- foreach (var sibling in oldSiblings)
- {
- RemoveFromCache(sibling);
- }
-
- foreach (var sibling in newSiblings)
- {
- RemoveFromCache(sibling);
- }
- }
- _api.Sites.InvalidateSitemap(model.SiteId);
- }
-
- ///
- /// Saves the given page model
- ///
- /// The page model
- public void Save(T model) where T : Models.PageBase
- {
- var type = _api.PageTypes.GetById(model.TypeId);
- var shouldUpdateSiteDate = false;
-
- if (type != null)
- {
- // Ensure that we have a slug
- if (string.IsNullOrWhiteSpace(model.Slug))
- {
- var prefix = "";
-
- // Check if we should generate hierarchical slugs
- using (var config = new Config(_api))
- {
- if (config.HierarchicalPageSlugs && model.ParentId.HasValue)
- {
- var parentSlug = _db.Pages
- .AsNoTracking()
- .FirstOrDefault(p => p.Id == model.ParentId)?.Slug;
-
- if (!string.IsNullOrWhiteSpace(parentSlug))
- {
- prefix = parentSlug + "/";
- }
- }
- model.Slug = prefix + Utils.GenerateSlug(model.NavigationTitle != null ? model.NavigationTitle : model.Title);
- }
- }
- else
- {
- model.Slug = Utils.GenerateSlug(model.Slug);
- }
-
- // Set content type
- model.ContentType = type.ContentTypeId;
-
- var page = _db.Pages
- .Include(p => p.Blocks).ThenInclude(b => b.Block).ThenInclude(b => b.Fields)
- .Include(p => p.Fields)
- .FirstOrDefault(p => p.Id == model.Id);
- var site = _db.Sites
- .FirstOrDefault(s => s.Id == model.SiteId);
-
- if (model.OriginalPageId.HasValue)
- {
- var originalPageIsCopy = _db.Pages.FirstOrDefault(p => p.Id == model.OriginalPageId)?.OriginalPageId.HasValue ?? false;
- if (originalPageIsCopy)
- {
- throw new InvalidOperationException("Can not set copy of a copy");
- }
-
- var originalPageType = _db.Pages.FirstOrDefault(p => p.Id == model.OriginalPageId)?.PageTypeId;
- if (originalPageType != model.TypeId)
- {
- throw new InvalidOperationException("Copy can not have a different content type");
- }
-
- // Transform the model
- if (page == null)
- {
- page = new Page()
- {
- Id = model.Id != Guid.Empty ? model.Id : Guid.NewGuid(),
- };
-
- _db.Pages.Add(page);
-
- // Make room for the new page
- MovePages(page.Id, model.SiteId, model.ParentId, model.SortOrder, true);
-
- // We're adding a page to the site structure, update
- // the global last modified date
- shouldUpdateSiteDate = true;
- }
- else
- {
- // Check if the page has been moved
- if (page.ParentId != model.ParentId || page.SortOrder != model.SortOrder)
- {
- // Remove the old position for the page
- MovePages(page.Id, page.SiteId, page.ParentId, page.SortOrder + 1, false);
- // Add room for the new position of the page
- MovePages(page.Id, model.SiteId, model.ParentId, model.SortOrder, true);
-
- // We've moved pages, update the global last
- // modified date
- shouldUpdateSiteDate = true;
- }
- }
-
- if (page.Title != model.Title || page.NavigationTitle != model.NavigationTitle)
- {
- // We've changed the title which is reflected in the
- // sitemap, update the global last modified date.
- shouldUpdateSiteDate = true;
- }
-
- page.PageTypeId = model.TypeId;
- page.OriginalPageId = model.OriginalPageId;
- page.SiteId = model.SiteId;
- page.Title = model.Title;
- page.NavigationTitle = model.NavigationTitle;
- page.Slug = model.Slug;
- page.ParentId = model.ParentId;
- page.SortOrder = model.SortOrder;
- page.IsHidden = model.IsHidden;
- page.Route = model.Route;
- page.Published = model.Published;
-
- if (shouldUpdateSiteDate)
- {
- site.ContentLastModified = DateTime.Now;
- }
-
- _db.SaveChanges();
-
- if (_cache != null)
- {
- RemoveFromCache(page);
- }
-
- _api.Sites.InvalidateSitemap(model.SiteId);
- return;
- }
-
- // Transform the model
- if (page == null)
- {
- page = new Page
- {
- Id = model.Id != Guid.Empty ? model.Id : Guid.NewGuid(),
- ParentId = model.ParentId,
- SortOrder = model.SortOrder,
- PageTypeId = model.TypeId,
- Created = DateTime.Now,
- LastModified = DateTime.Now
- };
- _db.Pages.Add(page);
- model.Id = page.Id;
-
- // Make room for the new page
- MovePages(page.Id, model.SiteId, model.ParentId, model.SortOrder, true);
-
- // We're adding a page to the site structure, update
- // the global last modified date
- shouldUpdateSiteDate = true;
- }
- else
- {
- // Check if the page has been moved
- if (page.ParentId != model.ParentId || page.SortOrder != model.SortOrder)
- {
- // Remove the old position for the page
- MovePages(page.Id, page.SiteId, page.ParentId, page.SortOrder + 1, false);
- // Add room for the new position of the page
- MovePages(page.Id, model.SiteId, model.ParentId, model.SortOrder, true);
-
- // We've moved pages, update the global last
- // modified date
- shouldUpdateSiteDate = true;
- }
- page.LastModified = DateTime.Now;
- }
-
- if (page.Title != model.Title || page.NavigationTitle != model.NavigationTitle)
- {
- // We've changed the title which is reflected in the
- // sitemap, update the global last modified date.
- shouldUpdateSiteDate = true;
- }
-
- page = _contentService.Transform(model, type, page);
-
- // Transform blocks
- var blockModels = model.Blocks;
-
- if (blockModels != null)
- {
- var pageBlocks = _contentService.TransformBlocks(blockModels);
-
- var current = pageBlocks.Select(b => b.Block.Id).ToArray();
-
- // Delete removed blocks
- var removed = page.Blocks
- .Where(b => !current.Contains(b.BlockId) && !b.Block.IsReusable)
- .Select(b => b.Block);
- _db.Blocks.RemoveRange(removed);
-
- // Delete the old page blocks
- page.Blocks.Clear();
-
- // Now map the new block
- for (var n = 0; n < pageBlocks.Count; n++)
- {
- var block = _db.Blocks
- .Include(b => b.Fields)
- .FirstOrDefault(b => b.Id == pageBlocks[n].Block.Id);
- if (block == null)
- {
- block = new Block
- {
- Id = pageBlocks[n].Block.Id != Guid.Empty ? pageBlocks[n].Block.Id : Guid.NewGuid(),
- Created = DateTime.Now
- };
- _db.Blocks.Add(block);
- }
- block.CLRType = pageBlocks[n].Block.CLRType;
- block.IsReusable = pageBlocks[n].Block.IsReusable;
- block.Title = pageBlocks[n].Block.Title;
- block.LastModified = DateTime.Now;
-
- var currentFields = pageBlocks[n].Block.Fields.Select(f => f.FieldId).Distinct();
- var removedFields = block.Fields.Where(f => !currentFields.Contains(f.FieldId));
- _db.BlockFields.RemoveRange(removedFields);
-
- foreach (var newField in pageBlocks[n].Block.Fields)
- {
- var field = block.Fields.FirstOrDefault(f => f.FieldId == newField.FieldId);
- if (field == null)
- {
- field = new BlockField
- {
- Id = newField.Id != Guid.Empty ? newField.Id : Guid.NewGuid(),
- BlockId = block.Id,
- FieldId = newField.FieldId
- };
- _db.BlockFields.Add(field);
- block.Fields.Add(field);
- }
- field.SortOrder = newField.SortOrder;
- field.CLRType = newField.CLRType;
- field.Value = newField.Value;
- }
-
- // Create the page block
- page.Blocks.Add(new PageBlock
- {
- Id = pageBlocks[n].Id,
- ParentId = pageBlocks[n].ParentId,
- BlockId = block.Id,
- Block = block,
- PageId = page.Id,
- SortOrder = n
- });
- }
- }
-
- if (shouldUpdateSiteDate)
- {
- site.ContentLastModified = DateTime.Now;
- }
-
- _db.SaveChanges();
-
- if (_cache != null)
- {
- RemoveFromCache(page);
- }
- _api.Sites.InvalidateSitemap(model.SiteId);
- }
- }
-
- ///
- /// Deletes the model with the specified id.
- ///
- /// The unique id
- public virtual void Delete(Guid id)
- {
- var model = _db.Pages
- .Include(p => p.Blocks).ThenInclude(b => b.Block).ThenInclude(b => b.Fields)
- .Include(p => p.Fields)
- .FirstOrDefault(p => p.Id == id);
-
- if (model != null)
- {
- // Make sure this page isn't copied
- var copyCount = _db.Pages.Count(p => p.OriginalPageId == model.Id);
- if (copyCount > 0)
- {
- throw new InvalidOperationException("Can not delete page because it has copies");
- }
-
- // Get the site
- var site = _db.Sites.FirstOrDefault(s => s.Id == model.SiteId);
-
- // Remove all blocks that are not reusable
- foreach (var pageBlock in model.Blocks)
- {
- if (!pageBlock.Block.IsReusable)
- {
- _db.Blocks.Remove(pageBlock.Block);
- }
- }
-
- // Remove the main page.
- _db.Pages.Remove(model);
-
- // Move all remaining pages after this page in the site structure.
- MovePages(id, model.SiteId, model.ParentId, model.SortOrder + 1, false);
-
- // We've removed a page from the site structure, we have to
- // update the global last modified date for the site.
- site.ContentLastModified = DateTime.Now;
-
- _db.SaveChanges();
-
- // Check if we have the page in cache, and if so remove it
- if (_cache != null)
- {
- var page = _cache.Get(model.Id.ToString());
- if (page != null)
- {
- RemoveFromCache(page);
- }
- }
- _api.Sites.InvalidateSitemap(model.SiteId);
- }
- }
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- public virtual void Delete(T model) where T : Models.PageBase
- {
- Delete(model.Id);
- }
-
- ///
- /// Gets the base query for loading pages.
- ///
- /// If this is a full load or not
- /// The requested model type
- /// The queryable
- private IQueryable GetQuery(out bool fullModel)
- {
- var loadRelated = !typeof(Models.IContentInfo).IsAssignableFrom(typeof(T));
-
- var query = _db.Pages
- .AsNoTracking();
-
- if (loadRelated)
- {
- query = query
- .Include(p => p.Blocks).ThenInclude(b => b.Block).ThenInclude(b => b.Fields)
- .Include(p => p.Fields);
- fullModel = true;
- }
- else
- {
- fullModel = false;
- }
- return query;
- }
-
- ///
- /// Performs additional processing and loads related models.
- ///
- /// The source page
- /// The targe model
- private void Process(Data.Page page, T model) where T : Models.PageBase
- {
- if (!(model is Models.IContentInfo))
- {
- if (page.Blocks.Count > 0)
- {
- model.Blocks = _contentService.TransformBlocks(page.Blocks.OrderBy(b => b.SortOrder));
- }
- }
- }
-
- ///
- /// Moves the pages around. This is done when a page is deleted or moved in the structure.
- ///
- /// The id of the page that is moved
- /// The site id
- /// The parent id
- /// The sort order
- /// If sort order should be increase or decreased
- private void MovePages(Guid pageId, Guid siteId, Guid? parentId, int sortOrder, bool increase)
- {
- var pages = _db.Pages
- .Where(p => p.SiteId == siteId && p.ParentId == parentId && p.SortOrder >= sortOrder && p.Id != pageId)
- .ToList();
-
- foreach (var page in pages)
- {
- page.SortOrder = increase ? page.SortOrder + 1 : page.SortOrder - 1;
- }
- }
-
- ///
- /// Updates the LastModified date of the pages and
- /// removes it from the cache.
- ///
- /// The id of the pages
- internal void Touch(params Guid[] pages)
- {
- var models = _db.Pages
- .Where(p => pages.Contains(p.Id))
- .ToArray();
-
- foreach (var page in models)
- {
- page.LastModified = DateTime.Now;
- _db.SaveChanges();
- RemoveFromCache(page);
- }
- }
-
- ///
- /// Internal method for getting the data page by id.
- ///
- /// The unique id
- /// The page
- internal Page GetPageById(Guid id)
- {
- var page = _cache != null ? _cache.Get(id.ToString()) : null;
-
- if (page == null)
- {
- page = _db.Pages
- .AsNoTracking()
- .Include(p => p.Blocks).ThenInclude(b => b.Block).ThenInclude(b => b.Fields)
- .Include(p => p.Fields)
- .FirstOrDefault(p => p.Id == id);
-
- if (page != null)
- {
- if (_cache != null)
- {
- AddToCache(page);
- }
- }
- }
- return page;
- }
-
- private T MapOriginalPage(Page page) where T : Models.PageBase
- {
- var originalPage = GetById(page.OriginalPageId.Value);
- if (originalPage == null)
- {
- return null;
- }
- return SetOriginalPageProperties(originalPage, page);
- }
-
- private T SetOriginalPageProperties(T originalPage, Page page) where T : Models.PageBase
- {
- originalPage.Id = page.Id;
- originalPage.SiteId = page.SiteId;
- originalPage.Title = page.Title;
- originalPage.NavigationTitle = page.NavigationTitle;
- originalPage.Slug = page.Slug;
- originalPage.ParentId = page.ParentId;
- originalPage.SortOrder = page.SortOrder;
- originalPage.IsHidden = page.IsHidden;
- originalPage.Route = page.Route;
- originalPage.OriginalPageId = page.OriginalPageId;
- originalPage.Published = page.Published;
- originalPage.Created = page.Created;
- originalPage.LastModified = page.LastModified;
- return originalPage;
- }
-
- ///
- /// Sorts the items.
- ///
- /// The full page list
- /// The current parent id
- /// The sitemap
- private Models.Sitemap Sort(IEnumerable pages, IEnumerable pageTypes, Guid? parentId = null, int level = 0)
- {
- var result = new Models.Sitemap();
-
- foreach (var page in pages.Where(p => p.ParentId == parentId).OrderBy(p => p.SortOrder))
- {
- var item = App.Mapper.Map(page);
-
- item.Level = level;
- item.PageTypeName = pageTypes.First(t => t.Id == page.PageTypeId).Title;
- item.Items = Sort(pages, pageTypes, page.Id, level + 1);
-
- result.Add(item);
- }
- return result;
- }
-
- ///
- /// Adds the given model to cache.
- ///
- /// The page
- private void AddToCache(Page page)
- {
- _cache.Set(page.Id.ToString(), page);
- _cache.Set($"PageId_{page.SiteId}_{page.Slug}", page.Id);
- if (!page.ParentId.HasValue && page.SortOrder == 0)
- {
- _cache.Set($"Page_{page.SiteId}", page);
- }
- }
-
- ///
- /// Removes the given model from cache.
- ///
- /// The page
- private void RemoveFromCache(Page page)
- {
- _cache.Remove(page.Id.ToString());
- _cache.Remove($"PageId_{page.SiteId}_{page.Slug}");
- if (!page.ParentId.HasValue && page.SortOrder == 0)
- {
- _cache.Remove($"Page_{page.SiteId}");
- }
- }
- }
-}
diff --git a/core/Piranha/Repositories/PageTypeRepository.cs b/core/Piranha/Repositories/PageTypeRepository.cs
deleted file mode 100644
index f077bf2db..000000000
--- a/core/Piranha/Repositories/PageTypeRepository.cs
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2017 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Newtonsoft.Json;
-
-namespace Piranha.Repositories
-{
- public class PageTypeRepository : IPageTypeRepository
- {
- private readonly IDb _db;
- private static readonly Dictionary _types = new Dictionary();
- private static object _typesMutex = new Object();
- private static volatile bool _isInitialized = false;
-
- ///
- /// Default constructor.
- ///
- /// The current db connection
- public PageTypeRepository(IDb db)
- {
- _db = db;
-
- if (!_isInitialized)
- {
- lock (_typesMutex)
- {
- if (!_isInitialized)
- {
- Load();
-
- _isInitialized = true;
- }
- }
- }
- }
-
- ///
- /// Gets all available models.
- ///
- /// The available models
- public IEnumerable GetAll()
- {
- return _types.Values.OrderBy(t => t.Id);
- }
-
- ///
- /// Gets the model with the specified id.
- ///
- /// The unique i
- ///
- public Models.PageType GetById(string id)
- {
- if (_types.TryGetValue(id, out var type))
- return type;
- return null;
- }
-
- ///
- /// Adds or updates the given model in the database
- /// depending on its state.
- ///
- /// The model
- public void Save(Models.PageType model)
- {
- var type = _db.PageTypes
- .FirstOrDefault(t => t.Id == model.Id);
-
- if (type == null)
- {
- type = new Data.PageType
- {
- Id = model.Id,
- Created = DateTime.Now
- };
- _db.PageTypes.Add(type);
- }
- type.CLRType = model.CLRType;
- type.Body = JsonConvert.SerializeObject(model);
- type.LastModified = DateTime.Now;
-
- _db.SaveChanges();
-
- lock (_typesMutex)
- {
- Load();
- }
- }
-
- ///
- /// Deletes the model with the specified id.
- ///
- /// The unique id
- public void Delete(string id)
- {
- var type = _db.PageTypes
- .FirstOrDefault(t => t.Id == id);
-
- if (type != null)
- {
- _db.PageTypes.Remove(type);
- _db.SaveChanges();
-
- lock (_typesMutex)
- {
- Load();
- }
- }
- }
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- public void Delete(Models.PageType model)
- {
- Delete(model.Id);
- }
-
- ///
- /// Reloads the page types from the database.
- ///
- private void Load()
- {
- _types.Clear();
-
- foreach (var pageType in _db.PageTypes)
- {
- _types[pageType.Id] = JsonConvert.DeserializeObject(pageType.Body);
- }
- }
- }
-}
diff --git a/core/Piranha/Repositories/ParamRepository.cs b/core/Piranha/Repositories/ParamRepository.cs
deleted file mode 100644
index 2fd140f60..000000000
--- a/core/Piranha/Repositories/ParamRepository.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2017-2018 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Linq;
-using Microsoft.EntityFrameworkCore;
-using Piranha.Data;
-
-namespace Piranha.Repositories
-{
- public class ParamRepository : BaseRepositoryWithAll, IParamRepository
- {
- ///
- /// Default constructor.
- ///
- /// The current db context
- /// The optional model cache
- public ParamRepository(IDb db, ICache cache = null)
- : base(db, cache) { }
-
- ///
- /// Gets the model with the given key.
- ///
- /// The unique key
- /// The model
- public Param GetByKey(string key) {
- var id = cache != null ? cache.Get($"ParamKey_{key}") : null;
- Param model = null;
-
- if (id.HasValue) {
- model = GetById(id.Value);
- } else {
- id = db.Params
- .AsNoTracking()
- .Where(p => p.Key == key)
- .Select(p => p.Id)
- .FirstOrDefault();
-
- if (id != Guid.Empty)
- model = GetById(id.Value);
- }
- return model;
- }
-
- #region Protected methods
- ///
- /// Adds a new model to the database.
- ///
- /// The model
- protected override void Add(Param model) {
- PrepareInsert(model);
-
- db.Params.Add(model);
- }
-
- ///
- /// Updates the given model in the database.
- ///
- /// The model
- protected override void Update(Param model) {
- PrepareUpdate(model);
-
- var param = db.Params.FirstOrDefault(p => p.Id == model.Id);
- if (param != null) {
- App.Mapper.Map(model, param);
- }
- }
-
- ///
- /// Adds the given model to cache.
- ///
- /// The model
- protected override void AddToCache(Param model) {
- cache.Set(model.Id.ToString(), model);
- cache.Set($"ParamKey_{model.Key}", model.Id);
- }
-
- ///
- /// Removes the given model from cache.
- ///
- /// The model
- protected override void RemoveFromCache(Param model) {
- cache.Remove(model.Id.ToString());
- cache.Remove($"ParamKey_{model.Key}");
- }
- #endregion
- }
-}
diff --git a/core/Piranha/Repositories/PostTypeRepository.cs b/core/Piranha/Repositories/PostTypeRepository.cs
deleted file mode 100644
index 73f1071cc..000000000
--- a/core/Piranha/Repositories/PostTypeRepository.cs
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2017 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Newtonsoft.Json;
-
-namespace Piranha.Repositories
-{
- public class PostTypeRepository : IPostTypeRepository
- {
- private readonly IDb _db;
- private static readonly Dictionary _types = new Dictionary();
- private static object _typesMutex = new Object();
- private static volatile bool _isInitialized = false;
-
- ///
- /// Default constructor.
- ///
- /// The current db connection
- public PostTypeRepository(IDb db)
- {
- _db = db;
-
- if (!_isInitialized)
- {
- lock (_typesMutex)
- {
- if (!_isInitialized)
- {
- Load();
-
- _isInitialized = true;
- }
- }
- }
- }
-
- ///
- /// Gets all available models.
- ///
- /// The available models
- public IEnumerable GetAll()
- {
- return _types.Values.OrderBy(t => t.Id);
- }
-
- ///
- /// Gets the model with the specified id.
- ///
- /// The unique id
- ///
- public Models.PostType GetById(string id)
- {
- if (_types.TryGetValue(id, out var type))
- return type;
- return null;
- }
-
- ///
- /// Adds or updates the given model in the database
- /// depending on its state.
- ///
- /// The model
- public void Save(Models.PostType model)
- {
- var type = _db.PostTypes
- .FirstOrDefault(t => t.Id == model.Id);
-
- if (type == null)
- {
- type = new Data.PostType
- {
- Id = model.Id,
- Created = DateTime.Now
- };
- _db.PostTypes.Add(type);
- }
- type.CLRType = model.CLRType;
- type.Body = JsonConvert.SerializeObject(model);
- type.LastModified = DateTime.Now;
-
- _db.SaveChanges();
-
- lock (_typesMutex)
- {
- Load();
- }
- }
-
- ///
- /// Deletes the model with the specified id.
- ///
- /// The unique id
- public void Delete(string id)
- {
- var type = _db.PostTypes
- .FirstOrDefault(t => t.Id == id);
-
- if (type != null)
- {
- _db.PostTypes.Remove(type);
- _db.SaveChanges();
-
- lock (_typesMutex)
- {
- Load();
- }
- }
- }
-
- ///
- /// Deletes the given model.
- ///
- /// The model
- public void Delete(Models.PostType model)
- {
- Delete(model.Id);
- }
-
- ///
- /// Reloads the page types from the database.
- ///
- private void Load()
- {
- _types.Clear();
-
- foreach (var postType in _db.PostTypes)
- {
- _types[postType.Id] = JsonConvert.DeserializeObject(postType.Body);
- }
- }
- }
-}
diff --git a/core/Piranha/Repositories/SiteRepository.cs b/core/Piranha/Repositories/SiteRepository.cs
deleted file mode 100644
index aa5f5c3a8..000000000
--- a/core/Piranha/Repositories/SiteRepository.cs
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- * Copyright (c) 2017-2018 Håkan Edling
- *
- * This software may be modified and distributed under the terms
- * of the MIT license. See the LICENSE file for details.
- *
- * http://github.com/piranhacms/piranha
- *
- */
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.EntityFrameworkCore;
-using Piranha.Data;
-using Piranha.Services;
-
-namespace Piranha.Repositories
-{
- public class SiteRepository : BaseRepositoryWithAll, ISiteRepository
- {
- [Serializable]
- public class SiteMapping
- {
- public Guid Id { get; set; }
- public string Hostnames { get; set; }
- }
-
- private readonly Api api;
- // This is a hack as we don't really want to transform the models, we only want
- // to access the create methods.
- private readonly IContentService contentService;
- private const string SITE_MAPPINGS = "Site_Mappings";
-
- ///
- /// Default constructor.
- ///
- /// The current api
- /// The current db context
- /// The content service factory
- /// The optional model cache
- public SiteRepository(Api api, IDb db, IContentServiceFactory factory, ICache cache = null)
- : base(db, cache)
- {
- this.api = api;
- this.contentService = factory.CreateSiteService();
- }
-
- ///
- /// Gets the model with the given internal id.
- ///
- /// The unique internal i
- /// The model
- public Site GetByInternalId(string internalId)
- {
- var id = cache?.Get($"SiteId_{internalId}");
- Site model = null;
-
- if (id != null)
- {
- model = GetById(id.Value);
- }
- else
- {
- id = db.Sites
- .AsNoTracking()
- .Where(s => s.InternalId == internalId)
- .Select(s => s.Id)
- .FirstOrDefault();
-
- if (id != Guid.Empty)
- model = GetById(id.Value);
- }
- return model;
- }
-
- ///
- /// Gets the model with the given hostname.
- ///
- /// The hostname
- /// The model
- public Site GetByHostname(string hostname)
- {
- IList mappings;
-
- if (cache != null)
- {
- mappings = cache.Get>(SITE_MAPPINGS);
-
- if (mappings == null)
- {
- mappings = db.Sites
- .AsNoTracking()
- .Where(s => s.Hostnames != null)
- .Select(s => new SiteMapping
- {
- Id = s.Id,
- Hostnames = s.Hostnames
- })
- .ToList();
- cache.Set(SITE_MAPPINGS, mappings);
- }
- }
- else
- {
- mappings = db.Sites
- .AsNoTracking()
- .Where(s => s.Hostnames.Contains(hostname))
- .Select(s => new SiteMapping
- {
- Id = s.Id,
- Hostnames = s.Hostnames
- })
- .ToList();
- }
-
- foreach (var mapping in mappings)
- {
- foreach (var host in mapping.Hostnames.Split(new [] { ',' }))
- {
- if (host.Trim().ToLower() == hostname)
- {
- return GetById(mapping.Id);
- }
- }
- }
- return null;
- }
-
- ///