Web.Routing - refactor wildcard domains

This commit is contained in:
Stephan
2013-02-26 16:52:43 -01:00
parent 71d8736e7e
commit eba5fc84c0
2 changed files with 22 additions and 11 deletions

View File

@@ -11,13 +11,6 @@ namespace Umbraco.Web.Routing
/// </summary>
internal class DomainHelper
{
private static bool IsWildcardDomain(Domain d)
{
// supporting null or whitespace for backward compatibility,
// although we should not allow ppl to create them anymore
return string.IsNullOrWhiteSpace(d.Name) || d.Name.StartsWith("*");
}
private static Domain SanitizeForBackwardCompatibility(Domain d)
{
// this is a _really_ nasty one that should be removed in 6.x
@@ -55,7 +48,7 @@ namespace Umbraco.Web.Routing
// we need to order so example.com/foo matches before example.com/
var scheme = current == null ? Uri.UriSchemeHttp : current.Scheme;
var domainsAndUris = domains
.Where(d => !IsWildcardDomain(d))
.Where(d => !d.IsWildcard)
.Select(SanitizeForBackwardCompatibility)
.Select(d => new { Domain = d, UriString = UriUtility.EndPathWithSlash(UriUtility.StartWithScheme(d.Name, scheme)) })
.OrderByDescending(t => t.UriString)
@@ -104,7 +97,7 @@ namespace Umbraco.Web.Routing
{
var scheme = current == null ? Uri.UriSchemeHttp : current.Scheme;
var domainsAndUris = domains
.Where(d => !IsWildcardDomain(d))
.Where(d => !d.IsWildcard)
.Select(SanitizeForBackwardCompatibility)
.Select(d => new { Domain = d, UriString = UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(d.Name, scheme)) })
.OrderByDescending(t => t.UriString)
@@ -127,7 +120,7 @@ namespace Umbraco.Web.Routing
.Reverse()
.Select(int.Parse)
.TakeWhile(id => id != stopNodeId)
.Any(id => domains.Any(d => d.RootNodeId == id && !IsWildcardDomain(d)));
.Any(id => domains.Any(d => d.RootNodeId == id && !d.IsWildcard));
}
/// <summary>
@@ -148,7 +141,7 @@ namespace Umbraco.Web.Routing
.Skip(1)
.Reverse()
.TakeWhile(id => !rootNodeId.HasValue || id != rootNodeId)
.Select(nodeId => domains.FirstOrDefault(d => d.RootNodeId == nodeId && IsWildcardDomain(d)))
.Select(nodeId => domains.FirstOrDefault(d => d.RootNodeId == nodeId && d.IsWildcard))
.FirstOrDefault(domain => domain != null);
}

View File

@@ -259,5 +259,23 @@ namespace umbraco.cms.businesslogic.web
if (AfterDelete != null)
AfterDelete(this, e);
}
#region Pipeline Refactoring
// NOTE: the wildcard name thing should be managed by the Domain class
// internally but that would break too much backward compatibility, so
// we don't do it now. Will do it when the Domain class migrates to the
// new Core.Models API.
/// <summary>
/// Gets a value indicating whether the domain is a wildcard domain.
/// </summary>
/// <returns>A value indicating whether the domain is a wildcard domain.</returns>
public bool IsWildcard
{
get { return string.IsNullOrWhiteSpace(Name) || Name.StartsWith("*"); }
}
#endregion
}
}