mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Slightly refactor AppDomain restart code
--HG-- branch : dev
This commit is contained in:
@@ -46,7 +46,8 @@
|
||||
<add namespace="System.Web.Routing"/>
|
||||
<add namespace="System.Linq"/>
|
||||
<add namespace="System.Collections.Generic"/>
|
||||
</namespaces>
|
||||
<add namespace="Orchard.Mvc.Html"/>
|
||||
</namespaces>
|
||||
</pages>
|
||||
</system.web>
|
||||
<system.web.extensions/>
|
||||
|
@@ -26,7 +26,6 @@ namespace Orchard.Environment {
|
||||
private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator;
|
||||
private readonly ICacheManager _cacheManager;
|
||||
private readonly object _syncLock = new object();
|
||||
private readonly SetupExtensionsContext _setupExtensionsContext = new SetupExtensionsContext();
|
||||
|
||||
private IEnumerable<ShellContext> _current;
|
||||
|
||||
@@ -134,7 +133,7 @@ namespace Orchard.Environment {
|
||||
}
|
||||
|
||||
private void SetupExtensions() {
|
||||
_extensionLoaderCoordinator.SetupExtensions(_setupExtensionsContext);
|
||||
_extensionLoaderCoordinator.SetupExtensions();
|
||||
}
|
||||
|
||||
private void MonitorExtensions() {
|
||||
@@ -152,22 +151,6 @@ namespace Orchard.Environment {
|
||||
protected virtual void BeginRequest() {
|
||||
MonitorExtensions();
|
||||
BuildCurrent();
|
||||
|
||||
// If setting up extensions/modules requires an AppDomain restart, it's very unlikely the
|
||||
// current request can be processed correctly. So, we redirect to the same URL, so that the
|
||||
// new request will come to the newly started AppDomain.
|
||||
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 {
|
||||
HttpContext.Current.Response.WriteFile("~/Refresh.html");
|
||||
HttpContext.Current.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -44,7 +44,7 @@ namespace Orchard.Environment.Extensions {
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public void SetupExtensions(SetupExtensionsContext setupExtensionsContext) {
|
||||
public void SetupExtensions() {
|
||||
Logger.Information("Start loading extensions...");
|
||||
|
||||
var context = CreateLoadingContext();
|
||||
@@ -71,9 +71,18 @@ namespace Orchard.Environment.Extensions {
|
||||
// And finally save the new entries in the dependencies folder
|
||||
_dependenciesFolder.StoreDescriptors(context.NewDependencies);
|
||||
|
||||
setupExtensionsContext.RestartAppDomain = context.RestartAppDomain;
|
||||
|
||||
Logger.Information("Done loading extensions...");
|
||||
|
||||
// Very last step: Notify the host environment to restart the AppDomain if needed
|
||||
if (context.ResetSiteCompilation) {
|
||||
Logger.Information("Reset site compilation state required.");
|
||||
_hostEnvironment.ResetSiteCompilation();
|
||||
}
|
||||
|
||||
if (context.RestartAppDomain) {
|
||||
Logger.Information("AppDomain restart required.");
|
||||
_hostEnvironment.RestartAppDomain();
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessExtension(ExtensionLoadingContext context, ExtensionDescriptor extension) {
|
||||
@@ -277,16 +286,6 @@ namespace Orchard.Environment.Extensions {
|
||||
foreach (var action in ctx.CopyActions) {
|
||||
action();
|
||||
}
|
||||
|
||||
if (ctx.RestartAppDomain) {
|
||||
Logger.Information("AppDomain restart required.");
|
||||
_hostEnvironment.RestartAppDomain();
|
||||
}
|
||||
|
||||
if (ctx.ResetSiteCompilation) {
|
||||
Logger.Information("Reset site compilation state required.");
|
||||
_hostEnvironment.ResetSiteCompilation();
|
||||
}
|
||||
}
|
||||
|
||||
public void MonitorExtensions(Action<IVolatileToken> monitor) {
|
||||
|
@@ -2,12 +2,8 @@
|
||||
using Orchard.Caching;
|
||||
|
||||
namespace Orchard.Environment.Extensions {
|
||||
public class SetupExtensionsContext {
|
||||
public bool RestartAppDomain { get; set; }
|
||||
}
|
||||
|
||||
public interface IExtensionLoaderCoordinator {
|
||||
void SetupExtensions(SetupExtensionsContext setupExtensionsContext);
|
||||
void SetupExtensions();
|
||||
void MonitorExtensions(Action<IVolatileToken> monitor);
|
||||
}
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Services;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
/// <summary>
|
||||
@@ -37,6 +39,20 @@ namespace Orchard.Environment {
|
||||
public void ResetSiteCompilation() {
|
||||
// Touch web.config
|
||||
File.SetLastWriteTimeUtc(MapPath("~/web.config"), _clock.UtcNow);
|
||||
|
||||
// If setting up extensions/modules requires an AppDomain restart, it's very unlikely the
|
||||
// current request can be processed correctly. So, we redirect to the same URL, so that the
|
||||
// new request will come to the newly started AppDomain.
|
||||
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 {
|
||||
HttpContext.Current.Response.WriteFile("~/Refresh.html");
|
||||
HttpContext.Current.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,6 +33,5 @@ namespace Orchard.Utility.Extensions {
|
||||
public static string ToUrlString(this HttpRequest request) {
|
||||
return string.Format("{0}://{1}{2}", request.Url.Scheme, request.Headers["Host"], request.RawUrl);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user