Skip to content

Commit

Permalink
Fix for initial issue described in maartenba#236, the SiteMapTitle at…
Browse files Browse the repository at this point in the history
…tribute doesn't work when setting the CacheDuration to 0. The other issue in maartenba#236 (random exceptions) is still open.
  • Loading branch information
NightOwl888 committed Feb 2, 2014
1 parent d904bff commit 4e3ab75
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class AttributeDictionary
{
public AttributeDictionary(
string siteMapNodeKey,
string memberName,
ISiteMap siteMap,
ILocalizationService localizationService,
IReservedAttributeNameProvider reservedAttributeNameProvider,
Expand All @@ -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)
Expand All @@ -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 + "_";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace MvcSiteMapProvider.Collections.Specialized
/// </summary>
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace MvcSiteMapProvider.Collections.Specialized
/// </summary>
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class RouteValueDictionary
{
public RouteValueDictionary(
string siteMapNodeKey,
string memberName,
ISiteMap siteMap,
IReservedAttributeNameProvider reservedAttributeNameProvider,
IJsonToDictionaryDeserializer jsonToDictionaryDeserializer,
Expand All @@ -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;

Expand All @@ -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 + "_";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@ namespace MvcSiteMapProvider
/// </summary>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ IRequestCache requestCache
}

private readonly IRequestCache requestCache;
private readonly Guid instanceId = Guid.NewGuid();

#region Request Cacheable Members

Expand Down Expand Up @@ -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<string, object> dictionary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ IUrlPath urlPath
}

private readonly IRequestCache requestCache;
private readonly Guid instanceId = Guid.NewGuid();


#region ISiteMapNode Members

Expand Down Expand Up @@ -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<string, object> dictionary)
Expand Down
4 changes: 2 additions & 2 deletions src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4e3ab75

Please sign in to comment.