Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ISkinService for Abstractions Project #5838

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Collections/IObjectList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.Collections;

using System.Collections.Generic;

/// <inheritdoc cref="IList{T}"/>
public interface IObjectList<T> : IList<T>
{
/// <summary>
/// Adds a new instance of <typeparamref name="T"/> to the list.
/// </summary>
/// <returns>The new instance.</returns>
T AddNew();

/// <summary>
/// Adds a range of items to the list.
/// </summary>
/// <param name="items">The items to add.</param>
void AddRange(IEnumerable<T> items);
}
18 changes: 18 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/ISkinInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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;

/// <summary>Represents a skin.</summary>
public interface ISkinInfo
{
/// <summary>Gets or sets the ID of the skin.</summary>
int SkinId { get; set; }

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

/// <summary>Gets or sets the source of the skin.</summary>
string SkinSrc { get; set; }
}
32 changes: 32 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/ISkinPackageInfo.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

namespace DotNetNuke.Abstractions.Skins;

using System.Collections.Generic;

using DotNetNuke.Abstractions.Collections;

/// <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 the skins in the skin package.</summary>
IObjectList<ISkinInfo> Skins { get; }

/// <summary>Gets or sets the type of the skin.</summary>
SkinPackageType SkinType { get; set; }
}
122 changes: 122 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/ISkinService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// 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;

/// <summary>Handles the Business Control Layer for Skins.</summary>
public interface ISkinService
{
/// <summary>Gets the folder name for the specified <paramref name="packageType"/>.</summary>
/// <param name="packageType">The type of the skin package.</param>
/// <returns>The folder name.</returns>
string GetFolderName(SkinPackageType packageType);

/// <summary>Gets the global default skin src.</summary>
/// <param name="packageType">The type of the skin package.</param>
/// <param name="skinType">The type of the skin.</param>
/// <returns>The global default edit skin.</returns>
string GetDefaultSkinSrc(SkinPackageType packageType, SkinType skinType);

/// <summary>Gets a skin package by its id.</summary>
/// <param name="packageId">The skin package id.</param>
/// <returns>The skin package.</returns>
ISkinPackageInfo GetSkinPackageById(int packageId);

/// <summary>Gets a skin package by its id.</summary>
/// <param name="portalId">The portal id.</param>
/// <param name="skinName">The name of the skin.</param>
/// <param name="packageType">The type of the skin package.</param>
/// <returns>The skin package.</returns>
ISkinPackageInfo GetSkinPackage(int portalId, string skinName, SkinPackageType packageType);

/// <summary>Creates a new instance of <see cref="ISkinInfo"/>.</summary>
/// <returns>The skin.</returns>
ISkinInfo CreateSkin();

/// <summary>Creates a new instance of <see cref="ISkinPackageInfo"/>.</summary>
/// <returns>The skin package.</returns>
ISkinPackageInfo CreateSkinPackage();

/// <summary>Adds a new skin.</summary>
/// <param name="skin">The skin to add.</param>
/// <returns>The skin id.</returns>
int AddSkin(ISkinInfo skin);

/// <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 CanDeleteSkinFolder(string folderPath, string portalHomeDirMapPath);

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

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

/// <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="packageType">The type of the skin package.</param>
/// <param name="portalId">The portal to set the skin for or <c>-1</c> for the global skin.</param>
/// <param name="skinType">The type of the skin.</param>
/// <param name="skinSrc">The skin source path.</param>
void SetSkin(SkinPackageType packageType, int portalId, SkinType skinType, string skinSrc);

/// <summary>Updates a existing skin.</summary>
/// <param name="skin">The skin to update.</param>
void UpdateSkin(ISkinInfo skin);

/// <summary>Updates a existing skin package.</summary>
/// <param name="skinPackage">The skin package to update.</param>
void UpdateSkinPackage(ISkinPackageInfo skinPackage);

/// <summary>Get all skins for the specified <paramref name="portalInfo"/> within the specified <paramref name="folder"/>.</summary>
/// <param name="portalInfo">The portal to get the skins for.</param>
/// <param name="skinRoot">The skin type to search for skins. Default: <see cref="SkinPackageType.Skin"/>.</param>
/// <param name="folder">The scope to search for skins. Default: <see cref="SkinFolder.All"/>.</param>
/// <returns>A list of skins.</returns>
IEnumerable<KeyValuePair<string, string>> GetSkinsInFolder(IPortalInfo portalInfo, SkinType skinRoot = SkinType.Site, SkinFolder folder = SkinFolder.All);
}
23 changes: 23 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/SkinFolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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;

