Split feature lifetime events to "xx'ing" and "xx'ed"

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-12-04 15:31:24 -08:00
parent b12a25e169
commit f794b3f955
6 changed files with 93 additions and 32 deletions

View File

@@ -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) {
}
}
}

View File

@@ -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) {
}
}
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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);
}
}