mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
Fix feature enable from command line
When enabling features from the command line, we need a way to signal the WebHost app that the OrchardHost needs to re-compute the list of activated features. We enable this by touching and monitoring a local file in "App_Data". The file is touched whenever a feature is enabled or disabled, and is monitored by the OrchardHost to watch for a re-initialization. --HG-- branch : dev
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Caching;
|
||||
@@ -19,9 +18,9 @@ using Orchard.Utility.Extensions;
|
||||
namespace Orchard.Environment {
|
||||
public class DefaultOrchardHost : IOrchardHost, IShellSettingsManagerEventHandler, IShellDescriptorManagerEventHandler {
|
||||
private readonly ControllerBuilder _controllerBuilder;
|
||||
private readonly IHostLocalRestart _hostLocalRestart;
|
||||
private readonly IShellSettingsManager _shellSettingsManager;
|
||||
private readonly IShellContextFactory _shellContextFactory;
|
||||
private readonly IShellDescriptorCache _shellDescriptorCache;
|
||||
private readonly IRunningShellTable _runningShellTable;
|
||||
private readonly IProcessingEngine _processingEngine;
|
||||
private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator;
|
||||
@@ -33,21 +32,21 @@ namespace Orchard.Environment {
|
||||
public DefaultOrchardHost(
|
||||
IShellSettingsManager shellSettingsManager,
|
||||
IShellContextFactory shellContextFactory,
|
||||
IShellDescriptorCache shellDescriptorCache,
|
||||
IRunningShellTable runningShellTable,
|
||||
IProcessingEngine processingEngine,
|
||||
IExtensionLoaderCoordinator extensionLoaderCoordinator,
|
||||
ICacheManager cacheManager,
|
||||
ControllerBuilder controllerBuilder) {
|
||||
ControllerBuilder controllerBuilder,
|
||||
IHostLocalRestart hostLocalRestart ) {
|
||||
|
||||
_shellSettingsManager = shellSettingsManager;
|
||||
_shellContextFactory = shellContextFactory;
|
||||
_shellDescriptorCache = shellDescriptorCache;
|
||||
_runningShellTable = runningShellTable;
|
||||
_processingEngine = processingEngine;
|
||||
_extensionLoaderCoordinator = extensionLoaderCoordinator;
|
||||
_cacheManager = cacheManager;
|
||||
_controllerBuilder = controllerBuilder;
|
||||
_hostLocalRestart = hostLocalRestart;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -152,7 +151,7 @@ namespace Orchard.Environment {
|
||||
_cacheManager.Get("OrchardHost_Extensions",
|
||||
ctx => {
|
||||
_extensionLoaderCoordinator.MonitorExtensions(ctx.Monitor);
|
||||
_shellDescriptorCache.Monitor(ctx.Monitor);
|
||||
_hostLocalRestart.Monitor(ctx.Monitor);
|
||||
_current = null;
|
||||
return "";
|
||||
});
|
||||
|
||||
@@ -27,11 +27,6 @@ namespace Orchard.Environment.Descriptor {
|
||||
/// Loss of storage is expected.
|
||||
/// </summary>
|
||||
void Store(string shellName, ShellDescriptor descriptor);
|
||||
|
||||
/// <summary>
|
||||
/// Monitor changes on the persistent storage.
|
||||
/// </summary>
|
||||
void Monitor(Action<IVolatileToken> monitor);
|
||||
}
|
||||
|
||||
public class ShellDescriptorCache : IShellDescriptorCache {
|
||||
@@ -104,10 +99,6 @@ namespace Orchard.Environment.Descriptor {
|
||||
_appDataFolder.CreateFile(DescriptorCacheFileName, saveWriter.ToString());
|
||||
}
|
||||
|
||||
public void Monitor(Action<IVolatileToken> monitor) {
|
||||
monitor(_appDataFolder.WhenPathChanges(DescriptorCacheFileName));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void VerifyCacheFile() {
|
||||
|
||||
52
src/Orchard/Environment/IHostLocalRestart.cs
Normal file
52
src/Orchard/Environment/IHostLocalRestart.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.Logging;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
public interface IHostLocalRestart {
|
||||
/// <summary>
|
||||
/// Monitor changes on the persistent storage.
|
||||
/// </summary>
|
||||
void Monitor(Action<IVolatileToken> monitor);
|
||||
}
|
||||
|
||||
public class DefaultHostLocalRestart : IHostLocalRestart, IShellDescriptorManagerEventHandler, IShellSettingsManagerEventHandler {
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
private const string fileName = "hrestart.txt";
|
||||
|
||||
public DefaultHostLocalRestart(IAppDataFolder appDataFolder) {
|
||||
_appDataFolder = appDataFolder;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public void Monitor(Action<IVolatileToken> monitor) {
|
||||
if (!_appDataFolder.FileExists(fileName))
|
||||
TouchFile();
|
||||
|
||||
monitor(_appDataFolder.WhenPathChanges(fileName));
|
||||
}
|
||||
|
||||
void IShellSettingsManagerEventHandler.Saved(ShellSettings settings) {
|
||||
TouchFile();
|
||||
}
|
||||
|
||||
void IShellDescriptorManagerEventHandler.Changed(ShellDescriptor descriptor) {
|
||||
TouchFile();
|
||||
}
|
||||
|
||||
private void TouchFile() {
|
||||
try {
|
||||
_appDataFolder.CreateFile(fileName, "Host Restart");
|
||||
}
|
||||
catch(Exception e) {
|
||||
Logger.Warning("Error updateting file '{0}': {1}", fileName, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ namespace Orchard.Environment {
|
||||
builder.RegisterType<DefaultOrchardEventBus>().As<IEventBus>().SingleInstance();
|
||||
builder.RegisterType<DefaultCacheHolder>().As<ICacheHolder>().SingleInstance();
|
||||
builder.RegisterType<DefaultHostEnvironment>().As<IHostEnvironment>().SingleInstance();
|
||||
builder.RegisterType<DefaultHostLocalRestart>().As<IHostLocalRestart>().SingleInstance();
|
||||
builder.RegisterType<DefaultBuildManager>().As<IBuildManager>().SingleInstance();
|
||||
builder.RegisterType<WebFormVirtualPathProvider>().As<ICustomVirtualPathProvider>().SingleInstance();
|
||||
builder.RegisterType<DynamicModuleVirtualPathProvider>().As<ICustomVirtualPathProvider>().SingleInstance();
|
||||
|
||||
@@ -368,6 +368,7 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\DataMigrations\FrameworkDataMigration.cs" />
|
||||
<Compile Include="Environment\IHostLocalRestart.cs" />
|
||||
<Compile Include="Environment\IShellContainerRegistrations.cs" />
|
||||
<Compile Include="FileSystems\Dependencies\DynamicModuleVirtualPathProvider.cs" />
|
||||
<Compile Include="Services\IHtmlFilter.cs" />
|
||||
|
||||
Reference in New Issue
Block a user