From 4e3ab7557f7b23399405aaf5a5ae7290908a6219 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Mon, 3 Feb 2014 02:18:44 +0700 Subject: [PATCH] Fix for initial issue described in #236, the SiteMapTitle attribute doesn't work when setting the CacheDuration to 0. The other issue in #236 (random exceptions) is still open. --- .../Specialized/RouteValueDictionaryTest.cs | 2 +- .../Specialized/AttributeDictionary.cs | 8 ++++++-- .../Specialized/AttributeDictionaryFactory.cs | 10 ++-------- .../IAttributeDictionaryFactory.cs | 5 +---- .../IRouteValueDictionaryFactory.cs | 5 +---- .../Specialized/RouteValueDictionary.cs | 8 ++++++-- .../RouteValueDictionaryFactory.cs | 10 ++-------- .../ISiteMapNodeChildStateFactory.cs | 12 ++--------- .../RequestCacheableSiteMap.cs | 3 +-- .../RequestCacheableSiteMapNode.cs | 4 +--- .../MvcSiteMapProvider/SiteMapNode.cs | 4 ++-- .../SiteMapNodeChildStateFactory.cs | 20 ++++--------------- 12 files changed, 29 insertions(+), 62 deletions(-) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Collections/Specialized/RouteValueDictionaryTest.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Collections/Specialized/RouteValueDictionaryTest.cs index d8a4ffff..4b84e453 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Collections/Specialized/RouteValueDictionaryTest.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Collections/Specialized/RouteValueDictionaryTest.cs @@ -46,7 +46,7 @@ public void Dispose() private IRouteValueDictionary NewRouteValueDictionaryInstance() { - return new RouteValueDictionary("testNodeKey", mSiteMap.Object, mReservedAttributeNameProvider.Object, mjsonToDictionaryDeserializer.Object, mRequestCache.Object); + return new RouteValueDictionary("testNodeKey", "RouteValues", mSiteMap.Object, mReservedAttributeNameProvider.Object, mjsonToDictionaryDeserializer.Object, mRequestCache.Object); } #endregion diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionary.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionary.cs index 6e3d5510..49ea1d5e 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionary.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionary.cs @@ -20,6 +20,7 @@ public class AttributeDictionary { public AttributeDictionary( string siteMapNodeKey, + string memberName, ISiteMap siteMap, ILocalizationService localizationService, IReservedAttributeNameProvider reservedAttributeNameProvider, @@ -30,6 +31,8 @@ ICache cache { if (string.IsNullOrEmpty(siteMapNodeKey)) throw new ArgumentNullException("siteMapNodeKey"); + if (string.IsNullOrEmpty(memberName)) + throw new ArgumentNullException("memberName"); if (localizationService == null) throw new ArgumentNullException("localizationService"); if (reservedAttributeNameProvider == null) @@ -38,20 +41,21 @@ ICache cache throw new ArgumentNullException("jsonToDictionaryDeserializer"); this.siteMapNodeKey = siteMapNodeKey; + this.memberName = memberName; this.localizationService = localizationService; this.reservedAttributeNameProvider = reservedAttributeNameProvider; this.jsonToDictionaryDeserializer = jsonToDictionaryDeserializer; } protected readonly string siteMapNodeKey; + protected readonly string memberName; protected readonly ILocalizationService localizationService; protected readonly IReservedAttributeNameProvider reservedAttributeNameProvider; protected readonly IJsonToDictionaryDeserializer jsonToDictionaryDeserializer; protected override string GetCacheKey() { - // TODO: Update cache key with siteMapCacheKey and siteMapNodeKey so it will persist between SiteMap rebuilds - return "__ATTRIBUTE_DICTIONARY_" + this.instanceId.ToString(); + return "__ATTRIBUTE_DICTIONARY_" + this.siteMap.CacheKey + "_" + this.siteMapNodeKey + "_" + this.memberName + "_"; } /// diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionaryFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionaryFactory.cs index a27a64bf..3aeff6fc 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionaryFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/AttributeDictionaryFactory.cs @@ -37,15 +37,9 @@ IJsonToDictionaryDeserializer jsonToDictionaryDeserializer #region IAttributeDictionaryFactory Members - public virtual IAttributeDictionary Create(string siteMapNodeKey, ISiteMap siteMap, ILocalizationService localizationService) + public virtual IAttributeDictionary Create(string siteMapNodeKey, string memberName, ISiteMap siteMap, ILocalizationService localizationService) { - return new AttributeDictionary(siteMapNodeKey, siteMap, localizationService, this.reservedAttributeNameProvider, this.jsonToDictionaryDeserializer, this.requestCache); - } - - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - public virtual IAttributeDictionary Create(ISiteMap siteMap, ILocalizationService localizationService) - { - return new AttributeDictionary("NO_KEY", siteMap, localizationService, this.reservedAttributeNameProvider, this.jsonToDictionaryDeserializer, this.requestCache); + return new AttributeDictionary(siteMapNodeKey, memberName, siteMap, localizationService, this.reservedAttributeNameProvider, this.jsonToDictionaryDeserializer, this.requestCache); } #endregion diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IAttributeDictionaryFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IAttributeDictionaryFactory.cs index 97e66f6c..35ab41c5 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IAttributeDictionaryFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IAttributeDictionaryFactory.cs @@ -10,9 +10,6 @@ namespace MvcSiteMapProvider.Collections.Specialized /// public interface IAttributeDictionaryFactory { - IAttributeDictionary Create(string siteMapNodeKey, ISiteMap siteMap, ILocalizationService localizationService); - - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - IAttributeDictionary Create(ISiteMap siteMap, ILocalizationService localizationService); + IAttributeDictionary Create(string siteMapNodeKey, string memberName, ISiteMap siteMap, ILocalizationService localizationService); } } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IRouteValueDictionaryFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IRouteValueDictionaryFactory.cs index 51e7d72f..1287cb43 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IRouteValueDictionaryFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/IRouteValueDictionaryFactory.cs @@ -8,9 +8,6 @@ namespace MvcSiteMapProvider.Collections.Specialized /// public interface IRouteValueDictionaryFactory { - IRouteValueDictionary Create(string siteMapNodeKey, ISiteMap siteMap); - - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - IRouteValueDictionary Create(ISiteMap siteMap); + IRouteValueDictionary Create(string siteMapNodeKey, string memberName, ISiteMap siteMap); } } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionary.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionary.cs index f4fa0091..da06e75d 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionary.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionary.cs @@ -21,6 +21,7 @@ public class RouteValueDictionary { public RouteValueDictionary( string siteMapNodeKey, + string memberName, ISiteMap siteMap, IReservedAttributeNameProvider reservedAttributeNameProvider, IJsonToDictionaryDeserializer jsonToDictionaryDeserializer, @@ -29,12 +30,15 @@ ICache cache { if (string.IsNullOrEmpty(siteMapNodeKey)) throw new ArgumentNullException("siteMapNodeKey"); + if (string.IsNullOrEmpty(memberName)) + throw new ArgumentNullException("memberName"); if (reservedAttributeNameProvider == null) throw new ArgumentNullException("reservedAttributeNameProvider"); if (jsonToDictionaryDeserializer == null) throw new ArgumentNullException("jsonToDictionaryDeserializer"); this.siteMapNodeKey = siteMapNodeKey; + this.memberName = memberName; this.reservedAttributeNameProvider = reservedAttributeNameProvider; this.jsonToDictionaryDeserializer = jsonToDictionaryDeserializer; @@ -43,13 +47,13 @@ ICache cache } protected readonly string siteMapNodeKey; + protected readonly string memberName; protected readonly IReservedAttributeNameProvider reservedAttributeNameProvider; protected readonly IJsonToDictionaryDeserializer jsonToDictionaryDeserializer; protected override string GetCacheKey() { - // TODO: Update cache key with siteMapCacheKey and siteMapNodeKey so it will persist between SiteMap rebuilds - return "__ROUTE_VALUE_DICTIONARY_" + this.instanceId.ToString(); + return "__ROUTE_VALUE_DICTIONARY_" + this.siteMap.CacheKey + "_" + this.siteMapNodeKey + "_" + this.memberName + "_"; } /// diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionaryFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionaryFactory.cs index c9067e09..22b05ec1 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionaryFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Collections/Specialized/RouteValueDictionaryFactory.cs @@ -37,15 +37,9 @@ IJsonToDictionaryDeserializer jsonToDictionaryDeserializer #region IRouteValueDictionaryFactory Members - public IRouteValueDictionary Create(string siteMapNodeKey, ISiteMap siteMap) + public IRouteValueDictionary Create(string siteMapNodeKey, string memberName, ISiteMap siteMap) { - return new RouteValueDictionary(siteMapNodeKey, siteMap, this.reservedAttributeNameProvider, this.jsonToDictionaryDeserializer, this.requestCache); - } - - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - public virtual IRouteValueDictionary Create(ISiteMap siteMap) - { - return new RouteValueDictionary("NO_KEY", siteMap, this.reservedAttributeNameProvider, this.jsonToDictionaryDeserializer, this.requestCache); + return new RouteValueDictionary(siteMapNodeKey, memberName, siteMap, this.reservedAttributeNameProvider, this.jsonToDictionaryDeserializer, this.requestCache); } #endregion diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapNodeChildStateFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapNodeChildStateFactory.cs index 2bcd8faa..78652cb4 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapNodeChildStateFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapNodeChildStateFactory.cs @@ -10,16 +10,8 @@ namespace MvcSiteMapProvider /// public interface ISiteMapNodeChildStateFactory { - IAttributeDictionary CreateAttributeDictionary(string siteMapNodeKey, ISiteMap siteMap, ILocalizationService localizationService); - - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - IAttributeDictionary CreateAttributeDictionary(ISiteMap siteMap, ILocalizationService localizationService); - - IRouteValueDictionary CreateRouteValueDictionary(string siteMapNodeKey, ISiteMap siteMap); - - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - IRouteValueDictionary CreateRouteValueDictionary(ISiteMap siteMap); - + IAttributeDictionary CreateAttributeDictionary(string siteMapNodeKey, string memberName, ISiteMap siteMap, ILocalizationService localizationService); + IRouteValueDictionary CreateRouteValueDictionary(string siteMapNodeKey, string memberName, ISiteMap siteMap); IPreservedRouteParameterCollection CreatePreservedRouteParameterCollection(ISiteMap siteMap); IRoleCollection CreateRoleCollection(ISiteMap siteMap); IMetaRobotsValueCollection CreateMetaRobotsValueCollection(ISiteMap siteMap); diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMap.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMap.cs index a6e890a5..37c74e49 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMap.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMap.cs @@ -33,7 +33,6 @@ IRequestCache requestCache } private readonly IRequestCache requestCache; - private readonly Guid instanceId = Guid.NewGuid(); #region Request Cacheable Members @@ -102,7 +101,7 @@ protected virtual string GetCacheKey(string memberName) { // NOTE: We must include IsReadOnly in the request cache key because we may have a different // result when the sitemap is being constructed than when it is being read by the presentation layer. - return "__MVCSITEMAP_" + memberName + "_" + this.IsReadOnly.ToString() + "_" + this.instanceId.ToString(); + return "__MVCSITEMAP_" + this.CacheKey + "_" + memberName + "_" + this.IsReadOnly.ToString() + "_"; } protected virtual string GetDictionaryKey(IDictionary dictionary) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMapNode.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMapNode.cs index e1ca5d77..4643aa77 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMapNode.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/RequestCacheableSiteMapNode.cs @@ -44,8 +44,6 @@ IUrlPath urlPath } private readonly IRequestCache requestCache; - private readonly Guid instanceId = Guid.NewGuid(); - #region ISiteMapNode Members @@ -160,7 +158,7 @@ protected string GetCacheKey(string memberName) { // NOTE: We must include IsReadOnly in the request cache key because we may have a different // result when the sitemap is being constructed than when it is being read by the presentation layer. - return "__MVCSITEMAPNODE_" + memberName + "_" + this.Key + "_" + this.IsReadOnly.ToString() + "_" + this.instanceId.ToString(); + return "__MVCSITEMAPNODE_" + this.SiteMap.CacheKey + "_" + this.Key + "_" + memberName + "_" + this.IsReadOnly.ToString() + "_"; } protected virtual string GetDictionaryKey(IDictionary dictionary) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs index ee87fec6..4b4f5e08 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs @@ -52,8 +52,8 @@ IUrlPath urlPath this.urlPath = urlPath; // Initialize child collections - this.attributes = siteMapNodeChildStateFactory.CreateAttributeDictionary(key, siteMap, localizationService); - this.routeValues = siteMapNodeChildStateFactory.CreateRouteValueDictionary(key, siteMap); + this.attributes = siteMapNodeChildStateFactory.CreateAttributeDictionary(key, "Attributes", siteMap, localizationService); + this.routeValues = siteMapNodeChildStateFactory.CreateRouteValueDictionary(key, "RouteValues", siteMap); this.preservedRouteParameters = siteMapNodeChildStateFactory.CreatePreservedRouteParameterCollection(siteMap); this.roles = siteMapNodeChildStateFactory.CreateRoleCollection(siteMap); this.metaRobotsValues = siteMapNodeChildStateFactory.CreateMetaRobotsValueCollection(siteMap); diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNodeChildStateFactory.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNodeChildStateFactory.cs index fa935050..84d76aa5 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNodeChildStateFactory.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNodeChildStateFactory.cs @@ -30,26 +30,14 @@ IRouteValueDictionaryFactory routeValueDictionaryFactory #region ISiteMapNodeChildStateFactory Members - public virtual IAttributeDictionary CreateAttributeDictionary(string siteMapNodeKey, ISiteMap siteMap, ILocalizationService localizationService) + public virtual IAttributeDictionary CreateAttributeDictionary(string siteMapNodeKey, string memberName, ISiteMap siteMap, ILocalizationService localizationService) { - return attributeDictionaryFactory.Create(siteMapNodeKey, siteMap, localizationService); + return attributeDictionaryFactory.Create(siteMapNodeKey, memberName, siteMap, localizationService); } - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - public virtual IAttributeDictionary CreateAttributeDictionary(ISiteMap siteMap, ILocalizationService localizationService) + public virtual IRouteValueDictionary CreateRouteValueDictionary(string siteMapNodeKey, string memberName, ISiteMap siteMap) { - return attributeDictionaryFactory.Create(string.Empty, siteMap, localizationService); - } - - public virtual IRouteValueDictionary CreateRouteValueDictionary(string siteMapNodeKey, ISiteMap siteMap) - { - return routeValueDictionaryFactory.Create(siteMapNodeKey, siteMap); - } - - [Obsolete("Use the overload that accepts a siteMapNodeKey instead. This overload will be removed in version 5.")] - public virtual IRouteValueDictionary CreateRouteValueDictionary(ISiteMap siteMap) - { - return routeValueDictionaryFactory.Create(string.Empty, siteMap); + return routeValueDictionaryFactory.Create(siteMapNodeKey, memberName, siteMap); } public virtual IPreservedRouteParameterCollection CreatePreservedRouteParameterCollection(ISiteMap siteMap)