Half completes: U4-2462 Does the app_plugins manager monitor file changes?
This commit is contained in:
49
src/Umbraco.Core/Manifest/ManifestWatcher.cs
Normal file
49
src/Umbraco.Core/Manifest/ManifestWatcher.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core.Manifest
|
||||
{
|
||||
internal class ManifestWatcher : DisposableObject
|
||||
{
|
||||
private readonly List<FileSystemWatcher> _fws = new List<FileSystemWatcher>();
|
||||
|
||||
public void Start(params string[] packageFolders)
|
||||
{
|
||||
foreach (var packageFolder in packageFolders)
|
||||
{
|
||||
if (Directory.Exists(packageFolder) && File.Exists(Path.Combine(packageFolder, "package.manifest")))
|
||||
{
|
||||
//NOTE: 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FswChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (e.Name.InvariantContains("package.manifest"))
|
||||
{
|
||||
LogHelper.Info<ManifestWatcher>("manifest has changed, app pool is restarting (" + e.FullPath + ")");
|
||||
HttpRuntime.UnloadAppDomain();
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
foreach (var fw in _fws)
|
||||
{
|
||||
fw.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -316,6 +316,7 @@
|
||||
<Compile Include="Manifest\ManifestBuilder.cs" />
|
||||
<Compile Include="Manifest\ManifestParser.cs" />
|
||||
<Compile Include="Manifest\ManifestValidatorConverter.cs" />
|
||||
<Compile Include="Manifest\ManifestWatcher.cs" />
|
||||
<Compile Include="Manifest\PackageManifest.cs" />
|
||||
<Compile Include="Manifest\ParameterEditorConverter.cs" />
|
||||
<Compile Include="Manifest\PreValueFieldConverter.cs" />
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.businesslogic;
|
||||
|
||||
@@ -18,7 +22,25 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
public class UmbracoApplication : UmbracoApplicationBase
|
||||
{
|
||||
|
||||
private readonly ManifestWatcher _mw = new ManifestWatcher();
|
||||
|
||||
protected override void OnApplicationStarted(object sender, EventArgs e)
|
||||
{
|
||||
base.OnApplicationStarted(sender, e);
|
||||
|
||||
if (ApplicationContext.Current.IsConfigured && GlobalSettings.DebugMode)
|
||||
{
|
||||
_mw.Start(Directory.GetDirectories(IOHelper.MapPath("~/App_Plugins/")));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnApplicationEnd(object sender, EventArgs e)
|
||||
{
|
||||
base.OnApplicationEnd(sender, e);
|
||||
|
||||
_mw.Dispose();
|
||||
}
|
||||
|
||||
protected override IBootManager GetBootManager()
|
||||
{
|
||||
return new WebBootManager(this);
|
||||
|
||||
Reference in New Issue
Block a user