Removing some obsolete install/feature state code

Changing blog/page slug updater to use orchard shell events interface
Changing default role/permission to use feature install event
Renaming state manager/provider to be consistent with other components

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-05-28 14:01:10 -07:00
parent 13f44990ca
commit 52ef9f3c8c
22 changed files with 77 additions and 163 deletions

View File

@@ -10,6 +10,7 @@
<ALIGN_MULTIPLE_DECLARATION>False</ALIGN_MULTIPLE_DECLARATION> <ALIGN_MULTIPLE_DECLARATION>False</ALIGN_MULTIPLE_DECLARATION>
<ANONYMOUS_METHOD_DECLARATION_BRACES>END_OF_LINE</ANONYMOUS_METHOD_DECLARATION_BRACES> <ANONYMOUS_METHOD_DECLARATION_BRACES>END_OF_LINE</ANONYMOUS_METHOD_DECLARATION_BRACES>
<CASE_BLOCK_BRACES>END_OF_LINE</CASE_BLOCK_BRACES> <CASE_BLOCK_BRACES>END_OF_LINE</CASE_BLOCK_BRACES>
<EMPTY_BLOCK_STYLE>TOGETHER</EMPTY_BLOCK_STYLE>
<FORCE_FIXED_BRACES_STYLE>ALWAYS_ADD</FORCE_FIXED_BRACES_STYLE> <FORCE_FIXED_BRACES_STYLE>ALWAYS_ADD</FORCE_FIXED_BRACES_STYLE>
<FORCE_FOR_BRACES_STYLE>ALWAYS_ADD</FORCE_FOR_BRACES_STYLE> <FORCE_FOR_BRACES_STYLE>ALWAYS_ADD</FORCE_FOR_BRACES_STYLE>
<FORCE_FOREACH_BRACES_STYLE>ALWAYS_ADD</FORCE_FOREACH_BRACES_STYLE> <FORCE_FOREACH_BRACES_STYLE>ALWAYS_ADD</FORCE_FOREACH_BRACES_STYLE>

View File

