diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index f9fde4c47e..5dd2499624 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -145,9 +145,7 @@ namespace Umbraco.Cms.Core.DependencyInjection this.AddAllCoreCollectionBuilders(); this.AddNotificationHandler(); - Services.AddSingleton(); Services.AddSingleton(); - this.AddNotificationAsyncHandler(); Services.AddUnique(); diff --git a/src/Umbraco.Core/Manifest/ManifestWatcher.cs b/src/Umbraco.Core/Manifest/ManifestWatcher.cs deleted file mode 100644 index 26c54a8b5e..0000000000 --- a/src/Umbraco.Core/Manifest/ManifestWatcher.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Hosting; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Manifest -{ - public class ManifestWatcher : IDisposable - { - private static readonly object Locker = new object(); - private static volatile bool _isRestarting; - - private readonly ILogger _logger; - private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime; - private readonly List _fws = new List(); - private bool _disposed; - - public ManifestWatcher(ILogger logger, IUmbracoApplicationLifetime umbracoApplicationLifetime) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _umbracoApplicationLifetime = umbracoApplicationLifetime; - } - - public void Start(params string[] packageFolders) - { - foreach (var packageFolder in packageFolders.Where(IsWatchable)) - { - // for some reason *.manifest doesn't work - var fsw = new FileSystemWatcher(packageFolder, "*package.*") - { - IncludeSubdirectories = false, - NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite - }; - - _fws.Add(fsw); - - fsw.Changed += FswChanged; - fsw.EnableRaisingEvents = true; - } - } - - private static bool IsWatchable(string folder) - { - return Directory.Exists(folder) && File.Exists(Path.Combine(folder, "package.manifest")); - } - - private void FswChanged(object sender, FileSystemEventArgs e) - { - if (!e.Name.InvariantContains("package.manifest")) - { - return; - } - - // ensure the app is not restarted multiple times for multiple - // savings during the same app domain execution - restart once - lock (Locker) - { - if (_isRestarting) return; - - _isRestarting = true; - _logger.LogInformation("Manifest has changed, app pool is restarting ({Path})", e.FullPath); - _umbracoApplicationLifetime.Restart(); - } - } - - private void Dispose(bool disposing) - { - // ReSharper disable InvertIf - if (disposing && !_disposed) - { - foreach (FileSystemWatcher fw in _fws) - { - fw.Dispose(); - } - - _disposed = true; - } - - // ReSharper restore InvertIf - } - - public void Dispose() => Dispose(true); - } -} diff --git a/src/Umbraco.Core/Runtime/AppPluginsManifestWatcherNotificationHandler.cs b/src/Umbraco.Core/Runtime/AppPluginsManifestWatcherNotificationHandler.cs deleted file mode 100644 index a416452966..0000000000 --- a/src/Umbraco.Core/Runtime/AppPluginsManifestWatcherNotificationHandler.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using Umbraco.Cms.Core.Events; -using Umbraco.Cms.Core.Hosting; -using Umbraco.Cms.Core.Manifest; -using Umbraco.Cms.Core.Notifications; - -namespace Umbraco.Cms.Core.Runtime -{ - /// - /// Starts monitoring AppPlugins directory during debug runs, to restart site when a plugin manifest changes. - /// - public sealed class AppPluginsManifestWatcherNotificationHandler : INotificationAsyncHandler - { - private readonly ManifestWatcher _manifestWatcher; - private readonly IHostingEnvironment _hostingEnvironment; - - public AppPluginsManifestWatcherNotificationHandler(ManifestWatcher manifestWatcher, IHostingEnvironment hostingEnvironment) - { - _manifestWatcher = manifestWatcher ?? throw new ArgumentNullException(nameof(manifestWatcher)); - _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); - } - - public Task HandleAsync(UmbracoApplicationStartingNotification notification, CancellationToken cancellationToken) - { - if (!_hostingEnvironment.IsDebugMode) - { - return Task.CompletedTask; - } - - var appPlugins = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins); - - if (!Directory.Exists(appPlugins)) - { - return Task.CompletedTask; - } - - _manifestWatcher.Start(Directory.GetDirectories(appPlugins)); - - return Task.CompletedTask; - } - } -}