Orchard host recreates shell context based on significant events

At the moment the events related to shell settings and shell descriptor changes will cause the host to rebuild their compositions.

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-04-28 12:44:16 -07:00
parent 963c159743
commit cadfd78c55
11 changed files with 53 additions and 29 deletions

View File

@@ -12,3 +12,4 @@ glob:src/Orchard.Web/Modules/Orchard.DevTools/Module.txt
glob:src/Orchard.Web/Modules/Orchard.Sandbox/Module.txt glob:src/Orchard.Web/Modules/Orchard.Sandbox/Module.txt
glob:src/Orchard.Web/Media/* glob:src/Orchard.Web/Media/*
glob:desktop.ini glob:desktop.ini
glob:src/Orchard.Azure.suo

View File

@@ -47,23 +47,11 @@ namespace Orchard.Specs.Bindings {
descriptor.EnabledFeatures.Concat(new[] { new ShellFeature { Name = name } }), descriptor.EnabledFeatures.Concat(new[] { new ShellFeature { Name = name } }),
descriptor.Parameters); descriptor.Parameters);
} }
Trace.WriteLine("This call to Host.Reinitialize should not be needed, eventually");
MvcApplication.Host.Reinitialize_Obsolete();
}); });
} }
[When(@"I cycle the app domain")]
public void WhenICycleTheAppDomain() {
var webApp = Binding<WebAppHosting>();
webApp.Host.Execute(() => {
Trace.WriteLine("This call to Host.Reinitialize should not be needed, eventually");
MvcApplication.Host.Reinitialize_Obsolete();
});
}
[Given(@"I have tenant ""(.*)\"" on ""(.*)\"" as ""(.*)\""")] [Given(@"I have tenant ""(.*)\"" on ""(.*)\"" as ""(.*)\""")]
public void GivenIHaveTenantOnSiteAsName(string shellName, string hostName, string siteName) { public void GivenIHaveTenantOnSiteAsName(string shellName, string hostName, string siteName) {
var webApp = Binding<WebAppHosting>(); var webApp = Binding<WebAppHosting>();
@@ -76,7 +64,6 @@ namespace Orchard.Specs.Bindings {
using (var environment = MvcApplication.CreateStandaloneEnvironment("Default")) { using (var environment = MvcApplication.CreateStandaloneEnvironment("Default")) {
environment.Resolve<IShellSettingsManager>().SaveSettings(shellSettings); environment.Resolve<IShellSettingsManager>().SaveSettings(shellSettings);
} }
MvcApplication.Host.Reinitialize_Obsolete();
}); });
webApp.WhenIGoToPathOnHost("Setup", hostName); webApp.WhenIGoToPathOnHost("Setup", hostName);

View File

@@ -1,7 +1,9 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Moq;
using NUnit.Framework; using NUnit.Framework;
using Orchard.Environment.Configuration; using Orchard.Environment.Configuration;
using Orchard.Events;
namespace Orchard.Tests.Environment.Configuration { namespace Orchard.Tests.Environment.Configuration {
[TestFixture] [TestFixture]
@@ -26,7 +28,7 @@ namespace Orchard.Tests.Environment.Configuration {
_appData.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SQLite\r\nDataConnectionString: something else"); _appData.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SQLite\r\nDataConnectionString: something else");
IShellSettingsManager loader = new ShellSettingsManager(_appData); IShellSettingsManager loader = new ShellSettingsManager(_appData, new Mock<IEventBus>().Object);
var settings = loader.LoadSettings().Single(); var settings = loader.LoadSettings().Single();
Assert.That(settings, Is.Not.Null); Assert.That(settings, Is.Not.Null);
Assert.That(settings.Name, Is.EqualTo("Default")); Assert.That(settings.Name, Is.EqualTo("Default"));
@@ -41,7 +43,7 @@ namespace Orchard.Tests.Environment.Configuration {
_appData.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SQLite\r\nDataConnectionString: something else"); _appData.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SQLite\r\nDataConnectionString: something else");
_appData.CreateFile("Sites\\Another\\Settings.txt", "Name: Another\r\nDataProvider: SQLite2\r\nDataConnectionString: something else2"); _appData.CreateFile("Sites\\Another\\Settings.txt", "Name: Another\r\nDataProvider: SQLite2\r\nDataConnectionString: something else2");
IShellSettingsManager loader = new ShellSettingsManager(_appData); IShellSettingsManager loader = new ShellSettingsManager(_appData, new Mock<IEventBus>().Object);
var settings = loader.LoadSettings(); var settings = loader.LoadSettings();
Assert.That(settings.Count(), Is.EqualTo(2)); Assert.That(settings.Count(), Is.EqualTo(2));
@@ -60,7 +62,7 @@ namespace Orchard.Tests.Environment.Configuration {
public void NewSettingsCanBeStored() { public void NewSettingsCanBeStored() {
_appData.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SQLite\r\nDataConnectionString: something else"); _appData.CreateFile("Sites\\Default\\Settings.txt", "Name: Default\r\nDataProvider: SQLite\r\nDataConnectionString: something else");
IShellSettingsManager loader = new ShellSettingsManager(_appData); IShellSettingsManager loader = new ShellSettingsManager(_appData, new Mock<IEventBus>().Object);
var foo = new ShellSettings {Name = "Foo", DataProvider = "Bar", DataConnectionString = "Quux"}; var foo = new ShellSettings {Name = "Foo", DataProvider = "Bar", DataConnectionString = "Quux"};
Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1)); Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1));

View File

@@ -86,7 +86,7 @@ namespace Orchard.Core.Settings.Topology {
} }
_eventBus.Notify( _eventBus.Notify(
typeof(IShellDescriptorManager).FullName + ".UpdateShellDescriptor", "ShellDescriptor_Changed",
null); null);
} }
} }

View File

@@ -173,9 +173,6 @@ namespace Orchard.Setup.Controllers {
_shellSettingsManager.SaveSettings(shellSettings); _shellSettingsManager.SaveSettings(shellSettings);
// MultiTenancy: This will not be needed when host listens to event bus
_orchardHost.Reinitialize_Obsolete();
// redirect to the welcome page. // redirect to the welcome page.
return Redirect("~/"); return Redirect("~/");
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Yaml.Serialization; using System.Yaml.Serialization;
using Orchard.Events;
using Orchard.Localization; using Orchard.Localization;
namespace Orchard.Environment.Configuration { namespace Orchard.Environment.Configuration {
@@ -13,10 +14,12 @@ namespace Orchard.Environment.Configuration {
public class ShellSettingsManager : IShellSettingsManager { public class ShellSettingsManager : IShellSettingsManager {
private readonly IAppDataFolder _appDataFolder; private readonly IAppDataFolder _appDataFolder;
private readonly IEventBus _eventBus;
Localizer T { get; set; } Localizer T { get; set; }
public ShellSettingsManager(IAppDataFolder appDataFolder) { public ShellSettingsManager(IAppDataFolder appDataFolder, IEventBus eventBus) {
_appDataFolder = appDataFolder; _appDataFolder = appDataFolder;
_eventBus = eventBus;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -32,6 +35,8 @@ namespace Orchard.Environment.Configuration {
var filePath = Path.Combine(Path.Combine("Sites", settings.Name), "Settings.txt"); var filePath = Path.Combine(Path.Combine("Sites", settings.Name), "Settings.txt");
_appDataFolder.CreateFile(filePath, ComposeSettings(settings)); _appDataFolder.CreateFile(filePath, ComposeSettings(settings));
_eventBus.Notify("ShellSettings_Saved", null);
} }
IEnumerable<ShellSettings> LoadSettings() { IEnumerable<ShellSettings> LoadSettings() {

View File

@@ -1,7 +1,7 @@
using System;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Autofac; using Autofac;
using Autofac.Integration.Web;
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.Environment.Configuration; using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
@@ -131,5 +131,13 @@ namespace Orchard.Environment {
} }
} }
public void Process(string messageName, IDictionary<string, string> eventData) {
if (messageName == "ShellSettings_Saved") {
_current = null;
}
else if (messageName == "ShellDescriptor_Changed") {
_current = null;
}
}
} }
} }

View File

@@ -0,0 +1,23 @@
using System.Collections.Generic;
using Orchard.Events;
namespace Orchard.Environment {
/// <summary>
/// This handler forwards calls to the IOrchardHost when it is an instance of DefaultOrchardHost.
/// The reason for this is to avoid adding IEventBusHandler, because DefaultOrchardHost is a component
/// that should not be detected and registererd automatically as an IDependency.
/// </summary>
public class DefaultOrchardHostEventSink : IEventBusHandler {
private readonly DefaultOrchardHost _host;
public DefaultOrchardHostEventSink(IOrchardHost host) {
_host = host as DefaultOrchardHost;
}
public void Process(string messageName, IDictionary<string, string> eventData) {
if (_host != null) {
_host.Process(messageName, eventData);
}
}
}
}

View File

@@ -28,5 +28,4 @@ namespace Orchard.Environment {
/// </summary> /// </summary>
IStandaloneEnvironment CreateStandaloneEnvironment(ShellSettings shellSettings); IStandaloneEnvironment CreateStandaloneEnvironment(ShellSettings shellSettings);
} }
} }

View File

@@ -1,11 +1,12 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using Orchard.Logging; using Orchard.Logging;
namespace Orchard.Events { namespace Orchard.Events {
public class DefaultOrchardEventBus : IEventBus { public class DefaultOrchardEventBus : IEventBus {
private readonly IEnumerable<IEventBusHandler> _handlers; private readonly Func<IEnumerable<IEventBusHandler>> _handlers;
public DefaultOrchardEventBus(IEnumerable<IEventBusHandler> handlers) { public DefaultOrchardEventBus(Func<IEnumerable<IEventBusHandler>> handlers) {
_handlers = handlers; _handlers = handlers;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
} }
@@ -15,7 +16,7 @@ namespace Orchard.Events {
#region Implementation of IEventBus #region Implementation of IEventBus
public void Notify(string messageName, IDictionary<string, string> eventData) { public void Notify(string messageName, IDictionary<string, string> eventData) {
_handlers.Invoke(handler => handler.Process(messageName, eventData), Logger); _handlers().Invoke(handler => handler.Process(messageName, eventData), Logger);
} }
#endregion #endregion

View File

@@ -163,6 +163,7 @@
<Compile Include="Data\SessionFactoryHolder.cs" /> <Compile Include="Data\SessionFactoryHolder.cs" />
<Compile Include="Environment\AutofacUtil\LifetimeScopeContainer.cs" /> <Compile Include="Environment\AutofacUtil\LifetimeScopeContainer.cs" />
<Compile Include="Environment\Configuration\TenantState.cs" /> <Compile Include="Environment\Configuration\TenantState.cs" />
<Compile Include="Environment\DefaultOrchardHostEventSink.cs" />
<Compile Include="Environment\RunningShellTable.cs" /> <Compile Include="Environment\RunningShellTable.cs" />
<Compile Include="Environment\AutofacUtil\DynamicProxy2\DynamicProxyContext.cs" /> <Compile Include="Environment\AutofacUtil\DynamicProxy2\DynamicProxyContext.cs" />
<Compile Include="Environment\AutofacUtil\DynamicProxy2\DynamicProxyExtensions.cs" /> <Compile Include="Environment\AutofacUtil\DynamicProxy2\DynamicProxyExtensions.cs" />