Skip to content

Commit 60bb4f6

Browse files
committed
Moved GetContentTypeDescriptors() to TopicRepositoryBase
Generally, `GetContentTypeDescriptors()` should be able to operate independent of any underlying implementation; it is a convenience method to consolidate data loaded by `Load()`. As such, its definition can be centralized via the `TopicRepositoryBase`. As part of this, the part of `Save()` that interacts with `GetContentTypeDescriptors()` was also able to be centralized as part of `TopicRepositoryBase`.
1 parent 7b2e7ad commit 60bb4f6

8 files changed

Lines changed: 81 additions & 80 deletions

File tree

Ignia.Topics.Data.Caching/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1751.0")]
25-
[assembly: AssemblyFileVersion("3.5.1783.0")]
24+
[assembly: AssemblyVersion("3.5.1758.0")]
25+
[assembly: AssemblyFileVersion("3.5.1790.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("206b7f91-ca25-4e9d-9576-60d2e54a2c0a")]
2828

Ignia.Topics.Data.Sql/SqlTopicRepository.cs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class SqlTopicRepository : TopicRepositoryBase, ITopicRepository {
3434
/*==========================================================================================================================
3535
| PRIVATE VARIABLES
3636
\-------------------------------------------------------------------------------------------------------------------------*/
37-
private ContentTypeDescriptorCollection _contentTypeDescriptors = null;
3837
private readonly string _connectionString = null;
3938

4039
/*==========================================================================================================================
@@ -264,56 +263,6 @@ private static void SetDerivedTopics(Dictionary<int, Topic> topics) {
264263

265264
}
266265

267-
/*==========================================================================================================================
268-
| GET CONTENT TYPE DESCRIPTORS
269-
\-------------------------------------------------------------------------------------------------------------------------*/
270-
/// <summary>
271-
/// Retrieves a collection of Content Type Descriptor objects from the configuration section of the data provider.
272-
/// </summary>
273-
public override ContentTypeDescriptorCollection GetContentTypeDescriptors() {
274-
275-
/*------------------------------------------------------------------------------------------------------------------------
276-
| Initialize content types
277-
\-----------------------------------------------------------------------------------------------------------------------*/
278-
if (_contentTypeDescriptors == null) {
279-
280-
/*----------------------------------------------------------------------------------------------------------------------
281-
| Load configuration data
282-
\---------------------------------------------------------------------------------------------------------------------*/
283-
var configuration = Load("Configuration");
284-
285-
/*----------------------------------------------------------------------------------------------------------------------
286-
| Add available Content Types to the collection
287-
\---------------------------------------------------------------------------------------------------------------------*/
288-
_contentTypeDescriptors = new ContentTypeDescriptorCollection();
289-
290-
/*----------------------------------------------------------------------------------------------------------------------
291-
| Ensure the parent ContentTypes topic is available to iterate over
292-
\---------------------------------------------------------------------------------------------------------------------*/
293-
if (configuration.Children.GetTopic("ContentTypes") == null) {
294-
throw new Exception("Unable to load section Configuration:ContentTypes.");
295-
}
296-
297-
/*----------------------------------------------------------------------------------------------------------------------
298-
| Add available Content Types to the collection
299-
\---------------------------------------------------------------------------------------------------------------------*/
300-
foreach (var topic in configuration.Children.GetTopic("ContentTypes").FindAllByAttribute("ContentType", "ContentType")) {
301-
// Ensure the Topic is used as the strongly-typed ContentType
302-
// Add ContentType Topic to collection if not already added
303-
if (
304-
topic is ContentTypeDescriptor contentTypeDescriptor &&
305-
!_contentTypeDescriptors.Contains(contentTypeDescriptor.Key)
306-
) {
307-
_contentTypeDescriptors.Add(contentTypeDescriptor);
308-
}
309-
}
310-
311-
}
312-
313-
return _contentTypeDescriptors;
314-
315-
}
316-
317266
/*==========================================================================================================================
318267
| METHOD: SET VERSION HISTORY
319268
\-------------------------------------------------------------------------------------------------------------------------*/
@@ -752,22 +701,7 @@ public override int Save(Topic topic, bool isRecursive = false, bool isDraft = f
752701
/*------------------------------------------------------------------------------------------------------------------------
753702
| Validate content type
754703
\-----------------------------------------------------------------------------------------------------------------------*/
755-
var contentTypes = GetContentTypeDescriptors();
756-
if (!contentTypes.Contains(topic.Attributes.GetValue("ContentType"))) {
757-
throw new Exception(
758-
"The Content Type \"" + topic.Attributes.GetValue("ContentType", "Page") + "\" referenced by \"" + topic.Key +
759-
"\" could not be found. under \"Configuration:ContentTypes\". There are " + contentTypes.Count +
760-
" ContentTypes in the Repository."
761-
);
762-
}
763-
var contentType = contentTypes[topic.Attributes.GetValue("ContentType", "Page")];
764-
765-
/*------------------------------------------------------------------------------------------------------------------------
766-
| Update content types collection, if appropriate
767-
\-----------------------------------------------------------------------------------------------------------------------*/
768-
if (topic is ContentTypeDescriptor && !contentTypes.Contains(topic.Key)) {
769-
_contentTypeDescriptors.Add(topic as ContentTypeDescriptor);
770-
}
704+
var contentType = GetContentTypeDescriptors()[topic.Attributes.GetValue("ContentType", "Page")];
771705

772706
/*------------------------------------------------------------------------------------------------------------------------
773707
| Establish attribute strings

Ignia.Topics.Tests/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1771.0")]
25-
[assembly: AssemblyFileVersion("3.5.1819.0")]
24+
[assembly: AssemblyVersion("3.5.1786.0")]
25+
[assembly: AssemblyFileVersion("3.5.1834.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("27632801-bfe3-41d9-8678-3c4bbe45e6c9")]

Ignia.Topics.ViewModels/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1752.0")]
25-
[assembly: AssemblyFileVersion("3.5.1783.0")]
24+
[assembly: AssemblyVersion("3.5.1758.0")]
25+
[assembly: AssemblyFileVersion("3.5.1789.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("e52fc633-b4c5-4a2b-8caf-30e756d7a6a7")]
2828

Ignia.Topics.Web.Mvc/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1756.0")]
25-
[assembly: AssemblyFileVersion("3.5.1788.0")]
24+
[assembly: AssemblyVersion("3.5.1762.0")]
25+
[assembly: AssemblyFileVersion("3.5.1794.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("3b3ce34d-b5e5-47ca-bfef-e6740650f378")]

Ignia.Topics.Web/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1750.0")]
25-
[assembly: AssemblyFileVersion("3.5.1774.0")]
24+
[assembly: AssemblyVersion("3.5.1754.0")]
25+
[assembly: AssemblyFileVersion("3.5.1778.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("c98f7b48-a085-4394-b820-c244f23868ce")]

Ignia.Topics/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
[assembly: AssemblyTrademark("")]
2323
[assembly: AssemblyCulture("")]
2424
[assembly: ComVisible(false)]
25-
[assembly: AssemblyVersion("3.5.1751.0")]
26-
[assembly: AssemblyFileVersion("3.5.1783.0")]
25+
[assembly: AssemblyVersion("3.5.1757.0")]
26+
[assembly: AssemblyFileVersion("3.5.1789.0")]
2727
[assembly: InternalsVisibleTo("Ignia.Topics.Tests")]
2828
[assembly: CLSCompliant(true)]
2929
[assembly: GuidAttribute("3CA9F6CB-B45A-4E74-AAA4-0C87CAA2704F")]

Ignia.Topics/Repositories/TopicRepositoryBase.cs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Diagnostics.Contracts;
88
using Ignia.Topics.Collections;
9+
using Ignia.Topics.Querying;
910

1011
namespace Ignia.Topics.Repositories {
1112

@@ -17,6 +18,11 @@ namespace Ignia.Topics.Repositories {
1718
/// </summary>
1819
public abstract class TopicRepositoryBase : ITopicRepository {
1920

21+
/*==========================================================================================================================
22+
| PRIVATE VARIABLES
23+
\-------------------------------------------------------------------------------------------------------------------------*/
24+
private ContentTypeDescriptorCollection _contentTypeDescriptors = null;
25+
2026
/*==========================================================================================================================
2127
| EVENT HANDLERS
2228
\-------------------------------------------------------------------------------------------------------------------------*/
@@ -41,7 +47,50 @@ public abstract class TopicRepositoryBase : ITopicRepository {
4147
/// <summary>
4248
/// Retrieves a collection of Content Type Descriptor objects from the configuration section of the data provider.
4349
/// </summary>
44-
public abstract ContentTypeDescriptorCollection GetContentTypeDescriptors();
50+
public virtual ContentTypeDescriptorCollection GetContentTypeDescriptors() {
51+
52+
/*------------------------------------------------------------------------------------------------------------------------
53+
| Initialize content types
54+
\-----------------------------------------------------------------------------------------------------------------------*/
55+
if (_contentTypeDescriptors == null) {
56+
57+
/*----------------------------------------------------------------------------------------------------------------------
58+
| Load configuration data
59+
\---------------------------------------------------------------------------------------------------------------------*/
60+
var configuration = Load("Configuration");
61+
62+
/*----------------------------------------------------------------------------------------------------------------------
63+
| Add available Content Types to the collection
64+
\---------------------------------------------------------------------------------------------------------------------*/
65+
_contentTypeDescriptors = new ContentTypeDescriptorCollection();
66+
67+
/*----------------------------------------------------------------------------------------------------------------------
68+
| Ensure the parent ContentTypes topic is available to iterate over
69+
\---------------------------------------------------------------------------------------------------------------------*/
70+
if (configuration.Children.GetTopic("ContentTypes") == null) {
71+
throw new Exception("Unable to load section Configuration:ContentTypes.");
72+
}
73+
74+
/*----------------------------------------------------------------------------------------------------------------------
75+
| Add available Content Types to the collection
76+
\---------------------------------------------------------------------------------------------------------------------*/
77+
foreach (var topic in configuration.Children.GetTopic("ContentTypes").FindAllByAttribute("ContentType", "ContentType")) {
78+
// Ensure the Topic is used as the strongly-typed ContentType
79+
// Add ContentType Topic to collection if not already added
80+
if (
81+
topic is ContentTypeDescriptor contentTypeDescriptor &&
82+
!_contentTypeDescriptors.Contains(contentTypeDescriptor.Key)
83+
) {
84+
_contentTypeDescriptors.Add(contentTypeDescriptor);
85+
}
86+
}
87+
88+
}
89+
90+
return _contentTypeDescriptors;
91+
92+
}
93+
4594

4695
/*==========================================================================================================================
4796
| METHOD: LOAD
@@ -167,6 +216,24 @@ public void Rollback(Topic topic, DateTime version) {
167216
/// <exception cref="ArgumentNullException">topic</exception>
168217
public virtual int Save(Topic topic, bool isRecursive = false, bool isDraft = false) {
169218

219+
/*------------------------------------------------------------------------------------------------------------------------
220+
| Validate content type
221+
\-----------------------------------------------------------------------------------------------------------------------*/
222+
var contentTypes = GetContentTypeDescriptors();
223+
if (!contentTypes.Contains(topic.ContentType)) {
224+
throw new ArgumentException(
225+
$"The Content Type \"{topic.ContentType}\" referenced by \"{topic.Key}\" could not be found under " +
226+
$"\"Configuration:ContentTypes\". There are currently {contentTypes.Count} ContentTypes in the Repository."
227+
);
228+
}
229+
230+
/*------------------------------------------------------------------------------------------------------------------------
231+
| Update content types collection, if appropriate
232+
\-----------------------------------------------------------------------------------------------------------------------*/
233+
if (topic is ContentTypeDescriptor && !contentTypes.Contains(topic.Key)) {
234+
_contentTypeDescriptors.Add(topic as ContentTypeDescriptor);
235+
}
236+
170237
/*------------------------------------------------------------------------------------------------------------------------
171238
| Trigger event
172239
\-----------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)