Skip to content

Commit b9eb1ac

Browse files
GerardSmitbdukes
authored andcommitted
Add ISkinService for Abstractions Project
Fixes #5837
1 parent a240d23 commit b9eb1ac

File tree

16 files changed

+818
-95
lines changed

16 files changed

+818
-95
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Collections;
6+
7+
using System.Collections.Generic;
8+
9+
/// <inheritdoc cref="IList{T}"/>
10+
public interface IObjectList<T> : IList<T>
11+
{
12+
/// <summary>
13+
/// Adds a new instance of <typeparamref name="T"/> to the list.
14+
/// </summary>
15+
/// <returns>The new instance.</returns>
16+
T AddNew();
17+
18+
/// <summary>
19+
/// Adds a range of items to the list.
20+
/// </summary>
21+
/// <param name="items">The items to add.</param>
22+
void AddRange(IEnumerable<T> items);
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Skins;
6+
7+
/// <summary>Represents a skin.</summary>
8+
public interface ISkinInfo
9+
{
10+
/// <summary>Gets or sets the ID of the skin.</summary>
11+
int SkinId { get; set; }
12+
13+
/// <summary>Gets or sets the ID of the skin package.</summary>
14+
int SkinPackageId { get; set; }
15+
16+
/// <summary>Gets or sets the source of the skin.</summary>
17+
string SkinSrc { get; set; }
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Skins;
6+
7+
using System.Collections.Generic;
8+
9+
using DotNetNuke.Abstractions.Collections;
10+
11+
/// <summary>The skin package info.</summary>
12+
public interface ISkinPackageInfo
13+
{
14+
/// <summary>Gets or sets the ID of the package.</summary>
15+
int PackageId { get; set; }
16+
17+
/// <summary>Gets or sets the ID of the skin package.</summary>
18+
int SkinPackageId { get; set; }
19+
20+
/// <summary>Gets or sets the ID of the portal.</summary>
21+
/// <remarks>If the portal ID is <c>-1</c>, then the skin package is a global skin package.</remarks>
22+
int PortalId { get; set; }
23+
24+
/// <summary>Gets or sets the name of the skin.</summary>
25+
string SkinName { get; set; }
26+
27+
/// <summary>Gets the skins in the skin package.</summary>
28+
IObjectList<ISkinInfo> Skins { get; }
29+
30+
/// <summary>Gets or sets the type of the skin.</summary>
31+
SkinPackageType SkinType { get; set; }
32+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Skins;
6+
7+
using System.Collections.Generic;
8+
9+
using DotNetNuke.Abstractions.Portals;
10+
11+
/// <summary>Handles the Business Control Layer for Skins.</summary>
12+
public interface ISkinService
13+
{
14+
/// <summary>Gets the folder name for the specified <paramref name="packageType"/>.</summary>
15+
/// <param name="packageType">The type of the skin package.</param>
16+
/// <returns>The folder name.</returns>
17+
string GetFolderName(SkinPackageType packageType);
18+
19+
/// <summary>Gets the global default skin src.</summary>
20+
/// <param name="packageType">The type of the skin package.</param>
21+
/// <param name="skinType">The type of the skin.</param>
22+
/// <returns>The global default edit skin.</returns>
23+
string GetDefaultSkinSrc(SkinPackageType packageType, SkinType skinType);
24+
25+
/// <summary>Gets a skin package by its id.</summary>
26+
/// <param name="packageId">The skin package id.</param>
27+
/// <returns>The skin package.</returns>
28+
ISkinPackageInfo GetSkinPackageById(int packageId);
29+
30+
/// <summary>Gets a skin package by its id.</summary>
31+
/// <param name="portalId">The portal id.</param>
32+
/// <param name="skinName">The name of the skin.</param>
33+
/// <param name="packageType">The type of the skin package.</param>
34+
/// <returns>The skin package.</returns>
35+
ISkinPackageInfo GetSkinPackage(int portalId, string skinName, SkinPackageType packageType);
36+
37+
/// <summary>Creates a new instance of <see cref="ISkinInfo"/>.</summary>
38+
/// <returns>The skin.</returns>
39+
ISkinInfo CreateSkin();
40+
41+
/// <summary>Creates a new instance of <see cref="ISkinPackageInfo"/>.</summary>
42+
/// <returns>The skin package.</returns>
43+
ISkinPackageInfo CreateSkinPackage();
44+
45+
/// <summary>Adds a new skin.</summary>
46+
/// <param name="skin">The skin to add.</param>
47+
/// <returns>The skin id.</returns>
48+
int AddSkin(ISkinInfo skin);
49+
50+
/// <summary>Adds a skin package.</summary>
51+
/// <param name="skinPackage">The skin package to add.</param>
52+
/// <returns>The skin package id.</returns>
53+
int AddSkinPackage(ISkinPackageInfo skinPackage);
54+
55+
/// <summary>Checks if a skin can be deleted.</summary>
56+
/// <param name="folderPath">Path to the skin folder.</param>
57+
/// <param name="portalHomeDirMapPath">Path to the portal home directory (<see cref="IPortalSettings.HomeDirectoryMapPath"/>).</param>
58+
/// <returns>True if the skin can be deleted.</returns>
59+
bool CanDeleteSkinFolder(string folderPath, string portalHomeDirMapPath);
60+
61+
/// <summary>Deletes a skin.</summary>
62+
/// <param name="skin">The skin to delete.</param>
63+
void DeleteSkin(ISkinInfo skin);
64+
65+
/// <summary>Deletes a skin package.</summary>
66+
/// <param name="skinPackage">The skin package to delete.</param>
67+
void DeleteSkinPackage(ISkinPackageInfo skinPackage);
68+
69+
/// <summary>Gets the skin source path.</summary>
70+
/// <example>
71+
/// <c>[G]Skins/Xcillion/Inner.ascx</c> becomes <c>[G]Skins/Xcillion</c>.
72+
/// </example>
73+
/// <param name="skinSrc">The input skin source path.</param>
74+
/// <returns>The skin source path.</returns>
75+
string FormatSkinPath(string skinSrc);
76+
77+
/// <summary>Formats the skin source path.</summary>
78+
/// <remarks>
79+
/// By default the following tokens are replaced:<br />
80+
/// <c>[G]</c> - Host path (default: '/Portals/_default/').<br />
81+
/// <c>[S]</c> - Home system directory (default: '/Portals/[PortalID]-System/').<br />
82+
/// <c>[L]</c> - Home directory (default: '/Portals/[PortalID]/').
83+
/// </remarks>
84+
/// <example>
85+
/// <c>[G]Skins/Xcillion/Inner.ascx</c> becomes <c>/Portals/_default/Skins/Xcillion/Inner.ascx</c>.
86+
/// </example>
87+
/// <param name="skinSrc">The input skin source path.</param>
88+
/// <param name="portalSettings">The portal settings containing configuration data.</param>
89+
/// <returns>The formatted skin source path.</returns>
90+
string FormatSkinSrc(string skinSrc, IPortalSettings portalSettings);
91+
92+
/// <summary>Determines if a given skin is defined as a global skin.</summary>
93+
/// <param name="skinSrc">This is the app relative path and filename of the skin to be checked.</param>
94+
/// <returns>True if the skin is located in the HostPath child directories.</returns>
95+
/// <remarks>This function performs a quick check to detect the type of skin that is
96+
/// passed as a parameter. Using this method abstracts knowledge of the actual location
97+
/// of skins in the file system.
98+
/// </remarks>
99+
bool IsGlobalSkin(string skinSrc);
100+
101+
/// <summary>Sets the skin for the specified <paramref name="portalId"/> and <paramref name="skinType"/>.</summary>
102+
/// <param name="packageType">The type of the skin package.</param>
103+
/// <param name="portalId">The portal to set the skin for or <c>-1</c> for the global skin.</param>
104+
/// <param name="skinType">The type of the skin.</param>
105+
/// <param name="skinSrc">The skin source path.</param>
106+
void SetSkin(SkinPackageType packageType, int portalId, SkinType skinType, string skinSrc);
107+
108+
/// <summary>Updates a existing skin.</summary>
109+
/// <param name="skin">The skin to update.</param>
110+
void UpdateSkin(ISkinInfo skin);
111+
112+
/// <summary>Updates a existing skin package.</summary>
113+
/// <param name="skinPackage">The skin package to update.</param>
114+
void UpdateSkinPackage(ISkinPackageInfo skinPackage);
115+
116+
/// <summary>Get all skins for the specified <paramref name="portalInfo"/> within the specified <paramref name="folder"/>.</summary>
117+
/// <param name="portalInfo">The portal to get the skins for.</param>
118+
/// <param name="skinRoot">The skin type to search for skins. Default: <see cref="SkinPackageType.Skin"/>.</param>
119+
/// <param name="folder">The scope to search for skins. Default: <see cref="SkinFolder.All"/>.</param>
120+
/// <returns>A list of skins.</returns>
121+
IEnumerable<KeyValuePair<string, string>> GetSkinsInFolder(IPortalInfo portalInfo, SkinType skinRoot = SkinType.Site, SkinFolder folder = SkinFolder.All);
122+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Skins;
6+
7+
using System;
8+
9+
/// <summary>The scope of a skin.</summary>
10+
/// <remarks>This enum is used for <see cref="ISkinService.GetSkinsInFolder"/>.</remarks>
11+
public enum SkinFolder
12+
{
13+
/// <summary>All scopes are specified.</summary>
14+
All = 0,
15+
16+
/// <summary>The skin can be used for all portals.</summary>
17+
/// <remarks>These skins are by default in the folder 'Portals\_default\'.</remarks>
18+
Host = 1,
19+
20+
/// <summary>The skin can only be used for the given portal.</summary>
21+
/// <remarks>These skins are by default in the folder 'Portals\[PortalId]\' and 'Portals\[PortalId]-System\'.</remarks>
22+
Portal = 2,
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Skins;
6+
7+
/// <summary>The type of a skin package.</summary>
8+
public enum SkinPackageType
9+
{
10+
/// <summary>The skin package is a skin.</summary>
11+
Skin = 0,
12+
13+
/// <summary>The skin package is a container.</summary>
14+
Container = 1,
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Abstractions.Skins;
6+
7+
/// <summary>The type of a skin.</summary>
8+
public enum SkinType
9+
{
10+
/// <summary>The skin is a site skin.</summary>
11+
Site = 0,
12+
13+
/// <summary>The skin is an edit skin.</summary>
14+
Edit = 1,
15+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace DotNetNuke.Collections;
6+
7+
using System.Collections;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
11+
using DotNetNuke.Abstractions.Collections;
12+
13+
/// <inheritdoc cref="IObjectList{TInterface}"/>
14+
/// <remarks>
15+
/// This class is used to abstract a list of objects of type <typeparamref name="TInterface"/> to a list of objects of
16+
/// type <typeparamref name="TImplementation"/>.
17+
/// </remarks>
18+
public class AbstractionList<TInterface, TImplementation> : IObjectList<TInterface>
19+
where TImplementation : TInterface, new()
20+
{
21+
private readonly IList list;
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="AbstractionList{TInterface, TImplementation}"/> class.
25+
/// </summary>
26+
/// <param name="list">The list.</param>
27+
public AbstractionList(IList list)
28+
{
29+
this.list = list;
30+
}
31+
32+
/// <inheritdoc />
33+
public int Count => this.list.Count;
34+
35+
/// <inheritdoc />
36+
public bool IsReadOnly => this.list.IsReadOnly;
37+
38+
/// <inheritdoc />
39+
public TInterface this[int index]
40+
{
41+
get => (TInterface)this.list[index];
42+
set => this.list[index] = value;
43+
}
44+
45+
/// <inheritdoc />
46+
public TInterface AddNew()
47+
{
48+
var item = new TImplementation();
49+
this.list.Add(item);
50+
return item;
51+
}
52+
53+
/// <inheritdoc cref="IObjectList{T}.AddRange"/>
54+
public void AddRange(IEnumerable<TInterface> items)
55+
{
56+
foreach (var item in items)
57+
{
58+
this.Add(item);
59+
}
60+
}
61+
62+
/// <inheritdoc />
63+
public IEnumerator<TInterface> GetEnumerator()
64+
{
65+
return this.list.Cast<TInterface>().GetEnumerator();
66+
}
67+
68+
/// <inheritdoc />
69+
IEnumerator IEnumerable.GetEnumerator()
70+
{
71+
return this.GetEnumerator();
72+
}
73+
74+
/// <inheritdoc />
75+
public void Add(TInterface item)
76+
{
77+
if (item is not TImplementation implementation)
78+
{
79+
throw new System.InvalidCastException();
80+
}
81+
82+
this.list.Add(implementation);
83+
}
84+
85+
/// <inheritdoc />
86+
public void Clear()
87+
{
88+
this.list.Clear();
89+
}
90+
91+
/// <inheritdoc />
92+
public bool Contains(TInterface item)
93+
{
94+
return this.list.Contains(item);
95+
}
96+
97+
/// <inheritdoc />
98+
public void CopyTo(TInterface[] array, int arrayIndex)
99+
{
100+
this.list.CopyTo(array, arrayIndex);
101+
}
102+
103+
/// <inheritdoc />
104+
public bool Remove(TInterface item)
105+
{
106+
var count = this.list.Count;
107+
this.list.Remove(item);
108+
return count != this.list.Count;
109+
}
110+
111+
/// <inheritdoc />
112+
public int IndexOf(TInterface item)
113+
{
114+
return this.list.IndexOf(item);
115+
}
116+
117+
/// <inheritdoc />
118+
public void Insert(int index, TInterface item)
119+
{
120+
this.list.Insert(index, item);
121+
}
122+
123+
/// <inheritdoc />
124+
public void RemoveAt(int index)
125+
{
126+
this.list.RemoveAt(index);
127+
}
128+
}

0 commit comments

Comments
 (0)