From 897cb63ad63795e157b29f9712dffdc9ea5d3986 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 18 Dec 2019 11:16:43 +0100 Subject: [PATCH] AB4227 - Moved Packaging, Compose, Dictionary, Manifest and Sync --- .../Hosting/IHostingEnvironment.cs | 2 + .../Services/IRuntimeState.cs | 2 + .../Runtime/CoreInitialComposer.cs | 5 ++- src/Umbraco.Core/Umbraco.Core.csproj | 25 ++---------- .../Compose/ManifestWatcherComponent.cs | 0 .../Compose/ManifestWatcherComposer.cs | 0 .../Compose/RelateOnCopyComponent.cs | 20 +++++++--- .../Compose/RelateOnCopyComposer.cs | 0 .../Compose/RelateOnTrashComponent.cs | 16 ++++---- .../Compose/RelateOnTrashComposer.cs | 0 .../Dictionary/UmbracoCultureDictionary.cs | 0 .../UmbracoCultureDictionaryFactory.cs | 0 .../Events/MigrationEventArgs.cs | 0 .../Manifest/DashboardAccessRuleConverter.cs | 0 .../Manifest/DataEditorConverter.cs | 0 .../Manifest/ManifestParser.cs | 0 .../Manifest/ValueValidatorConverter.cs | 0 .../Packaging/PackageDataInstallation.cs | 8 ++-- .../Packaging/PackageInstallation.cs | 10 ++--- .../Sync/DatabaseServerMessenger.cs | 38 ++++++++++--------- .../Sync/RefreshInstruction.cs | 0 .../Sync/RefreshInstructionEnvelope.cs | 0 .../Sync/ServerMessengerBase.cs | 23 +++++------ .../BatchedDatabaseServerMessenger.cs | 2 +- .../Hosting/AspNetHostingEnvironment.cs | 3 ++ 25 files changed, 79 insertions(+), 75 deletions(-) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Compose/ManifestWatcherComponent.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Compose/ManifestWatcherComposer.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Compose/RelateOnCopyComponent.cs (64%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Compose/RelateOnCopyComposer.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Compose/RelateOnTrashComponent.cs (95%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Compose/RelateOnTrashComposer.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Dictionary/UmbracoCultureDictionary.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Dictionary/UmbracoCultureDictionaryFactory.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Events/MigrationEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Manifest/DashboardAccessRuleConverter.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Manifest/DataEditorConverter.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Manifest/ManifestParser.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Manifest/ValueValidatorConverter.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Packaging/PackageDataInstallation.cs (99%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Packaging/PackageInstallation.cs (98%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Sync/DatabaseServerMessenger.cs (95%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Sync/RefreshInstruction.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Sync/RefreshInstructionEnvelope.cs (100%) rename src/{Umbraco.Core => Umbraco.Infrastructure}/Sync/ServerMessengerBase.cs (99%) diff --git a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs index 5ce8392ab4..a71c449bb8 100644 --- a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs +++ b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs @@ -9,6 +9,8 @@ namespace Umbraco.Core.Hosting string LocalTempPath { get; } string ApplicationVirtualPath { get; } + int CurrentDomainId { get; } + bool IsDebugMode { get; } /// /// Gets a value indicating whether Umbraco is hosted. diff --git a/src/Umbraco.Abstractions/Services/IRuntimeState.cs b/src/Umbraco.Abstractions/Services/IRuntimeState.cs index 30c768ab01..38da246cc1 100644 --- a/src/Umbraco.Abstractions/Services/IRuntimeState.cs +++ b/src/Umbraco.Abstractions/Services/IRuntimeState.cs @@ -76,5 +76,7 @@ namespace Umbraco.Core /// Gets the exception that caused the boot to fail. /// BootFailedException BootFailedException { get; } + + IMainDom MainDom { get; } } } diff --git a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs index 1e145b33d6..159eb8bca9 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs @@ -110,8 +110,9 @@ namespace Umbraco.Core.Runtime factory.GetInstance(), factory.GetInstance(), true, new DatabaseServerMessengerOptions(), - factory.GetInstance() - )); + factory.GetInstance(), + factory.GetInstance() + )); composition.CacheRefreshers() .Add(() => composition.TypeLoader.GetCacheRefreshers()); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f6ca9a19be..a6716e5264 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -128,12 +128,6 @@ --> - - - - - - @@ -144,28 +138,22 @@ - - - - - - - + + - @@ -187,7 +175,6 @@ - @@ -198,12 +185,10 @@ - - @@ -212,13 +197,9 @@ - - - - @@ -242,7 +223,7 @@ - + \ No newline at end of file diff --git a/src/Umbraco.Core/Compose/ManifestWatcherComponent.cs b/src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs similarity index 100% rename from src/Umbraco.Core/Compose/ManifestWatcherComponent.cs rename to src/Umbraco.Infrastructure/Compose/ManifestWatcherComponent.cs diff --git a/src/Umbraco.Core/Compose/ManifestWatcherComposer.cs b/src/Umbraco.Infrastructure/Compose/ManifestWatcherComposer.cs similarity index 100% rename from src/Umbraco.Core/Compose/ManifestWatcherComposer.cs rename to src/Umbraco.Infrastructure/Compose/ManifestWatcherComposer.cs diff --git a/src/Umbraco.Core/Compose/RelateOnCopyComponent.cs b/src/Umbraco.Infrastructure/Compose/RelateOnCopyComponent.cs similarity index 64% rename from src/Umbraco.Core/Compose/RelateOnCopyComponent.cs rename to src/Umbraco.Infrastructure/Compose/RelateOnCopyComponent.cs index b56ff8b87e..56a97e4cba 100644 --- a/src/Umbraco.Core/Compose/RelateOnCopyComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/RelateOnCopyComponent.cs @@ -8,6 +8,15 @@ namespace Umbraco.Core.Compose // TODO: This should just exist in the content service/repo! public sealed class RelateOnCopyComponent : IComponent { + private readonly IRelationService _relationService; + private readonly IAuditService _auditService; + + public RelateOnCopyComponent(IRelationService relationService, IAuditService auditService) + { + _relationService = relationService; + _auditService = auditService; + } + public void Initialize() { ContentService.Copied += ContentServiceCopied; @@ -16,13 +25,12 @@ namespace Umbraco.Core.Compose public void Terminate() { } - private static void ContentServiceCopied(IContentService sender, Events.CopyEventArgs e) + private void ContentServiceCopied(IContentService sender, Events.CopyEventArgs e) { if (e.RelateToOriginal == false) return; - var relationService = Current.Services.RelationService; - var relationType = relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias); + var relationType = _relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias); if (relationType == null) { @@ -32,13 +40,13 @@ namespace Umbraco.Core.Compose Constants.ObjectTypes.Document, Constants.ObjectTypes.Document); - relationService.Save(relationType); + _relationService.Save(relationType); } var relation = new Relation(e.Original.Id, e.Copy.Id, relationType); - relationService.Save(relation); + _relationService.Save(relation); - Current.Services.AuditService.Add( + _auditService.Add( AuditType.Copy, e.Copy.WriterId, e.Copy.Id, ObjectTypes.GetName(UmbracoObjectTypes.Document), diff --git a/src/Umbraco.Core/Compose/RelateOnCopyComposer.cs b/src/Umbraco.Infrastructure/Compose/RelateOnCopyComposer.cs similarity index 100% rename from src/Umbraco.Core/Compose/RelateOnCopyComposer.cs rename to src/Umbraco.Infrastructure/Compose/RelateOnCopyComposer.cs diff --git a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs b/src/Umbraco.Infrastructure/Compose/RelateOnTrashComponent.cs similarity index 95% rename from src/Umbraco.Core/Compose/RelateOnTrashComponent.cs rename to src/Umbraco.Infrastructure/Compose/RelateOnTrashComponent.cs index e7b3292956..c81aa2fd7d 100644 --- a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/RelateOnTrashComponent.cs @@ -12,20 +12,22 @@ namespace Umbraco.Core.Compose private readonly IRelationService _relationService; private readonly IEntityService _entityService; private readonly ILocalizedTextService _textService; + private readonly IAuditService _auditService; - public RelateOnTrashComponent(IRelationService relationService, IEntityService entityService, ILocalizedTextService textService) + public RelateOnTrashComponent(IRelationService relationService, IEntityService entityService, ILocalizedTextService textService, IAuditService auditService) { _relationService = relationService; _entityService = entityService; _textService = textService; + _auditService = auditService; } public void Initialize() { ContentService.Moved += (sender, args) => ContentService_Moved(sender, args, _relationService); - ContentService.Trashed += (sender, args) => ContentService_Trashed(sender, args, _relationService, _entityService, _textService); + ContentService.Trashed += (sender, args) => ContentService_Trashed(sender, args, _relationService, _entityService, _textService, _auditService); MediaService.Moved += (sender, args) => MediaService_Moved(sender, args, _relationService); - MediaService.Trashed += (sender, args) => MediaService_Trashed(sender, args, _relationService, _entityService, _textService); + MediaService.Trashed += (sender, args) => MediaService_Trashed(sender, args, _relationService, _entityService, _textService, _auditService); } public void Terminate() @@ -59,7 +61,7 @@ namespace Umbraco.Core.Compose } } - private static void ContentService_Trashed(IContentService sender, MoveEventArgs e, IRelationService relationService, IEntityService entityService, ILocalizedTextService textService) + private static void ContentService_Trashed(IContentService sender, MoveEventArgs e, IRelationService relationService, IEntityService entityService, ILocalizedTextService textService, IAuditService auditService) { const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias; var relationType = relationService.GetRelationTypeByAlias(relationTypeAlias); @@ -90,7 +92,7 @@ namespace Umbraco.Core.Compose var relation = new Relation(originalParentId, item.Entity.Id, relationType); relationService.Save(relation); - Current.Services.AuditService.Add(AuditType.Delete, + auditService.Add(AuditType.Delete, item.Entity.WriterId, item.Entity.Id, ObjectTypes.GetName(UmbracoObjectTypes.Document), @@ -101,7 +103,7 @@ namespace Umbraco.Core.Compose } } - private static void MediaService_Trashed(IMediaService sender, MoveEventArgs e, IRelationService relationService, IEntityService entityService, ILocalizedTextService textService) + private static void MediaService_Trashed(IMediaService sender, MoveEventArgs e, IRelationService relationService, IEntityService entityService, ILocalizedTextService textService, IAuditService auditService) { const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias; var relationType = relationService.GetRelationTypeByAlias(relationTypeAlias); @@ -126,7 +128,7 @@ namespace Umbraco.Core.Compose // Add a relation for the item being deleted, so that we can know the original parent for if we need to restore later var relation = new Relation(originalParentId, item.Entity.Id, relationType); relationService.Save(relation); - Current.Services.AuditService.Add(AuditType.Delete, + auditService.Add(AuditType.Delete, item.Entity.CreatorId, item.Entity.Id, ObjectTypes.GetName(UmbracoObjectTypes.Media), diff --git a/src/Umbraco.Core/Compose/RelateOnTrashComposer.cs b/src/Umbraco.Infrastructure/Compose/RelateOnTrashComposer.cs similarity index 100% rename from src/Umbraco.Core/Compose/RelateOnTrashComposer.cs rename to src/Umbraco.Infrastructure/Compose/RelateOnTrashComposer.cs diff --git a/src/Umbraco.Core/Dictionary/UmbracoCultureDictionary.cs b/src/Umbraco.Infrastructure/Dictionary/UmbracoCultureDictionary.cs similarity index 100% rename from src/Umbraco.Core/Dictionary/UmbracoCultureDictionary.cs rename to src/Umbraco.Infrastructure/Dictionary/UmbracoCultureDictionary.cs diff --git a/src/Umbraco.Core/Dictionary/UmbracoCultureDictionaryFactory.cs b/src/Umbraco.Infrastructure/Dictionary/UmbracoCultureDictionaryFactory.cs similarity index 100% rename from src/Umbraco.Core/Dictionary/UmbracoCultureDictionaryFactory.cs rename to src/Umbraco.Infrastructure/Dictionary/UmbracoCultureDictionaryFactory.cs diff --git a/src/Umbraco.Core/Events/MigrationEventArgs.cs b/src/Umbraco.Infrastructure/Events/MigrationEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/MigrationEventArgs.cs rename to src/Umbraco.Infrastructure/Events/MigrationEventArgs.cs diff --git a/src/Umbraco.Core/Manifest/DashboardAccessRuleConverter.cs b/src/Umbraco.Infrastructure/Manifest/DashboardAccessRuleConverter.cs similarity index 100% rename from src/Umbraco.Core/Manifest/DashboardAccessRuleConverter.cs rename to src/Umbraco.Infrastructure/Manifest/DashboardAccessRuleConverter.cs diff --git a/src/Umbraco.Core/Manifest/DataEditorConverter.cs b/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs similarity index 100% rename from src/Umbraco.Core/Manifest/DataEditorConverter.cs rename to src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Infrastructure/Manifest/ManifestParser.cs similarity index 100% rename from src/Umbraco.Core/Manifest/ManifestParser.cs rename to src/Umbraco.Infrastructure/Manifest/ManifestParser.cs diff --git a/src/Umbraco.Core/Manifest/ValueValidatorConverter.cs b/src/Umbraco.Infrastructure/Manifest/ValueValidatorConverter.cs similarity index 100% rename from src/Umbraco.Core/Manifest/ValueValidatorConverter.cs rename to src/Umbraco.Infrastructure/Manifest/ValueValidatorConverter.cs diff --git a/src/Umbraco.Core/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs similarity index 99% rename from src/Umbraco.Core/Packaging/PackageDataInstallation.cs rename to src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index 0b317c4029..f6902d77b8 100644 --- a/src/Umbraco.Core/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -19,7 +19,7 @@ using Umbraco.Core.Strings; namespace Umbraco.Core.Packaging { - internal class PackageDataInstallation + public class PackageDataInstallation { private readonly ILogger _logger; private readonly IFileService _fileService; @@ -678,7 +678,7 @@ namespace Umbraco.Core.Packaging foreach (var templateElement in allowedTemplatesElement.Elements("Template")) { var alias = templateElement.Value; - var template = _fileService.GetTemplate(alias.ToSafeAlias()); + var template = _fileService.GetTemplate(alias.ToSafeAlias(_shortStringHelper)); if (template != null) { if (allowedTemplates.Any(x => x.Id == template.Id)) continue; @@ -695,7 +695,7 @@ namespace Umbraco.Core.Packaging if (string.IsNullOrEmpty((string)defaultTemplateElement) == false) { - var defaultTemplate = _fileService.GetTemplate(defaultTemplateElement.Value.ToSafeAlias()); + var defaultTemplate = _fileService.GetTemplate(defaultTemplateElement.Value.ToSafeAlias(_shortStringHelper)); if (defaultTemplate != null) { contentType.SetDefaultTemplate(defaultTemplate); @@ -1231,7 +1231,7 @@ namespace Umbraco.Core.Packaging var name = prop.Element("Name")?.Value; if (sp == null) { - sp = new StylesheetProperty(name, "#" + name.ToSafeAlias(), ""); + sp = new StylesheetProperty(name, "#" + name.ToSafeAlias(_shortStringHelper), ""); s.AddProperty(sp); } else diff --git a/src/Umbraco.Core/Packaging/PackageInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageInstallation.cs similarity index 98% rename from src/Umbraco.Core/Packaging/PackageInstallation.cs rename to src/Umbraco.Infrastructure/Packaging/PackageInstallation.cs index a42ee1aeb2..e307802606 100644 --- a/src/Umbraco.Core/Packaging/PackageInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageInstallation.cs @@ -11,7 +11,7 @@ using Umbraco.Core.Services; namespace Umbraco.Core.Packaging { - internal class PackageInstallation : IPackageInstallation + public class PackageInstallation : IPackageInstallation { private readonly PackageExtraction _packageExtraction; private readonly PackageDataInstallation _packageDataInstallation; @@ -95,7 +95,7 @@ namespace Umbraco.Core.Packaging installationSummary.Actions = CompiledPackageXmlParser.GetPackageActions(XElement.Parse(compiledPackage.Actions), compiledPackage.Name); installationSummary.MetaData = compiledPackage; installationSummary.FilesInstalled = packageDefinition.Files; - + //make sure the definition is up to date with everything foreach (var x in installationSummary.DataTypesInstalled) packageDefinition.DataTypes.Add(x.Id.ToInvariantString()); foreach (var x in installationSummary.LanguagesInstalled) packageDefinition.Languages.Add(x.Id.ToInvariantString()); @@ -117,7 +117,7 @@ namespace Umbraco.Core.Packaging { foreach (var n in actions) { - //if there is an undo section then save it to the definition so we can run it at uninstallation + //if there is an undo section then save it to the definition so we can run it at uninstallation var undo = n.Undo; if (undo) packageDefinition.Actions += n.XmlData.ToString(); @@ -189,7 +189,7 @@ namespace Umbraco.Core.Packaging } } - - + + } } diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Infrastructure/Sync/DatabaseServerMessenger.cs similarity index 95% rename from src/Umbraco.Core/Sync/DatabaseServerMessenger.cs rename to src/Umbraco.Infrastructure/Sync/DatabaseServerMessenger.cs index 0e7194d5de..948304e4e4 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Infrastructure/Sync/DatabaseServerMessenger.cs @@ -33,6 +33,7 @@ namespace Umbraco.Core.Sync private readonly object _locko = new object(); private readonly IProfilingLogger _profilingLogger; private readonly IHostingEnvironment _hostingEnvironment; + private readonly CacheRefresherCollection _cacheRefreshers; private readonly ISqlContext _sqlContext; private readonly Lazy _distCacheFilePath; private int _lastId = -1; @@ -46,7 +47,7 @@ namespace Umbraco.Core.Sync public DatabaseServerMessenger( IRuntimeState runtime, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, - bool distributedEnabled, DatabaseServerMessengerOptions options, IHostingEnvironment hostingEnvironment) + bool distributedEnabled, DatabaseServerMessengerOptions options, IHostingEnvironment hostingEnvironment, CacheRefresherCollection cacheRefreshers) : base(distributedEnabled) { ScopeProvider = scopeProvider ?? throw new ArgumentNullException(nameof(scopeProvider)); @@ -54,6 +55,7 @@ namespace Umbraco.Core.Sync _runtime = runtime; _profilingLogger = proflog ?? throw new ArgumentNullException(nameof(proflog)); _hostingEnvironment = hostingEnvironment; + _cacheRefreshers = cacheRefreshers; Logger = proflog; Options = options ?? throw new ArgumentNullException(nameof(options)); _lastPruned = _lastSync = DateTime.UtcNow; @@ -123,10 +125,12 @@ namespace Umbraco.Core.Sync // the service will *not* be able to properly handle our notifications anymore const int weight = 10; - if (!(_runtime is RuntimeState runtime)) - throw new NotSupportedException($"Unsupported IRuntimeState implementation {_runtime.GetType().FullName}, expecting {typeof(RuntimeState).FullName}."); - var registered = runtime.MainDom.Register( + //TODO Why do we have interface if we expect to be exact type!!!? + // if (!(_runtime is RuntimeState runtime)) + // throw new NotSupportedException($"Unsupported IRuntimeState implementation {_runtime.GetType().FullName}, expecting {typeof(RuntimeState).FullName}."); + + var registered = _runtime.MainDom.Register( () => { lock (_locko) @@ -226,7 +230,7 @@ namespace Umbraco.Core.Sync /// /// Synchronize the server (throttled). /// - protected internal void Sync() + public void Sync() { lock (_locko) { @@ -262,7 +266,7 @@ namespace Umbraco.Core.Sync _lastPruned = _lastSync; - switch (Current.RuntimeState.ServerRole) + switch (_runtime.ServerRole) { case ServerRole.Single: case ServerRole.Master: @@ -524,8 +528,8 @@ namespace Umbraco.Core.Sync /// Practically, all we really need is the guid, the other infos are here for information /// and debugging purposes. /// - protected static readonly string LocalIdentity = NetworkHelper.MachineName // eg DOMAIN\SERVER - + "/" + Current.HostingEnvironment.ApplicationId // eg /LM/S3SVC/11/ROOT + protected string LocalIdentity => NetworkHelper.MachineName // eg DOMAIN\SERVER + + "/" + _hostingEnvironment.ApplicationId // eg /LM/S3SVC/11/ROOT + " [P" + Process.GetCurrentProcess().Id // eg 1234 + "/D" + AppDomain.CurrentDomain.Id // eg 22 + "] " + Guid.NewGuid().ToString("N").ToUpper(); // make it truly unique @@ -550,15 +554,15 @@ namespace Umbraco.Core.Sync #region Notify refreshers - private static ICacheRefresher GetRefresher(Guid id) + private ICacheRefresher GetRefresher(Guid id) { - var refresher = Current.CacheRefreshers[id]; + var refresher = _cacheRefreshers[id]; if (refresher == null) throw new InvalidOperationException("Cache refresher with ID \"" + id + "\" does not exist."); return refresher; } - private static IJsonCacheRefresher GetJsonRefresher(Guid id) + private IJsonCacheRefresher GetJsonRefresher(Guid id) { return GetJsonRefresher(GetRefresher(id)); } @@ -647,38 +651,38 @@ namespace Umbraco.Core.Sync return true; } - private static void RefreshAll(Guid uniqueIdentifier) + private void RefreshAll(Guid uniqueIdentifier) { var refresher = GetRefresher(uniqueIdentifier); refresher.RefreshAll(); } - private static void RefreshByGuid(Guid uniqueIdentifier, Guid id) + private void RefreshByGuid(Guid uniqueIdentifier, Guid id) { var refresher = GetRefresher(uniqueIdentifier); refresher.Refresh(id); } - private static void RefreshById(Guid uniqueIdentifier, int id) + private void RefreshById(Guid uniqueIdentifier, int id) { var refresher = GetRefresher(uniqueIdentifier); refresher.Refresh(id); } - private static void RefreshByIds(Guid uniqueIdentifier, string jsonIds) + private void RefreshByIds(Guid uniqueIdentifier, string jsonIds) { var refresher = GetRefresher(uniqueIdentifier); foreach (var id in JsonConvert.DeserializeObject(jsonIds)) refresher.Refresh(id); } - private static void RefreshByJson(Guid uniqueIdentifier, string jsonPayload) + private void RefreshByJson(Guid uniqueIdentifier, string jsonPayload) { var refresher = GetJsonRefresher(uniqueIdentifier); refresher.Refresh(jsonPayload); } - private static void RemoveById(Guid uniqueIdentifier, int id) + private void RemoveById(Guid uniqueIdentifier, int id) { var refresher = GetRefresher(uniqueIdentifier); refresher.Remove(id); diff --git a/src/Umbraco.Core/Sync/RefreshInstruction.cs b/src/Umbraco.Infrastructure/Sync/RefreshInstruction.cs similarity index 100% rename from src/Umbraco.Core/Sync/RefreshInstruction.cs rename to src/Umbraco.Infrastructure/Sync/RefreshInstruction.cs diff --git a/src/Umbraco.Core/Sync/RefreshInstructionEnvelope.cs b/src/Umbraco.Infrastructure/Sync/RefreshInstructionEnvelope.cs similarity index 100% rename from src/Umbraco.Core/Sync/RefreshInstructionEnvelope.cs rename to src/Umbraco.Infrastructure/Sync/RefreshInstructionEnvelope.cs diff --git a/src/Umbraco.Core/Sync/ServerMessengerBase.cs b/src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs similarity index 99% rename from src/Umbraco.Core/Sync/ServerMessengerBase.cs rename to src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs index bbf00c3a6b..3b47cabbaf 100644 --- a/src/Umbraco.Core/Sync/ServerMessengerBase.cs +++ b/src/Umbraco.Infrastructure/Sync/ServerMessengerBase.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using Umbraco.Composing; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Logging; @@ -66,7 +67,7 @@ namespace Umbraco.Core.Sync public void PerformRefresh(ICacheRefresher refresher, string jsonPayload) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (jsonPayload == null) throw new ArgumentNullException(nameof(jsonPayload)); @@ -75,7 +76,7 @@ namespace Umbraco.Core.Sync public void PerformRefresh(ICacheRefresher refresher, Func getNumericId, params T[] instances) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (getNumericId == null) throw new ArgumentNullException(nameof(getNumericId)); if (instances == null || instances.Length == 0) return; @@ -86,7 +87,7 @@ namespace Umbraco.Core.Sync public void PerformRefresh(ICacheRefresher refresher, Func getGuidId, params T[] instances) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (getGuidId == null) throw new ArgumentNullException(nameof(getGuidId)); if (instances == null || instances.Length == 0) return; @@ -97,7 +98,7 @@ namespace Umbraco.Core.Sync public void PerformRemove(ICacheRefresher refresher, Func getNumericId, params T[] instances) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (getNumericId == null) throw new ArgumentNullException(nameof(getNumericId)); if (instances == null || instances.Length == 0) return; @@ -108,7 +109,7 @@ namespace Umbraco.Core.Sync public void PerformRemove(ICacheRefresher refresher, params int[] numericIds) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (numericIds == null || numericIds.Length == 0) return; @@ -117,7 +118,7 @@ namespace Umbraco.Core.Sync public void PerformRefresh(ICacheRefresher refresher, params int[] numericIds) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (numericIds == null || numericIds.Length == 0) return; @@ -126,7 +127,7 @@ namespace Umbraco.Core.Sync public void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); if (guidIds == null || guidIds.Length == 0) return; @@ -135,7 +136,7 @@ namespace Umbraco.Core.Sync public void PerformRefreshAll(ICacheRefresher refresher) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); Deliver(refresher, MessageType.RefreshAll); @@ -288,7 +289,7 @@ namespace Umbraco.Core.Sync protected virtual void Deliver(ICacheRefresher refresher, TPayload[] payload) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); // deliver local @@ -305,7 +306,7 @@ namespace Umbraco.Core.Sync protected virtual void Deliver(ICacheRefresher refresher, MessageType messageType, IEnumerable ids = null, string json = null) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); var idsA = ids?.ToArray(); @@ -323,7 +324,7 @@ namespace Umbraco.Core.Sync protected virtual void Deliver(ICacheRefresher refresher, MessageType messageType, Func getId, IEnumerable instances) { - + if (refresher == null) throw new ArgumentNullException(nameof(refresher)); var instancesA = instances.ToArray(); diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs index 85b8e62d28..228e3144b2 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web public BatchedDatabaseServerMessenger( IRuntimeState runtime, IUmbracoDatabaseFactory databaseFactory, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, DatabaseServerMessengerOptions options, IHostingEnvironment hostingEnvironment) - : base(runtime, scopeProvider, sqlContext, proflog, true, options, hostingEnvironment ) + : base(runtime, scopeProvider, sqlContext, proflog, true, options, hostingEnvironment, Current.CacheRefreshers) { _databaseFactory = databaseFactory; } diff --git a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs index f1ae5af1f9..2da1c19948 100644 --- a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs @@ -20,8 +20,11 @@ namespace Umbraco.Web.Hosting ApplicationId = HostingEnvironment.ApplicationID; ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath; ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath; + CurrentDomainId = AppDomain.CurrentDomain.Id; } + public int CurrentDomainId { get; } + public string SiteName { get; } public string ApplicationId { get; } public string ApplicationPhysicalPath { get; }