/// <summary>The scope of a skin.</summary>
/// <remarks>This enum is used for <see cref="ISkinService.GetSkinsInFolder"/>.</remarks>
public enum SkinFolder
{
/// <summary>All scopes are specified.</summary>
All = 0,

/// <summary>The skin can be used for all portals.</summary>
/// <remarks>These skins are by default in the folder 'Portals\_default\'.</remarks>
Host = 1,

/// <summary>The skin can only be used for the given portal.</summary>
/// <remarks>These skins are by default in the folder 'Portals\[PortalId]\' and 'Portals\[PortalId]-System\'.</remarks>
Portal = 2,
}
15 changes: 15 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/SkinPackageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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;

/// <summary>The type of a skin package.</summary>
public enum SkinPackageType
{
/// <summary>The skin package is a skin.</summary>
Skin = 0,

/// <summary>The skin package is a container.</summary>
Container = 1,
}
15 changes: 15 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Skins/SkinType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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;

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

/// <summary>The skin is an edit skin.</summary>
Edit = 1,
}
128 changes: 128 additions & 0 deletions DNN Platform/Library/Collections/AbstractionList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// 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.Collections;

using System.Collections;
using System.Collections.Generic;
using System.Linq;

using DotNetNuke.Abstractions.Collections;

/// <inheritdoc cref="IObjectList{TInterface}"/>
/// <remarks>
/// This class is used to abstract a list of objects of type <typeparamref name="TInterface"/> to a list of objects of
/// type <typeparamref name="TImplementation"/>.
/// </remarks>
public class AbstractionList<TInterface, TImplementation> : IObjectList<TInterface>
where TImplementation : TInterface, new()
{
private readonly IList list;

/// <summary>
/// Initializes a new instance of the <see cref="AbstractionList{TInterface, TImplementation}"/> class.
/// </summary>
/// <param name="list">The list.</param>
public AbstractionList(IList list)
{
this.list = list;
}

/// <inheritdoc />
public int Count => this.list.Count;

/// <inheritdoc />
public bool IsReadOnly => this.list.IsReadOnly;

/// <inheritdoc />
public TInterface this[int index]
{
get => (TInterface)this.list[index];
set => this.list[index] = value;
}

/// <inheritdoc />
public TInterface AddNew()
{
var item = new TImplementation();
this.list.Add(item);
return item;
}

/// <inheritdoc cref="IObjectList{T}.AddRange"/>
public void AddRange(IEnumerable<TInterface> items)
{
foreach (var item in items)
{
this.Add(item);
}
}

/// <inheritdoc />
public IEnumerator<TInterface> GetEnumerator()
{
return this.list.Cast<TInterface>().GetEnumerator();
}

/// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}

/// <inheritdoc />
public void Add(TInterface item)
{
if (item is not TImplementation implementation)
{
throw new System.InvalidCastException();
}

this.list.Add(implementation);
}

/// <inheritdoc />
public void Clear()
{
this.list.Clear();
}

/// <inheritdoc />
public bool Contains(TInterface item)
{
return this.list.Contains(item);
}

/// <inheritdoc />
public void CopyTo(TInterface[] array, int arrayIndex)
{
this.list.CopyTo(array, arrayIndex);
}

/// <inheritdoc />
public bool Remove(TInterface item)
{
var count = this.list.Count;
this.list.Remove(item);
return count != this.list.Count;
}

/// <inheritdoc />
public int IndexOf(TInterface item)
{
return this.list.IndexOf(item);
}

/// <inheritdoc />
public void Insert(int index, TInterface item)
{
this.list.Insert(index, item);
}

/// <inheritdoc />
public void RemoveAt(int index)
{
this.list.RemoveAt(index);
}
}
Loading