Skip to content

Commit

Permalink
Add ISkinService for Abstractions Project
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardSmit committed Oct 10, 2023
1 parent 3af88c5 commit 15f2053
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 53 deletions.
30 changes: 30 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/ISkinPackageInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Abstractions.Skins;

using System.Collections.Generic;

/// <summary>The skin package info.</summary>
public interface ISkinPackageInfo
{
/// <summary>Gets or sets the ID of the package.</summary>
int PackageId { get; set; }

/// <summary>Gets or sets the ID of the skin package.</summary>
int SkinPackageId { get; set; }

/// <summary>Gets or sets the ID of the portal.</summary>
/// <remarks>If the portal ID is <c>-1</c>, then the skin package is a global skin package.</remarks>
int PortalId { get; set; }

/// <summary>Gets or sets the name of the skin.</summary>
string SkinName { get; set; }

/// <summary>Gets or sets the skins in the skin package.</summary>
Dictionary<int, string> Skins { get; set; }

/// <summary>Gets or sets the type of the skin.</summary>
string SkinType { get; set; }
}
129 changes: 129 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/ISkinService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Abstractions.Skins;

using System.Collections.Generic;

using DotNetNuke.Abstractions.Portals;
using DotNetNuke.UI.Skins;

/// <summary>Handles the Business Control Layer for Skins.</summary>
public interface ISkinService
{
/// <summary>Gets the root folder for the skins.</summary>
string RootSkin { get; }

/// <summary>Gets the root folder for the containers.</summary>
string RootContainer { get; }

/// <summary>Adds a skin to the skin package.</summary>
/// <param name="skinPackageId">The skin package id.</param>
/// <param name="skinSrc">The skin source path.</param>
/// <returns>The skin id.</returns>
int AddSkin(int skinPackageId, string skinSrc);

/// <summary>Adds a skin package.</summary>
/// <param name="skinPackage">The skin package to add.</param>
/// <returns>The skin package id.</returns>
int AddSkinPackage(ISkinPackageInfo skinPackage);

/// <summary>Checks if a skin can be deleted.</summary>
/// <param name="folderPath">Path to the skin folder.</param>
/// <param name="portalHomeDirMapPath">Path to the portal home directory (<see cref="IPortalSettings.HomeDirectoryMapPath"/>).</param>
/// <returns>True if the skin can be deleted.</returns>
bool CanDeleteSkin(string folderPath, string portalHomeDirMapPath);

/// <summary>Deletes a skin.</summary>
/// <param name="skinId">The skin to delete.</param>
void DeleteSkin(int skinId);

/// <summary>Deletes a skin package.</summary>
/// <param name="skinPackage">The skin package to delete.</param>
void DeleteSkinPackage(ISkinPackageInfo skinPackage);

/// <summary>Gets the global default admin container.</summary>
/// <remarks>
/// This is not the default admin container for the portal.
/// To get the default admin container for the portal use <see cref="IPortalSettings.DefaultAdminContainer"/> instead.
/// </remarks>
/// <returns>The global default admin container.</returns>
string GetDefaultAdminContainer();

/// <summary>Gets the global default admin skin.</summary>
/// <remarks>
/// This is not the default admin skin for the portal.
/// To get the default admin skin for the portal use <see cref="IPortalSettings.DefaultAdminSkin"/> instead.
/// </remarks>
/// <returns>The global default admin skin.</returns>
string GetDefaultAdminSkin();

/// <summary>Gets the global default container.</summary>
/// <remarks>
/// This is not the default container for the portal.
/// To get the default container for the portal use <see cref="IPortalSettings.DefaultPortalContainer"/> instead.
/// </remarks>
/// <returns>The global default container.</returns>
string GetDefaultPortalContainer();

/// <summary>Gets the global default skin.</summary>
/// <remarks>
/// This is not the default skin for the portal.
/// To get the default skin for the portal use <see cref="IPortalSettings.DefaultPortalSkin"/> instead.
/// </remarks>
/// <returns>The global default skin.</returns>
string GetDefaultPortalSkin();

/// <summary>Gets the skin source path.</summary>
/// <example>
/// <c>[G]Skins/Xcillion/Inner.ascx</c> becomes <c>[G]Skins/Xcillion</c>.
/// </example>
/// <param name="skinSrc">The input skin source path.</param>
/// <returns>The skin source path.</returns>
string FormatSkinPath(string skinSrc);

/// <summary>Formats the skin source path.</summary>
/// <remarks>
/// By default the following tokens are replaced:<br />
/// <c>[G]</c> - Host path (default: '/Portals/_default/').<br />
/// <c>[S]</c> - Home system directory (default: '/Portals/[PortalID]-System/').<br />
/// <c>[L]</c> - Home directory (default: '/Portals/[PortalID]/').
/// </remarks>
/// <example>
/// <c>[G]Skins/Xcillion/Inner.ascx</c> becomes <c>/Portals/_default/Skins/Xcillion/Inner.ascx</c>.
/// </example>
/// <param name="skinSrc">The input skin source path.</param>
/// <param name="portalSettings">The portal settings containing configuration data.</param>
/// <returns>The formatted skin source path.</returns>
string FormatSkinSrc(string skinSrc, IPortalSettings portalSettings);

/// <summary>Determines if a given skin is defined as a global skin.</summary>
/// <param name="skinSrc">This is the app relative path and filename of the skin to be checked.</param>
/// <returns>True if the skin is located in the HostPath child directories.</returns>
/// <remarks>This function performs a quick check to detect the type of skin that is
/// passed as a parameter. Using this method abstracts knowledge of the actual location
/// of skins in the file system.
/// </remarks>
bool IsGlobalSkin(string skinSrc);

/// <summary>Sets the skin for the specified <paramref name="portalId"/> and <paramref name="skinType"/>.</summary>
/// <param name="skinRoot">The root folder of the skin. Either <see cref="RootSkin"/> or <see cref="RootContainer"/>.</param>
/// <param name="portalId">The portal to set the skin for.</param>
/// <param name="skinType">The type of the skin.</param>
/// <param name="skinSrc">The skin source path.</param>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown if <paramref name="skinRoot"/> is not <see cref="RootSkin"/> or <see cref="RootContainer"/>.</exception>
void SetSkin(string skinRoot, int portalId, SkinType skinType, string skinSrc);

/// <summary>Sets the skin source path.</summary>
/// <param name="skinId">The skin to set the source path for.</param>
/// <param name="skinSrc">The skin source path.</param>
void UpdateSkin(int skinId, string skinSrc);

/// <summary>Get all skins for the specified <paramref name="portalInfo"/> within the specified <paramref name="scope"/>.</summary>
/// <param name="portalInfo">The portal to get the skins for.</param>
/// <param name="skinRoot">The root folder to search for skins. Default: <see cref="RootSkin"/>.</param>
/// <param name="scope">The scope to search for skins. Default: All.</param>
/// <returns>A list of skin names and their source paths.</returns>
IEnumerable<KeyValuePair<string, string>> GetSkins(IPortalInfo portalInfo, string skinRoot = null, SkinScope scope = SkinScope.All);
}
32 changes: 32 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/SkinScope.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

