Skip to content

Commit d008f01

Browse files
committed
Introduce WebFormsTopicLookupService
The legacy **OnTopic Editor** relies on a `DefaultConfiguration` attribute—previously exposed on `AttributeDescriptor`—for type specific configuration values. This was removed in **OnTopic Library 4.0.0**. Instead, it's now available on the `ConfigurableAttributeDescriptor`, which is part of **OnTopic Web Forms 4.0.0**. That said, in order for topics to be reliable created as such, the `TopicFactory.TypeLookupService` needs to be replaced with a `TypeLookupService` that's aware of the `ConfigurableAttribtueDescriptor`. This is done using the `WebFormsTopicLookupService`. (_Note:_ The **OnTopic Web Forms 4.0.0** library contains such a service as well, but there's a bug in it making it unusable for our needs; that bug will be fixes in an upcoming hotfix, but for now this should satisfy its requirements.) In addition, because the `ContentTypeDescriptor.AttributeDescriptors` collection stores values as `AttributeDescriptor`s, they need to be cast back to `ConfigurableAttributeDescriptor` anytime the code needs to operate off of the `DefaultConfiguration` or related members (e.g., `GetConfigurationValue()`).
1 parent bdfd662 commit d008f01

5 files changed

Lines changed: 61 additions & 8 deletions

File tree

OnTopic.Editor.Web.Host/Global.asax.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Web.Routing;
99
using OnTopic.Data.Caching;
1010
using OnTopic.Data.Sql;
11+
using OnTopic.Web;
1112

1213
namespace OnTopic.Editor.Web.Host {
1314

@@ -28,6 +29,15 @@ public class Global : System.Web.HttpApplication {
2829
[Obsolete]
2930
protected void Application_Start(object sender, EventArgs e) {
3031

32+
/*------------------------------------------------------------------------------------------------------------------------
33+
| ESTABLISH TOPIC LOOKUP SERVICE
34+
>-------------------------------------------------------------------------------------------------------------------------
35+
| This ensures that the TopicFactory is able to correctly create `ConfigurableAttributeDescriptor` topics as their
36+
| strongly typed class, which is necessary to provide access to members which parse and query the DefaultConfiguration
37+
| property.
38+
\-----------------------------------------------------------------------------------------------------------------------*/
39+
TopicFactory.TypeLookupService = new OnTopic.Editor.Web.WebFormsTopicLookupService();
40+
3141
/*------------------------------------------------------------------------------------------------------------------------
3242
| CONFIGURE REPOSITORY
3343
\-----------------------------------------------------------------------------------------------------------------------*/

OnTopic.Editor.Web.Host/OnTopic.Editor.Web.Host.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@
150150
<Folder Include="App_Data\" />
151151
</ItemGroup>
152152
<ItemGroup>
153-
<ProjectReference Include="..\OnTopic.Web\OnTopic.Web.csproj">
154-
<Project>{c98f7b48-a085-4394-b820-c244f23868ce}</Project>
155-
<Name>OnTopic.Web</Name>
153+
<ProjectReference Include="..\OnTopic.Editor.Web\OnTopic.Editor.Web.csproj">
154+
<Project>{ed551277-df8a-4027-863f-7f8f72ca678c}</Project>
155+
<Name>OnTopic.Editor.Web</Name>
156156
</ProjectReference>
157157
</ItemGroup>
158158
<PropertyGroup>

OnTopic.Editor.Web/Default.aspx.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public partial class TopicsEditorPage : TopicPage {
3131
| PRIVATE FIELDS
3232
\---------------------------------------------------------------------------------------------------------------------------*/
3333
private ContentTypeDescriptor _contentType = null;
34-
private List<Ignia.Topics.AttributeDescriptor> _contentTypeAttributes = null;
34+
private List<ConfigurableAttributeDescriptor> _contentTypeAttributes = null;
3535

3636
/*============================================================================================================================
3737
| PUBLIC PROPERTIES
@@ -204,7 +204,7 @@ public ContentTypeDescriptor ContentType {
204204
/// Automatically crawls up the ContentType hierarchy to add any Attributes inherited from parent ContentTypes; this
205205
/// allows ContentTypes to be nested, thus deriving properties from their parents.
206206
/// </remarks>
207-
public List<Ignia.Topics.AttributeDescriptor> ContentTypeAttributes {
207+
public List<ConfigurableAttributeDescriptor> ContentTypeAttributes {
208208
get {
209209

210210
/*------------------------------------------------------------------------------------------------------------------------
@@ -215,12 +215,12 @@ public List<Ignia.Topics.AttributeDescriptor> ContentTypeAttributes {
215215
/*------------------------------------------------------------------------------------------------------------------------
216216
| Look up Content Type Topic Attributes
217217
\-----------------------------------------------------------------------------------------------------------------------*/
218-
_contentTypeAttributes = new List<Ignia.Topics.AttributeDescriptor>();
218+
_contentTypeAttributes = new List<ConfigurableAttributeDescriptor>();
219219

220220
if (ContentType != null) {
221221

222222
// Get Attributes
223-
_contentTypeAttributes = ContentType.AttributeDescriptors.ToList();
223+
_contentTypeAttributes = ContentType.AttributeDescriptors.Cast<ConfigurableAttributeDescriptor>().ToList();
224224

225225
// Set Order
226226
_contentTypeAttributes = _contentTypeAttributes
@@ -323,7 +323,7 @@ public void AddAttributesToPage() {
323323
// Attributes are drawn based on the defined ContentType's Attributes, as opposed to the Attributes found in the current
324324
// Topic. As a result, any "ad hoc" attributes added programmatically or orphaned from a previous ContentType setting will
325325
// not be displayed.
326-
foreach (Ignia.Topics.AttributeDescriptor contentTypeAttribute in ContentTypeAttributes) {
326+
foreach (ConfigurableAttributeDescriptor contentTypeAttribute in ContentTypeAttributes) {
327327

328328
/*------------------------------------------------------------------------------------------------------------------------
329329
| Ignore hidden Attributes
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using OnTopic.Web.Editor;
9+
10+
namespace OnTopic.Editor.Web {
11+
12+
/*============================================================================================================================
13+
| CLASS: TOPIC LOOKUP SERVICE (WEB FORMS)
14+
\---------------------------------------------------------------------------------------------------------------------------*/
15+
/// <summary>
16+
/// The <see cref="WebFormsTopicLookupService"/> provides access to all of the standard <see cref="Topic"/> types available
17+
/// in the <see cref="DefaultTopicLookupService"/>, as well as custom <see cref="Topic"/>s available for WebForms.
18+
/// </summary>
19+
public class WebFormsTopicLookupService: DefaultTopicLookupService {
20+
21+
/*==========================================================================================================================
22+
| CONSTRUCTOR
23+
\-------------------------------------------------------------------------------------------------------------------------*/
24+
/// <summary>
25+
/// Establishes a new instance of a <see cref="WebFormsTopicLookupService"/>. Optionally accepts a list of <see
26+
/// cref="Type"/> instances and a default <see cref="Type"/> value.
27+
/// </summary>
28+
/// <remarks><inheritdoc /></remarks>
29+
/// <param name="types"><inheritdoc /></param>
30+
/// <param name="defaultType"><inheritdoc /></param>
31+
public WebFormsTopicLookupService(IEnumerable<Type> types = null, Type defaultType = null) :
32+
base(types, defaultType?? typeof(Topic)) {
33+
34+
/*------------------------------------------------------------------------------------------------------------------------
35+
| Ensure editor types are accounted for
36+
\-----------------------------------------------------------------------------------------------------------------------*/
37+
if (!Contains(nameof(ConfigurableAttributeDescriptor))) Add(typeof(ConfigurableAttributeDescriptor));
38+
39+
}
40+
41+
} //Class
42+
} //Namespace

OnTopic.Editor.Web/OnTopic.Editor.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@
10491049
<DependentUpon>Default.aspx</DependentUpon>
10501050
<SubType>ASPXCodeBehind</SubType>
10511051
</Content>
1052+
<Compile Include="Infrastructure\WebFormsTopicLookupService.cs" />
10521053
<Compile Include="Properties\AssemblyInfo.cs" />
10531054
</ItemGroup>
10541055
<ItemGroup>

0 commit comments

Comments
 (0)