generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIWebPageFieldsSourceExtensions.cs
More file actions
53 lines (45 loc) · 3.03 KB
/
IWebPageFieldsSourceExtensions.cs
File metadata and controls
53 lines (45 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using CMS.Websites;
namespace XperienceCommunity.DataRepository.Extensions;
/// <summary>
/// Extension methods for <see cref="IWebPageFieldsSource"/>.
/// </summary>
public static class IWebPageFieldsSourceExtensions
{
private const string WebPageItemCachePrefix = "webpageitem|byid|";
/// <summary>
/// Determines whether the specified content item is secure.
/// </summary>
/// <param name="source">The content item fields source.</param>
/// <returns><c>true</c> if the content item is secure; otherwise, <c>false</c>.</returns>
public static bool IsSecureItem(this IWebPageFieldsSource? source) => source?.SystemFields?.ContentItemIsSecured ?? false;
/// <summary>
/// Determines whether the collection contains any secure content items.
/// </summary>
/// <param name="source">The collection of content item fields sources.</param>
/// <returns><c>true</c> if the collection contains any secure content items; otherwise, <c>false</c>.</returns>
public static bool HasSecureItems(this IEnumerable<IWebPageFieldsSource>? source) => source?.Any(x => x.SystemFields.ContentItemIsSecured) == true;
/// <summary>
/// Gets the cache dependency key for the specified <see cref="IWebPageFieldsSource"/>.
/// </summary>
/// <param name="source">The source to get the cache dependency key for.</param>
/// <returns>An array containing the cache dependency key.</returns>
public static string[] GetCacheDependencyKey(this IWebPageFieldsSource? source) => source is null ? [] : [$"{WebPageItemCachePrefix}{source.SystemFields.WebPageItemID}"];
/// <summary>
/// Gets the cache dependency keys for the specified collection of <see cref="IWebPageFieldsSource"/>.
/// </summary>
/// <param name="source">The collection of sources to get the cache dependency keys for.</param>
/// <returns>An array containing the cache dependency keys.</returns>
public static string[] GetCacheDependencyKeys(this IEnumerable<IWebPageFieldsSource>? source) => source?.Select(x => $"{WebPageItemCachePrefix}{x.SystemFields.WebPageItemID}")?.ToArray() ?? [];
/// <summary>
/// Gets the web page item IDs for the specified collection of <see cref="IWebPageFieldsSource"/>.
/// </summary>
/// <param name="source">The collection of sources to get the web page item IDs for.</param>
/// <returns>An enumerable containing the web page item IDs.</returns>
public static IEnumerable<int> GetWebPageItemIds(this IEnumerable<IWebPageFieldsSource>? source) => source?.Select(x => x.SystemFields.WebPageItemID) ?? [];
/// <summary>
/// Gets the web page item GUIDs for the specified collection of <see cref="IWebPageFieldsSource"/>.
/// </summary>
/// <param name="source">The collection of sources to get the web page item GUIDs for.</param>
/// <returns>An enumerable containing the web page item GUIDs.</returns>
public static IEnumerable<Guid> GetWebPageItemGuids(this IEnumerable<IWebPageFieldsSource>? source) => source?.Select(x => x.SystemFields.WebPageItemGUID) ?? [];
}