diff --git a/src/Umbraco.Core/Models/IDomain.cs b/src/Umbraco.Core/Models/IDomain.cs index 29978d9cf6..9fb3e8019d 100644 --- a/src/Umbraco.Core/Models/IDomain.cs +++ b/src/Umbraco.Core/Models/IDomain.cs @@ -4,7 +4,7 @@ namespace Umbraco.Core.Models { public interface IDomain : IAggregateRoot, IRememberBeingDirty, ICanBeDirty { - ILanguage DefaultLanguage { get; set; } + ILanguage Language { get; set; } string DomainName { get; set; } IContent RootContent { get; set; } bool IsWildcard { get; } diff --git a/src/Umbraco.Core/Models/UmbracoDomain.cs b/src/Umbraco.Core/Models/UmbracoDomain.cs index 90c94cb4c6..d2f5772e93 100644 --- a/src/Umbraco.Core/Models/UmbracoDomain.cs +++ b/src/Umbraco.Core/Models/UmbracoDomain.cs @@ -15,12 +15,12 @@ namespace Umbraco.Core.Models private ILanguage _language; private string _domainName; - private static readonly PropertyInfo DefaultLanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.DefaultLanguage); + private static readonly PropertyInfo DefaultLanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.Language); private static readonly PropertyInfo DomainNameSelector = ExpressionHelper.GetPropertyInfo(x => x.DomainName); private static readonly PropertyInfo ContentSelector = ExpressionHelper.GetPropertyInfo(x => x.RootContent); [DataMember] - public ILanguage DefaultLanguage + public ILanguage Language { get { return _language; } set diff --git a/src/Umbraco.Core/Persistence/Repositories/DomainRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DomainRepository.cs index 93d6d82341..fd29c81c71 100644 --- a/src/Umbraco.Core/Persistence/Repositories/DomainRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/DomainRepository.cs @@ -294,7 +294,7 @@ namespace Umbraco.Core.Persistence.Repositories { Id = cacheableDomain.Id, //lookup from repo - this will be cached - DefaultLanguage = cacheableDomain.DefaultLanguageId.HasValue ? langItems.FirstOrDefault(l => l.Id == cacheableDomain.DefaultLanguageId.Value) : null, + Language = cacheableDomain.DefaultLanguageId.HasValue ? langItems.FirstOrDefault(l => l.Id == cacheableDomain.DefaultLanguageId.Value) : null, DomainName = cacheableDomain.DomainName, //lookup from repo - this will be cached RootContent = cacheableDomain.RootContentId.HasValue ? contentItems.FirstOrDefault(l => l.Id == cacheableDomain.RootContentId.Value) : null, @@ -309,7 +309,7 @@ namespace Umbraco.Core.Persistence.Repositories { Id = cacheableDomain.Id, //lookup from repo - this will be cached - DefaultLanguage = cacheableDomain.DefaultLanguageId.HasValue ? languageRepository.Get(cacheableDomain.DefaultLanguageId.Value) : null, + Language = cacheableDomain.DefaultLanguageId.HasValue ? languageRepository.Get(cacheableDomain.DefaultLanguageId.Value) : null, DomainName = cacheableDomain.DomainName, //lookup from repo - this will be cached RootContent = cacheableDomain.RootContentId.HasValue ? contentRepository.Get(cacheableDomain.RootContentId.Value) : null @@ -321,7 +321,7 @@ namespace Umbraco.Core.Persistence.Repositories var domain = new CacheableDomain { Id = entity.Id, - DefaultLanguageId = entity.DefaultLanguage == null ? null : (int?)entity.DefaultLanguage.Id, + DefaultLanguageId = entity.Language == null ? null : (int?)entity.Language.Id, DomainName = entity.DomainName, RootContentId = entity.RootContent == null ? null : (int?)entity.RootContent.Id }; diff --git a/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs b/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs index 7e74c2a0d0..1403d5e6c4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/LanguageRepository.cs @@ -51,6 +51,11 @@ namespace Umbraco.Core.Persistence.Repositories sql.Where("umbracoLanguage.id in (@ids)", new { ids = ids }); } + //this needs to be sorted since that is the way legacy worked - default language is the first one!! + //even though legacy didn't sort, it should be by id + sql.OrderBy(dto => dto.Id, SqlSyntax); + + return Database.Fetch(sql).Select(ConvertFromDto); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs index 66f9589d31..af0c3b86b5 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DomainRepositoryTest.cs @@ -71,7 +71,7 @@ namespace Umbraco.Tests.Persistence.Repositories var lang = langRepo.GetByIsoCode("en-AU"); var content = contentRepo.Get(contentId); - var domain = (IDomain)new UmbracoDomain { RootContent = content, DefaultLanguage = lang, DomainName = "test.com" }; + var domain = (IDomain)new UmbracoDomain { RootContent = content, Language = lang, DomainName = "test.com" }; repo.AddOrUpdate(domain); unitOfWork.Commit(); @@ -83,7 +83,7 @@ namespace Umbraco.Tests.Persistence.Repositories Assert.Greater(domain.Id, 0); Assert.AreEqual("test.com", domain.DomainName); Assert.AreEqual(content.Id, domain.RootContent.Id); - Assert.AreEqual(lang.Id, domain.DefaultLanguage.Id); + Assert.AreEqual(lang.Id, domain.Language.Id); } @@ -107,11 +107,11 @@ namespace Umbraco.Tests.Persistence.Repositories var lang = langRepo.GetByIsoCode("en-AU"); var content = contentRepo.Get(contentId); - var domain1 = (IDomain)new UmbracoDomain { RootContent = content, DefaultLanguage = lang, DomainName = "test.com" }; + var domain1 = (IDomain)new UmbracoDomain { RootContent = content, Language = lang, DomainName = "test.com" }; repo.AddOrUpdate(domain1); unitOfWork.Commit(); - var domain2 = (IDomain)new UmbracoDomain { RootContent = content, DefaultLanguage = lang, DomainName = "test.com" }; + var domain2 = (IDomain)new UmbracoDomain { RootContent = content, Language = lang, DomainName = "test.com" }; repo.AddOrUpdate(domain2); Assert.Throws(unitOfWork.Commit); @@ -140,7 +140,7 @@ namespace Umbraco.Tests.Persistence.Repositories var lang = langRepo.GetByIsoCode("en-AU"); var content = contentRepo.Get(contentId); - var domain = (IDomain)new UmbracoDomain { RootContent = content, DefaultLanguage = lang, DomainName = "test.com" }; + var domain = (IDomain)new UmbracoDomain { RootContent = content, Language = lang, DomainName = "test.com" }; repo.AddOrUpdate(domain); unitOfWork.Commit(); @@ -183,7 +183,7 @@ namespace Umbraco.Tests.Persistence.Repositories unitOfWork.Commit(); - var domain = (IDomain)new UmbracoDomain { RootContent = content1, DefaultLanguage = lang1, DomainName = "test.com" }; + var domain = (IDomain)new UmbracoDomain { RootContent = content1, Language = lang1, DomainName = "test.com" }; repo.AddOrUpdate(domain); unitOfWork.Commit(); @@ -192,7 +192,7 @@ namespace Umbraco.Tests.Persistence.Repositories domain.DomainName = "blah.com"; domain.RootContent = content2; - domain.DefaultLanguage = lang2; + domain.Language = lang2; repo.AddOrUpdate(domain); unitOfWork.Commit(); @@ -201,7 +201,7 @@ namespace Umbraco.Tests.Persistence.Repositories Assert.AreEqual("blah.com", domain.DomainName); Assert.AreEqual(content2.Id, domain.RootContent.Id); - Assert.AreEqual(lang2.Id, domain.DefaultLanguage.Id); + Assert.AreEqual(lang2.Id, domain.Language.Id); } @@ -227,7 +227,7 @@ namespace Umbraco.Tests.Persistence.Repositories for (int i = 0; i < 10; i++) { - var domain = (IDomain)new UmbracoDomain { RootContent = content, DefaultLanguage = lang, DomainName = "test " + i + ".com" }; + var domain = (IDomain)new UmbracoDomain { RootContent = content, Language = lang, DomainName = "test " + i + ".com" }; repo.AddOrUpdate(domain); unitOfWork.Commit(); } @@ -259,7 +259,7 @@ namespace Umbraco.Tests.Persistence.Repositories var ids = new List(); for (int i = 0; i < 10; i++) { - var domain = (IDomain)new UmbracoDomain { RootContent = content, DefaultLanguage = lang, DomainName = "test " + i + ".com" }; + var domain = (IDomain)new UmbracoDomain { RootContent = content, Language = lang, DomainName = "test " + i + ".com" }; repo.AddOrUpdate(domain); unitOfWork.Commit(); ids.Add(domain.Id); @@ -294,7 +294,7 @@ namespace Umbraco.Tests.Persistence.Repositories var domain = (IDomain)new UmbracoDomain { RootContent = content, - DefaultLanguage = lang, + Language = lang, DomainName = (i%2==0) ? "test " + i + ".com" : ("*" + i) }; repo.AddOrUpdate(domain); @@ -341,7 +341,7 @@ namespace Umbraco.Tests.Persistence.Repositories var domain = (IDomain)new UmbracoDomain { RootContent = (i % 2 == 0) ? contentItems[0] : contentItems[1], - DefaultLanguage = lang, + Language = lang, DomainName = (i % 2 == 0) ? "test " + i + ".com" : ("*" + i) }; repo.AddOrUpdate(domain); @@ -393,7 +393,7 @@ namespace Umbraco.Tests.Persistence.Repositories var domain = (IDomain)new UmbracoDomain { RootContent = (i % 2 == 0) ? contentItems[0] : contentItems[1], - DefaultLanguage = lang, + Language = lang, DomainName = (i % 2 == 0) ? "test " + i + ".com" : ("*" + i) }; repo.AddOrUpdate(domain); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentRequestEngineTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentRequestEngineTests.cs index 25fa7df5f7..ff72ad1d1e 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentRequestEngineTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentRequestEngineTests.cs @@ -16,7 +16,11 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Ctor_Throws_On_Null_PCR() { - Assert.Throws(() => new PublishedContentRequestEngine(null)); + Assert.Throws(() => new PublishedContentRequestEngine( + ServiceContext.DomainService, + ServiceContext.LocalizationService, + ProfilingLogger, + null)); } [Test] @@ -25,6 +29,9 @@ namespace Umbraco.Tests.PublishedContent var routeCtx = GetRoutingContext("/test"); var pcre = new PublishedContentRequestEngine( + ServiceContext.DomainService, + ServiceContext.LocalizationService, + ProfilingLogger, new PublishedContentRequest( routeCtx.UmbracoContext.CleanedUmbracoUrl, routeCtx)); @@ -42,7 +49,11 @@ namespace Umbraco.Tests.PublishedContent pcr.PublishedContent = pc.Object; pcr.Culture = new CultureInfo("en-AU"); pcr.SetRedirect("/hello"); - var pcre = new PublishedContentRequestEngine(pcr); + var pcre = new PublishedContentRequestEngine( + ServiceContext.DomainService, + ServiceContext.LocalizationService, + ProfilingLogger, + pcr); var result = pcre.ConfigureRequest(); Assert.IsFalse(result); @@ -57,7 +68,11 @@ namespace Umbraco.Tests.PublishedContent var pc = GetPublishedContentMock(); pcr.PublishedContent = pc.Object; pcr.Culture = new CultureInfo("en-AU"); - var pcre = new PublishedContentRequestEngine(pcr); + var pcre = new PublishedContentRequestEngine( + ServiceContext.DomainService, + ServiceContext.LocalizationService, + ProfilingLogger, + pcr); pcre.ConfigureRequest(); @@ -74,7 +89,11 @@ namespace Umbraco.Tests.PublishedContent var pc = GetPublishedContentMock(); pcr.Culture = new CultureInfo("en-AU"); pcr.PublishedContent = pc.Object; - var pcre = new PublishedContentRequestEngine(pcr); + var pcre = new PublishedContentRequestEngine( + ServiceContext.DomainService, + ServiceContext.LocalizationService, + ProfilingLogger, + pcr); pcre.ConfigureRequest(); diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs index f3b133a645..71c27f2bee 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs @@ -54,10 +54,12 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache content = content ?? DetermineIdByRoute(umbracoContext, preview, route, hideTopLevelNode.Value); // cache if we have a content and not previewing - if (content != null && !preview) + if (content != null && preview == false) { var domainRootNodeId = route.StartsWith("/") ? -1 : int.Parse(route.Substring(0, route.IndexOf('/'))); - var iscanon = !UnitTesting && !DomainHelper.ExistsDomainInPath(DomainHelper.GetAllDomains(false), content.Path, domainRootNodeId); + var iscanon = + UnitTesting == false + && DomainHelper.ExistsDomainInPath(umbracoContext.Application.Services.DomainService.GetAll(false), content.Path, domainRootNodeId) == false; // and only if this is the canonical url (the one GetUrl would return) if (iscanon) _routesCache.Store(contentId, route); @@ -79,7 +81,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache route = DetermineRouteById(umbracoContext, preview, contentId); // cache if we have a route and not previewing - if (route != null && !preview) + if (route != null && preview == false) _routesCache.Store(contentId, route); return route; @@ -120,12 +122,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache if (node == null) return null; + var domainHelper = new DomainHelper(umbracoContext.Application.Services.DomainService); + // walk up from that node until we hit a node with a domain, // or we reach the content root, collecting urls in the way var pathParts = new List(); var n = node; - var hasDomains = DomainHelper.NodeHasDomains(n.Id); - while (!hasDomains && n != null) // n is null at root + var hasDomains = domainHelper.NodeHasDomains(n.Id); + while (hasDomains == false && n != null) // n is null at root { // get the url var urlName = n.UrlName; @@ -133,11 +137,11 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache // move to parent node n = n.Parent; - hasDomains = n != null && DomainHelper.NodeHasDomains(n.Id); + hasDomains = n != null && domainHelper.NodeHasDomains(n.Id); } // no domain, respect HideTopLevelNodeFromPath for legacy purposes - if (!hasDomains && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath) + if (hasDomains == false && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath) ApplyHideTopLevelNodeFromPath(umbracoContext, node, pathParts); // assemble the route diff --git a/src/Umbraco.Web/Routing/AliasUrlProvider.cs b/src/Umbraco.Web/Routing/AliasUrlProvider.cs index d8846afd60..6629b96c6a 100644 --- a/src/Umbraco.Web/Routing/AliasUrlProvider.cs +++ b/src/Umbraco.Web/Routing/AliasUrlProvider.cs @@ -62,13 +62,15 @@ namespace Umbraco.Web.Routing if (string.IsNullOrWhiteSpace(umbracoUrlName)) return Enumerable.Empty(); + var domainHelper = new DomainHelper(umbracoContext.Application.Services.DomainService); + var n = node; - var domainUris = DomainHelper.DomainsForNode(n.Id, current, false); + var domainUris = domainHelper.DomainsForNode(n.Id, current, false); while (domainUris == null && n != null) // n is null at root { // move to parent node n = n.Parent; - domainUris = n == null ? null : DomainHelper.DomainsForNode(n.Id, current, false); + domainUris = n == null ? null : domainHelper.DomainsForNode(n.Id, current, false); } var path = "/" + umbracoUrlName; diff --git a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs index 41cadbf2f9..13855e80b3 100644 --- a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs @@ -46,11 +46,15 @@ namespace Umbraco.Web.Routing return null; } + var domainHelper = new DomainHelper(umbracoContext.Application.Services.DomainService); + // extract domainUri and path // route is / or / var pos = route.IndexOf('/'); var path = pos == 0 ? route : route.Substring(pos); - var domainUri = pos == 0 ? null : DomainHelper.DomainForNode(int.Parse(route.Substring(0, pos)), current); + var domainUri = pos == 0 + ? null + : domainHelper.DomainForNode(int.Parse(route.Substring(0, pos)), current); // assemble the url from domainUri (maybe null) and path return AssembleUrl(domainUri, path, current, mode).ToString(); @@ -84,11 +88,13 @@ namespace Umbraco.Web.Routing return null; } + var domainHelper = new DomainHelper(umbracoContext.Application.Services.DomainService); + // extract domainUri and path // route is / or / var pos = route.IndexOf('/'); var path = pos == 0 ? route : route.Substring(pos); - var domainUris = pos == 0 ? null : DomainHelper.DomainsForNode(int.Parse(route.Substring(0, pos)), current); + var domainUris = pos == 0 ? null : domainHelper.DomainsForNode(int.Parse(route.Substring(0, pos)), current); // assemble the alternate urls from domainUris (maybe empty) and path return AssembleUrls(domainUris, path).Select(uri => uri.ToString()); diff --git a/src/Umbraco.Web/Routing/DomainAndUri.cs b/src/Umbraco.Web/Routing/DomainAndUri.cs index ec3e52ff11..cef8231375 100644 --- a/src/Umbraco.Web/Routing/DomainAndUri.cs +++ b/src/Umbraco.Web/Routing/DomainAndUri.cs @@ -1,6 +1,8 @@ using System; +using System.ComponentModel; using Umbraco.Core; using umbraco.cms.businesslogic.web; +using Umbraco.Core.Models; namespace Umbraco.Web.Routing { @@ -13,30 +15,47 @@ namespace Umbraco.Web.Routing /// public class DomainAndUri { + /// /// Initializes a new instance of the class with a Domain and a uri scheme. /// /// The domain. /// The uri scheme. - public DomainAndUri(Domain domain, string scheme) + public DomainAndUri(IDomain domain, string scheme) { - Domain = domain; + UmbracoDomain = domain; try { - Uri = new Uri(UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(domain.Name, scheme))); + Uri = new Uri(UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(domain.DomainName, scheme))); } catch (UriFormatException) { - var name = domain.Name.ToCSharpString(); + var name = domain.DomainName.ToCSharpString(); throw new ArgumentException(string.Format("Failed to parse invalid domain: node id={0}, hostname=\"{1}\"." - + " Hostname should be a valid uri.", domain.RootNodeId, name), "domain"); + + " Hostname should be a valid uri.", domain.RootContent.Id, name), "domain"); } } + [Obsolete("This should not be used, use the other contructor specifying the non legacy IDomain instead")] + [EditorBrowsable(EditorBrowsableState.Never)] + public DomainAndUri(Domain domain, string scheme) + : this(domain.DomainEntity, scheme) + { + + } + + + [Obsolete("This should not be used, use the non-legacy property called UmbracoDomain instead")] + [EditorBrowsable(EditorBrowsableState.Never)] + public Domain Domain + { + get { return new Domain(UmbracoDomain); } + } + /// - /// Gets or sets the Umbraco domain. + /// Gets the Umbraco domain. /// - public Domain Domain { get; private set; } + public IDomain UmbracoDomain { get; private set; } /// /// Gets or sets the normalized uri of the domain. @@ -49,7 +68,7 @@ namespace Umbraco.Web.Routing /// A string that represents the current instance. public override string ToString() { - return string.Format("{{ \"{0}\", \"{1}\" }}", Domain.Name, Uri); + return string.Format("{{ \"{0}\", \"{1}\" }}", UmbracoDomain.DomainName, Uri); } } } diff --git a/src/Umbraco.Web/Routing/DomainHelper.cs b/src/Umbraco.Web/Routing/DomainHelper.cs index 1efe0eed0d..ef202b5599 100644 --- a/src/Umbraco.Web/Routing/DomainHelper.cs +++ b/src/Umbraco.Web/Routing/DomainHelper.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using Umbraco.Core; -using umbraco.cms.businesslogic.web; +using Umbraco.Core.Models; +using Umbraco.Core.Services; namespace Umbraco.Web.Routing { @@ -12,33 +12,19 @@ namespace Umbraco.Web.Routing /// public class DomainHelper { - #region Temp. abstract Umbraco's API + private readonly IDomainService _domainService; - /// - /// Gets all domains defined in the system. - /// - /// A value indicating whether to include wildcard domains. - /// All domains defined in the system. - /// This is to temporarily abstract Umbraco's API. - internal static Domain[] GetAllDomains(bool includeWildcards) + [Obsolete("Use the contructor specifying all dependencies instead")] + public DomainHelper() + : this(ApplicationContext.Current.Services.DomainService) { - return Domain.GetDomains(includeWildcards).ToArray(); } - /// - /// Gets all domains defined in the system at a specified node. - /// - /// The node identifier. - /// A value indicating whether to include wildcard domains. - /// All domains defined in the system at the specified node. - /// This is to temporarily abstract Umbraco's API. - internal static Domain[] GetNodeDomains(int nodeId, bool includeWildcards) + public DomainHelper(IDomainService domainService) { - return Domain.GetDomains(includeWildcards).Where(d => d.RootNodeId == nodeId).ToArray(); + _domainService = domainService; } - #endregion - #region Domain for Node /// @@ -49,17 +35,17 @@ namespace Umbraco.Web.Routing /// The domain and its uri, if any, that best matches the specified uri, else null. /// If at least a domain is set on the node then the method returns the domain that /// best matches the specified uri, else it returns null. - internal static DomainAndUri DomainForNode(int nodeId, Uri current) + internal DomainAndUri DomainForNode(int nodeId, Uri current) { // be safe if (nodeId <= 0) return null; // get the domains on that node - var domains = GetNodeDomains(nodeId, false); + var domains = _domainService.GetAssignedDomains(nodeId, false).ToArray(); // none? - if (!domains.Any()) + if (domains.Any() == false) return null; // else filter @@ -77,9 +63,9 @@ namespace Umbraco.Web.Routing /// /// The node identifier. /// True if the node has domains, else false. - internal static bool NodeHasDomains(int nodeId) + internal bool NodeHasDomains(int nodeId) { - return nodeId > 0 && GetNodeDomains(nodeId, false).Any(); + return nodeId > 0 && _domainService.GetAssignedDomains(nodeId, false).Any(); } /// @@ -91,17 +77,17 @@ namespace Umbraco.Web.Routing /// The domains and their uris, that match the specified uri, else null. /// If at least a domain is set on the node then the method returns the domains that /// best match the specified uri, else it returns null. - internal static IEnumerable DomainsForNode(int nodeId, Uri current, bool excludeDefault = true) + internal IEnumerable DomainsForNode(int nodeId, Uri current, bool excludeDefault = true) { // be safe if (nodeId <= 0) return null; // get the domains on that node - var domains = GetNodeDomains(nodeId, false); + var domains = _domainService.GetAssignedDomains(nodeId, false).ToArray(); // none? - if (!domains.Any()) + if (domains.Any() == false) return null; // get the domains and their uris @@ -128,20 +114,20 @@ namespace Umbraco.Web.Routing /// the right one, unless it is null, in which case the method returns null. /// The filter, if any, will be called only with a non-empty argument, and _must_ return something. /// - internal static DomainAndUri DomainForUri(Domain[] domains, Uri current, Func filter = null) + internal static DomainAndUri DomainForUri(IEnumerable domains, Uri current, Func filter = null) { // sanitize the list to have proper uris for comparison (scheme, path end with /) // we need to end with / because example.com/foo cannot match example.com/foobar // 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 => !d.IsWildcard) + .Where(d => d.IsWildcard == false) .Select(SanitizeForBackwardCompatibility) .Select(d => new DomainAndUri(d, scheme)) .OrderByDescending(d => d.Uri.ToString()) .ToArray(); - if (!domainsAndUris.Any()) + if (domainsAndUris.Any() == false) return null; DomainAndUri domainAndUri; @@ -179,11 +165,11 @@ namespace Umbraco.Web.Routing /// The group of domains. /// The uri, or null. /// The domains and their normalized uris, that match the specified uri. - internal static IEnumerable DomainsForUri(Domain[] domains, Uri current) + internal static IEnumerable DomainsForUri(IEnumerable domains, Uri current) { var scheme = current == null ? Uri.UriSchemeHttp : current.Scheme; return domains - .Where(d => !d.IsWildcard) + .Where(d => d.IsWildcard == false) .Select(SanitizeForBackwardCompatibility) .Select(d => new DomainAndUri(d, scheme)) .OrderByDescending(d => d.Uri.ToString()); @@ -202,14 +188,14 @@ namespace Umbraco.Web.Routing /// using hostnames such as "/en" which happened to work pre-4.10 but really make no sense at /// all... and 4.10 throws on them, so here we just try to find a way so 4.11 does not throw. /// But really... no. - private static Domain SanitizeForBackwardCompatibility(Domain domain) + private static IDomain SanitizeForBackwardCompatibility(IDomain domain) { var context = System.Web.HttpContext.Current; - if (context != null && domain.Name.StartsWith("/")) + if (context != null && domain.DomainName.StartsWith("/")) { // turn "/en" into "http://whatever.com/en" so it becomes a parseable uri var authority = context.Request.Url.GetLeftPart(UriPartial.Authority); - domain.Name = authority + domain.Name; + domain.DomainName = authority + domain.DomainName; } return domain; } @@ -222,7 +208,7 @@ namespace Umbraco.Web.Routing /// The current domain root node identifier, or null. /// A value indicating if there is another domain defined down in the path. /// Looks _under_ rootNodeId but not _at_ rootNodeId. - internal static bool ExistsDomainInPath(Domain[] domains, string path, int? rootNodeId) + internal static bool ExistsDomainInPath(IEnumerable domains, string path, int? rootNodeId) { return FindDomainInPath(domains, path, rootNodeId) != null; } @@ -235,7 +221,7 @@ namespace Umbraco.Web.Routing /// The current domain root node identifier, or null. /// The deepest non-wildcard Domain in the path, or null. /// Looks _under_ rootNodeId but not _at_ rootNodeId. - internal static Domain FindDomainInPath(Domain[] domains, string path, int? rootNodeId) + internal static IDomain FindDomainInPath(IEnumerable domains, string path, int? rootNodeId) { var stopNodeId = rootNodeId ?? -1; @@ -243,7 +229,7 @@ namespace Umbraco.Web.Routing .Reverse() .Select(int.Parse) .TakeWhile(id => id != stopNodeId) - .Select(id => domains.FirstOrDefault(d => d.RootNodeId == id && !d.IsWildcard)) + .Select(id => domains.FirstOrDefault(d => d.RootContent.Id == id && d.IsWildcard == false)) .SkipWhile(domain => domain == null) .FirstOrDefault(); } @@ -256,7 +242,7 @@ namespace Umbraco.Web.Routing /// The current domain root node identifier, or null. /// The deepest wildcard Domain in the path, or null. /// Looks _under_ rootNodeId but not _at_ rootNodeId. - internal static Domain FindWildcardDomainInPath(Domain[] domains, string path, int? rootNodeId) + internal static IDomain FindWildcardDomainInPath(IEnumerable domains, string path, int? rootNodeId) { var stopNodeId = rootNodeId ?? -1; @@ -264,7 +250,7 @@ namespace Umbraco.Web.Routing .Reverse() .Select(int.Parse) .TakeWhile(id => id != stopNodeId) - .Select(id => domains.FirstOrDefault(d => d.RootNodeId == id && d.IsWildcard)) + .Select(id => domains.FirstOrDefault(d => d.RootContent.Id == id && d.IsWildcard)) .FirstOrDefault(domain => domain != null); } diff --git a/src/Umbraco.Web/Routing/PublishedContentRequest.cs b/src/Umbraco.Web/Routing/PublishedContentRequest.cs index 6e154793bb..d2639becf6 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequest.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequest.cs @@ -44,7 +44,11 @@ namespace Umbraco.Web.Routing Uri = uri; RoutingContext = routingContext; - _engine = new PublishedContentRequestEngine(this); + _engine = new PublishedContentRequestEngine( + routingContext.UmbracoContext.Application.Services.DomainService, + routingContext.UmbracoContext.Application.Services.LocalizationService, + routingContext.UmbracoContext.Application.ProfilingLogger, + this); RenderingEngine = RenderingEngine.Unknown; } @@ -94,7 +98,7 @@ namespace Umbraco.Web.Routing if (Prepared != null) Prepared(this, EventArgs.Empty); - if (!HasPublishedContent) + if (HasPublishedContent == false) Is404 = true; // safety _readonly = true; @@ -334,10 +338,17 @@ namespace Umbraco.Web.Routing #region Domain and Culture - /// + [Obsolete("Do not use this property, use the non-legacy UmbracoDomain property instead")] + public Domain Domain + { + get { return new Domain(UmbracoDomain); } + } + + //TODO: Should we publicize the setter now that we are using a non-legacy entity?? + /// /// Gets or sets the content request's domain. /// - public Domain Domain { get; internal set; } + public IDomain UmbracoDomain { get; internal set; } /// /// Gets or sets the content request's domain Uri. @@ -350,7 +361,7 @@ namespace Umbraco.Web.Routing /// public bool HasDomain { - get { return Domain != null; } + get { return UmbracoDomain != null; } } private CultureInfo _culture; @@ -432,7 +443,7 @@ namespace Umbraco.Web.Routing /// /// Gets a value indicating whether the content request triggers a redirect (permanent or not). /// - public bool IsRedirect { get { return !string.IsNullOrWhiteSpace(RedirectUrl); } } + public bool IsRedirect { get { return string.IsNullOrWhiteSpace(RedirectUrl) == false; } } /// /// Gets or sets a value indicating whether the redirect is permanent. diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs index fee5b44360..076429f261 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs @@ -14,23 +14,37 @@ using umbraco; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.language; using umbraco.cms.businesslogic.member; +using Umbraco.Core.Services; using RenderingEngine = Umbraco.Core.RenderingEngine; namespace Umbraco.Web.Routing { internal class PublishedContentRequestEngine { - private readonly PublishedContentRequest _pcr; + private readonly IDomainService _domainService; + private readonly ILocalizationService _localizationService; + private readonly ProfilingLogger _profilingLogger; + private readonly PublishedContentRequest _pcr; private readonly RoutingContext _routingContext; - /// - /// Initializes a new instance of the class with a content request. - /// - /// The content request. - public PublishedContentRequestEngine(PublishedContentRequest pcr) + /// + /// Initializes a new instance of the class with a content request. + /// + /// + /// + /// + /// The content request. + public PublishedContentRequestEngine(IDomainService domainService, ILocalizationService localizationService, ProfilingLogger profilingLogger, PublishedContentRequest pcr) { - if (pcr == null) throw new ArgumentException("pcr is null."); - _pcr = pcr; + if (domainService == null) throw new ArgumentNullException("domainService"); + if (localizationService == null) throw new ArgumentNullException("localizationService"); + if (profilingLogger == null) throw new ArgumentNullException("profilingLogger"); + if (pcr == null) throw new ArgumentException("pcr is null."); + + _domainService = domainService; + _localizationService = localizationService; + _profilingLogger = profilingLogger; + _pcr = pcr; _routingContext = pcr.RoutingContext; if (_routingContext == null) throw new ArgumentException("pcr.RoutingContext is null."); @@ -169,7 +183,7 @@ namespace Umbraco.Web.Routing if (_pcr.IsRedirect) return; - if (!_pcr.HasPublishedContent) + if (_pcr.HasPublishedContent == false) { // means the engine could not find a proper document to handle 404 // restore the saved content so we know it exists @@ -177,7 +191,7 @@ namespace Umbraco.Web.Routing return; } - if (!_pcr.HasTemplate) + if (_pcr.HasTemplate == false) { // means we may have a document, but we have no template // at that point there isn't much we can do and there is no point returning @@ -213,7 +227,7 @@ namespace Umbraco.Web.Routing LogHelper.Debug("{0}Uri=\"{1}\"", () => tracePrefix, () => _pcr.Uri); // try to find a domain matching the current request - var domainAndUri = DomainHelper.DomainForUri(DomainHelper.GetAllDomains(false), _pcr.Uri); + var domainAndUri = DomainHelper.DomainForUri(_domainService.GetAll(false), _pcr.Uri); // handle domain if (domainAndUri != null) @@ -221,13 +235,13 @@ namespace Umbraco.Web.Routing // matching an existing domain LogHelper.Debug("{0}Matches domain=\"{1}\", rootId={2}, culture=\"{3}\"", () => tracePrefix, - () => domainAndUri.Domain.Name, - () => domainAndUri.Domain.RootNodeId, - () => domainAndUri.Domain.Language.CultureAlias); + () => domainAndUri.UmbracoDomain.DomainName, + () => domainAndUri.UmbracoDomain.RootContent.Id, + () => domainAndUri.UmbracoDomain.Language.IsoCode); - _pcr.Domain = domainAndUri.Domain; + _pcr.UmbracoDomain = domainAndUri.UmbracoDomain; _pcr.DomainUri = domainAndUri.Uri; - _pcr.Culture = new CultureInfo(domainAndUri.Domain.Language.CultureAlias); + _pcr.Culture = new CultureInfo(domainAndUri.UmbracoDomain.Language.IsoCode); // canonical? not implemented at the moment // if (...) @@ -241,13 +255,13 @@ namespace Umbraco.Web.Routing // not matching any existing domain LogHelper.Debug("{0}Matches no domain", () => tracePrefix); - var defaultLanguage = Language.GetAllAsList().FirstOrDefault(); - _pcr.Culture = defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.CultureAlias); + var defaultLanguage = _localizationService.GetAllLanguages().FirstOrDefault(); + _pcr.Culture = defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.IsoCode); } LogHelper.Debug("{0}Culture=\"{1}\"", () => tracePrefix, () => _pcr.Culture.Name); - return _pcr.Domain != null; + return _pcr.UmbracoDomain != null; } /// @@ -257,19 +271,19 @@ namespace Umbraco.Web.Routing { const string tracePrefix = "HandleWildcardDomains: "; - if (!_pcr.HasPublishedContent) + if (_pcr.HasPublishedContent == false) return; var nodePath = _pcr.PublishedContent.Path; LogHelper.Debug("{0}Path=\"{1}\"", () => tracePrefix, () => nodePath); - var rootNodeId = _pcr.HasDomain ? _pcr.Domain.RootNodeId : (int?)null; - var domain = DomainHelper.FindWildcardDomainInPath(DomainHelper.GetAllDomains(true), nodePath, rootNodeId); + var rootNodeId = _pcr.HasDomain ? _pcr.UmbracoDomain.RootContent.Id : (int?)null; + var domain = DomainHelper.FindWildcardDomainInPath(_domainService.GetAll(true), nodePath, rootNodeId); if (domain != null) { - _pcr.Culture = new CultureInfo(domain.Language.CultureAlias); + _pcr.Culture = new CultureInfo(domain.Language.IsoCode); LogHelper.Debug("{0}Got domain on node {1}, set culture to \"{2}\".", () => tracePrefix, - () => domain.RootNodeId, () => _pcr.Culture.Name); + () => domain.RootContent.Id, () => _pcr.Culture.Name); } else { @@ -308,7 +322,7 @@ namespace Umbraco.Web.Routing internal bool FindTemplateRenderingEngineInDirectory(DirectoryInfo directory, string alias, string[] extensions) { - if (directory == null || !directory.Exists) + if (directory == null || directory.Exists == false) return false; var pos = alias.IndexOf('/'); @@ -374,13 +388,14 @@ namespace Umbraco.Web.Routing // the first successful finder, if any, will set this.PublishedContent, and may also set this.Template // some finders may implement caching - using (DisposableTimer.DebugDuration( - () => string.Format("{0}Begin finders", tracePrefix), - () => string.Format("{0}End finders, {1}", tracePrefix, (_pcr.HasPublishedContent ? "a document was found" : "no document was found")))) + using (_profilingLogger.DebugDuration( + string.Format("{0}Begin finders", tracePrefix), + string.Format("{0}End finders, {1}", tracePrefix, (_pcr.HasPublishedContent ? "a document was found" : "no document was found")))) { if (_routingContext.PublishedContentFinders == null) throw new InvalidOperationException("There is no finder collection."); - _routingContext.PublishedContentFinders.Any(finder => finder.TryFindContent(_pcr)); + + _routingContext.PublishedContentFinders.ForEach(finder => finder.TryFindContent(_pcr)); } // indicate that the published content (if any) we have at the moment is the @@ -407,14 +422,14 @@ namespace Umbraco.Web.Routing LogHelper.Debug("{0}{1}", () => tracePrefix, () => (i == 0 ? "Begin" : "Loop")); // handle not found - if (!_pcr.HasPublishedContent) + if (_pcr.HasPublishedContent == false) { _pcr.Is404 = true; LogHelper.Debug("{0}No document, try last chance lookup", () => tracePrefix); // if it fails then give up, there isn't much more that we can do var lastChance = _routingContext.PublishedContentLastChanceFinder; - if (lastChance == null || !lastChance.TryFindContent(_pcr)) + if (lastChance == null || lastChance.TryFindContent(_pcr) == false) { LogHelper.Debug("{0}Failed to find a document, give up", () => tracePrefix); break; @@ -438,7 +453,7 @@ namespace Umbraco.Web.Routing // got us to nowhere and now we need to run the notFoundLookup again // as long as it's not running out of control ie infinite loop of some sort - } while (!_pcr.HasPublishedContent && i++ < maxLoop); + } while (_pcr.HasPublishedContent == false && i++ < maxLoop); if (i == maxLoop || j == maxLoop) { @@ -467,12 +482,12 @@ namespace Umbraco.Web.Routing bool redirect = false; var internalRedirect = _pcr.PublishedContent.GetPropertyValue(Constants.Conventions.Content.InternalRedirectId); - if (!string.IsNullOrWhiteSpace(internalRedirect)) + if (string.IsNullOrWhiteSpace(internalRedirect) == false) { LogHelper.Debug("{0}Found umbracoInternalRedirectId={1}", () => tracePrefix, () => internalRedirect); int internalRedirectId; - if (!int.TryParse(internalRedirect, out internalRedirectId)) + if (int.TryParse(internalRedirect, out internalRedirectId) == false) internalRedirectId = -1; if (internalRedirectId <= 0) @@ -529,7 +544,7 @@ namespace Umbraco.Web.Routing // a member logs in. Then we can check if the value exists and just use that, otherwise lookup // the member like we are currently doing. - System.Web.Security.MembershipUser user = null; + MembershipUser user = null; try { var provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider(); @@ -540,14 +555,14 @@ namespace Umbraco.Web.Routing LogHelper.Debug("{0}Membership.GetUser returned ArgumentException", () => tracePrefix); } - if (user == null || !Member.IsLoggedOn()) + if (user == null || Member.IsLoggedOn() == false) { LogHelper.Debug("{0}Not logged in, redirect to login page", () => tracePrefix); var loginPageId = Access.GetLoginPage(path); if (loginPageId != _pcr.PublishedContent.Id) _pcr.PublishedContent = _routingContext.UmbracoContext.ContentCache.GetById(loginPageId); } - else if (!Access.HasAccces(_pcr.PublishedContent.Id, user.ProviderUserKey)) + else if (Access.HasAccces(_pcr.PublishedContent.Id, user.ProviderUserKey) == false) { LogHelper.Debug("{0}Current member has not access, redirect to error page", () => tracePrefix); var errorPageId = Access.GetErrorPage(path); @@ -647,7 +662,7 @@ namespace Umbraco.Web.Routing } } - if (!_pcr.HasTemplate) + if (_pcr.HasTemplate == false) { LogHelper.Debug("{0}No template was found.", () => tracePrefix); @@ -672,7 +687,7 @@ namespace Umbraco.Web.Routing /// As per legacy, if the redirect does not work, we just ignore it. private void FollowExternalRedirect() { - if (!_pcr.HasPublishedContent) return; + if (_pcr.HasPublishedContent == false) return; var redirectId = _pcr.PublishedContent.GetPropertyValue(Constants.Conventions.Content.Redirect, -1); var redirectUrl = "#"; diff --git a/src/Umbraco.Web/Routing/SiteDomainHelper.cs b/src/Umbraco.Web/Routing/SiteDomainHelper.cs index d56bd5844b..5170ce1f5a 100644 --- a/src/Umbraco.Web/Routing/SiteDomainHelper.cs +++ b/src/Umbraco.Web/Routing/SiteDomainHelper.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading; using System.Text.RegularExpressions; using Umbraco.Core; -using umbraco.cms.businesslogic.web; namespace Umbraco.Web.Routing { diff --git a/src/Umbraco.Web/WebServices/DomainsApiController.cs b/src/Umbraco.Web/WebServices/DomainsApiController.cs index 02a4269ac5..f6c55309c0 100644 --- a/src/Umbraco.Web/WebServices/DomainsApiController.cs +++ b/src/Umbraco.Web/WebServices/DomainsApiController.cs @@ -4,7 +4,10 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; +using System.Web.Services.Description; using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Web.Routing; using Umbraco.Web.WebApi; //using umbraco.cms.businesslogic.language; using umbraco.BusinessLogic.Actions; @@ -41,9 +44,9 @@ namespace Umbraco.Web.WebServices } model.Valid = true; - var domains = Routing.DomainHelper.GetNodeDomains(model.NodeId, true); - var languages = global::umbraco.cms.businesslogic.language.Language.GetAllAsList().ToArray(); - var language = model.Language > 0 ? languages.FirstOrDefault(l => l.id == model.Language) : null; + var domains = Services.DomainService.GetAssignedDomains(model.NodeId, true).ToArray(); + var languages = Services.LocalizationService.GetAllLanguages().ToArray(); + var language = model.Language > 0 ? languages.FirstOrDefault(l => l.Id == model.Language) : null; // process wildcard @@ -52,28 +55,44 @@ namespace Umbraco.Web.WebServices var wildcard = domains.FirstOrDefault(d => d.IsWildcard); if (wildcard != null) wildcard.Language = language; - else // yet there is a race condition here... - Domain.MakeNew("*" + model.NodeId, model.NodeId, model.Language); + else + { + // yet there is a race condition here... + var newDomain = new UmbracoDomain + { + DomainName = "*" + model.NodeId, + Language = Services.LocalizationService.GetLanguageById(model.Language), + RootContent = Services.ContentService.GetById(model.NodeId) + }; + Services.DomainService.Save(newDomain); + } + } else { var wildcard = domains.FirstOrDefault(d => d.IsWildcard); if (wildcard != null) - wildcard.Delete(); + { + Services.DomainService.Delete(wildcard); + } + } // process domains // delete every (non-wildcard) domain, that exists in the DB yet is not in the model - foreach (var domain in domains.Where(d => d.IsWildcard == false && model.Domains.All(m => m.Name.Equals(d.Name, StringComparison.OrdinalIgnoreCase) == false))) - domain.Delete(); + foreach (var domain in domains.Where(d => d.IsWildcard == false && model.Domains.All(m => m.Name.InvariantEquals(d.DomainName) == false))) + { + Services.DomainService.Delete(domain); + } + var names = new List(); // create or update domains in the model foreach (var domainModel in model.Domains.Where(m => string.IsNullOrWhiteSpace(m.Name) == false)) { - language = languages.FirstOrDefault(l => l.id == domainModel.Lang); + language = languages.FirstOrDefault(l => l.Id == domainModel.Lang); if (language == null) continue; var name = domainModel.Name.ToLowerInvariant(); @@ -83,13 +102,22 @@ namespace Umbraco.Web.WebServices continue; } names.Add(name); - var domain = domains.FirstOrDefault(d => d.Name.Equals(domainModel.Name, StringComparison.OrdinalIgnoreCase)); + var domain = domains.FirstOrDefault(d => d.DomainName.InvariantEquals(domainModel.Name)); if (domain != null) domain.Language = language; - else if (Domain.Exists(domainModel.Name)) + else if (Services.DomainService.Exists(domainModel.Name)) domainModel.Duplicate = true; - else // yet there is a race condition here... - Domain.MakeNew(name, model.NodeId, domainModel.Lang); + else + { + // yet there is a race condition here... + var newDomain = new UmbracoDomain + { + DomainName = name, + Language = Services.LocalizationService.GetLanguageById(domainModel.Lang), + RootContent = Services.ContentService.GetById(model.NodeId) + }; + Services.DomainService.Save(newDomain); + } } model.Valid = model.Domains.All(m => m.Duplicate == false); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/AssignDomain2.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/AssignDomain2.aspx.cs index 5fb2a27875..136cc1a27d 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/AssignDomain2.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/AssignDomain2.aspx.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; using System.Linq; +using umbraco.BusinessLogic.Actions; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Web.UI.Pages; @@ -19,7 +20,7 @@ namespace umbraco.dialogs base.OnLoad(e); var nodeId = GetNodeId(); - var node = ApplicationContext.Current.Services.ContentService.GetById(nodeId); + var node = Services.ContentService.GetById(nodeId); if (node == null) { @@ -30,7 +31,7 @@ namespace umbraco.dialogs return; } - if (!UmbracoUser.GetPermissions(node.Path).Contains(BusinessLogic.Actions.ActionAssignDomain.Instance.Letter)) + if (UmbracoUser.GetPermissions(node.Path).Contains(ActionAssignDomain.Instance.Letter) == false) { feedback.Text = ui.Text("assignDomain", "permissionDenied"); pane_language.Visible = false; @@ -43,7 +44,7 @@ namespace umbraco.dialogs pane_domains.Title = ui.Text("assignDomain", "setDomains"); prop_language.Text = ui.Text("assignDomain", "language"); - var nodeDomains = DomainHelper.GetNodeDomains(nodeId, true); + var nodeDomains = Services.DomainService.GetAssignedDomains(nodeId, true).ToArray(); var wildcard = nodeDomains.FirstOrDefault(d => d.IsWildcard); var sb = new StringBuilder(); @@ -53,12 +54,12 @@ namespace umbraco.dialogs sb.AppendFormat("{0}{{ \"Id\": {1}, \"Code\": \"{2}\" }}", (i++ == 0 ? "" : ","), language.Id, language.IsoCode); sb.Append("]\r\n"); - sb.AppendFormat(",language: {0}", wildcard == null ? "undefined" : wildcard.Language.id.ToString()); + sb.AppendFormat(",language: {0}", wildcard == null ? "undefined" : wildcard.Language.Id.ToString()); sb.Append(",domains: ["); i = 0; - foreach (var domain in nodeDomains.Where(d => !d.IsWildcard)) - sb.AppendFormat("{0}{{ \"Name\": \"{1}\", \"Lang\": \"{2}\" }}", (i++ == 0 ? "" :","), domain.Name, domain.Language.id); + foreach (var domain in nodeDomains.Where(d => d.IsWildcard == false)) + sb.AppendFormat("{0}{{ \"Name\": \"{1}\", \"Lang\": \"{2}\" }}", (i++ == 0 ? "" :","), domain.DomainName, domain.Language.Id); sb.Append("]\r\n"); data.Text = sb.ToString(); @@ -67,7 +68,7 @@ namespace umbraco.dialogs protected int GetNodeId() { int nodeId; - if (!int.TryParse(Request.QueryString["id"], out nodeId)) + if (int.TryParse(Request.QueryString["id"], out nodeId) == false) nodeId = -1; return nodeId; } diff --git a/src/umbraco.cms/businesslogic/web/Domain.cs b/src/umbraco.cms/businesslogic/web/Domain.cs index 17df5fd194..3c1f8381bc 100644 --- a/src/umbraco.cms/businesslogic/web/Domain.cs +++ b/src/umbraco.cms/businesslogic/web/Domain.cs @@ -64,8 +64,8 @@ namespace umbraco.cms.businesslogic.web public Language Language { - get { return new Language(DomainEntity.DefaultLanguage); } - set { DomainEntity.DefaultLanguage = value.LanguageEntity; } + get { return new Language(DomainEntity.Language); } + set { DomainEntity.Language = value.LanguageEntity; } } public int RootNodeId @@ -168,7 +168,7 @@ namespace umbraco.cms.businesslogic.web { DomainName = DomainName, RootContent = content, - DefaultLanguage = lang + Language = lang }; ApplicationContext.Current.Services.DomainService.Save(domain);