From f794b3f955f3140b567b74480736dff19e7c647f Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Sat, 4 Dec 2010 15:31:24 -0800 Subject: [PATCH] Split feature lifetime events to "xx'ing" and "xx'ed" --HG-- branch : dev --- .../DefaultIndexingUpdater.cs | 25 +++++++++++------ .../DefaultPackagingUpdater.cs | 27 ++++++++++++++----- .../Orchard.Roles/DefaultRoleUpdater.cs | 26 ++++++++++++++---- .../Migration/DataMigrationCoordinator.cs | 23 ++++++++++++---- .../Environment/IOrchardShellEvents.cs | 12 ++++++--- .../State/ShellStateCoordinator.cs | 12 ++++++--- 6 files changed, 93 insertions(+), 32 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/DefaultIndexingUpdater.cs b/src/Orchard.Web/Modules/Orchard.Indexing/DefaultIndexingUpdater.cs index cf4ceb089..9312e29e0 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/DefaultIndexingUpdater.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/DefaultIndexingUpdater.cs @@ -1,14 +1,11 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; using Orchard.Environment; +using Orchard.Environment.Extensions.Models; using Orchard.Tasks.Indexing; using Orchard.ContentManagement; namespace Orchard.Indexing { public class DefaultIndexingUpdater : IFeatureEventHandler { - private readonly IIndexingTaskManager _indexingTaskManager; private readonly IContentManager _contentManager; @@ -17,10 +14,16 @@ namespace Orchard.Indexing { _contentManager = contentManager; } - public void Install(Environment.Extensions.Models.Feature feature) { + public void Installing(Feature feature) { } - public void Enable(Environment.Extensions.Models.Feature feature) { + public void Installed(Feature feature) { + } + + public void Enabling(Feature feature) { + } + + public void Enabled(Feature feature) { // create indexing tasks for all currently existing content, even when the module is enabled again // as some content might have been created while this module was not active, and indexing tasks // would not exist for them, resulting in an uncomplete index. @@ -30,10 +33,16 @@ namespace Orchard.Indexing { } } - public void Disable(Environment.Extensions.Models.Feature feature) { + public void Disabling(Feature feature) { } - public void Uninstall(Environment.Extensions.Models.Feature feature) { + public void Disabled(Feature feature) { + } + + public void Uninstalling(Feature feature) { + } + + public void Uninstalled(Feature feature) { } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs b/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs index 5be632a8c..59ea45e2d 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/DefaultPackagingUpdater.cs @@ -1,4 +1,5 @@ -using Orchard.Environment; +using System; +using Orchard.Environment; using Orchard.Environment.Extensions; using Orchard.Environment.Extensions.Models; using Orchard.Localization; @@ -15,17 +16,31 @@ namespace Orchard.Packaging { public Localizer T { get; set; } - public void Install(Feature feature) { - _packagingSourceManager.AddSource( "Orchard Extensions Gallery", "http://feed.nuget.org/ctp2/odata/v1" ); + public void Installing(Feature feature) { } - public void Enable(Feature feature) { + public void Installed(Feature feature) { + if (feature.Descriptor.Id == "Gallery") { + _packagingSourceManager.AddSource("Orchard Extensions Gallery", "http://feed.nuget.org/ctp2/odata/v1"); + } } - public void Disable(Feature feature) { + public void Enabling(Feature feature) { } - public void Uninstall(Feature feature) { + public void Enabled(Feature feature) { + } + + public void Disabling(Feature feature) { + } + + public void Disabled(Feature feature) { + } + + public void Uninstalling(Feature feature) { + } + + public void Uninstalled(Feature feature) { } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Roles/DefaultRoleUpdater.cs b/src/Orchard.Web/Modules/Orchard.Roles/DefaultRoleUpdater.cs index 1fe867fa4..1b4c69d64 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/DefaultRoleUpdater.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/DefaultRoleUpdater.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using Orchard.Environment; @@ -24,15 +25,30 @@ namespace Orchard.Roles { public ILogger Logger { get; set; } - void IFeatureEventHandler.Install(Feature feature) { + void IFeatureEventHandler.Installing(Feature feature) { AddDefaultRolesForFeature(feature); } - void IFeatureEventHandler.Enable(Feature feature) {} + void IFeatureEventHandler.Installed(Feature feature) { + } - void IFeatureEventHandler.Disable(Feature feature) {} + void IFeatureEventHandler.Enabling(Feature feature) { + } - void IFeatureEventHandler.Uninstall(Feature feature) {} + void IFeatureEventHandler.Enabled(Feature feature) { + } + + void IFeatureEventHandler.Disabling(Feature feature) { + } + + void IFeatureEventHandler.Disabled(Feature feature) { + } + + void IFeatureEventHandler.Uninstalling(Feature feature) { + } + + void IFeatureEventHandler.Uninstalled(Feature feature) { + } public void AddDefaultRolesForFeature(Feature feature) { var featureName = feature.Descriptor.Id; diff --git a/src/Orchard/Data/Migration/DataMigrationCoordinator.cs b/src/Orchard/Data/Migration/DataMigrationCoordinator.cs index 58573ec95..0438db2ed 100644 --- a/src/Orchard/Data/Migration/DataMigrationCoordinator.cs +++ b/src/Orchard/Data/Migration/DataMigrationCoordinator.cs @@ -1,4 +1,5 @@ -using Orchard.Environment; +using System; +using Orchard.Environment; using Orchard.Environment.Extensions.Models; namespace Orchard.Data.Migration { @@ -21,18 +22,30 @@ namespace Orchard.Data.Migration { _dataMigrationManager = dataMigrationManager; } - public void Install(Feature feature) { + public void Installing(Feature feature) { var featureName = feature.Descriptor.Id; _dataMigrationManager.Update(featureName); } - public void Enable(Feature feature) { + public void Installed(Feature feature) { } - public void Disable(Feature feature) { + public void Enabling(Feature feature) { } - public void Uninstall(Feature feature) { + public void Enabled(Feature feature) { + } + + public void Disabling(Feature feature) { + } + + public void Disabled(Feature feature) { + } + + public void Uninstalling(Feature feature) { + } + + public void Uninstalled(Feature feature) { var featureName = feature.Descriptor.Id; if ( _dataMigrationManager.IsFeatureAlreadyInstalled(featureName) ) { _dataMigrationManager.Uninstall(featureName); diff --git a/src/Orchard/Environment/IOrchardShellEvents.cs b/src/Orchard/Environment/IOrchardShellEvents.cs index d845199b1..889dc8cd9 100644 --- a/src/Orchard/Environment/IOrchardShellEvents.cs +++ b/src/Orchard/Environment/IOrchardShellEvents.cs @@ -8,9 +8,13 @@ namespace Orchard.Environment { } public interface IFeatureEventHandler : IEventHandler { - void Install(Feature feature); - void Enable(Feature feature); - void Disable(Feature feature); - void Uninstall(Feature feature); + void Installing(Feature feature); + void Installed(Feature feature); + void Enabling(Feature feature); + void Enabled(Feature feature); + void Disabling(Feature feature); + void Disabled(Feature feature); + void Uninstalling(Feature feature); + void Uninstalled(Feature feature); } } diff --git a/src/Orchard/Environment/State/ShellStateCoordinator.cs b/src/Orchard/Environment/State/ShellStateCoordinator.cs index 5f9d36972..03e8eb20d 100644 --- a/src/Orchard/Environment/State/ShellStateCoordinator.cs +++ b/src/Orchard/Environment/State/ShellStateCoordinator.cs @@ -157,28 +157,32 @@ namespace Orchard.Environment.State { // lower enabled states in reverse order foreach (var entry in allEntries.Reverse().Where(entry => entry.FeatureState.EnableState == ShellFeatureState.State.Falling)) { Logger.Information("Disabling feature '{0}'", entry.Feature.Descriptor.Id); - _featureEvents.Disable(entry.Feature); + _featureEvents.Disabling(entry.Feature); _stateManager.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Down); + _featureEvents.Disabled(entry.Feature); } // lower installed states in reverse order foreach (var entry in allEntries.Reverse().Where(entry => entry.FeatureState.InstallState == ShellFeatureState.State.Falling)) { Logger.Information("Uninstalling feature '{0}'", entry.Feature.Descriptor.Id); - _featureEvents.Uninstall(entry.Feature); + _featureEvents.Uninstalling(entry.Feature); _stateManager.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Down); + _featureEvents.Uninstalled(entry.Feature); } // raise install and enabled states in order foreach (var entry in allEntries.Where(entry => IsRising(entry.FeatureState))) { if (entry.FeatureState.InstallState == ShellFeatureState.State.Rising) { Logger.Information("Installing feature '{0}'", entry.Feature.Descriptor.Id); - _featureEvents.Install(entry.Feature); + _featureEvents.Installing(entry.Feature); _stateManager.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Up); + _featureEvents.Installed(entry.Feature); } if (entry.FeatureState.EnableState == ShellFeatureState.State.Rising) { Logger.Information("Enabling feature '{0}'", entry.Feature.Descriptor.Id); - _featureEvents.Enable(entry.Feature); + _featureEvents.Enabling(entry.Feature); _stateManager.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Up); + _featureEvents.Enabled(entry.Feature); } }