@@ -169,7 +169,7 @@ namespace Orchard.Specs.Bindings {
foreach (var row in table.Rows) { foreach (var row in table.Rows) {
var r = row; var r = row;
var input = inputs.First(x => x.GetAttributeValue("name", x.GetAttributeValue("id", "")) == r["name"]); var input = inputs.FirstOrDefault(x => x.GetAttributeValue("name", x.GetAttributeValue("id", "")) == r["name"]);
Assert.That(input, Is.Not.Null, "Unable to locate <input> name {0} in page html:\r\n\r\n{1}", r["name"], Details.ResponseText); Assert.That(input, Is.Not.Null, "Unable to locate <input> name {0} in page html:\r\n\r\n{1}", r["name"], Details.ResponseText);
var inputType = input.GetAttributeValue("type", ""); var inputType = input.GetAttributeValue("type", "");
switch(inputType) { switch(inputType) {

View File

@@ -52,6 +52,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Autofac, Version=2.1.13.813, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL"> <Reference Include="Autofac, Version=2.1.13.813, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">

View File

@@ -147,7 +147,7 @@ namespace Orchard.Tests.Modules.Settings.Topology {
[Test] [Test]
public void ManagerReturnsStateForFeaturesInDescriptor() { public void ManagerReturnsStateForFeaturesInDescriptor() {
var descriptorManager = _container.Resolve<IShellDescriptorManager>(); var descriptorManager = _container.Resolve<IShellDescriptorManager>();
var stateManager = _container.Resolve<IShellStateProvider>(); var stateManager = _container.Resolve<IShellStateManager>();
var state = stateManager.GetShellState(); var state = stateManager.GetShellState();
Assert.That(state.Features.Count(), Is.EqualTo(0)); Assert.That(state.Features.Count(), Is.EqualTo(0));
descriptorManager.UpdateShellDescriptor( descriptorManager.UpdateShellDescriptor(

View File

@@ -9,24 +9,20 @@ using Orchard.Environment.Topology.Models;
using Orchard.Events; using Orchard.Events;
using Orchard.Tests.Utility; using Orchard.Tests.Utility;
namespace Orchard.Tests.Environment.State namespace Orchard.Tests.Environment.State {
{
[TestFixture] [TestFixture]
public class DefaultProcessingEngineTests public class DefaultProcessingEngineTests {
{
private IContainer _container; private IContainer _container;
private ShellContext _shellContext; private ShellContext _shellContext;
[SetUp] [SetUp]
public void Init() public void Init() {
{
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
builder.RegisterType<DefaultProcessingEngine>().As<IProcessingEngine>(); builder.RegisterType<DefaultProcessingEngine>().As<IProcessingEngine>();
builder.RegisterAutoMocking(); builder.RegisterAutoMocking();
_container = builder.Build(); _container = builder.Build();
_shellContext = new ShellContext _shellContext = new ShellContext {
{
Descriptor = new ShellDescriptor(), Descriptor = new ShellDescriptor(),
Settings = new ShellSettings(), Settings = new ShellSettings(),
LifetimeScope = _container.BeginLifetimeScope(), LifetimeScope = _container.BeginLifetimeScope(),
@@ -39,16 +35,14 @@ namespace Orchard.Tests.Environment.State
} }
[Test] [Test]
public void NoTasksPendingByDefault() public void NoTasksPendingByDefault() {
{
var engine = _container.Resolve<IProcessingEngine>(); var engine = _container.Resolve<IProcessingEngine>();
var pending = engine.AreTasksPending(); var pending = engine.AreTasksPending();
Assert.That(pending, Is.False); Assert.That(pending, Is.False);
} }
[Test] [Test]
public void ExecuteTaskIsSafeToCallWhenItDoesNothing() public void ExecuteTaskIsSafeToCallWhenItDoesNothing() {
{
var engine = _container.Resolve<IProcessingEngine>(); var engine = _container.Resolve<IProcessingEngine>();
var pending1 = engine.AreTasksPending(); var pending1 = engine.AreTasksPending();
engine.ExecuteNextTask(); engine.ExecuteNextTask();
@@ -58,11 +52,10 @@ namespace Orchard.Tests.Environment.State
} }
[Test] [Test]
public void CallingAddTaskReturnsResultIdentifierAndCausesPendingToBeTrue() public void CallingAddTaskReturnsResultIdentifierAndCausesPendingToBeTrue() {
{
var engine = _container.Resolve<IProcessingEngine>(); var engine = _container.Resolve<IProcessingEngine>();
var pending1 = engine.AreTasksPending(); var pending1 = engine.AreTasksPending();
var resultId = engine.AddTask(null, null, null, null); var resultId = engine.AddTask(new ShellSettings {Name = "Default"}, null, null, null);
var pending2 = engine.AreTasksPending(); var pending2 = engine.AreTasksPending();
Assert.That(pending1, Is.False); Assert.That(pending1, Is.False);
Assert.That(resultId, Is.Not.Null); Assert.That(resultId, Is.Not.Null);
@@ -71,10 +64,9 @@ namespace Orchard.Tests.Environment.State
} }
[Test] [Test]
public void CallingExecuteCausesEventToFireAndPendingFlagToBeCleared() public void CallingExecuteCausesEventToFireAndPendingFlagToBeCleared() {
{
_container.Mock<IEventBus>() _container.Mock<IEventBus>()
.Setup(x => x.Notify(It.IsAny<string>(), It.IsAny<Dictionary<string,object>>())); .Setup(x => x.Notify(It.IsAny<string>(), It.IsAny<Dictionary<string, object>>()));
var engine = _container.Resolve<IProcessingEngine>(); var engine = _container.Resolve<IProcessingEngine>();
var pending1 = engine.AreTasksPending(); var pending1 = engine.AreTasksPending();

View File

@@ -52,6 +52,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Autofac, Version=2.1.13.813, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL"> <Reference Include="Autofac, Version=2.1.13.813, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">

View File

@@ -1,3 +1,2 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BodyDisplayViewModel>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BodyDisplayViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%> <%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
</div>

View File

@@ -133,7 +133,7 @@
<Compile Include="Settings\Permissions.cs" /> <Compile Include="Settings\Permissions.cs" />
<Compile Include="Settings\State\Records\ShellFeatureStateRecord.cs" /> <Compile Include="Settings\State\Records\ShellFeatureStateRecord.cs" />
<Compile Include="Settings\State\Records\ShellStateRecord.cs" /> <Compile Include="Settings\State\Records\ShellStateRecord.cs" />
<Compile Include="Settings\State\ShellStateProvider.cs" /> <Compile Include="Settings\State\ShellStateManager.cs" />
<Compile Include="Settings\Topology\Records\ShellFeatureRecord.cs" /> <Compile Include="Settings\Topology\Records\ShellFeatureRecord.cs" />
<Compile Include="Settings\Topology\Records\ShellParameterRecord.cs" /> <Compile Include="Settings\Topology\Records\ShellParameterRecord.cs" />
<Compile Include="Settings\Topology\Records\ShellDescriptorRecord.cs" /> <Compile Include="Settings\Topology\Records\ShellDescriptorRecord.cs" />

View File

@@ -7,11 +7,11 @@ using Orchard.Environment.Topology;
using Orchard.Logging; using Orchard.Logging;
namespace Orchard.Core.Settings.State { namespace Orchard.Core.Settings.State {
public class ShellStateProvider : Component, IShellStateProvider { public class ShellStateManager : Component, IShellStateManager {
private readonly IRepository<ShellStateRecord> _shellStateRepository; private readonly IRepository<ShellStateRecord> _shellStateRepository;
private readonly IShellDescriptorManager _shellDescriptorManager; private readonly IShellDescriptorManager _shellDescriptorManager;
public ShellStateProvider( public ShellStateManager(
IRepository<ShellStateRecord> shellStateRepository, IRepository<ShellStateRecord> shellStateRepository,
IShellDescriptorManager shellDescriptorManager) { IShellDescriptorManager shellDescriptorManager) {
_shellStateRepository = shellStateRepository; _shellStateRepository = shellStateRepository;

View File

@@ -1,12 +1,12 @@
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Blogs.Services; using Orchard.Blogs.Services;
using Orchard.Environment.Extensions; using Orchard.Environment;
using Orchard.Tasks; using Orchard.Tasks;
namespace Orchard.Blogs.Routing { namespace Orchard.Blogs.Routing {
[UsedImplicitly] [UsedImplicitly]
public class BlogSlugConstraintUpdator : ExtensionManagerEvents, IBackgroundTask { public class BlogSlugConstraintUpdator : IOrchardShellEvents, IBackgroundTask {
private readonly IBlogSlugConstraint _blogSlugConstraint; private readonly IBlogSlugConstraint _blogSlugConstraint;
private readonly IBlogService _blogService; private readonly IBlogService _blogService;
@@ -15,13 +15,14 @@ namespace Orchard.Blogs.Routing {
_blogService = blogService; _blogService = blogService;
} }
public override void Activated(ExtensionEventContext context) { void IOrchardShellEvents.Activated() {
if (context.Extension.Descriptor.Name == "Orchard.Blogs") { Refresh();
Refresh();
}
} }
public void Sweep() { void IOrchardShellEvents.Terminating() {
}
void IBackgroundTask.Sweep() {
Refresh(); Refresh();
} }

View File

@@ -1,12 +1,12 @@
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Environment.Extensions; using Orchard.Environment;
using Orchard.Pages.Services; using Orchard.Pages.Services;
using Orchard.Tasks; using Orchard.Tasks;
namespace Orchard.Pages.Routing { namespace Orchard.Pages.Routing {
[UsedImplicitly] [UsedImplicitly]
public class PageSlugConstraintUpdator : ExtensionManagerEvents, IBackgroundTask { public class PageSlugConstraintUpdator : IOrchardShellEvents, IBackgroundTask {
private readonly IPageSlugConstraint _pageSlugConstraint; private readonly IPageSlugConstraint _pageSlugConstraint;
private readonly IPageService _pageService; private readonly IPageService _pageService;
@@ -15,18 +15,20 @@ namespace Orchard.Pages.Routing {
_pageService = pageService; _pageService = pageService;
} }
public override void Activated(ExtensionEventContext context) { void IOrchardShellEvents.Activated() {
if (context.Extension.Descriptor.Name == "Orchard.Pages") { Refresh();
Refresh();
}
} }
public void Sweep() { void IOrchardShellEvents.Terminating() {
}
void IBackgroundTask.Sweep() {
Refresh(); Refresh();
} }
private void Refresh() { private void Refresh() {
_pageSlugConstraint.SetSlugs(_pageService.Get(PageStatus.Published).Select(p => p.Slug)); _pageSlugConstraint.SetSlugs(_pageService.Get(PageStatus.Published).Select(p => p.Slug));
} }
} }
} }

View File

@@ -1,18 +1,19 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Environment.Extensions; using Orchard.Environment;
using Orchard.Environment.Extensions.Models;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Roles.Services; using Orchard.Roles.Services;
using Orchard.Security.Permissions; using Orchard.Security.Permissions;
namespace Orchard.Roles { namespace Orchard.Roles {
[UsedImplicitly] [UsedImplicitly]
public class Extension : ExtensionManagerEvents { public class DefaultRoleUpdater : IFeatureEventHandler {
private readonly IRoleService _roleService; private readonly IRoleService _roleService;
private readonly IEnumerable<IPermissionProvider> _permissionProviders; private readonly IEnumerable<IPermissionProvider> _permissionProviders;
public Extension( public DefaultRoleUpdater(
IRoleService roleService, IRoleService roleService,
IEnumerable<IPermissionProvider> permissionProviders) { IEnumerable<IPermissionProvider> permissionProviders) {
_roleService = roleService; _roleService = roleService;
@@ -23,18 +24,27 @@ namespace Orchard.Roles {
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public override void Enabled(ExtensionEventContext context) { void IFeatureEventHandler.Install(Feature feature) {
var extensionDisplayName = context.Extension.Descriptor.DisplayName ?? context.Extension.Descriptor.Name; AddDefaultRolesForFeature(feature);
}
void IFeatureEventHandler.Enable(Feature feature) {}
void IFeatureEventHandler.Disable(Feature feature) {}
void IFeatureEventHandler.Uninstall(Feature feature) {}
public void AddDefaultRolesForFeature(Feature feature) {
var featureName = feature.Descriptor.Name;
// when another module is being enabled, locate matching permission providers // when another module is being enabled, locate matching permission providers
var providersForEnabledModule = var providersForEnabledModule = _permissionProviders.Where(x => x.ModuleName == featureName);
_permissionProviders.Where(x => x.ModuleName == extensionDisplayName);
if (providersForEnabledModule.Any()) { if (providersForEnabledModule.Any()) {
Logger.Debug("Configuring default roles for module {0}", extensionDisplayName); Logger.Debug("Configuring default roles for module {0}", featureName);
} }
else { else {
Logger.Debug("No default roles for module {0}", extensionDisplayName); Logger.Debug("No default roles for module {0}", featureName);
} }
foreach (var permissionProvider in providersForEnabledModule) { foreach (var permissionProvider in providersForEnabledModule) {

View File

@@ -68,7 +68,7 @@
<Compile Include="AdminMenu.cs" /> <Compile Include="AdminMenu.cs" />
<Compile Include="Controllers\AdminController.cs" /> <Compile Include="Controllers\AdminController.cs" />
<Compile Include="Drivers\UserRolesDriver.cs" /> <Compile Include="Drivers\UserRolesDriver.cs" />
<Compile Include="Extension.cs" /> <Compile Include="DefaultRoleUpdater.cs" />
<Compile Include="Models\IUserRoles.cs" /> <Compile Include="Models\IUserRoles.cs" />
<Compile Include="Models\UserSimulation.cs" /> <Compile Include="Models\UserSimulation.cs" />
<Compile Include="Permissions.cs" /> <Compile Include="Permissions.cs" />

View File

@@ -80,7 +80,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Module.txt" /> <Content Include="Module.txt" />
<Content Include="Views\DisplayTemplates\Fields\Sandbox.BingMap.ascx" />
<Content Include="Views\Page\Edit.aspx" /> <Content Include="Views\Page\Edit.aspx" />
<Content Include="Views\Page\Create.aspx" /> <Content Include="Views\Page\Create.aspx" />
<Content Include="Views\Page\Show.aspx" /> <Content Include="Views\Page\Show.aspx" />

View File

@@ -132,9 +132,10 @@ namespace Orchard.Setup.Services {
var contentManager = environment.Resolve<IContentManager>(); var contentManager = environment.Resolve<IContentManager>();
// this needs to exit the standalone environment? rework this process entirely?
// simulate installation-time module activation events // simulate installation-time module activation events
var hackInstallationGenerator = environment.Resolve<IHackInstallationGenerator>(); //var hackInstallationGenerator = environment.Resolve<IHackInstallationGenerator>();
hackInstallationGenerator.GenerateInstallEvents(); //hackInstallationGenerator.GenerateInstallEvents();
// create home page as a CMS page // create home page as a CMS page
var page = contentManager.Create("page", VersionOptions.Draft); var page = contentManager.Create("page", VersionOptions.Draft);

View File

@@ -45,7 +45,6 @@ namespace Orchard.Setup {
builder.RegisterType<HelpCommand>().As<ICommandHandler>().InstancePerLifetimeScope(); builder.RegisterType<HelpCommand>().As<ICommandHandler>().InstancePerLifetimeScope();
// setup mode specific implementations of needed service interfaces // setup mode specific implementations of needed service interfaces
builder.RegisterType<NullHackInstallationGenerator>().As<IHackInstallationGenerator>().InstancePerLifetimeScope();
builder.RegisterType<SafeModeThemeService>().As<IThemeService>().InstancePerLifetimeScope(); builder.RegisterType<SafeModeThemeService>().As<IThemeService>().InstancePerLifetimeScope();
builder.RegisterType<SafeModeText>().As<IText>().InstancePerLifetimeScope(); builder.RegisterType<SafeModeText>().As<IText>().InstancePerLifetimeScope();
builder.RegisterType<SafeModeSiteService>().As<ISiteService>().InstancePerLifetimeScope(); builder.RegisterType<SafeModeSiteService>().As<ISiteService>().InstancePerLifetimeScope();
@@ -88,10 +87,6 @@ namespace Orchard.Setup {
public void UninstallTheme(string themeName) { } public void UninstallTheme(string themeName) { }
} }
class NullHackInstallationGenerator : IHackInstallationGenerator {
public void GenerateInstallEvents() { }
public void GenerateActivateEvents() { }
}
class SafeModeSiteService : ISiteService { class SafeModeSiteService : ISiteService {
public ISite GetSiteSettings() { public ISite GetSiteSettings() {

View File

@@ -1,54 +0,0 @@
using System.Collections.Generic;
using Orchard.Logging;
using Orchard.Utility.Extensions;
namespace Orchard.Environment.Extensions {
public interface IHackInstallationGenerator : IDependency {
void GenerateInstallEvents();
void GenerateActivateEvents();
}
public class HackInstallationGenerator : IHackInstallationGenerator {
private readonly IExtensionManager _extensionManager;
private readonly IEnumerable<IExtensionManagerEvents> _extensionEvents;
public HackInstallationGenerator(
IExtensionManager extensionManager,
IEnumerable<IExtensionManagerEvents> extensionEvents) {
_extensionManager = extensionManager;
_extensionEvents = extensionEvents;
Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
public void GenerateInstallEvents() {
//TEMP: this is really part of the extension manager's job. an extension
// install event is being simulated here on each web app startup
var enabled = new List<ExtensionEntry>();
foreach (var extension in _extensionManager.ActiveExtensions_Obsolete()) {
var context = new ExtensionEventContext {
Extension = extension,
EnabledExtensions = enabled.ToReadOnlyCollection(),
};
_extensionEvents.Invoke(x => x.Enabling(context), Logger);
enabled.Add(extension);
context.EnabledExtensions = enabled.ToReadOnlyCollection();
_extensionEvents.Invoke(x => x.Enabled(context), Logger);
}
}
public void GenerateActivateEvents() {
//TEMP: This is really part of the extension manager's job.
var extensions = _extensionManager.ActiveExtensions_Obsolete().ToReadOnlyCollection();
foreach (var extension in extensions) {
var context = new ExtensionEventContext {
Extension = extension,
EnabledExtensions = extensions,
};
_extensionEvents.Invoke(x => x.Activating(context), Logger);
_extensionEvents.Invoke(x => x.Activated(context), Logger);
}
}
}
}

View File

@@ -1,30 +0,0 @@
using System.Collections.Generic;
namespace Orchard.Environment.Extensions {
public interface IExtensionManagerEvents : IEvents {
void Enabling(ExtensionEventContext context);
void Enabled(ExtensionEventContext context);
void Disabling(ExtensionEventContext context);
void Disabled(ExtensionEventContext context);
void Activating(ExtensionEventContext context);
void Activated(ExtensionEventContext context);
void Deactivating(ExtensionEventContext context);
void Deactivated(ExtensionEventContext context);
}
public abstract class ExtensionManagerEvents : IExtensionManagerEvents {
public virtual void Enabling(ExtensionEventContext context) { }
public virtual void Enabled(ExtensionEventContext context) { }
public virtual void Disabling(ExtensionEventContext context) {}
public virtual void Disabled(ExtensionEventContext context) {}
public virtual void Activating(ExtensionEventContext context) {}
public virtual void Activated(ExtensionEventContext context) {}
public virtual void Deactivating(ExtensionEventContext context) {}
public virtual void Deactivated(ExtensionEventContext context) {}
}
public class ExtensionEventContext {
public ExtensionEntry Extension { get; set; }
public IEnumerable<ExtensionEntry> EnabledExtensions { get; set; }
}
}

View File

@@ -1,7 +1,7 @@
using Orchard.Environment.State.Models; using Orchard.Environment.State.Models;
namespace Orchard.Environment.State { namespace Orchard.Environment.State {
public interface IShellStateProvider : IDependency { public interface IShellStateManager : IDependency {
ShellState GetShellState(); ShellState GetShellState();
void UpdateEnabledState(ShellFeatureState featureState, ShellFeatureState.State value); void UpdateEnabledState(ShellFeatureState featureState, ShellFeatureState.State value);
void UpdateInstalledState(ShellFeatureState featureState, ShellFeatureState.State value); void UpdateInstalledState(ShellFeatureState featureState, ShellFeatureState.State value);

View File

@@ -17,7 +17,6 @@ namespace Orchard.Environment.State.Models {
public bool IsInstalled { get { return InstallState == State.Up; } } public bool IsInstalled { get { return InstallState == State.Up; } }
public bool IsEnabled { get { return EnableState == State.Up; } } public bool IsEnabled { get { return EnableState == State.Up; } }
public bool IsDisabled { get { return EnableState == State.Down || EnableState == State.Undefined; } } public bool IsDisabled { get { return EnableState == State.Down || EnableState == State.Undefined; } }
public bool IsUninstalled { get { return InstallState == State.Down || InstallState == State.Undefined; } }
public enum State { public enum State {
Undefined, Undefined,

View File

@@ -9,21 +9,21 @@ using Orchard.Environment.Topology;
using Orchard.Environment.Topology.Models; using Orchard.Environment.Topology.Models;
namespace Orchard.Environment.State { namespace Orchard.Environment.State {
public class ShellStateManager : IShellStateManagerEventHandler, IShellDescriptorManagerEventHandler { public class ShellStateCoordinator : IShellStateManagerEventHandler, IShellDescriptorManagerEventHandler {
private readonly ShellSettings _settings; private readonly ShellSettings _settings;
private readonly IShellStateProvider _stateProvider; private readonly IShellStateManager _stateManager;
private readonly IExtensionManager _extensionManager; private readonly IExtensionManager _extensionManager;
private readonly IProcessingEngine _processingEngine; private readonly IProcessingEngine _processingEngine;
private readonly IFeatureEventHandler _featureEvents; private readonly IFeatureEventHandler _featureEvents;
public ShellStateManager( public ShellStateCoordinator(
ShellSettings settings, ShellSettings settings,
IShellStateProvider stateProvider, IShellStateManager stateManager,
IExtensionManager extensionManager, IExtensionManager extensionManager,
IProcessingEngine processingEngine, IProcessingEngine processingEngine,
IFeatureEventHandler featureEvents) { IFeatureEventHandler featureEvents) {
_settings = settings; _settings = settings;
_stateProvider = stateProvider; _stateManager = stateManager;
_extensionManager = extensionManager; _extensionManager = extensionManager;
_processingEngine = processingEngine; _processingEngine = processingEngine;
_featureEvents = featureEvents; _featureEvents = featureEvents;
@@ -31,7 +31,7 @@ namespace Orchard.Environment.State {
void IShellDescriptorManagerEventHandler.Changed(ShellDescriptor descriptor) { void IShellDescriptorManagerEventHandler.Changed(ShellDescriptor descriptor) {
// deduce and apply state changes involved // deduce and apply state changes involved
var shellState = _stateProvider.GetShellState(); var shellState = _stateManager.GetShellState();
foreach (var feature in descriptor.Features) { foreach (var feature in descriptor.Features) {
var featureName = feature.Name; var featureName = feature.Name;
var featureState = shellState.Features.SingleOrDefault(f => f.Name == featureName); var featureState = shellState.Features.SingleOrDefault(f => f.Name == featureName);
@@ -42,10 +42,10 @@ namespace Orchard.Environment.State {
shellState.Features = shellState.Features.Concat(new[] { featureState }); shellState.Features = shellState.Features.Concat(new[] { featureState });
} }
if (!featureState.IsInstalled) { if (!featureState.IsInstalled) {
_stateProvider.UpdateInstalledState(featureState, ShellFeatureState.State.Rising); _stateManager.UpdateInstalledState(featureState, ShellFeatureState.State.Rising);
} }
if (!featureState.IsEnabled) { if (!featureState.IsEnabled) {
_stateProvider.UpdateEnabledState(featureState, ShellFeatureState.State.Rising); _stateManager.UpdateEnabledState(featureState, ShellFeatureState.State.Rising);
} }
} }
foreach (var featureState in shellState.Features) { foreach (var featureState in shellState.Features) {
@@ -54,7 +54,7 @@ namespace Orchard.Environment.State {
continue; continue;
} }
if (!featureState.IsDisabled) { if (!featureState.IsDisabled) {
_stateProvider.UpdateEnabledState(featureState, ShellFeatureState.State.Falling); _stateManager.UpdateEnabledState(featureState, ShellFeatureState.State.Falling);
} }
} }
@@ -62,7 +62,7 @@ namespace Orchard.Environment.State {
} }
private void FireApplyChangesIfNeeded() { private void FireApplyChangesIfNeeded() {
var shellState = _stateProvider.GetShellState(); var shellState = _stateManager.GetShellState();
if (shellState.Features.Any(FeatureIsChanging)) { if (shellState.Features.Any(FeatureIsChanging)) {
var descriptor = new ShellDescriptor { var descriptor = new ShellDescriptor {
Features = shellState.Features Features = shellState.Features
@@ -98,7 +98,7 @@ namespace Orchard.Environment.State {
} }
void IShellStateManagerEventHandler.ApplyChanges() { void IShellStateManagerEventHandler.ApplyChanges() {
var shellState = _stateProvider.GetShellState(); var shellState = _stateManager.GetShellState();
// start with description of all declared features in order - order preserved with all merging // start with description of all declared features in order - order preserved with all merging
var orderedFeatureDescriptors = AllFeaturesInOrder(); var orderedFeatureDescriptors = AllFeaturesInOrder();
@@ -150,24 +150,24 @@ namespace Orchard.Environment.State {
// lower enabled states in reverse order // lower enabled states in reverse order
foreach (var entry in allEntries.Where(entry => entry.FeatureState.EnableState == ShellFeatureState.State.Falling)) { foreach (var entry in allEntries.Where(entry => entry.FeatureState.EnableState == ShellFeatureState.State.Falling)) {
_featureEvents.Disable(entry.Feature); _featureEvents.Disable(entry.Feature);
_stateProvider.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Down); _stateManager.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Down);
} }
// lower installed states in reverse order // lower installed states in reverse order
foreach (var entry in allEntries.Where(entry => entry.FeatureState.InstallState == ShellFeatureState.State.Falling)) { foreach (var entry in allEntries.Where(entry => entry.FeatureState.InstallState == ShellFeatureState.State.Falling)) {
_featureEvents.Uninstall(entry.Feature); _featureEvents.Uninstall(entry.Feature);
_stateProvider.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Down); _stateManager.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Down);
} }
// raise install and enabled states in order // raise install and enabled states in order
foreach (var entry in allEntries.Where(entry => IsRising(entry.FeatureState))) { foreach (var entry in allEntries.Where(entry => IsRising(entry.FeatureState))) {
if (entry.FeatureState.InstallState == ShellFeatureState.State.Rising) { if (entry.FeatureState.InstallState == ShellFeatureState.State.Rising) {
_featureEvents.Install(entry.Feature); _featureEvents.Install(entry.Feature);
_stateProvider.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Up); _stateManager.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Up);
} }
if (entry.FeatureState.EnableState == ShellFeatureState.State.Rising) { if (entry.FeatureState.EnableState == ShellFeatureState.State.Rising) {
_featureEvents.Enable(entry.Feature); _featureEvents.Enable(entry.Feature);
_stateProvider.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Up); _stateManager.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Up);
} }
} }

View File

@@ -140,8 +140,8 @@
<Compile Include="Environment\State\DefaultProcessingEngine.cs" /> <Compile Include="Environment\State\DefaultProcessingEngine.cs" />
<Compile Include="Environment\State\IProcessingEngine.cs" /> <Compile Include="Environment\State\IProcessingEngine.cs" />
<Compile Include="Environment\State\IShellStateManagerEventHandler.cs" /> <Compile Include="Environment\State\IShellStateManagerEventHandler.cs" />
<Compile Include="Environment\State\IShellStateProvider.cs" /> <Compile Include="Environment\State\IShellStateManager.cs" />
<Compile Include="Environment\State\ShellStateManager.cs" /> <Compile Include="Environment\State\ShellStateCoordinator.cs" />
<Compile Include="IDependency.cs" /> <Compile Include="IDependency.cs" />
<Compile Include="Mvc\Html\ThemeExtensions.cs" /> <Compile Include="Mvc\Html\ThemeExtensions.cs" />
<Compile Include="Mvc\Routes\IRoutePublisher.cs" /> <Compile Include="Mvc\Routes\IRoutePublisher.cs" />
@@ -325,8 +325,6 @@
<Compile Include="ContentManagement\Records\ContentPartVersionRecord.cs" /> <Compile Include="ContentManagement\Records\ContentPartVersionRecord.cs" />
<Compile Include="ContentManagement\Records\ContentTypeRecord.cs" /> <Compile Include="ContentManagement\Records\ContentTypeRecord.cs" />
<Compile Include="ContentManagement\Records\Utility.cs" /> <Compile Include="ContentManagement\Records\Utility.cs" />
<Compile Include="Environment\Extensions\HackInstallationGenerator.cs" />
<Compile Include="Environment\Extensions\IExtensionManagerEvents.cs" />
<Compile Include="Localization\Text.cs" /> <Compile Include="Localization\Text.cs" />
<Compile Include="Mvc\ViewModels\ContentItemViewModel.cs" /> <Compile Include="Mvc\ViewModels\ContentItemViewModel.cs" />
<Compile Include="ContentManagement\ViewModels\TemplateViewModel.cs" /> <Compile Include="ContentManagement\ViewModels\TemplateViewModel.cs" />
@@ -501,7 +499,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="ContentManagement\MetaData\Models\" /> <Folder Include="ContentManagement\MetaData\Models\" />
<Folder Include="Environment\ProcessEngine\" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.