Merge pull request #10612 from umbraco/v9/feature/remove-manifest-watcher

V9: Remove manifest watcher
This commit is contained in:
Bjarke Berg
2021-07-07 10:39:08 +02:00
committed by GitHub
3 changed files with 0 additions and 134 deletions

View File

@@ -145,9 +145,7 @@ namespace Umbraco.Cms.Core.DependencyInjection
this.AddAllCoreCollectionBuilders();
this.AddNotificationHandler<UmbracoApplicationStartingNotification, EssentialDirectoryCreator>();
Services.AddSingleton<ManifestWatcher>();
Services.AddSingleton<UmbracoRequestPaths>();
this.AddNotificationAsyncHandler<UmbracoApplicationStartingNotification, AppPluginsManifestWatcherNotificationHandler>();
Services.AddUnique<InstallStatusTracker>();

View File

@@ -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<ManifestWatcher> _logger;
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
private readonly List<FileSystemWatcher> _fws = new List<FileSystemWatcher>();
private bool _disposed;
public ManifestWatcher(ILogger<ManifestWatcher> 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);
}
}

View File

@@ -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
{
/// <summary>
/// Starts monitoring AppPlugins directory during debug runs, to restart site when a plugin manifest changes.
/// </summary>
public sealed class AppPluginsManifestWatcherNotificationHandler : INotificationAsyncHandler<UmbracoApplicationStartingNotification>
{
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;
}
}
}