diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index ed472ea35a..956903d96d 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -98,8 +98,7 @@ namespace Umbraco.Core.Sync protected void Boot() { ReadLastSynced(); - if (_lastId < 0) // never synced before - Initialize(); + Initialize(); } /// @@ -107,24 +106,28 @@ namespace Umbraco.Core.Sync /// /// /// Thread safety: this is NOT thread safe. Because it is NOT meant to run multi-threaded. + /// Callers MUST ensure thread-safety. /// private void Initialize() { - // we haven't synced - in this case we aren't going to sync the whole thing, we will assume this is a new - // server and it will need to rebuild it's own caches, eg Lucene or the xml cache file. - LogHelper.Warn("No last synced Id found, this generally means this is a new server/install. The server will rebuild its caches and indexes and then adjust it's last synced id to the latest found in the database and will start maintaining cache updates based on that id"); + if (_lastId < 0) // never synced before + { + // we haven't synced - in this case we aren't going to sync the whole thing, we will assume this is a new + // server and it will need to rebuild it's own caches, eg Lucene or the xml cache file. + LogHelper.Warn("No last synced Id found, this generally means this is a new server/install. The server will rebuild its caches and indexes and then adjust it's last synced id to the latest found in the database and will start maintaining cache updates based on that id"); - // go get the last id in the db and store it - // note: do it BEFORE initializing otherwise some instructions might get lost - // when doing it before, some instructions might run twice - not an issue - var lastId = _appContext.DatabaseContext.Database.ExecuteScalar("SELECT MAX(id) FROM umbracoCacheInstruction"); - if (lastId > 0) - SaveLastSynced(lastId); + // go get the last id in the db and store it + // note: do it BEFORE initializing otherwise some instructions might get lost + // when doing it before, some instructions might run twice - not an issue + var lastId = _appContext.DatabaseContext.Database.ExecuteScalar("SELECT MAX(id) FROM umbracoCacheInstruction"); + if (lastId > 0) + SaveLastSynced(lastId); - // execute initializing callbacks - if (_options.InitializingCallbacks != null) - foreach (var callback in _options.InitializingCallbacks) - callback(); + // execute initializing callbacks + if (_options.InitializingCallbacks != null) + foreach (var callback in _options.InitializingCallbacks) + callback(); + } _initialized = true; } diff --git a/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs b/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs index e2f400ea71..8bf02b873d 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerRegistrar.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Sync /// /// A registrar that stores registered server nodes in the database. /// - internal sealed class DatabaseServerRegistrar : IServerRegistrar + public sealed class DatabaseServerRegistrar : IServerRegistrar { private readonly Lazy _registrationService; diff --git a/src/Umbraco.Core/Sync/RefreshInstruction.cs b/src/Umbraco.Core/Sync/RefreshInstruction.cs index a950b9bf78..fe37aa8fc7 100644 --- a/src/Umbraco.Core/Sync/RefreshInstruction.cs +++ b/src/Umbraco.Core/Sync/RefreshInstruction.cs @@ -15,6 +15,18 @@ namespace Umbraco.Core.Sync // but at the moment it is exposed in CacheRefresher webservice // so for the time being we keep it as-is for backward compatibility reasons + // need the public one so it can be de-serialized + // otherwise, should use GetInstructions(...) + public RefreshInstruction(Guid refresherId, RefreshMethodType refreshType, Guid guidId, int intId, string jsonIds, string jsonPayload) + { + RefresherId = refresherId; + RefreshType = refreshType; + GuidId = guidId; + IntId = intId; + JsonIds = jsonIds; + JsonPayload = jsonPayload; + } + private RefreshInstruction(ICacheRefresher refresher, RefreshMethodType refreshType) { RefresherId = refresher.UniqueIdentifier; diff --git a/src/Umbraco.Core/Sync/ServerMessengerBase.cs b/src/Umbraco.Core/Sync/ServerMessengerBase.cs index fed29b85a8..2585922078 100644 --- a/src/Umbraco.Core/Sync/ServerMessengerBase.cs +++ b/src/Umbraco.Core/Sync/ServerMessengerBase.cs @@ -148,7 +148,7 @@ namespace Umbraco.Core.Sync { if (refresher == null) throw new ArgumentNullException("refresher"); - LogHelper.Debug("Invoking refresher {0} on local server for message type {1}", + LogHelper.Debug("Invoking refresher {0} on local server for message type {1}", refresher.GetType, () => messageType); @@ -200,7 +200,7 @@ namespace Umbraco.Core.Sync { if (refresher == null) throw new ArgumentNullException("refresher"); - LogHelper.Debug("Invoking refresher {0} on local server for message type {1}", + LogHelper.Debug("Invoking refresher {0} on local server for message type {1}", refresher.GetType, () => messageType); @@ -238,7 +238,7 @@ namespace Umbraco.Core.Sync //{ // if (refresher == null) throw new ArgumentNullException("refresher"); - // LogHelper.Debug("Invoking refresher {0} on local server for message type Notify", + // LogHelper.Debug("Invoking refresher {0} on local server for message type Notify", // () => refresher.GetType()); // refresher.Notify(payload); diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs index f98138c7f3..4bf4852f77 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs @@ -64,7 +64,11 @@ namespace Umbraco.Web { var httpContext = UmbracoContext.Current == null ? null : UmbracoContext.Current.HttpContext; if (httpContext == null) - throw new NotSupportedException("Cannot execute without a valid/current UmbracoContext with an HttpContext assigned."); + { + if (ensure) + throw new NotSupportedException("Cannot execute without a valid/current UmbracoContext with an HttpContext assigned."); + return null; + } var key = typeof (BatchedDatabaseServerMessenger).Name; diff --git a/src/Umbraco.Web/BatchedWebServiceServerMessenger.cs b/src/Umbraco.Web/BatchedWebServiceServerMessenger.cs index 1789f92d9a..fca0b193db 100644 --- a/src/Umbraco.Web/BatchedWebServiceServerMessenger.cs +++ b/src/Umbraco.Web/BatchedWebServiceServerMessenger.cs @@ -34,7 +34,11 @@ namespace Umbraco.Web { var httpContext = UmbracoContext.Current == null ? null : UmbracoContext.Current.HttpContext; if (httpContext == null) - throw new NotSupportedException("Cannot execute without a valid/current UmbracoContext with an HttpContext assigned."); + { + if (ensure) + throw new NotSupportedException("Cannot execute without a valid/current UmbracoContext with an HttpContext assigned."); + return null; + } var key = typeof(BatchedWebServiceServerMessenger).Name;