Redirect the request if the AppDomain needs to be restarted

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-01 12:12:39 -07:00
parent bafc6ab6f0
commit bf9e6f78f8
3 changed files with 28 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.Caching; using Orchard.Caching;
@@ -9,6 +10,7 @@ using Orchard.Environment.ShellBuilders;
using Orchard.Environment.State; using Orchard.Environment.State;
using Orchard.Environment.Descriptor; using Orchard.Environment.Descriptor;
using Orchard.Environment.Descriptor.Models; using Orchard.Environment.Descriptor.Models;
using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Mvc; using Orchard.Mvc;
using Orchard.Mvc.ViewEngines; using Orchard.Mvc.ViewEngines;
@@ -24,6 +26,7 @@ namespace Orchard.Environment {
private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator; private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator;
private readonly ICacheManager _cacheManager; private readonly ICacheManager _cacheManager;
private readonly object _syncLock = new object(); private readonly object _syncLock = new object();
private readonly SetupExtensionsContext _setupExtensionsContext = new SetupExtensionsContext();
private IEnumerable<ShellContext> _current; private IEnumerable<ShellContext> _current;
@@ -44,9 +47,11 @@ namespace Orchard.Environment {
_cacheManager = cacheManager; _cacheManager = cacheManager;
_controllerBuilder = controllerBuilder; _controllerBuilder = controllerBuilder;
T = NullLocalizer.Instance;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
} }
public Localizer T { get; set; }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public IList<ShellContext> Current { public IList<ShellContext> Current {
@@ -129,10 +134,13 @@ namespace Orchard.Environment {
} }
private void SetupExtensions() { private void SetupExtensions() {
_extensionLoaderCoordinator.SetupExtensions(); _extensionLoaderCoordinator.SetupExtensions(_setupExtensionsContext);
} }
private void MonitorExtensions() { private void MonitorExtensions() {
// This is a "fake" cache entry to allow the extension loader coordinator
// notify us (by resetting _current to "null") when an extension has changed
// on disk, and we need to reload new/updated extensions.
_cacheManager.Get("OrchardHost_Extensions", _cacheManager.Get("OrchardHost_Extensions",
ctx => { ctx => {
_extensionLoaderCoordinator.MonitorExtensions(ctx.Monitor); _extensionLoaderCoordinator.MonitorExtensions(ctx.Monitor);
@@ -144,6 +152,14 @@ namespace Orchard.Environment {
protected virtual void BeginRequest() { protected virtual void BeginRequest() {
MonitorExtensions(); MonitorExtensions();
BuildCurrent(); BuildCurrent();
if (_setupExtensionsContext.RestartAppDomain) {
if (HttpContext.Current != null)
// Don't redirect posts...
if (HttpContext.Current.Request.RequestType == "GET")
HttpContext.Current.Response.Redirect(HttpContext.Current.Request.ToUrlString(), true/*endResponse*/);
else
throw new HttpException(T("Orchard is temporarily unavailable as a change in configuration requires a restart. A simple page refresh usually solve this issue.").Text);
}
} }

View File

@@ -41,8 +41,8 @@ namespace Orchard.Environment.Extensions {
public Localizer T { get; set; } public Localizer T { get; set; }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public void SetupExtensions() { public void SetupExtensions(SetupExtensionsContext setupExtensionsContext) {
Logger.Information("Loading extensions."); Logger.Information("Start loading extensions...");
var context = CreateLoadingContext(); var context = CreateLoadingContext();
@@ -67,7 +67,10 @@ namespace Orchard.Environment.Extensions {
// And finally save the new entries in the dependencies folder // And finally save the new entries in the dependencies folder
_dependenciesFolder.StoreDescriptors(context.NewDependencies); _dependenciesFolder.StoreDescriptors(context.NewDependencies);
Logger.Information("Done loading extensions.");
setupExtensionsContext.RestartAppDomain = context.RestartAppDomain;
Logger.Information("Done loading extensions...");
} }
private void ProcessExtension(ExtensionLoadingContext context, ExtensionDescriptor extension) { private void ProcessExtension(ExtensionLoadingContext context, ExtensionDescriptor extension) {

View File

@@ -2,8 +2,12 @@
using Orchard.Caching; using Orchard.Caching;
namespace Orchard.Environment.Extensions { namespace Orchard.Environment.Extensions {
public class SetupExtensionsContext {
public bool RestartAppDomain { get; set; }
}
public interface IExtensionLoaderCoordinator { public interface IExtensionLoaderCoordinator {
void SetupExtensions(); void SetupExtensions(SetupExtensionsContext setupExtensionsContext);
void MonitorExtensions(Action<IVolatileToken> monitor); void MonitorExtensions(Action<IVolatileToken> monitor);
} }
} }