Skip to content

Commit 3e3930f

Browse files
committed
Introduce ContentTypeDescriptorCollection.Refresh() method
The `Refresh()` method makes it easier for the `ContentTypeDescriptionCollection` to be used as a cache for the flatterned version of the `ContentTypeDescriptor`s used for the `ITopicRepository.GetContentTypes()` cache—which is it's primary use case today. Specifically, the `Refresh()` method allows callers to send a `rootContentType` (i.e., `Root:Configuration:ContentTypes`) to the `Refresh()` method in order to update the cached values.
1 parent 27391f5 commit 3e3930f

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

OnTopic/Metadata/ContentTypeDescriptorCollection.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
| Client Ignia, LLC
44
| Project Topics Library
55
\=============================================================================================================================*/
6+
using System;
7+
using System.Diagnostics.Contracts;
8+
using System.Linq;
69
using OnTopic.Collections;
10+
using OnTopic.Querying;
11+
using OnTopic.Repositories;
712

813
namespace OnTopic.Metadata {
914

@@ -13,6 +18,13 @@ namespace OnTopic.Metadata {
1318
/// <summary>
1419
/// Represents a collection of <see cref="ContentTypeDescriptor"/> objects.
1520
/// </summary>
21+
/// <remarks>
22+
/// While the <see cref="ContentTypeDescriptorCollection"/> can be used to store any collection of <see cref=
23+
/// "ContentTypeDescriptor"/> objects, it has additional tooling in the form of the <see cref="Refresh(
24+
/// ContentTypeDescriptor?)"/> as well as the <see cref="ContentTypeDescriptorCollection(ContentTypeDescriptor?)"/>
25+
/// constructor for handling a flattened list of <see cref="ContentTypeDescriptor"/>s used for the <see cref=
26+
/// "ITopicRepository.GetContentTypeDescriptors()"/> method.
27+
/// </remarks>
1628
public class ContentTypeDescriptorCollection : TopicCollection<ContentTypeDescriptor> {
1729

1830
/*==========================================================================================================================
@@ -24,5 +36,39 @@ public class ContentTypeDescriptorCollection : TopicCollection<ContentTypeDescri
2436
public ContentTypeDescriptorCollection() : base(null) {
2537
}
2638

39+
/*==========================================================================================================================
40+
| REFRESH
41+
\-------------------------------------------------------------------------------------------------------------------------*/
42+
/// <summary>
43+
/// Updates the current instance of the <see cref="ContentTypeDescriptorCollection"/> based on a new root <see cref=
44+
/// "ContentTypeDescriptor"/>.
45+
/// </summary>
46+
/// <param name="rootContentType">The <see cref="ContentTypeDescriptor"/> from which to initialize the collection.</param>
47+
public void Refresh(ContentTypeDescriptor? rootContentType) {
48+
49+
/*------------------------------------------------------------------------------------------------------------------------
50+
| Validate parameters
51+
\-----------------------------------------------------------------------------------------------------------------------*/
52+
if (rootContentType == null || rootContentType.Children.Count == 0) {
53+
return;
54+
}
55+
56+
/*------------------------------------------------------------------------------------------------------------------------
57+
| Clear any existing values
58+
\-----------------------------------------------------------------------------------------------------------------------*/
59+
Clear();
60+
61+
/*------------------------------------------------------------------------------------------------------------------------
62+
| Add all ContentTypeDescriptors to collection
63+
\-----------------------------------------------------------------------------------------------------------------------*/
64+
var contentTypeDescriptors = rootContentType
65+
.FindAll(t => typeof(ContentTypeDescriptor).IsAssignableFrom(t.GetType()))
66+
.Cast<ContentTypeDescriptor>();
67+
foreach (var contentType in contentTypeDescriptors) {
68+
Add((ContentTypeDescriptor)contentType);
69+
}
70+
71+
}
72+
2773
} //Class
2874
} //Namespace

0 commit comments

Comments
 (0)