// ReSharper disable once CheckNamespace
namespace DotNetNuke.UI.Skins;

using DotNetNuke.Abstractions.Skins;

/// <summary>
/// The scope of a skin.
/// </summary>
/// <remarks>
/// This enum is used for <see cref="ISkinService.GetSkins"/>.
/// </remarks>
public enum SkinScope
{
/// <summary>
/// The skin is applied to all portals and the current portal.
/// </summary>
All = 0,

/// <summary>
/// The skin is applied to all portals.
/// </summary>
Host = 1,

/// <summary>
/// The skin is applied to the current portal only.
/// </summary>
Site = 2,
}
21 changes: 21 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/SkinType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.UI.Skins;

/// <summary>
/// The type of a skin.
/// </summary>
public enum SkinType
{
/// <summary>
/// The skin is a portal skin.
/// </summary>
Portal = 0,

/// <summary>
/// The skin is an admin skin.
/// </summary>
Admin = 1,
}
4 changes: 4 additions & 0 deletions DNN Platform/Library/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace DotNetNuke
using DotNetNuke.Abstractions.Portals;
using DotNetNuke.Abstractions.Portals.Templates;
using DotNetNuke.Abstractions.Prompt;
using DotNetNuke.Abstractions.Skins;
using DotNetNuke.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Internal;
Expand All @@ -35,6 +36,7 @@ namespace DotNetNuke
using DotNetNuke.Services.Search.Controllers;
using DotNetNuke.UI.Modules;
using DotNetNuke.UI.Modules.Html5;
using DotNetNuke.UI.Skins;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -58,6 +60,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<IEventLogService, EventLogController>();
#pragma warning restore CS0618

services.AddScoped<ISkinService, SkinController>();

services.AddTransient<IPortalController, PortalController>();
services.AddTransient<IBusinessControllerProvider, BusinessControllerProvider>();
services.AddScoped<IHostSettingsService, HostController>();
Expand Down
Loading

0 comments on commit 15f2053

Please sign in to comment.