diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/DistributedCallElement.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/DistributedCallElement.cs deleted file mode 100644 index af035d2e0e..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/DistributedCallElement.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class DistributedCallElement : ConfigurationElement, IDistributedCallSection - { - [ConfigurationProperty("enable", DefaultValue = false)] - internal bool Enabled - { - get { return (bool)base["enable"]; } - } - - [ConfigurationProperty("user")] - internal InnerTextConfigurationElement UserId - { - get - { - return new OptionalInnerTextConfigurationElement( - (InnerTextConfigurationElement)this["user"], - //set the default - 0); - } - } - - [ConfigurationCollection(typeof(ServerCollection), AddItemName = "server")] - [ConfigurationProperty("servers", IsDefaultCollection = true)] - internal ServerCollection Servers - { - get { return (ServerCollection)base["servers"]; } - } - - bool IDistributedCallSection.Enabled - { - get { return Enabled; } - } - - int IDistributedCallSection.UserId - { - get { return UserId; } - } - - IEnumerable IDistributedCallSection.Servers - { - get { return Servers; } - } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IDistributedCallSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IDistributedCallSection.cs deleted file mode 100644 index 96f695c8c7..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IDistributedCallSection.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IDistributedCallSection : IUmbracoConfigurationSection - { - bool Enabled { get; } - - int UserId { get; } - - IEnumerable Servers { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IServer.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IServer.cs deleted file mode 100644 index 26b1db056e..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IServer.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - public interface IServer - { - string ForcePortnumber { get; } - string ForceProtocol { get; } - string ServerAddress { get; } - - string AppId { get; } - string ServerName { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IUmbracoSettingsSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IUmbracoSettingsSection.cs index 1776f1cbf2..09cc698756 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IUmbracoSettingsSection.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/IUmbracoSettingsSection.cs @@ -19,8 +19,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings IScheduledTasksSection ScheduledTasks { get; } - IDistributedCallSection DistributedCall { get; } - IProvidersSection Providers { get; } IWebRoutingSection WebRouting { get; } diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ServerCollection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/ServerCollection.cs deleted file mode 100644 index dfaa5c5247..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ServerCollection.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; -using System.Configuration; - -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ServerCollection : ConfigurationElementCollection, IEnumerable - { - protected override ConfigurationElement CreateNewElement() - { - return new ServerElement(); - } - - protected override object GetElementKey(ConfigurationElement element) - { - return ((ServerElement)element).Value; - } - - IEnumerator IEnumerable.GetEnumerator() - { - for (var i = 0; i < Count; i++) - { - yield return BaseGet(i) as IServer; - } - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ServerElement.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/ServerElement.cs deleted file mode 100644 index 30c836bc07..0000000000 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ServerElement.cs +++ /dev/null @@ -1,49 +0,0 @@ -namespace Umbraco.Core.Configuration.UmbracoSettings -{ - internal class ServerElement : InnerTextConfigurationElement, IServer - { - public string ForcePortnumber - { - get - { - return RawXml.Attribute("forcePortnumber") == null - ? null - : RawXml.Attribute("forcePortnumber").Value; - } - } - - public string ForceProtocol - { - get - { - return RawXml.Attribute("forceProtocol") == null - ? null - : RawXml.Attribute("forceProtocol").Value; - } - } - - string IServer.ServerAddress - { - get { return Value; } - } - - public string AppId - { - get - { - return RawXml.Attribute("appId") == null - ? null - : RawXml.Attribute("appId").Value; - } - } - public string ServerName - { - get - { - return RawXml.Attribute("serverName") == null - ? null - : RawXml.Attribute("serverName").Value; - } - } - } -} diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs index 3b76a43c39..7a08ec3b18 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -50,13 +50,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings get { return (ScheduledTasksElement)this["scheduledTasks"]; } } - [ConfigurationProperty("distributedCall")] - internal DistributedCallElement DistributedCall - { - get { return (DistributedCallElement)this["distributedCall"]; } - } - - [ConfigurationProperty("providers")] internal ProvidersElement Providers { @@ -103,12 +96,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { get { return ScheduledTasks; } } - - IDistributedCallSection IUmbracoSettingsSection.DistributedCall - { - get { return DistributedCall; } - } - + IProvidersSection IUmbracoSettingsSection.Providers { get { return Providers; } diff --git a/src/Umbraco.Core/IO/FileSystems.cs b/src/Umbraco.Core/IO/FileSystems.cs index 2366bde7e2..33989122b8 100644 --- a/src/Umbraco.Core/IO/FileSystems.cs +++ b/src/Umbraco.Core/IO/FileSystems.cs @@ -354,7 +354,7 @@ namespace Umbraco.Core.IO if (Volatile.Read(ref _wkfsInitialized) == false) EnsureWellKnownFileSystems(); var typed = _wrappers.ToArray(); - var wrappers = new ShadowWrapper[typed.Length + 7]; + var wrappers = new ShadowWrapper[typed.Length + 6]; var i = 0; while (i < typed.Length) wrappers[i] = typed[i++]; wrappers[i++] = _macroPartialFileSystem; diff --git a/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs b/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs index fbcc9a74cc..a90d5b5b4c 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs @@ -71,12 +71,9 @@ namespace Umbraco.Core.Runtime composition.Container.RegisterSingleton(); composition.Container.RegisterSingleton(); - // register a server registrar, by default it's the db registrar unless the dev - // has the legacy dist calls enabled - fixme - should obsolete the legacy thing + // register a server registrar, by default it's the db registrar composition.Container.RegisterSingleton(f => { - if (UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled) - return new ConfigServerRegistrar(f.GetInstance(), f.GetInstance(), f.GetInstance()); if ("true".InvariantEquals(ConfigurationManager.AppSettings["umbracoDisableElectionForSingleServer"])) return new SingleServerRegistrar(f.GetInstance()); return new DatabaseServerRegistrar( diff --git a/src/Umbraco.Core/RuntimeState.cs b/src/Umbraco.Core/RuntimeState.cs index a1401e035a..53a474cef7 100644 --- a/src/Umbraco.Core/RuntimeState.cs +++ b/src/Umbraco.Core/RuntimeState.cs @@ -19,6 +19,8 @@ namespace Umbraco.Core private readonly ILogger _logger; private readonly Lazy _serverRegistrar; private readonly Lazy _mainDom; + private readonly IUmbracoSettingsSection _settings; + private readonly IGlobalSettings _globalSettings; private readonly HashSet _applicationUrls = new HashSet(); private RuntimeLevel _level; @@ -28,11 +30,13 @@ namespace Umbraco.Core /// A logger. /// A (lazy) server registrar. /// A (lazy) MainDom. - public RuntimeState(ILogger logger, Lazy serverRegistrar, Lazy mainDom) + public RuntimeState(ILogger logger, Lazy serverRegistrar, Lazy mainDom, IUmbracoSettingsSection settings, IGlobalSettings globalSettings) { _logger = logger; _serverRegistrar = serverRegistrar; _mainDom = mainDom; + _settings = settings; + _globalSettings = globalSettings; } private IServerRegistrar ServerRegistrar => _serverRegistrar.Value; @@ -103,15 +107,13 @@ namespace Umbraco.Core /// /// Ensures that the property has a value. /// - /// /// - /// - internal void EnsureApplicationUrl(IUmbracoSettingsSection settings, IGlobalSettings globalSettings, HttpRequestBase request = null) + internal void EnsureApplicationUrl(HttpRequestBase request = null) { // see U4-10626 - in some cases we want to reset the application url // (this is a simplified version of what was in 7.x) // note: should this be optional? is it expensive? - var url = request == null ? null : ApplicationUrlHelper.GetApplicationUrlFromCurrentRequest(request, globalSettings); + var url = request == null ? null : ApplicationUrlHelper.GetApplicationUrlFromCurrentRequest(request, _globalSettings); var change = url != null && !_applicationUrls.Contains(url); if (change) { @@ -120,7 +122,7 @@ namespace Umbraco.Core } if (ApplicationUrl != null && !change) return; - ApplicationUrl = new Uri(ApplicationUrlHelper.GetApplicationUrl(_logger, globalSettings, settings, request)); + ApplicationUrl = new Uri(ApplicationUrlHelper.GetApplicationUrl(_logger, _globalSettings, _settings, ServerRegistrar, request)); } private readonly ManualResetEventSlim _runLevel = new ManualResetEventSlim(false); diff --git a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs index 691a325eaa..4628271625 100644 --- a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs +++ b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs @@ -29,9 +29,9 @@ namespace Umbraco.Core.Sync // FIXME need another way to do it, eg an interface, injected! public static Func ApplicationUrlProvider { get; set; } - internal static string GetApplicationUrl(ILogger logger, IGlobalSettings globalSettings, IUmbracoSettingsSection settings, HttpRequestBase request = null) + internal static string GetApplicationUrl(ILogger logger, IGlobalSettings globalSettings, IUmbracoSettingsSection settings, IServerRegistrar serverRegistrar, HttpRequestBase request = null) { - var umbracoApplicationUrl = TryGetApplicationUrl(settings, logger, globalSettings); + var umbracoApplicationUrl = TryGetApplicationUrl(settings, logger, globalSettings, serverRegistrar); if (umbracoApplicationUrl != null) return umbracoApplicationUrl; @@ -50,7 +50,7 @@ namespace Umbraco.Core.Sync return umbracoApplicationUrl; } - internal static string TryGetApplicationUrl(IUmbracoSettingsSection settings, ILogger logger, IGlobalSettings globalSettings) + internal static string TryGetApplicationUrl(IUmbracoSettingsSection settings, ILogger logger, IGlobalSettings globalSettings, IServerRegistrar serverRegistrar) { // try umbracoSettings:settings/web.routing/@umbracoApplicationUrl // which is assumed to: @@ -88,7 +88,7 @@ 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" - url = Current.ServerRegistrar.GetCurrentServerUmbracoApplicationUrl(); + url = serverRegistrar.GetCurrentServerUmbracoApplicationUrl(); if (url.IsNullOrWhiteSpace() == false) { var umbracoApplicationUrl = url.TrimEnd('/'); diff --git a/src/Umbraco.Core/Sync/BatchedWebServiceServerMessenger.cs b/src/Umbraco.Core/Sync/BatchedWebServiceServerMessenger.cs deleted file mode 100644 index a0357111d1..0000000000 --- a/src/Umbraco.Core/Sync/BatchedWebServiceServerMessenger.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Umbraco.Core.Cache; - -namespace Umbraco.Core.Sync -{ - /// - /// An that works by messaging servers via web services. - /// - /// - /// Abstract because it needs to be inherited by a class that will - /// - implement ProcessBatch() - /// - trigger FlushBatch() when appropriate - /// - internal abstract class BatchedWebServiceServerMessenger : WebServiceServerMessenger - { - internal BatchedWebServiceServerMessenger() - { - } - - internal BatchedWebServiceServerMessenger(string login, string password) - : base(login, password) - { - } - - internal BatchedWebServiceServerMessenger(string login, string password, bool useDistributedCalls) - : base(login, password, useDistributedCalls) - { - } - - protected BatchedWebServiceServerMessenger(Func> getLoginAndPassword) - : base(getLoginAndPassword) - { - } - - protected abstract ICollection GetBatch(bool ensureHttpContext); - - protected void FlushBatch() - { - var batch = GetBatch(false); - if (batch == null) return; - - var batcha = batch.ToArray(); - batch.Clear(); - if (batcha.Length == 0) return; - - ProcessBatch(batcha); - } - - // needs to be overriden to actually do something - protected abstract void ProcessBatch(RefreshInstructionEnvelope[] batch); - - protected override void DeliverRemote(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) - { - var idsA = ids == null ? null : ids.ToArray(); - - Type arrayType; - if (GetArrayType(idsA, out arrayType) == false) - throw new ArgumentException("All items must be of the same type, either int or Guid.", "ids"); - - BatchMessage(servers, refresher, messageType, idsA, arrayType, json); - } - - protected void BatchMessage( - IEnumerable servers, - ICacheRefresher refresher, - MessageType messageType, - IEnumerable ids = null, - Type idType = null, - string json = null) - { - var batch = GetBatch(true); - if (batch == null) - throw new Exception("Failed to get a batch."); - - batch.Add(new RefreshInstructionEnvelope(servers, refresher, - RefreshInstruction.GetInstructions(refresher, messageType, ids, idType, json))); - } - } -} diff --git a/src/Umbraco.Core/Sync/ConfigServerAddress.cs b/src/Umbraco.Core/Sync/ConfigServerAddress.cs deleted file mode 100644 index be00544344..0000000000 --- a/src/Umbraco.Core/Sync/ConfigServerAddress.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.IO; - -namespace Umbraco.Core.Sync -{ - /// - /// Provides the address of a server based on the Xml configuration. - /// - internal class ConfigServerAddress : IServerAddress - { - public ConfigServerAddress(IServer n, IGlobalSettings globalSettings) - { - var webServicesUrl = IOHelper.ResolveUrl(SystemDirectories.WebServices); - - var protocol = globalSettings.UseHttps ? "https" : "http"; - if (n.ForceProtocol.IsNullOrWhiteSpace() == false) - protocol = n.ForceProtocol; - var domain = n.ServerAddress; - if (n.ForcePortnumber.IsNullOrWhiteSpace() == false) - domain += $":{n.ForcePortnumber}"; - ServerAddress = $"{protocol}://{domain}{webServicesUrl}/cacheRefresher.asmx"; - } - - public string ServerAddress { get; private set; } - - public override string ToString() - { - return ServerAddress; - } - } -} diff --git a/src/Umbraco.Core/Sync/ConfigServerRegistrar.cs b/src/Umbraco.Core/Sync/ConfigServerRegistrar.cs deleted file mode 100644 index 83e085b324..0000000000 --- a/src/Umbraco.Core/Sync/ConfigServerRegistrar.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Web; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.IO; -using Umbraco.Core.Logging; - -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 : IServerRegistrar - { - private readonly List _addresses; - private readonly ServerRole _serverRole; - private readonly string _umbracoApplicationUrl; - - public ConfigServerRegistrar(IUmbracoSettingsSection settings, ILogger logger, IGlobalSettings globalSettings) - : this(settings.DistributedCall, logger, globalSettings) - { } - - // for tests - internal ConfigServerRegistrar(IDistributedCallSection settings, ILogger logger, IGlobalSettings globalSettings) - { - if (settings.Enabled == false) - { - _addresses = new List(); - _serverRole = ServerRole.Single; - _umbracoApplicationUrl = null; // unspecified - return; - } - - var serversA = settings.Servers.ToArray(); - - _addresses = serversA - .Select(x => new ConfigServerAddress(x, globalSettings)) - .Cast() - .ToList(); - - if (serversA.Length == 0) - { - _serverRole = ServerRole.Unknown; // config error, actually - logger.Debug("Server Role Unknown: DistributedCalls are enabled but no servers are listed."); - } - else - { - var master = serversA[0]; // first one is master - var appId = master.AppId; - var serverName = master.ServerName; - - if (appId.IsNullOrWhiteSpace() && serverName.IsNullOrWhiteSpace()) - { - _serverRole = ServerRole.Unknown; // config error, actually - logger.Debug("Server Role Unknown: Server Name or AppId missing from Server configuration in DistributedCalls settings."); - } - else - { - _serverRole = IsCurrentServer(appId, serverName) - ? ServerRole.Master - : ServerRole.Slave; - } - } - - var currentServer = serversA.FirstOrDefault(x => IsCurrentServer(x.AppId, x.ServerName)); - if (currentServer != null) - { - // match, use the configured url - // ReSharper disable once UseStringInterpolation - _umbracoApplicationUrl = string.Format("{0}://{1}:{2}/{3}", - currentServer.ForceProtocol.IsNullOrWhiteSpace() ? "http" : currentServer.ForceProtocol, - currentServer.ServerAddress, - currentServer.ForcePortnumber.IsNullOrWhiteSpace() ? "80" : currentServer.ForcePortnumber, - IOHelper.ResolveUrl(SystemDirectories.Umbraco).TrimStart('/')); - } - } - - private static bool IsCurrentServer(string appId, string serverName) - { - // match by appId or computer name - return (appId.IsNullOrWhiteSpace() == false && appId.Trim().InvariantEquals(HttpRuntime.AppDomainAppId)) - || (serverName.IsNullOrWhiteSpace() == false && serverName.Trim().InvariantEquals(NetworkHelper.MachineName)); - } - - public IEnumerable Registrations => _addresses; - - public ServerRole GetCurrentServerRole() => _serverRole; - - public string GetCurrentServerUmbracoApplicationUrl() => _umbracoApplicationUrl; - } -} diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index 0fcb7036f7..a1b89e58bc 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -71,7 +71,7 @@ namespace Umbraco.Core.Sync #region Messenger - protected override bool RequiresDistributed(IEnumerable servers, ICacheRefresher refresher, MessageType dispatchType) + protected override bool RequiresDistributed(ICacheRefresher refresher, MessageType dispatchType) { // we don't care if there's servers listed or not, // if distributed call is enabled we will make the call @@ -79,7 +79,6 @@ namespace Umbraco.Core.Sync } protected override void DeliverRemote( - IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, diff --git a/src/Umbraco.Core/Sync/DatabaseServerRegistrarOptions.cs b/src/Umbraco.Core/Sync/DatabaseServerRegistrarOptions.cs index 6f019e7104..58b66ca8e6 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerRegistrarOptions.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerRegistrarOptions.cs @@ -14,14 +14,9 @@ namespace Umbraco.Core.Sync public DatabaseServerRegistrarOptions() { StaleServerTimeout = TimeSpan.FromMinutes(2); // 2 minutes - ThrottleSeconds = 30; // 30 seconds RecurringSeconds = 60; // do it every minute } - - [Obsolete("This is no longer used")] - [EditorBrowsable(EditorBrowsableState.Never)] - public int ThrottleSeconds { get; set; } - + /// /// The amount of seconds to wait between calls to the database on the background thread /// diff --git a/src/Umbraco.Core/Sync/IServerMessenger.cs b/src/Umbraco.Core/Sync/IServerMessenger.cs index 1df4ce9710..b3e5ef862d 100644 --- a/src/Umbraco.Core/Sync/IServerMessenger.cs +++ b/src/Umbraco.Core/Sync/IServerMessenger.cs @@ -13,78 +13,69 @@ namespace Umbraco.Core.Sync /// /// Notifies the distributed cache, for a specified . /// - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// The notification content. - void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, TPayload[] payload); + void PerformRefresh(ICacheRefresher refresher, TPayload[] payload); /// /// Notifies the distributed cache, for a specified . /// - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// The notification content. - void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, string jsonPayload); + void PerformRefresh(ICacheRefresher refresher, string jsonPayload); /// /// Notifies the distributed cache of specifieds item invalidation, for a specified . /// /// The type of the invalidated items. - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// A function returning the unique identifier of items. /// The invalidated items. - void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, Func getNumericId, params T[] instances); + void PerformRefresh(ICacheRefresher refresher, Func getNumericId, params T[] instances); /// /// Notifies the distributed cache of specifieds item invalidation, for a specified . /// /// The type of the invalidated items. - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// A function returning the unique identifier of items. /// The invalidated items. - void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, Func getGuidId, params T[] instances); + void PerformRefresh(ICacheRefresher refresher, Func getGuidId, params T[] instances); /// /// Notifies all servers of specified items removal, for a specified . /// /// The type of the removed items. - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// A function returning the unique identifier of items. /// The removed items. - void PerformRemove(IEnumerable servers, ICacheRefresher refresher, Func getNumericId, params T[] instances); + void PerformRemove(ICacheRefresher refresher, Func getNumericId, params T[] instances); /// /// Notifies all servers of specified items removal, for a specified . /// - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// The unique identifiers of the removed items. - void PerformRemove(IEnumerable servers, ICacheRefresher refresher, params int[] numericIds); + void PerformRemove(ICacheRefresher refresher, params int[] numericIds); /// /// Notifies all servers of specified items invalidation, for a specified . /// - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// The unique identifiers of the invalidated items. - void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, params int[] numericIds); + void PerformRefresh(ICacheRefresher refresher, params int[] numericIds); /// /// Notifies all servers of specified items invalidation, for a specified . /// - /// The servers that compose the load balanced environment. /// The ICacheRefresher. /// The unique identifiers of the invalidated items. - void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, params Guid[] guidIds); + void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds); /// /// Notifies all servers of a global invalidation for a specified . /// - /// The servers that compose the load balanced environment. /// The ICacheRefresher. - void PerformRefreshAll(IEnumerable servers, ICacheRefresher refresher); + void PerformRefreshAll(ICacheRefresher refresher); } } diff --git a/src/Umbraco.Core/Sync/RefreshInstructionEnvelope.cs b/src/Umbraco.Core/Sync/RefreshInstructionEnvelope.cs index ac51e14a30..9cd442da2d 100644 --- a/src/Umbraco.Core/Sync/RefreshInstructionEnvelope.cs +++ b/src/Umbraco.Core/Sync/RefreshInstructionEnvelope.cs @@ -9,14 +9,12 @@ namespace Umbraco.Core.Sync /// public sealed class RefreshInstructionEnvelope { - public RefreshInstructionEnvelope(IEnumerable servers, ICacheRefresher refresher, IEnumerable instructions) + public RefreshInstructionEnvelope(ICacheRefresher refresher, IEnumerable instructions) { - Servers = servers; Refresher = refresher; Instructions = instructions; } - public IEnumerable Servers { get; set; } public ICacheRefresher Refresher { get; set; } public IEnumerable Instructions { get; set; } } diff --git a/src/Umbraco.Core/Sync/ServerMessengerBase.cs b/src/Umbraco.Core/Sync/ServerMessengerBase.cs index d16c88eca3..68223a40e6 100644 --- a/src/Umbraco.Core/Sync/ServerMessengerBase.cs +++ b/src/Umbraco.Core/Sync/ServerMessengerBase.cs @@ -27,9 +27,9 @@ namespace Umbraco.Core.Sync /// The cache refresher. /// The message type. /// true if distributed calls are required; otherwise, false, all we have is the local server. - protected virtual bool RequiresDistributed(IEnumerable servers, ICacheRefresher refresher, MessageType messageType) + protected virtual bool RequiresDistributed(ICacheRefresher refresher, MessageType messageType) { - return DistributedEnabled && servers.Any(); + return DistributedEnabled; } // ensures that all items in the enumerable are of the same type, either int or Guid. @@ -56,98 +56,97 @@ namespace Umbraco.Core.Sync #region IServerMessenger - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, TPayload[] payload) + public void PerformRefresh(ICacheRefresher refresher, TPayload[] payload) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (payload == null) throw new ArgumentNullException(nameof(payload)); - Deliver(servers, refresher, payload); + Deliver(refresher, payload); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, string jsonPayload) + public void PerformRefresh(ICacheRefresher refresher, string jsonPayload) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (jsonPayload == null) throw new ArgumentNullException(nameof(jsonPayload)); - Deliver(servers, refresher, MessageType.RefreshByJson, json: jsonPayload); + Deliver(refresher, MessageType.RefreshByJson, json: jsonPayload); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, Func getNumericId, params T[] instances) + public void PerformRefresh(ICacheRefresher refresher, Func getNumericId, params T[] instances) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (getNumericId == null) throw new ArgumentNullException(nameof(getNumericId)); if (instances == null || instances.Length == 0) return; Func getId = x => getNumericId(x); - Deliver(servers, refresher, MessageType.RefreshByInstance, getId, instances); + Deliver(refresher, MessageType.RefreshByInstance, getId, instances); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, Func getGuidId, params T[] instances) + public void PerformRefresh(ICacheRefresher refresher, Func getGuidId, params T[] instances) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (getGuidId == null) throw new ArgumentNullException(nameof(getGuidId)); if (instances == null || instances.Length == 0) return; Func getId = x => getGuidId(x); - Deliver(servers, refresher, MessageType.RefreshByInstance, getId, instances); + Deliver(refresher, MessageType.RefreshByInstance, getId, instances); } - public void PerformRemove(IEnumerable servers, ICacheRefresher refresher, Func getNumericId, params T[] instances) + public void PerformRemove(ICacheRefresher refresher, Func getNumericId, params T[] instances) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (getNumericId == null) throw new ArgumentNullException(nameof(getNumericId)); if (instances == null || instances.Length == 0) return; Func getId = x => getNumericId(x); - Deliver(servers, refresher, MessageType.RemoveByInstance, getId, instances); + Deliver(refresher, MessageType.RemoveByInstance, getId, instances); } - public void PerformRemove(IEnumerable servers, ICacheRefresher refresher, params int[] numericIds) + public void PerformRemove(ICacheRefresher refresher, params int[] numericIds) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (numericIds == null || numericIds.Length == 0) return; - Deliver(servers, refresher, MessageType.RemoveById, numericIds.Cast()); + Deliver(refresher, MessageType.RemoveById, numericIds.Cast()); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, params int[] numericIds) + public void PerformRefresh(ICacheRefresher refresher, params int[] numericIds) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (numericIds == null || numericIds.Length == 0) return; - Deliver(servers, refresher, MessageType.RefreshById, numericIds.Cast()); + Deliver(refresher, MessageType.RefreshById, numericIds.Cast()); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, params Guid[] guidIds) + public void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (guidIds == null || guidIds.Length == 0) return; - Deliver(servers, refresher, MessageType.RefreshById, guidIds.Cast()); + Deliver(refresher, MessageType.RefreshById, guidIds.Cast()); } - public void PerformRefreshAll(IEnumerable servers, ICacheRefresher refresher) + public void PerformRefreshAll(ICacheRefresher refresher) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); - Deliver(servers, refresher, MessageType.RefreshAll); + Deliver(refresher, MessageType.RefreshAll); } - //public void PerformNotify(IEnumerable servers, ICacheRefresher refresher, object payload) + //public void PerformNotify(ICacheRefresher refresher, object payload) //{ // if (servers == null) throw new ArgumentNullException("servers"); // if (refresher == null) throw new ArgumentNullException("refresher"); - // Deliver(servers, refresher, payload); + // Deliver(refresher, payload); //} #endregion @@ -283,61 +282,57 @@ namespace Umbraco.Core.Sync // refresher.Notify(payload); //} - protected abstract void DeliverRemote(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null); + protected abstract void DeliverRemote(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null); - //protected abstract void DeliverRemote(IEnumerable servers, ICacheRefresher refresher, object payload); + //protected abstract void DeliverRemote(ICacheRefresher refresher, object payload); - protected virtual void Deliver(IEnumerable servers, ICacheRefresher refresher, TPayload[] payload) + protected virtual void Deliver(ICacheRefresher refresher, TPayload[] payload) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); - var serversA = servers.ToArray(); - // deliver local DeliverLocal(refresher, payload); // distribute? - if (RequiresDistributed(serversA, refresher, MessageType.RefreshByJson) == false) + if (RequiresDistributed(refresher, MessageType.RefreshByJson) == false) return; // deliver remote var json = JsonConvert.SerializeObject(payload); - DeliverRemote(serversA, refresher, MessageType.RefreshByJson, null, json); + DeliverRemote(refresher, MessageType.RefreshByJson, null, json); } - protected virtual void Deliver(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) + protected virtual void Deliver(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); - var serversA = servers.ToArray(); var idsA = ids?.ToArray(); // deliver local DeliverLocal(refresher, messageType, idsA, json); // distribute? - if (RequiresDistributed(serversA, refresher, messageType) == false) + if (RequiresDistributed(refresher, messageType) == false) return; // deliver remote - DeliverRemote(serversA, refresher, messageType, idsA, json); + DeliverRemote(refresher, messageType, idsA, json); } - protected virtual void Deliver(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, Func getId, IEnumerable instances) + protected virtual void Deliver(ICacheRefresher refresher, MessageType messageType, Func getId, IEnumerable instances) { - if (servers == null) throw new ArgumentNullException(nameof(servers)); + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); - var serversA = servers.ToArray(); var instancesA = instances.ToArray(); // deliver local DeliverLocal(refresher, messageType, getId, instancesA); // distribute? - if (RequiresDistributed(serversA, refresher, messageType) == false) + if (RequiresDistributed(refresher, messageType) == false) return; // deliver remote @@ -349,10 +344,10 @@ namespace Umbraco.Core.Sync // convert instances to identifiers var idsA = instancesA.Select(getId).ToArray(); - DeliverRemote(serversA, refresher, messageType, idsA); + DeliverRemote(refresher, messageType, idsA); } - //protected virtual void Deliver(IEnumerable servers, ICacheRefresher refresher, object payload) + //protected virtual void Deliver(ICacheRefresher refresher, object payload) //{ // if (servers == null) throw new ArgumentNullException("servers"); // if (refresher == null) throw new ArgumentNullException("refresher"); diff --git a/src/Umbraco.Core/Sync/WebServiceServerMessenger.cs b/src/Umbraco.Core/Sync/WebServiceServerMessenger.cs deleted file mode 100644 index dff839fe6f..0000000000 --- a/src/Umbraco.Core/Sync/WebServiceServerMessenger.cs +++ /dev/null @@ -1,383 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net; -using System.Threading; -using Newtonsoft.Json; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; -using Umbraco.Core.Cache; -using Umbraco.Core.Composing; - -namespace Umbraco.Core.Sync -{ - /// - /// An that works by messaging servers via web services. - /// - /// - /// this messenger sends ALL instructions to ALL servers, including the local server. - /// the CacheRefresher web service will run ALL instructions, so there may be duplicated, - /// except for "bulk" refresh, where it excludes those coming from the local server - /// - // - // TODO see Message() method: stop sending to local server! - // just need to figure out WebServerUtility permissions issues, if any - // - internal class WebServiceServerMessenger : ServerMessengerBase - { - private readonly Func> _getLoginAndPassword; - private volatile bool _hasLoginAndPassword; - private readonly object _locker = new object(); - - protected string Login { get; private set; } - protected string Password{ get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// Distribution is disabled. - internal WebServiceServerMessenger() - : base(false) - { } - - /// - /// Initializes a new instance of the class with a login and a password. - /// - /// The login. - /// The password. - /// Distribution will be enabled based on the umbraco config setting. - internal WebServiceServerMessenger(string login, string password) - : this(login, password, UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled) - { - } - - /// - /// Initializes a new instance of the class with a login and a password - /// and a value indicating whether distribution is enabled. - /// - /// The login. - /// The password. - /// A value indicating whether distribution is enabled. - internal WebServiceServerMessenger(string login, string password, bool distributedEnabled) - : base(distributedEnabled) - { - if (login == null) throw new ArgumentNullException("login"); - if (password == null) throw new ArgumentNullException("password"); - - Login = login; - Password = password; - } - - /// - /// Initializes a new instance of the with a function providing - /// a login and a password. - /// - /// A function providing a login and a password. - /// Distribution will be enabled based on the umbraco config setting. - public WebServiceServerMessenger(Func> getLoginAndPassword) - : base(false) // value will be overriden by EnsureUserAndPassword - { - _getLoginAndPassword = getLoginAndPassword; - } - - // lazy-get the login, password, and distributed setting - protected void EnsureLoginAndPassword() - { - if (_hasLoginAndPassword || _getLoginAndPassword == null) return; - - lock (_locker) - { - if (_hasLoginAndPassword) return; - _hasLoginAndPassword = true; - - try - { - var result = _getLoginAndPassword(); - if (result == null) - { - Login = null; - Password = null; - DistributedEnabled = false; - } - else - { - Login = result.Item1; - Password = result.Item2; - DistributedEnabled = UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled; - } - } - catch (Exception ex) - { - Current.Logger.Error("Could not resolve username/password delegate, server distribution will be disabled", ex); - Login = null; - Password = null; - DistributedEnabled = false; - } - } - } - - // this exists only for legacy reasons - we should just pass the server identity un-hashed - public static string GetCurrentServerHash() - { - if (SystemUtilities.GetCurrentTrustLevel() != System.Web.AspNetHostingPermissionLevel.Unrestricted) - throw new NotSupportedException("FullTrust ASP.NET permission level is required."); - return GetServerHash(NetworkHelper.MachineName, System.Web.HttpRuntime.AppDomainAppId); - } - - public static string GetServerHash(string machineName, string appDomainAppId) - { - using (var generator = new HashGenerator()) - { - generator.AddString(machineName); - generator.AddString(appDomainAppId); - return generator.GenerateHash(); - } - } - - protected override bool RequiresDistributed(IEnumerable servers, ICacheRefresher refresher, MessageType messageType) - { - EnsureLoginAndPassword(); - return base.RequiresDistributed(servers, refresher, messageType); - } - - protected override void DeliverRemote(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) - { - var idsA = ids == null ? null : ids.ToArray(); - - Type arrayType; - if (GetArrayType(idsA, out arrayType) == false) - throw new ArgumentException("All items must be of the same type, either int or Guid.", "ids"); - - Message(servers, refresher, messageType, idsA, arrayType, json); - } - - protected virtual void Message( - IEnumerable servers, - ICacheRefresher refresher, - MessageType messageType, - IEnumerable ids = null, - Type idArrayType = null, - string jsonPayload = null) - { - Current.Logger.Debug(() => - $"Performing distributed call for {refresher.GetType()}/{messageType} on servers ({string.Join(";", servers.Select(x => x.ToString()))}), ids: {(ids == null ? "" : string.Join(";", ids.Select(x => x.ToString())))}, json: {(jsonPayload ?? "")}"); - - try - { - // NOTE: we are messaging ALL servers including the local server - // at the moment, the web service, - // for bulk (batched) checks the origin and does NOT process the instructions again - // for anything else, processes the instructions again (but we don't use this anymore, batched is the default) - // TODO: see WebServerHelper, could remove local server from the list of servers - - // the default server messenger uses http requests - using (var client = new ServerSyncWebServiceClient()) - { - var asyncResults = new List(); - - LogStartDispatch(); - - // go through each configured node submitting a request asynchronously - // NOTE: 'asynchronously' in this case does not mean that it will continue while we give the page back to the user! - foreach (var n in servers) - { - // set the server address - client.Url = n.ServerAddress; - - // add the returned WaitHandle to the list for later checking - switch (messageType) - { - case MessageType.RefreshByJson: - asyncResults.Add(client.BeginRefreshByJson(refresher.RefresherUniqueId, jsonPayload, Login, Password, null, null)); - break; - - case MessageType.RefreshAll: - asyncResults.Add(client.BeginRefreshAll(refresher.RefresherUniqueId, Login, Password, null, null)); - break; - - case MessageType.RefreshById: - if (idArrayType == null) - throw new InvalidOperationException("Cannot refresh by id if the idArrayType is null."); - - if (idArrayType == typeof(int)) - { - // bulk of ints is supported - var json = JsonConvert.SerializeObject(ids.Cast().ToArray()); - var result = client.BeginRefreshByIds(refresher.RefresherUniqueId, json, Login, Password, null, null); - asyncResults.Add(result); - } - else // must be guids - { - // bulk of guids is not supported, iterate - asyncResults.AddRange(ids.Select(i => - client.BeginRefreshByGuid(refresher.RefresherUniqueId, (Guid)i, Login, Password, null, null))); - } - - break; - case MessageType.RemoveById: - if (idArrayType == null) - throw new InvalidOperationException("Cannot remove by id if the idArrayType is null."); - - // must be ints - asyncResults.AddRange(ids.Select(i => - client.BeginRemoveById(refresher.RefresherUniqueId, (int)i, Login, Password, null, null))); - break; - } - } - - // wait for all requests to complete - var waitHandles = asyncResults.Select(x => x.AsyncWaitHandle); - WaitHandle.WaitAll(waitHandles.ToArray()); - - // handle results - var errorCount = 0; - foreach (var asyncResult in asyncResults) - { - try - { - switch (messageType) - { - case MessageType.RefreshByJson: - client.EndRefreshByJson(asyncResult); - break; - - case MessageType.RefreshAll: - client.EndRefreshAll(asyncResult); - break; - - case MessageType.RefreshById: - if (idArrayType == typeof(int)) - client.EndRefreshById(asyncResult); - else - client.EndRefreshByGuid(asyncResult); - break; - - case MessageType.RemoveById: - client.EndRemoveById(asyncResult); - break; - } - } - catch (WebException ex) - { - LogDispatchNodeError(ex); - errorCount++; - } - catch (Exception ex) - { - LogDispatchNodeError(ex); - errorCount++; - } - } - - LogDispatchBatchResult(errorCount); - } - } - catch (Exception ee) - { - LogDispatchBatchError(ee); - } - } - - protected virtual void Message(IEnumerable envelopes) - { - var envelopesA = envelopes.ToArray(); - var servers = envelopesA.SelectMany(x => x.Servers).Distinct(); - - try - { - // NOTE: we are messaging ALL servers including the local server - // at the moment, the web service, - // for bulk (batched) checks the origin and does NOT process the instructions again - // for anything else, processes the instructions again (but we don't use this anymore, batched is the default) - // TODO: see WebServerHelper, could remove local server from the list of servers - - using (var client = new ServerSyncWebServiceClient()) - { - var asyncResults = new List(); - - LogStartDispatch(); - - // go through each configured node submitting a request asynchronously - // NOTE: 'asynchronously' in this case does not mean that it will continue while we give the page back to the user! - foreach (var server in servers) - { - // set the server address - client.Url = server.ServerAddress; - - var serverInstructions = envelopesA - .Where(x => x.Servers.Contains(server)) - .SelectMany(x => x.Instructions) - .Distinct() // only execute distinct instructions - no sense in running the same one. - .ToArray(); - - asyncResults.Add( - client.BeginBulkRefresh( - serverInstructions, - GetCurrentServerHash(), - Login, Password, null, null)); - } - - // wait for all requests to complete - var waitHandles = asyncResults.Select(x => x.AsyncWaitHandle).ToArray(); - WaitHandle.WaitAll(waitHandles.ToArray()); - - // handle results - var errorCount = 0; - foreach (var asyncResult in asyncResults) - { - try - { - client.EndBulkRefresh(asyncResult); - } - catch (WebException ex) - { - LogDispatchNodeError(ex); - errorCount++; - } - catch (Exception ex) - { - LogDispatchNodeError(ex); - errorCount++; - } - } - LogDispatchBatchResult(errorCount); - } - } - catch (Exception ee) - { - LogDispatchBatchError(ee); - } - } - - #region Logging - - private static void LogDispatchBatchError(Exception ee) - { - Current.Logger.Error("Error refreshing distributed list", ee); - } - - private static void LogDispatchBatchResult(int errorCount) - { - Current.Logger.Debug(string.Format("Distributed server push completed with {0} nodes reporting an error", errorCount == 0 ? "no" : errorCount.ToString(CultureInfo.InvariantCulture))); - } - - private static void LogDispatchNodeError(Exception ex) - { - Current.Logger.Error("Error refreshing a node in the distributed list", ex); - } - - private static void LogDispatchNodeError(WebException ex) - { - string url = (ex.Response != null) ? ex.Response.ResponseUri.ToString() : "invalid url (responseUri null)"; - Current.Logger.Error("Error refreshing a node in the distributed list, URI attempted: " + url, ex); - } - - private static void LogStartDispatch() - { - Current.Logger.Info("Submitting calls to distributed servers"); - } - - #endregion - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 18d51d6507..71bf8880b0 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -251,14 +251,12 @@ - - @@ -270,7 +268,6 @@ - @@ -284,8 +281,6 @@ - - @@ -1447,9 +1442,6 @@ - - - @@ -1464,7 +1456,6 @@ - diff --git a/src/Umbraco.Tests/Cache/CacheRefresherTests.cs b/src/Umbraco.Tests/Cache/CacheRefresherTests.cs deleted file mode 100644 index 8002cb9b4f..0000000000 --- a/src/Umbraco.Tests/Cache/CacheRefresherTests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using NUnit.Framework; -using Umbraco.Core.Sync; - -namespace Umbraco.Tests.Cache -{ - [TestFixture] - public class CacheRefresherTests - { - [TestCase("", "123456", "testmachine", true)] //empty hash will continue - [TestCase("2e6deefea4444a69dbd15a01b4c2749d", "123456", "testmachine", false)] //match, don't continue - [TestCase("2e6deefea4444a69dbd15a01b4c2749d", "12345", "testmachine", true)] // no match, continue - [TestCase("2e6deefea4444a69dbd15a01b4c2749d", "123456", "testmachin", true)] // same - [TestCase("2e6deefea4444a69dbd15a01b4c2749", "123456", "testmachine", true)] // same - public void Continue_Refreshing_For_Request(string hash, string appDomainAppId, string machineName, bool expected) - { - if (expected) - Assert.IsTrue(Continue(hash, WebServiceServerMessenger.GetServerHash(appDomainAppId, machineName))); - else - Assert.IsFalse(Continue(hash, WebServiceServerMessenger.GetServerHash(appDomainAppId, machineName))); - } - - // that's what CacheRefresher.asmx.cs does... - private bool Continue(string hash1, string hash2) - { - if (string.IsNullOrEmpty(hash1)) return true; - return hash1 != hash2; - } - } -} diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index ed28004477..dc67bb532f 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -129,52 +129,52 @@ namespace Umbraco.Tests.Cache.DistributedCache public List PayloadsRefreshed = new List(); public int CountOfFullRefreshes = 0; - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, TPayload[] payload) + public void PerformRefresh(ICacheRefresher refresher, TPayload[] payload) { // doing nothing } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, string jsonPayload) + public void PerformRefresh(ICacheRefresher refresher, string jsonPayload) { PayloadsRefreshed.Add(jsonPayload); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, Func getNumericId, params T[] instances) + public void PerformRefresh(ICacheRefresher refresher, Func getNumericId, params T[] instances) { IntIdsRefreshed.AddRange(instances.Select(getNumericId)); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, Func getGuidId, params T[] instances) + public void PerformRefresh(ICacheRefresher refresher, Func getGuidId, params T[] instances) { GuidIdsRefreshed.AddRange(instances.Select(getGuidId)); } - public void PerformRemove(IEnumerable servers, ICacheRefresher refresher, string jsonPayload) + public void PerformRemove(ICacheRefresher refresher, string jsonPayload) { PayloadsRemoved.Add(jsonPayload); } - public void PerformRemove(IEnumerable servers, ICacheRefresher refresher, Func getNumericId, params T[] instances) + public void PerformRemove(ICacheRefresher refresher, Func getNumericId, params T[] instances) { IntIdsRemoved.AddRange(instances.Select(getNumericId)); } - public void PerformRemove(IEnumerable servers, ICacheRefresher refresher, params int[] numericIds) + public void PerformRemove(ICacheRefresher refresher, params int[] numericIds) { IntIdsRemoved.AddRange(numericIds); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, params int[] numericIds) + public void PerformRefresh(ICacheRefresher refresher, params int[] numericIds) { IntIdsRefreshed.AddRange(numericIds); } - public void PerformRefresh(IEnumerable servers, ICacheRefresher refresher, params Guid[] guidIds) + public void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds) { GuidIdsRefreshed.AddRange(guidIds); } - public void PerformRefreshAll(IEnumerable servers, ICacheRefresher refresher) + public void PerformRefreshAll(ICacheRefresher refresher) { CountOfFullRefreshes++; } diff --git a/src/Umbraco.Tests/Composing/TypeFinderTests.cs b/src/Umbraco.Tests/Composing/TypeFinderTests.cs index c665fc366e..9a0d473db0 100644 --- a/src/Umbraco.Tests/Composing/TypeFinderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeFinderTests.cs @@ -90,7 +90,7 @@ namespace Umbraco.Tests.Composing Assert.AreEqual(0, typesFound.Count()); // 0 classes in _assemblies are marked with [Tree] typesFound = TypeFinder.FindClassesWithAttribute(new[] { typeof (UmbracoContext).Assembly }); - Assert.AreEqual(23, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree] + Assert.AreEqual(22, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree] } private static ProfilingLogger GetTestProfilingLogger() diff --git a/src/Umbraco.Tests/Composing/TypeLoaderTests.cs b/src/Umbraco.Tests/Composing/TypeLoaderTests.cs index 4cdd9687f5..46f024429e 100644 --- a/src/Umbraco.Tests/Composing/TypeLoaderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeLoaderTests.cs @@ -272,14 +272,14 @@ AnotherContentFinder public void Resolves_Actions() { var actions = _typeLoader.GetActions(); - Assert.AreEqual(37, actions.Count()); + Assert.AreEqual(35, actions.Count()); } [Test] public void Resolves_Trees() { var trees = _typeLoader.GetTrees(); - Assert.AreEqual(5, trees.Count()); + Assert.AreEqual(4, trees.Count()); } [Test] diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/DistributedCallElementDefaultTests.cs b/src/Umbraco.Tests/Configurations/UmbracoSettings/DistributedCallElementDefaultTests.cs deleted file mode 100644 index 2c3a843af6..0000000000 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/DistributedCallElementDefaultTests.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Linq; -using NUnit.Framework; - -namespace Umbraco.Tests.Configurations.UmbracoSettings -{ - [TestFixture] - public class DistributedCallElementDefaultTests : DistributedCallElementTests - { - protected override bool TestingDefaults - { - get { return true; } - } - - [Test] - public override void Enabled() - { - Assert.IsTrue(SettingsSection.DistributedCall.Enabled == false); - - } - - [Test] - public override void Servers() - { - Assert.IsTrue(SettingsSection.DistributedCall.Servers.Any() == false); - } - } -} diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/DistributedCallElementTests.cs b/src/Umbraco.Tests/Configurations/UmbracoSettings/DistributedCallElementTests.cs deleted file mode 100644 index c7796a3b0a..0000000000 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/DistributedCallElementTests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Linq; -using NUnit.Framework; - -namespace Umbraco.Tests.Configurations.UmbracoSettings -{ - [TestFixture] - public class DistributedCallElementTests : UmbracoSettingsTests - { - [Test] - public virtual void Enabled() - { - Assert.IsTrue(SettingsSection.DistributedCall.Enabled == true); - - } - [Test] - public void UserId() - { - Assert.IsTrue(SettingsSection.DistributedCall.UserId == 0); - - } - [Test] - public virtual void Servers() - { - Assert.IsTrue(SettingsSection.DistributedCall.Servers.Count() == 2); - Assert.IsTrue(SettingsSection.DistributedCall.Servers.ElementAt(0).ServerAddress == "127.0.0.1"); - Assert.IsTrue(SettingsSection.DistributedCall.Servers.ElementAt(1).ServerAddress == "127.0.0.2"); - Assert.IsTrue(SettingsSection.DistributedCall.Servers.ElementAt(1).ForceProtocol == "https"); - Assert.IsTrue(SettingsSection.DistributedCall.Servers.ElementAt(1).ForcePortnumber == "443"); - } - - } -} diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config index c278a99e95..fc59f62d12 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config @@ -150,14 +150,6 @@ Mvc - - - - cs - vb - - - false true @@ -177,19 +169,6 @@ - - - - - 0 - - - - 127.0.0.1 - 127.0.0.2 - - - diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config index 83b392f8d4..ba10dbca78 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.minimal.config @@ -42,18 +42,12 @@ Mvc - - - - - - diff --git a/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs b/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs index 9f83529d11..123b9c54c2 100644 --- a/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs @@ -123,12 +123,12 @@ namespace Umbraco.Tests.IO var created = _fileSystem.GetCreated("test.txt"); var modified = _fileSystem.GetLastModified("test.txt"); - Assert.AreEqual(DateTime.Today.Year, created.Year); - Assert.AreEqual(DateTime.Today.Month, created.Month); + Assert.AreEqual(DateTime.UtcNow.Year, created.Year); + Assert.AreEqual(DateTime.UtcNow.Month, created.Month); Assert.AreEqual(DateTime.UtcNow.Date, created.Date); - Assert.AreEqual(DateTime.Today.Year, modified.Year); - Assert.AreEqual(DateTime.Today.Month, modified.Month); + Assert.AreEqual(DateTime.UtcNow.Year, modified.Year); + Assert.AreEqual(DateTime.UtcNow.Month, modified.Month); Assert.AreEqual(DateTime.UtcNow.Date, modified.Date); _fileSystem.DeleteFile("test.txt"); diff --git a/src/Umbraco.Tests/Integration/ContentEventsTests.cs b/src/Umbraco.Tests/Integration/ContentEventsTests.cs index c87774ba27..246626f0a8 100644 --- a/src/Umbraco.Tests/Integration/ContentEventsTests.cs +++ b/src/Umbraco.Tests/Integration/ContentEventsTests.cs @@ -14,8 +14,10 @@ using Umbraco.Core.Sync; using Umbraco.Tests.Cache.DistributedCache; using Umbraco.Tests.Services; using Umbraco.Tests.TestHelpers.Entities; +using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Tests.Testing; using Umbraco.Web.Cache; +using static Umbraco.Tests.Cache.DistributedCache.DistributedCacheTests; namespace Umbraco.Tests.Integration { @@ -50,8 +52,8 @@ namespace Umbraco.Tests.Integration { base.Compose(); - Container.Register(_ => new DistributedCacheTests.TestServerRegistrar()); // localhost-only - Container.Register(new PerContainerLifetime()); + Container.Register(_ => new TestServerRegistrar()); // localhost-only + Container.Register(new PerContainerLifetime()); Container.RegisterCollectionBuilder() .Add() @@ -2234,5 +2236,15 @@ namespace Umbraco.Tests.Integration // all content type events #endregion + + public class LocalServerMessenger : ServerMessengerBase + { + public LocalServerMessenger() : base(false) + { } + + protected override void DeliverRemote(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) + { + } + } } } diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index 98d36ca616..a440da483a 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -68,7 +68,6 @@ namespace Umbraco.Tests.Macros Assert.AreEqual(converted.Result, prop.GetValue(ctrl)); } - [TestCase("Xslt", true)] [TestCase("PartialView", true)] [TestCase("UserControl", true)] [TestCase("Unknown", false)] diff --git a/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs b/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs index bb134d7e35..9c0560351b 100644 --- a/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs +++ b/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs @@ -11,25 +11,18 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Sync; using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.Cache.DistributedCache; +using Umbraco.Tests.TestHelpers.Stubs; + namespace Umbraco.Tests.Misc { [TestFixture] public class ApplicationUrlHelperTests { - private IServerRegistrar _registrar; - // note: in tests, read appContext._umbracoApplicationUrl and not the property, // because reading the property does run some code, as long as the field is null. - private void Initialize(IUmbracoSettingsSection settings, IGlobalSettings globalSettings) - { - _registrar = new ConfigServerRegistrar(settings.DistributedCall, Mock.Of(), globalSettings); - var container = new ServiceContainer(); - container.ConfigureUmbracoCore(); - container.Register(_ => _registrar); - } - [TearDown] public void Reset() { @@ -39,18 +32,42 @@ namespace Umbraco.Tests.Misc [Test] public void NoApplicationUrlByDefault() { - var state = new RuntimeState(Mock.Of(), new Lazy(Mock.Of), new Lazy(Mock.Of)); + var state = new RuntimeState(Mock.Of(), new Lazy(Mock.Of), new Lazy(Mock.Of), Mock.Of(), Mock.Of()); Assert.IsNull(state.ApplicationUrl); } + [Test] + public void SetApplicationUrlViaServerRegistrar() + { + // no applicable settings, but a provider + + var settings = Mock.Of(section => + section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string)null) + && section.ScheduledTasks == Mock.Of()); + + var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); + globalConfig.Setup(x => x.UseHttps).Returns(true); + + var registrar = new Mock(); + registrar.Setup(x => x.GetCurrentServerUmbracoApplicationUrl()).Returns("http://server1.com/umbraco"); + + var state = new RuntimeState( + Mock.Of(), + new Lazy(() => registrar.Object), + new Lazy(Mock.Of), settings, globalConfig.Object); + + state.EnsureApplicationUrl(); + + Assert.AreEqual("http://server1.com/umbraco", state.ApplicationUrl.ToString()); + } + [Test] public void SetApplicationUrlViaProvider() { // no applicable settings, but a provider var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) + section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) && section.ScheduledTasks == Mock.Of()); var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); @@ -58,11 +75,11 @@ namespace Umbraco.Tests.Misc ApplicationUrlHelper.ApplicationUrlProvider = request => "http://server1.com/umbraco"; - Initialize(settings, globalConfig.Object); + - var state = new RuntimeState(Mock.Of(), new Lazy(Mock.Of), new Lazy(Mock.Of)); + var state = new RuntimeState(Mock.Of(), new Lazy(Mock.Of), new Lazy(Mock.Of), settings, globalConfig.Object); - state.EnsureApplicationUrl(settings, globalConfig.Object); + state.EnsureApplicationUrl(); Assert.AreEqual("http://server1.com/umbraco", state.ApplicationUrl.ToString()); } @@ -73,176 +90,31 @@ namespace Umbraco.Tests.Misc // no applicable settings, cannot set url var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) + section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) && section.ScheduledTasks == Mock.Of()); var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); globalConfig.Setup(x => x.UseHttps).Returns(true); - Initialize(settings, globalConfig.Object); - - var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object); + var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object, Mock.Of()); // still NOT set Assert.IsNull(url); } - - [Test] - public void SetApplicationUrlFromDcSettingsSsl1() - { - // set from distributed call settings - // first server is master server - - var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Enabled && callSection.Servers == new[] - { - Mock.Of(server => server.ServerName == NetworkHelper.MachineName && server.ServerAddress == "server1.com"), - Mock.Of(server => server.ServerName == "ANOTHERNAME" && server.ServerAddress == "server2.com"), - }) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string)null) - && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == (string)null)); - - var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); - globalConfig.Setup(x => x.UseHttps).Returns(true); - - Initialize(settings, globalConfig.Object); - - var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object); - - Assert.AreEqual("http://server1.com:80/umbraco", url); - - var role = _registrar.GetCurrentServerRole(); - Assert.AreEqual(ServerRole.Master, role); - } - - [Test] - public void SetApplicationUrlFromDcSettingsSsl2() - { - // set from distributed call settings - // other servers are slave servers - - var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Enabled && callSection.Servers == new[] - { - Mock.Of(server => server.ServerName == "ANOTHERNAME" && server.ServerAddress == "server2.com"), - Mock.Of(server => server.ServerName == NetworkHelper.MachineName && server.ServerAddress == "server1.com"), - }) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string)null) - && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == (string)null)); - - var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); - globalConfig.Setup(x => x.UseHttps).Returns(true); - - Initialize(settings, globalConfig.Object); - - var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object); - - Assert.AreEqual("http://server1.com:80/umbraco", url); - - var role = _registrar.GetCurrentServerRole(); - Assert.AreEqual(ServerRole.Slave, role); - } - - [Test] - public void SetApplicationUrlFromDcSettingsSsl3() - { - // set from distributed call settings - // cannot set if not enabled - - var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Enabled == false && callSection.Servers == new[] - { - Mock.Of(server => server.ServerName == "ANOTHERNAME" && server.ServerAddress == "server2.com"), - Mock.Of(server => server.ServerName == NetworkHelper.MachineName && server.ServerAddress == "server1.com"), - }) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string)null) - && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == (string)null)); - - var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); - globalConfig.Setup(x => x.UseHttps).Returns(true); - - Initialize(settings, globalConfig.Object); - - var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object); - - Assert.IsNull(url); - - var role = _registrar.GetCurrentServerRole(); - Assert.AreEqual(ServerRole.Single, role); - } - - [Test] - public void ServerRoleSingle() - { - // distributed call settings disabled, single server - - var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Enabled == false && callSection.Servers == Enumerable.Empty()) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string)null) - && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == (string)null)); - - var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); - - Initialize(settings, globalConfig.Object); - - var role = _registrar.GetCurrentServerRole(); - Assert.AreEqual(ServerRole.Single, role); - } - - [Test] - public void ServerRoleUnknown1() - { - // distributed call enabled but missing servers, unknown server - - var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Enabled && callSection.Servers == Enumerable.Empty()) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string)null) - && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == (string)null)); - - var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); - - Initialize(settings, globalConfig.Object); - - var role = _registrar.GetCurrentServerRole(); - Assert.AreEqual(ServerRole.Unknown, role); - } - - [Test] - public void ServerRoleUnknown2() - { - // distributed call enabled, cannot find server, assume it's an undeclared slave - - var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Enabled && callSection.Servers == new[] - { - Mock.Of(server => server.ServerName == "ANOTHERNAME" && server.ServerAddress == "server2.com"), - }) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string)null) - && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == (string)null)); - - var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); - - Initialize(settings, globalConfig.Object); - - var role = _registrar.GetCurrentServerRole(); - Assert.AreEqual(ServerRole.Slave, role); - } - + [Test] public void SetApplicationUrlFromStSettingsNoSsl() { var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) + section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == "mycoolhost.com/umbraco")); var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); globalConfig.Setup(x => x.UseHttps).Returns(false); - Initialize(settings, globalConfig.Object); - var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object); + + var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object, Mock.Of()); Assert.AreEqual("http://mycoolhost.com/umbraco", url); } @@ -251,16 +123,15 @@ namespace Umbraco.Tests.Misc public void SetApplicationUrlFromStSettingsSsl() { var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) + section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == (string) null) && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == "mycoolhost.com/umbraco/")); var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); globalConfig.Setup(x => x.UseHttps).Returns(true); - Initialize(settings, globalConfig.Object); - var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object); + + var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object, Mock.Of()); Assert.AreEqual("https://mycoolhost.com/umbraco", url); } @@ -269,18 +140,19 @@ namespace Umbraco.Tests.Misc public void SetApplicationUrlFromWrSettingsSsl() { var settings = Mock.Of(section => - section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) - && section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == "httpx://whatever.com/umbraco/") + section.WebRouting == Mock.Of(wrSection => wrSection.UmbracoApplicationUrl == "httpx://whatever.com/umbraco/") && section.ScheduledTasks == Mock.Of(tasksSection => tasksSection.BaseUrl == "mycoolhost.com/umbraco")); var globalConfig = Mock.Get(SettingsForTests.GenerateMockGlobalSettings()); globalConfig.Setup(x => x.UseHttps).Returns(true); - Initialize(settings, globalConfig.Object); + - var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object); + var url = ApplicationUrlHelper.TryGetApplicationUrl(settings, Mock.Of(), globalConfig.Object, Mock.Of()); Assert.AreEqual("httpx://whatever.com/umbraco", url); } + + } } diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 23a0773f71..703179b184 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -10,7 +10,8 @@ using Umbraco.Web; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Sync; - +using Umbraco.Core.Configuration.UmbracoSettings; + namespace Umbraco.Tests.Routing { [TestFixture] @@ -24,14 +25,16 @@ namespace Umbraco.Tests.Routing base.SetUp(); //create the module - _module = new UmbracoModule(); - - // test - _module.Logger = Mock.Of(); - var runtime = new RuntimeState(_module.Logger, new Lazy(), new Lazy()); + _module = new UmbracoModule + { + GlobalSettings = TestObjects.GetGlobalSettings(), + Logger = Mock.Of() + }; + var runtime = new RuntimeState(_module.Logger, new Lazy(), new Lazy(), Mock.Of(), _module.GlobalSettings); + _module.Runtime = runtime; runtime.Level = RuntimeLevel.Run; - _module.GlobalSettings = TestObjects.GetGlobalSettings(); + //SettingsForTests.ReservedPaths = "~/umbraco,~/install/"; //SettingsForTests.ReservedUrls = "~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd"; diff --git a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs index c2ec892770..48bbdb1e22 100644 --- a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs @@ -334,7 +334,7 @@ namespace Umbraco.Tests.Scoping : base(false) { } - protected override void DeliverRemote(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) + protected override void DeliverRemote(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) { throw new NotImplementedException(); } diff --git a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs index 899d2f999e..9de2012dce 100644 --- a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs @@ -299,7 +299,7 @@ namespace Umbraco.Tests.Scoping : base(false) { } - protected override void DeliverRemote(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) + protected override void DeliverRemote(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) { throw new NotImplementedException(); } diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index 34c6a35833..35d3d72183 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -58,7 +58,6 @@ namespace Umbraco.Tests.TestHelpers var templates = new Mock(); var logging = new Mock(); var tasks = new Mock(); - var distCall = new Mock(); var providers = new Mock(); var routing = new Mock(); @@ -68,7 +67,6 @@ namespace Umbraco.Tests.TestHelpers settings.Setup(x => x.Templates).Returns(templates.Object); settings.Setup(x => x.Logging).Returns(logging.Object); settings.Setup(x => x.ScheduledTasks).Returns(tasks.Object); - settings.Setup(x => x.DistributedCall).Returns(distCall.Object); settings.Setup(x => x.Providers).Returns(providers.Object); settings.Setup(x => x.WebRouting).Returns(routing.Object); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index d39608c49c..827bfef4b7 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -206,7 +206,6 @@ - @@ -282,8 +281,6 @@ - - diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 7dbced3167..10e288092f 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -539,9 +539,6 @@ - - Form - diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config index 3f06c398f5..534a9e2640 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config @@ -90,50 +90,6 @@ - - - - - 0 - - - - - - - - - - - - - - - 0 - - - - - - - - - - - diff --git a/src/Umbraco.Web.UI/umbraco/webservices/CacheRefresher.asmx b/src/Umbraco.Web.UI/umbraco/webservices/CacheRefresher.asmx deleted file mode 100644 index 4347d8ede8..0000000000 --- a/src/Umbraco.Web.UI/umbraco/webservices/CacheRefresher.asmx +++ /dev/null @@ -1 +0,0 @@ -<%@ WebService Language="c#" Codebehind="CacheRefresher.asmx.cs" Class="umbraco.presentation.webservices.CacheRefresher" %> diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs index d03077bf24..a28a180d50 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs @@ -57,7 +57,7 @@ namespace Umbraco.Web FlushBatch(); } - protected override void DeliverRemote(IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) + protected override void DeliverRemote(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) { var idsA = ids?.ToArray(); @@ -65,7 +65,7 @@ namespace Umbraco.Web if (GetArrayType(idsA, out arrayType) == false) throw new ArgumentException("All items must be of the same type, either int or Guid.", nameof(ids)); - BatchMessage(servers, refresher, messageType, idsA, arrayType, json); + BatchMessage(refresher, messageType, idsA, arrayType, json); } public void FlushBatch() @@ -124,7 +124,6 @@ namespace Umbraco.Web } protected void BatchMessage( - IEnumerable servers, ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, @@ -149,7 +148,7 @@ namespace Umbraco.Web } else { - batch.Add(new RefreshInstructionEnvelope(servers, refresher, instructions)); + batch.Add(new RefreshInstructionEnvelope(refresher, instructions)); } } diff --git a/src/Umbraco.Web/BatchedWebServiceServerMessenger.cs b/src/Umbraco.Web/BatchedWebServiceServerMessenger.cs deleted file mode 100644 index 66a850e5c5..0000000000 --- a/src/Umbraco.Web/BatchedWebServiceServerMessenger.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Web; -using Umbraco.Core.Sync; -using Umbraco.Web.Routing; - -namespace Umbraco.Web -{ - /// - /// An that works by messaging servers via web services. - /// - /// - /// This binds to appropriate umbraco events in order to trigger the FlushBatch() calls - /// - internal class BatchedWebServiceServerMessenger : Core.Sync.BatchedWebServiceServerMessenger - { - internal BatchedWebServiceServerMessenger() - : base() - { - UmbracoModule.EndRequest += UmbracoModule_EndRequest; - } - - internal BatchedWebServiceServerMessenger(string login, string password) - : base(login, password) - { - UmbracoModule.EndRequest += UmbracoModule_EndRequest; - } - - internal BatchedWebServiceServerMessenger(string login, string password, bool useDistributedCalls) - : base(login, password, useDistributedCalls) - { - UmbracoModule.EndRequest += UmbracoModule_EndRequest; - } - - public BatchedWebServiceServerMessenger(Func> getLoginAndPassword) - : base(getLoginAndPassword) - { - UmbracoModule.EndRequest += UmbracoModule_EndRequest; - } - - protected override ICollection GetBatch(bool ensureHttpContext) - { - //try get the http context from the UmbracoContext, we do this because in the case we are launching an async - // thread and we know that the cache refreshers will execute, we will ensure the UmbracoContext and therefore we - // can get the http context from it - var httpContext = (UmbracoContext.Current == null ? null : UmbracoContext.Current.HttpContext) - //if this is null, it could be that an async thread is calling this method that we weren't aware of and the UmbracoContext - // wasn't ensured at the beginning of the thread. We can try to see if the HttpContext.Current is available which might be - // the case if the asp.net synchronization context has kicked in - ?? (HttpContext.Current == null ? null : new HttpContextWrapper(HttpContext.Current)); - - if (httpContext == null) - { - if (ensureHttpContext) - throw new NotSupportedException("Cannot execute without a valid/current HttpContext assigned."); - return null; - } - - var key = typeof(BatchedWebServiceServerMessenger).Name; - - // no thread-safety here because it'll run in only 1 thread (request) at a time - var batch = (ICollection)httpContext.Items[key]; - if (batch == null && ensureHttpContext) - httpContext.Items[key] = batch = new List(); - return batch; - } - - private void UmbracoModule_EndRequest(object sender, UmbracoRequestEventArgs e) - { - FlushBatch(); - } - - protected override void ProcessBatch(RefreshInstructionEnvelope[] batch) - { - Message(batch); - } - } -} diff --git a/src/Umbraco.Web/Cache/DistributedCache.cs b/src/Umbraco.Web/Cache/DistributedCache.cs index 23d1067282..6f5196d642 100644 --- a/src/Umbraco.Web/Cache/DistributedCache.cs +++ b/src/Umbraco.Web/Cache/DistributedCache.cs @@ -38,7 +38,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty || instances.Length == 0 || getNumericId == null) return; Current.ServerMessenger.PerformRefresh( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), getNumericId, instances); @@ -54,7 +53,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty || id == default(int)) return; Current.ServerMessenger.PerformRefresh( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), id); } @@ -69,7 +67,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty || id == Guid.Empty) return; Current.ServerMessenger.PerformRefresh( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), id); } @@ -81,7 +78,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty || payload == null) return; Current.ServerMessenger.PerformRefresh( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), payload); } @@ -93,7 +89,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty || payloads == null) return; Current.ServerMessenger.PerformRefresh( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), payloads.ToArray()); } @@ -107,7 +102,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty || jsonPayload.IsNullOrWhiteSpace()) return; Current.ServerMessenger.PerformRefresh( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), jsonPayload); } @@ -136,7 +130,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty) return; Current.ServerMessenger.PerformRefreshAll( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid)); } @@ -150,7 +143,6 @@ namespace Umbraco.Web.Cache if (refresherGuid == Guid.Empty || id == default(int)) return; Current.ServerMessenger.PerformRemove( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), id); } @@ -168,7 +160,6 @@ namespace Umbraco.Web.Cache public void Remove(Guid refresherGuid, Func getNumericId, params T[] instances) { Current.ServerMessenger.PerformRemove( - Current.ServerRegistrar.Registrations, GetRefresherById(refresherGuid), getNumericId, instances); diff --git a/src/Umbraco.Web/Components/DatabaseServerRegistrarAndMessengerComponent.cs b/src/Umbraco.Web/Components/DatabaseServerRegistrarAndMessengerComponent.cs index f679b00943..e07a36bbfc 100644 --- a/src/Umbraco.Web/Components/DatabaseServerRegistrarAndMessengerComponent.cs +++ b/src/Umbraco.Web/Components/DatabaseServerRegistrarAndMessengerComponent.cs @@ -50,9 +50,6 @@ namespace Umbraco.Web.Components public override void Compose(Composition composition) { - //fixme inject IUmbracoSettingsSection - if (UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled) return; - composition.SetServerMessenger(factory => { var runtime = factory.GetInstance(); @@ -96,8 +93,6 @@ namespace Umbraco.Web.Components public void Initialize(IRuntimeState runtime, IServerRegistrar serverRegistrar, IServerMessenger serverMessenger, IServerRegistrationService registrationService, ILogger logger, IExamineManager examineManager) { - if (UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled) return; - _registrar = serverRegistrar as DatabaseServerRegistrar; if (_registrar == null) throw new Exception("panic: registar."); diff --git a/src/Umbraco.Web/Components/LegacyServerRegistrarAndMessengerComponent.cs b/src/Umbraco.Web/Components/LegacyServerRegistrarAndMessengerComponent.cs deleted file mode 100644 index d494d239a3..0000000000 --- a/src/Umbraco.Web/Components/LegacyServerRegistrarAndMessengerComponent.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using LightInject; -using Umbraco.Core; -using Umbraco.Core.Components; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; -using Umbraco.Core.Services; -using Umbraco.Web.Runtime; - -namespace Umbraco.Web.Components -{ - // the legacy LB is not enabled by default, because LB is implemented by - // DatabaseServerRegistrarAndMessengerComponent instead - - [RuntimeLevel(MinLevel = RuntimeLevel.Run)] - [DisableComponent] // is not enabled by default - public sealed class LegacyServerRegistrarAndMessengerComponent : UmbracoComponentBase, IUmbracoCoreComponent - { - public override void Compose(Composition composition) - { - if (UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled == false) return; - - composition.SetServerMessenger(factory => - { - var runtime = factory.GetInstance(); - var logger = factory.GetInstance(); - var userService = factory.GetInstance(); - - return new BatchedWebServiceServerMessenger(() => - { - // we should not proceed to change this if the app/database is not configured since there will - // be no user, plus we don't need to have server messages sent if this is the case. - if (runtime.Level == RuntimeLevel.Run) - { - try - { - var user = userService.GetUserById(UmbracoConfig.For.UmbracoSettings().DistributedCall.UserId); - return Tuple.Create(user.Username, user.RawPasswordValue); - } - catch (Exception e) - { - logger.Error("An error occurred trying to set the IServerMessenger during application startup", e); - return null; - } - } - logger.Warn("Could not initialize the DefaultServerMessenger, the application is not configured or the database is not configured"); - return null; - }); - }); - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 0dd6ef73f1..5a39523707 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -417,7 +417,6 @@ - @@ -575,7 +574,6 @@ - @@ -1410,10 +1408,6 @@ - - CacheRefresher.asmx - Component - CheckForUpgrade.asmx Component @@ -1487,9 +1481,6 @@ ASPXCodeBehind - - Form - diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 1578f5dc53..24189fd601 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -89,7 +89,7 @@ namespace Umbraco.Web private void BeginRequest(HttpContextBase httpContext) { // ensure application url is initialized - ((RuntimeState) Current.RuntimeState).EnsureApplicationUrl(UmbracoSettings, GlobalSettings, httpContext.Request); + ((RuntimeState) Current.RuntimeState).EnsureApplicationUrl(httpContext.Request); // do not process if client-side request if (httpContext.Request.Url.IsClientSideRequest()) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx deleted file mode 100644 index 4347d8ede8..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx +++ /dev/null @@ -1 +0,0 @@ -<%@ WebService Language="c#" Codebehind="CacheRefresher.asmx.cs" Class="umbraco.presentation.webservices.CacheRefresher" %> diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs deleted file mode 100644 index c10c35a6c0..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/CacheRefresher.asmx.cs +++ /dev/null @@ -1,192 +0,0 @@ -using System; -using System.Linq; -using System.Web; -using System.Web.Services; -using System.Xml; -using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Identity.Owin; -using Newtonsoft.Json; -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Logging; -using Umbraco.Core.Sync; -using Umbraco.Core.Models.Identity; -using Umbraco.Core.Security; -using Umbraco.Core.Xml; -using Umbraco.Web.Security; -using Umbraco.Web; -using Umbraco.Web.Composing; - -namespace umbraco.presentation.webservices -{ - /// - /// CacheRefresher web service. - /// - [WebService(Namespace="http://umbraco.org/webservices/")] - public class CacheRefresher : WebService - { - #region Helpers - - // is the server originating from this server - ie are we self-messaging? - // in which case we should ignore the message because it's been processed locally already - internal static bool SelfMessage(string hash) - { - if (string.IsNullOrEmpty(hash)) return false; // no hash = don't know = not self - if (hash != WebServiceServerMessenger.GetCurrentServerHash()) return false; - - Current.Logger.Debug(() => - $"Ignoring self-message. (server: {NetworkHelper.MachineName}, appId: {HttpRuntime.AppDomainAppId}, hash: {hash})"); - - return true; - } - - private static ICacheRefresher GetRefresher(Guid id) - { - var refresher = Current.CacheRefreshers[id]; - if (refresher == null) - throw new InvalidOperationException("Cache refresher with ID \"" + id + "\" does not exist."); - return refresher; - } - - private static IJsonCacheRefresher GetJsonRefresher(Guid id) - { - return GetJsonRefresher(GetRefresher(id)); - } - - private static IJsonCacheRefresher GetJsonRefresher(ICacheRefresher refresher) - { - var jsonRefresher = refresher as IJsonCacheRefresher; - if (jsonRefresher == null) - throw new InvalidOperationException("Cache refresher with ID \"" + refresher.RefresherUniqueId + "\" does not implement " + typeof(IJsonCacheRefresher) + "."); - return jsonRefresher; - } - - private bool Authorized(string login, string rawPassword) - { - //TODO: This technique of passing the raw password in is a legacy idea and isn't really - // a very happy way to secure this webservice. To prevent brute force attacks, we need - // to ensure that the lockout policies are applied, though because we are not authenticating - // the user with their real password, we need to do this a bit manually. - - var userMgr = Context.GetOwinContext().GetBackOfficeUserManager(); - - var user = Current.Services.UserService.GetByUsername(login); - if (user == null) return false; - - var u = userMgr.FindById(user.Id); - if (u == null) return false; - - if (u.IsLockedOut) return false; - - if (user.RawPasswordValue != rawPassword) - { - //this performs the lockout and/or increments the access failed count - userMgr.AccessFailed(u.Id); - return false; - } - - return true; - } - - #endregion - - [WebMethod] - public void BulkRefresh(RefreshInstruction[] instructions, string appId, string login, string password) - { - if (Authorized(login, password) == false) return; - if (SelfMessage(appId)) return; // do not process self-messages - - // only execute distinct instructions - no sense in running the same one more than once - foreach (var instruction in instructions.Distinct()) - { - var refresher = GetRefresher(instruction.RefresherId); - switch (instruction.RefreshType) - { - case RefreshMethodType.RefreshAll: - refresher.RefreshAll(); - break; - case RefreshMethodType.RefreshByGuid: - refresher.Refresh(instruction.GuidId); - break; - case RefreshMethodType.RefreshById: - refresher.Refresh(instruction.IntId); - break; - case RefreshMethodType.RefreshByIds: // not directly supported by ICacheRefresher - foreach (var id in JsonConvert.DeserializeObject(instruction.JsonIds)) - refresher.Refresh(id); - break; - case RefreshMethodType.RefreshByJson: - GetJsonRefresher(refresher).Refresh(instruction.JsonPayload); - break; - case RefreshMethodType.RemoveById: - refresher.Remove(instruction.IntId); - break; - //case RefreshMethodType.RemoveByIds: // not directly supported by ICacheRefresher - // foreach (var id in JsonConvert.DeserializeObject(instruction.JsonIds)) - // refresher.Remove(id); - // break; - } - } - } - - [WebMethod] - public void RefreshAll(Guid uniqueIdentifier, string Login, string Password) - { - if (Authorized(Login, Password) == false) return; - GetRefresher(uniqueIdentifier).RefreshAll(); - } - - [WebMethod] - public void RefreshByGuid(Guid uniqueIdentifier, Guid Id, string Login, string Password) - { - if (Authorized(Login, Password) == false) return; - GetRefresher(uniqueIdentifier).Refresh(Id); - } - - [WebMethod] - public void RefreshById(Guid uniqueIdentifier, int Id, string Login, string Password) - { - if (Authorized(Login, Password) == false) return; - GetRefresher(uniqueIdentifier).Refresh(Id); - } - - [WebMethod] - public void RefreshByIds(Guid uniqueIdentifier, string jsonIds, string Login, string Password) - { - if (Authorized(Login, Password) == false) return; - var refresher = GetRefresher(uniqueIdentifier); - foreach (var id in JsonConvert.DeserializeObject(jsonIds)) - refresher.Refresh(id); - } - - [WebMethod] - public void RefreshByJson(Guid uniqueIdentifier, string jsonPayload, string Login, string Password) - { - if (Authorized(Login, Password) == false) return; - GetJsonRefresher(uniqueIdentifier).Refresh(jsonPayload); - } - - [WebMethod] - public void RemoveById(Guid uniqueIdentifier, int Id, string Login, string Password) - { - if (Authorized(Login, Password) == false) return; - GetRefresher(uniqueIdentifier).Remove(Id); - } - - [WebMethod] - public XmlDocument GetRefreshers(string Login, string Password) - { - if (Authorized(Login, Password) == false) return null; - - var xd = new XmlDocument(); - xd.LoadXml(""); - foreach (var cr in Current.CacheRefreshers) - { - var n = XmlHelper.AddTextNode(xd, "cacheRefresher", cr.Name); - n.Attributes.Append(XmlHelper.AddAttribute(xd, "uniqueIdentifier", cr.RefresherUniqueId.ToString())); - xd.DocumentElement.AppendChild(n); - } - return xd; - } - } -}