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/Media/*
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.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 ""(.*)\""")]
public void GivenIHaveTenantOnSiteAsName(string shellName, string hostName, string siteName) {
var webApp = Binding<WebAppHosting>();
@@ -76,7 +64,6 @@ namespace Orchard.Specs.Bindings {
using (var environment = MvcApplication.CreateStandaloneEnvironment("Default")) {
environment.Resolve<IShellSettingsManager>().SaveSettings(shellSettings);
}
MvcApplication.Host.Reinitialize_Obsolete();
});
webApp.WhenIGoToPathOnHost("Setup", hostName);

View File

@@ -1,7 +1,9 @@
using System.IO;
using System.Linq;
using Moq;
using NUnit.Framework;
using Orchard.Environment.Configuration;
using Orchard.Events;
namespace Orchard.Tests.Environment.Configuration {
[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");
IShellSettingsManager loader = new ShellSettingsManager(_appData);
IShellSettingsManager loader = new ShellSettingsManager(_appData, new Mock<IEventBus>().Object);
var settings = loader.LoadSettings().Single();
Assert.That(settings, Is.Not.Null);
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\\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();
Assert.That(settings.Count(), Is.EqualTo(2));
@@ -59,8 +61,8 @@ namespace Orchard.Tests.Environment.Configuration {
[Test]
public void NewSettingsCanBeStored() {
_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"};
Assert.That(loader.LoadSettings().Count(), Is.EqualTo(1));

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Web;
using System.Collections.Generic;
using Orchard.Environment.Configuration;
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

@@ -27,6 +27,5 @@ namespace Orchard.Environment {
/// Services may be resolved from within this instance to configure and initialize it's storage.
/// </summary>
IStandaloneEnvironment CreateStandaloneEnvironment(ShellSettings shellSettings);
}
}
}

View File

@@ -1,11 +1,12 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Orchard.Logging;
namespace Orchard.Events {
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;
Logger = NullLogger.Instance;
}
@@ -15,7 +16,7 @@ namespace Orchard.Events {
#region Implementation of IEventBus
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

View File

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