diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs index 00dbefa02c..c8b2e3325c 100644 --- a/src/Umbraco.Core/ApplicationContext.cs +++ b/src/Umbraco.Core/ApplicationContext.cs @@ -323,8 +323,8 @@ namespace Umbraco.Core /// internal ServerRole GetCurrentServerRole() { - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; - return registrar?.GetCurrentServerRole() ?? ServerRole.Unknown; + var registrar = ServerRegistrarResolver.Current.Registrar; + return registrar.GetCurrentServerRole(); } /// diff --git a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs index d0a4c53db7..7980f2936b 100644 --- a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs +++ b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs @@ -114,8 +114,8 @@ namespace Umbraco.Core.Sync // - contain a scheme // - end or not with a slash, it will be taken care of // eg "http://www.mysite.com/umbraco" - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; - url = registrar == null ? null : registrar.GetCurrentServerUmbracoApplicationUrl(); + var registrar = ServerRegistrarResolver.Current.Registrar; + url = registrar.GetCurrentServerUmbracoApplicationUrl(); if (url.IsNullOrWhiteSpace() == false) { appContext._umbracoApplicationUrl = url.TrimEnd('/'); diff --git a/src/Umbraco.Core/Sync/ConfigServerRegistrar.cs b/src/Umbraco.Core/Sync/ConfigServerRegistrar.cs index de93134826..30a1082f1e 100644 --- a/src/Umbraco.Core/Sync/ConfigServerRegistrar.cs +++ b/src/Umbraco.Core/Sync/ConfigServerRegistrar.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Sync /// Provides server registrations to the distributed cache by reading the legacy Xml configuration /// in umbracoSettings to get the list of (manually) configured server nodes. /// - internal class ConfigServerRegistrar : IServerRegistrar2 + internal class ConfigServerRegistrar : IServerRegistrar { private readonly List _addresses; private readonly ServerRole _serverRole; diff --git a/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs b/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs index 666e2105db..111f1b0c9f 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Sync /// /// A registrar that stores registered server nodes in the database. /// - public sealed class DatabaseServerRegistrar : IServerRegistrar2 + public sealed class DatabaseServerRegistrar : IServerRegistrar { private readonly Lazy _registrationService; diff --git a/src/Umbraco.Core/Sync/IServerRegistrar.cs b/src/Umbraco.Core/Sync/IServerRegistrar.cs index 821f42ffbf..802cf8ecaf 100644 --- a/src/Umbraco.Core/Sync/IServerRegistrar.cs +++ b/src/Umbraco.Core/Sync/IServerRegistrar.cs @@ -5,12 +5,25 @@ namespace Umbraco.Core.Sync /// /// Provides server registrations to the distributed cache. /// - /// You should implement IServerRegistrar2 instead. public interface IServerRegistrar { /// /// Gets the server registrations. /// IEnumerable Registrations { get; } + + /// + /// Gets the role of the current server in the application environment. + /// + ServerRole GetCurrentServerRole(); + + /// + /// Gets the current umbraco application url. + /// + /// + /// If the registrar does not provide the umbraco application url, should return null. + /// Must return null, or a url that ends with SystemDirectories.Umbraco, and contains a scheme, eg "http://www.mysite.com/umbraco". + /// + string GetCurrentServerUmbracoApplicationUrl(); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Sync/IServerRegistrar2.cs b/src/Umbraco.Core/Sync/IServerRegistrar2.cs deleted file mode 100644 index 4eb9743ccc..0000000000 --- a/src/Umbraco.Core/Sync/IServerRegistrar2.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Umbraco.Core.Sync -{ - /// - /// Provides server registrations to the distributed cache. - /// - /// This interface exists because IServerRegistrar could not be modified - /// for backward compatibility reasons - but IServerRegistrar is broken because it - /// does not support server role management. So ppl should really implement - /// IServerRegistrar2, and the two interfaces will get merged in v8. - public interface IServerRegistrar2 : IServerRegistrar - { - /// - /// Gets the role of the current server in the application environment. - /// - ServerRole GetCurrentServerRole(); - - /// - /// Gets the current umbraco application url. - /// - /// - /// If the registrar does not provide the umbraco application url, should return null. - /// Must return null, or a url that ends with SystemDirectories.Umbraco, and contains a scheme, eg "http://www.mysite.com/umbraco". - /// - string GetCurrentServerUmbracoApplicationUrl(); - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 38f34e690d..8224fb7f18 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -1228,7 +1228,6 @@ - diff --git a/src/Umbraco.Tests/ApplicationUrlHelperTests.cs b/src/Umbraco.Tests/ApplicationUrlHelperTests.cs index 4b222f6607..608f0cc2cd 100644 --- a/src/Umbraco.Tests/ApplicationUrlHelperTests.cs +++ b/src/Umbraco.Tests/ApplicationUrlHelperTests.cs @@ -121,7 +121,7 @@ namespace Umbraco.Tests Assert.AreEqual("http://server1.com:80/umbraco", appCtx._umbracoApplicationUrl); - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; + var registrar = ServerRegistrarResolver.Current.Registrar; var role = registrar.GetCurrentServerRole(); Assert.AreEqual(ServerRole.Master, role); } @@ -152,7 +152,7 @@ namespace Umbraco.Tests Assert.AreEqual("http://server1.com:80/umbraco", appCtx._umbracoApplicationUrl); - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; + var registrar = ServerRegistrarResolver.Current.Registrar; var role = registrar.GetCurrentServerRole(); Assert.AreEqual(ServerRole.Slave, role); } @@ -183,7 +183,7 @@ namespace Umbraco.Tests Assert.IsNull(appCtx._umbracoApplicationUrl); - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; + var registrar = ServerRegistrarResolver.Current.Registrar; var role = registrar.GetCurrentServerRole(); Assert.AreEqual(ServerRole.Single, role); } @@ -200,7 +200,7 @@ namespace Umbraco.Tests Initialize(settings); - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; + var registrar = ServerRegistrarResolver.Current.Registrar; var role = registrar.GetCurrentServerRole(); Assert.AreEqual(ServerRole.Single, role); } @@ -217,7 +217,7 @@ namespace Umbraco.Tests Initialize(settings); - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; + var registrar = ServerRegistrarResolver.Current.Registrar; var role = registrar.GetCurrentServerRole(); Assert.AreEqual(ServerRole.Unknown, role); } @@ -237,7 +237,7 @@ namespace Umbraco.Tests Initialize(settings); - var registrar = ServerRegistrarResolver.Current.Registrar as IServerRegistrar2; + var registrar = ServerRegistrarResolver.Current.Registrar; var role = registrar.GetCurrentServerRole(); Assert.AreEqual(ServerRole.Slave, role); } diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index 483dfad7ed..35c339c229 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -185,15 +185,19 @@ namespace Umbraco.Tests.Cache.DistributedCache internal class TestServerRegistrar : IServerRegistrar { - public IEnumerable Registrations + public IEnumerable Registrations => new List { - get - { - return new List() - { - new TestServerAddress("localhost") - }; - } + new TestServerAddress("localhost") + }; + + public ServerRole GetCurrentServerRole() + { + throw new NotImplementedException(); + } + + public string GetCurrentServerUmbracoApplicationUrl() + { + throw new NotImplementedException(); } }