Skip to content

Commit daa6705

Browse files
committed
Standardized identifiers of topicId, attributeKey, and attributeValue variables
Previously, `topicId` was either `id` or `sourceTopicId`; `attributeKey` was `name`; and `attributeValue` was `value`. To ensure these are more consistent with the database values they represent, these have been changed to `topicId`, `attributeKey`, and `attributeValue` respectively. The most notable of these was `name`, since it didn't map to any standard identifiers. The others are a bit more debatable, since they are otherwise consistent with the object model. But being explicit when working with the SQL interop is useful.
1 parent 95309bb commit daa6705

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ private static void AddTopic(SqlDataReader reader, Dictionary<int, Topic> topics
6969
/*------------------------------------------------------------------------------------------------------------------------
7070
| Identify attributes
7171
\-----------------------------------------------------------------------------------------------------------------------*/
72-
var id = reader.GetTopicId();
72+
var topicId = reader.GetTopicId();
7373
var key = reader.GetString("TopicKey");
7474
var contentType = reader.GetString("ContentType");
7575
var parentId = reader.GetInteger("ParentID");
7676

7777
/*------------------------------------------------------------------------------------------------------------------------
7878
| Establish topic
7979
\-----------------------------------------------------------------------------------------------------------------------*/
80-
var current = TopicFactory.Create(key, contentType, id);
80+
var current = TopicFactory.Create(key, contentType, topicId);
8181
topics.Add(current.Id, current);
8282

8383
/*------------------------------------------------------------------------------------------------------------------------
@@ -98,9 +98,9 @@ private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, T
9898
/*------------------------------------------------------------------------------------------------------------------------
9999
| Identify attributes
100100
\-----------------------------------------------------------------------------------------------------------------------*/
101-
var id = reader.GetTopicId();
102-
var name = reader.GetString("AttributeKey");
103-
var value = reader.GetString("AttributeValue");
101+
var topicId = reader.GetTopicId();
102+
var attributeKey = reader.GetString("AttributeKey");
103+
var attributeValue = reader.GetString("AttributeValue");
104104
var version = DateTime.Now;
105105

106106
//Check field count to avoid breaking changes with the 4.0.0 release, which didn't include a "Version" column
@@ -117,12 +117,12 @@ private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, T
117117
/*------------------------------------------------------------------------------------------------------------------------
118118
| Identify topic
119119
\-----------------------------------------------------------------------------------------------------------------------*/
120-
var current = topics[id];
120+
var current = topics[topicId];
121121

122122
/*------------------------------------------------------------------------------------------------------------------------
123123
| Set attribute value
124124
\-----------------------------------------------------------------------------------------------------------------------*/
125-
current.Attributes.SetValue(name, value, false, version);
125+
current.Attributes.SetValue(attributeKey, attributeValue, false, version);
126126

127127
}
128128

@@ -143,7 +143,7 @@ private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int,
143143
/*------------------------------------------------------------------------------------------------------------------------
144144
| Identify attributes
145145
\-----------------------------------------------------------------------------------------------------------------------*/
146-
var id = reader.GetTopicId();
146+
var topicId = reader.GetTopicId();
147147
var version = DateTime.Now;
148148

149149
//Check field count to avoid breaking changes with the 4.0.0 release, which didn't include a "Version" column
@@ -161,7 +161,7 @@ private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int,
161161
/*------------------------------------------------------------------------------------------------------------------------
162162
| Identify the current topic
163163
\-----------------------------------------------------------------------------------------------------------------------*/
164-
var current = topics[id];
164+
var current = topics[topicId];
165165

166166
/*------------------------------------------------------------------------------------------------------------------------
167167
| Handle scenario where there isn't an <attribute /> element
@@ -176,22 +176,23 @@ private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int,
176176
/*----------------------------------------------------------------------------------------------------------------------
177177
| Identify attributes
178178
\---------------------------------------------------------------------------------------------------------------------*/
179-
var name = (string)xmlReader.GetAttribute("key");
180-
var value = WebUtility.HtmlDecode(xmlReader.ReadInnerXml());
179+
var attributeKey = (string)xmlReader.GetAttribute("key");
180+
var attributeValue = WebUtility.HtmlDecode(xmlReader.ReadInnerXml());
181181

182182
/*----------------------------------------------------------------------------------------------------------------------
183183
| Validate assumptions
184184
\---------------------------------------------------------------------------------------------------------------------*/
185185
Contract.Assume(
186-
name,
187-
$"The @key attribute of the <attribute /> element is missing for Topic '{id}'; the data is not in the expected format."
186+
attributeKey,
187+
$"The @key attribute of the <attribute /> element is missing for Topic '{topicId}'; the data is not in the " +
188+
$"expected format."
188189
);
189190

190191
/*----------------------------------------------------------------------------------------------------------------------
191192
| Set attribute value
192193
\---------------------------------------------------------------------------------------------------------------------*/
193-
if (String.IsNullOrEmpty(value)) continue;
194-
current.Attributes.SetValue(name, value, false, version);
194+
if (String.IsNullOrEmpty(attributeValue)) continue;
195+
current.Attributes.SetValue(attributeKey, attributeValue, false, version);
195196

196197
} while (xmlReader.Name == "attribute");
197198

@@ -285,13 +286,13 @@ private static void SetVersionHistory(SqlDataReader reader, Dictionary<int, Topi
285286
/*------------------------------------------------------------------------------------------------------------------------
286287
| Identify attributes
287288
\-----------------------------------------------------------------------------------------------------------------------*/
288-
var sourceTopicId = reader.GetTopicId();
289+
var topicId = reader.GetTopicId();
289290
var dateTime = reader.GetVersion();
290291

291292
/*------------------------------------------------------------------------------------------------------------------------
292293
| Identify topic
293294
\-----------------------------------------------------------------------------------------------------------------------*/
294-
var current = topics[sourceTopicId];
295+
var current = topics[topicId];
295296

296297
/*------------------------------------------------------------------------------------------------------------------------
297298
| Set history
@@ -679,7 +680,7 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
679680

680681
Contract.Assume(
681682
contentType,
682-
"The Topics repository or database does not contain a ContentTypeDescriptor for the Page content type."
683+
$"The Topics repository or database does not contain a ContentTypeDescriptor for the {contentType} content type."
683684
);
684685

685686
/*------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)