mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Simplifying recipe step API for implementers.
This commit is contained in:
@@ -159,7 +159,7 @@
|
|||||||
<Compile Include="Packaging\Services\FileBasedProjectSystemTests.cs" />
|
<Compile Include="Packaging\Services\FileBasedProjectSystemTests.cs" />
|
||||||
<Compile Include="Packaging\Services\FolderUpdaterTests.cs" />
|
<Compile Include="Packaging\Services\FolderUpdaterTests.cs" />
|
||||||
<Compile Include="Packaging\Services\PackageInstallerTests.cs" />
|
<Compile Include="Packaging\Services\PackageInstallerTests.cs" />
|
||||||
<Compile Include="Recipes\RecipeHandlers\ModuleRecipeHandlerTest.cs" />
|
<Compile Include="Recipes\RecipeHandlers\ModuleStepTest.cs" />
|
||||||
<Compile Include="Recipes\RecipeHandlers\ThemeRecipeHandlerTest.cs" />
|
<Compile Include="Recipes\RecipeHandlers\ThemeRecipeHandlerTest.cs" />
|
||||||
<Compile Include="Recipes\Services\RecipeManagerTests.cs" />
|
<Compile Include="Recipes\Services\RecipeManagerTests.cs" />
|
||||||
<Compile Include="Scripting.Dlr\EvaluatorTests.cs" />
|
<Compile Include="Scripting.Dlr\EvaluatorTests.cs" />
|
||||||
|
|||||||
@@ -23,17 +23,16 @@ using Orchard.Packaging.GalleryServer;
|
|||||||
using Orchard.Packaging.Models;
|
using Orchard.Packaging.Models;
|
||||||
using Orchard.Packaging.Services;
|
using Orchard.Packaging.Services;
|
||||||
using Orchard.Recipes.Models;
|
using Orchard.Recipes.Models;
|
||||||
using Orchard.Recipes.RecipeHandlers;
|
using Orchard.Recipes.RecipeExecutionSteps;
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
using Orchard.Tests.Environment.Extensions;
|
using Orchard.Tests.Environment.Extensions;
|
||||||
using Orchard.Tests.Environment.Features;
|
using Orchard.Tests.Environment.Features;
|
||||||
using Orchard.Tests.Stubs;
|
using Orchard.Tests.Stubs;
|
||||||
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
|
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
|
||||||
using Orchard.Tests.Modules.Recipes.Services;
|
|
||||||
|
|
||||||
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ModuleRecipeHandlerTest : DatabaseEnabledTestsBase {
|
public class ModuleStepTest : DatabaseEnabledTestsBase {
|
||||||
private ExtensionManagerTests.StubFolders _folders;
|
private ExtensionManagerTests.StubFolders _folders;
|
||||||
private StubPackagingSourceManager _packagesInRepository;
|
private StubPackagingSourceManager _packagesInRepository;
|
||||||
private StubPackageManager _packageManager;
|
private StubPackageManager _packageManager;
|
||||||
@@ -66,7 +65,7 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
|||||||
builder.RegisterInstance(_packageManager).As<IPackageManager>();
|
builder.RegisterInstance(_packageManager).As<IPackageManager>();
|
||||||
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
|
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
|
||||||
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
|
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
|
||||||
builder.RegisterType<ModuleRecipeHandler>();
|
builder.RegisterType<ModuleStep>();
|
||||||
builder.RegisterSource(new EventsRegistrationSource());
|
builder.RegisterSource(new EventsRegistrationSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,16 +93,16 @@ Features:
|
|||||||
Enumerable.Empty<ShellFeature>(),
|
Enumerable.Empty<ShellFeature>(),
|
||||||
Enumerable.Empty<ShellParameter>());
|
Enumerable.Empty<ShellParameter>());
|
||||||
|
|
||||||
ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();
|
var moduleStep = _container.Resolve<ModuleStep>();
|
||||||
|
var recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
|
||||||
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
|
var recipeExecutionContext = new RecipeExecutionContext {RecipeStep = recipeContext.RecipeStep};
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Module.SuperWiki"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Module.SuperWiki"));
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
||||||
|
|
||||||
IFeatureManager featureManager = _container.Resolve<IFeatureManager>();
|
IFeatureManager featureManager = _container.Resolve<IFeatureManager>();
|
||||||
IEnumerable<FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();
|
IEnumerable<FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();
|
||||||
Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
|
Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
|
||||||
moduleRecipeHandler.ExecuteRecipeStep(recipeContext);
|
moduleStep.Execute(recipeExecutionContext);
|
||||||
|
|
||||||
|
|
||||||
var availableFeatures = featureManager.GetAvailableFeatures().Where(x => x.Id == "SuperWiki").FirstOrDefault();
|
var availableFeatures = featureManager.GetAvailableFeatures().Where(x => x.Id == "SuperWiki").FirstOrDefault();
|
||||||
@@ -122,12 +121,12 @@ Features:
|
|||||||
Description: My super wiki module for Orchard.
|
Description: My super wiki module for Orchard.
|
||||||
");
|
");
|
||||||
|
|
||||||
ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();
|
var moduleStep = _container.Resolve<ModuleStep>();
|
||||||
|
var recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
|
||||||
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
|
var recipeExecutionContext = new RecipeExecutionContext { RecipeStep = recipeContext.RecipeStep };
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
||||||
|
|
||||||
Assert.Throws(typeof (InvalidOperationException), () => moduleRecipeHandler.ExecuteRecipeStep(recipeContext));
|
Assert.Throws(typeof (InvalidOperationException), () => moduleStep.Execute(recipeExecutionContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -147,14 +146,15 @@ Features:
|
|||||||
IsLatestVersion = false,
|
IsLatestVersion = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();
|
var moduleStep = _container.Resolve<ModuleStep>();
|
||||||
|
var recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
|
||||||
|
var recipeExecutionContext = new RecipeExecutionContext { RecipeStep = recipeContext.RecipeStep };
|
||||||
|
|
||||||
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
|
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Module.SuperWiki"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Module.SuperWiki"));
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("version", "1.0.2"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("version", "1.0.2"));
|
||||||
|
|
||||||
moduleRecipeHandler.ExecuteRecipeStep(recipeContext);
|
moduleStep.Execute(recipeExecutionContext);
|
||||||
|
|
||||||
var installedPackage = _packageManager.GetInstalledPackages().FirstOrDefault(info => info.ExtensionName == "Orchard.Module.SuperWiki");
|
var installedPackage = _packageManager.GetInstalledPackages().FirstOrDefault(info => info.ExtensionName == "Orchard.Module.SuperWiki");
|
||||||
Assert.That(installedPackage, Is.Not.Null);
|
Assert.That(installedPackage, Is.Not.Null);
|
||||||
@@ -163,7 +163,7 @@ Features:
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class StubPackagingSourceManager : IPackagingSourceManager {
|
internal class StubPackagingSourceManager : IPackagingSourceManager {
|
||||||
private List<PublishedPackage> _publishedPackages = new List<PublishedPackage>();
|
private readonly List<PublishedPackage> _publishedPackages = new List<PublishedPackage>();
|
||||||
|
|
||||||
public IEnumerable<PackagingSource> GetSources() {
|
public IEnumerable<PackagingSource> GetSources() {
|
||||||
return Enumerable.Empty<PackagingSource>();
|
return Enumerable.Empty<PackagingSource>();
|
||||||
@@ -199,7 +199,7 @@ Features:
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class StubPackageManager : IPackageManager {
|
internal class StubPackageManager : IPackageManager {
|
||||||
private IList<PackageInfo> _installedPackages = new List<PackageInfo>();
|
private readonly IList<PackageInfo> _installedPackages = new List<PackageInfo>();
|
||||||
|
|
||||||
public IEnumerable<PackageInfo> GetInstalledPackages() {
|
public IEnumerable<PackageInfo> GetInstalledPackages() {
|
||||||
return _installedPackages;
|
return _installedPackages;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Hosting;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@@ -23,21 +22,21 @@ using Orchard.FileSystems.VirtualPath;
|
|||||||
using Orchard.Packaging.GalleryServer;
|
using Orchard.Packaging.GalleryServer;
|
||||||
using Orchard.Packaging.Services;
|
using Orchard.Packaging.Services;
|
||||||
using Orchard.Recipes.Models;
|
using Orchard.Recipes.Models;
|
||||||
using Orchard.Recipes.RecipeHandlers;
|
using Orchard.Recipes.RecipeExecutionSteps;
|
||||||
|
using Orchard.Recipes.Services;
|
||||||
using Orchard.Tests.DisplayManagement.Descriptors;
|
using Orchard.Tests.DisplayManagement.Descriptors;
|
||||||
using Orchard.Tests.Environment.Extensions;
|
using Orchard.Tests.Environment.Extensions;
|
||||||
using Orchard.Tests.Environment.Features;
|
using Orchard.Tests.Environment.Features;
|
||||||
using Orchard.Tests.Stubs;
|
using Orchard.Tests.Stubs;
|
||||||
using Orchard.Tests.UI.Navigation;
|
using Orchard.Tests.UI.Navigation;
|
||||||
using Orchard.Themes.Services;
|
using Orchard.Themes.Services;
|
||||||
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
|
|
||||||
|
|
||||||
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ThemeRecipeHandlerTest : DatabaseEnabledTestsBase {
|
public class ThemeRecipeHandlerTest : DatabaseEnabledTestsBase {
|
||||||
private ExtensionManagerTests.StubFolders _folders;
|
private ExtensionManagerTests.StubFolders _folders;
|
||||||
private ModuleRecipeHandlerTest.StubPackagingSourceManager _packagesInRepository;
|
private ModuleStepTest.StubPackagingSourceManager _packagesInRepository;
|
||||||
private ModuleRecipeHandlerTest.StubPackageManager _packageManager;
|
private ModuleStepTest.StubPackageManager _packageManager;
|
||||||
|
|
||||||
protected override IEnumerable<Type> DatabaseTypes {
|
protected override IEnumerable<Type> DatabaseTypes {
|
||||||
get {
|
get {
|
||||||
@@ -50,13 +49,13 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Register(ContainerBuilder builder) {
|
public override void Register(ContainerBuilder builder) {
|
||||||
var _testVirtualPathProvider = new StylesheetBindingStrategyTests.TestVirtualPathProvider();
|
var testVirtualPathProvider = new StylesheetBindingStrategyTests.TestVirtualPathProvider();
|
||||||
|
|
||||||
builder.RegisterInstance(new ShellSettings { Name = "Default" });
|
builder.RegisterInstance(new ShellSettings { Name = "Default" });
|
||||||
|
|
||||||
_folders = new ExtensionManagerTests.StubFolders();
|
_folders = new ExtensionManagerTests.StubFolders();
|
||||||
_packagesInRepository = new ModuleRecipeHandlerTest.StubPackagingSourceManager();
|
_packagesInRepository = new ModuleStepTest.StubPackagingSourceManager();
|
||||||
_packageManager = new ModuleRecipeHandlerTest.StubPackageManager();
|
_packageManager = new ModuleStepTest.StubPackageManager();
|
||||||
builder.RegisterInstance(_folders).As<IExtensionFolders>();
|
builder.RegisterInstance(_folders).As<IExtensionFolders>();
|
||||||
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
|
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
|
||||||
builder.RegisterType<FeatureManager>().As<IFeatureManager>();
|
builder.RegisterType<FeatureManager>().As<IFeatureManager>();
|
||||||
@@ -64,16 +63,16 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
|||||||
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
|
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
|
||||||
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
|
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
|
||||||
builder.RegisterType<ShellDescriptorManager>().As<IShellDescriptorManager>().SingleInstance();
|
builder.RegisterType<ShellDescriptorManager>().As<IShellDescriptorManager>().SingleInstance();
|
||||||
builder.RegisterType<ModuleRecipeHandlerTest.StubDataMigrationManager>().As<IDataMigrationManager>();
|
builder.RegisterType<ModuleStepTest.StubDataMigrationManager>().As<IDataMigrationManager>();
|
||||||
builder.RegisterInstance(_packagesInRepository).As<IPackagingSourceManager>();
|
builder.RegisterInstance(_packagesInRepository).As<IPackagingSourceManager>();
|
||||||
builder.RegisterInstance(_packageManager).As<IPackageManager>();
|
builder.RegisterInstance(_packageManager).As<IPackageManager>();
|
||||||
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
|
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
|
||||||
builder.RegisterInstance(_testVirtualPathProvider).As<IVirtualPathProvider>();
|
builder.RegisterInstance(testVirtualPathProvider).As<IVirtualPathProvider>();
|
||||||
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
|
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
|
||||||
builder.RegisterType<ThemeService>().As<IThemeService>();
|
builder.RegisterType<ThemeService>().As<IThemeService>();
|
||||||
builder.RegisterType<StubOrchardServices>().As<IOrchardServices>();
|
builder.RegisterType<StubOrchardServices>().As<IOrchardServices>();
|
||||||
builder.RegisterType<StubSiteThemeService>().As<ISiteThemeService>();
|
builder.RegisterType<StubSiteThemeService>().As<ISiteThemeService>();
|
||||||
builder.RegisterType<ThemeRecipeHandler>();
|
builder.RegisterType<ThemeStep>();
|
||||||
builder.RegisterSource(new EventsRegistrationSource());
|
builder.RegisterSource(new EventsRegistrationSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,16 +100,17 @@ Features:
|
|||||||
Enumerable.Empty<ShellFeature>(),
|
Enumerable.Empty<ShellFeature>(),
|
||||||
Enumerable.Empty<ShellParameter>());
|
Enumerable.Empty<ShellParameter>());
|
||||||
|
|
||||||
ThemeRecipeHandler themeRecipeHandler = _container.Resolve<ThemeRecipeHandler>();
|
var themeStep = _container.Resolve<ThemeStep>();
|
||||||
|
var recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Theme", Step = new XElement("SuperWiki") } };
|
||||||
|
var recipeExecutionContext = new RecipeExecutionContext {RecipeStep = recipeContext.RecipeStep};
|
||||||
|
|
||||||
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Theme", Step = new XElement("SuperWiki") } };
|
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Theme.SuperWiki"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Theme.SuperWiki"));
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
||||||
|
|
||||||
IFeatureManager featureManager = _container.Resolve<IFeatureManager>();
|
var featureManager = _container.Resolve<IFeatureManager>();
|
||||||
IEnumerable<FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();
|
var enabledFeatures = featureManager.GetEnabledFeatures();
|
||||||
Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
|
Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
|
||||||
themeRecipeHandler.ExecuteRecipeStep(recipeContext);
|
themeStep.Execute(recipeExecutionContext);
|
||||||
|
|
||||||
// without setting enable no feature should be activated...
|
// without setting enable no feature should be activated...
|
||||||
featureManager.GetEnabledFeatures();
|
featureManager.GetEnabledFeatures();
|
||||||
@@ -118,7 +118,7 @@ Features:
|
|||||||
|
|
||||||
// Adding enable the feature should get active
|
// Adding enable the feature should get active
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("enable", true));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("enable", true));
|
||||||
themeRecipeHandler.ExecuteRecipeStep(recipeContext);
|
themeStep.Execute(recipeExecutionContext);
|
||||||
|
|
||||||
enabledFeatures = featureManager.GetEnabledFeatures();
|
enabledFeatures = featureManager.GetEnabledFeatures();
|
||||||
Assert.That(enabledFeatures.FirstOrDefault(feature => feature.Id.Equals("SuperWiki")), Is.Not.Null);
|
Assert.That(enabledFeatures.FirstOrDefault(feature => feature.Id.Equals("SuperWiki")), Is.Not.Null);
|
||||||
@@ -137,12 +137,12 @@ Features:
|
|||||||
Description: My super wiki module for Orchard.
|
Description: My super wiki module for Orchard.
|
||||||
");
|
");
|
||||||
|
|
||||||
ThemeRecipeHandler themeRecipeHandler = _container.Resolve<ThemeRecipeHandler>();
|
var themeStep = _container.Resolve<ThemeStep>();
|
||||||
|
var recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Theme", Step = new XElement("SuperWiki") } };
|
||||||
|
var recipeExecutionContext = new RecipeExecutionContext { RecipeStep = recipeContext.RecipeStep };
|
||||||
|
|
||||||
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Theme", Step = new XElement("SuperWiki") } };
|
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
||||||
|
Assert.Throws(typeof (InvalidOperationException), () => themeStep.Execute(recipeExecutionContext));
|
||||||
Assert.Throws(typeof (InvalidOperationException), () => themeRecipeHandler.ExecuteRecipeStep(recipeContext));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -162,14 +162,15 @@ Features:
|
|||||||
IsLatestVersion = false,
|
IsLatestVersion = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
ThemeRecipeHandler themeRecipeHandler = _container.Resolve<ThemeRecipeHandler>();
|
var themeStep = _container.Resolve<ThemeStep>();
|
||||||
|
var recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Theme", Step = new XElement("SuperWiki") } };
|
||||||
|
var recipeExecutionContext = new RecipeExecutionContext { RecipeStep = recipeContext.RecipeStep };
|
||||||
|
|
||||||
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Theme", Step = new XElement("SuperWiki") } };
|
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Theme.SuperWiki"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Theme.SuperWiki"));
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
||||||
recipeContext.RecipeStep.Step.Add(new XAttribute("version", "1.0.2"));
|
recipeContext.RecipeStep.Step.Add(new XAttribute("version", "1.0.2"));
|
||||||
|
|
||||||
themeRecipeHandler.ExecuteRecipeStep(recipeContext);
|
themeStep.Execute(recipeExecutionContext);
|
||||||
|
|
||||||
var installedPackage = _packageManager.GetInstalledPackages().FirstOrDefault(info => info.ExtensionName == "Orchard.Theme.SuperWiki");
|
var installedPackage = _packageManager.GetInstalledPackages().FirstOrDefault(info => info.ExtensionName == "Orchard.Theme.SuperWiki");
|
||||||
Assert.That(installedPackage, Is.Not.Null);
|
Assert.That(installedPackage, Is.Not.Null);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ namespace Orchard.ImportExport.Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (SiteSettings) {
|
if (SiteSettings) {
|
||||||
var siteSettingsStep = _orchardServices.WorkContext.Resolve<SiteSettingsBuilderStep>();
|
var siteSettingsStep = _orchardServices.WorkContext.Resolve<SettingsBuilderStep>();
|
||||||
recipeBuilderSteps.Add(siteSettingsStep);
|
recipeBuilderSteps.Add(siteSettingsStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,18 +84,22 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RecipeBuilders\ContentRecipeBuilderStep.cs" />
|
<Compile Include="RecipeBuilders\ContentRecipeBuilderStep.cs" />
|
||||||
<Compile Include="RecipeBuilders\RecipeMetadataBuilderStep.cs" />
|
<Compile Include="RecipeBuilders\RecipeMetadataBuilderStep.cs" />
|
||||||
<Compile Include="RecipeBuilders\SiteSettingsBuilderStep.cs" />
|
<Compile Include="RecipeBuilders\SettingsBuilderStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\CommandRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\CommandStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\DataRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\ContentStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\FeatureRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\FeatureStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\MetadataRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\ContentSchemaStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\MigrationRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\MigrationStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\ModuleRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\ModuleStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\SettingsRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\SettingsStep.cs" />
|
||||||
<Compile Include="RecipeHandlers\ThemeRecipeHandler.cs" />
|
<Compile Include="RecipeExecutionSteps\ThemeStep.cs" />
|
||||||
|
<Compile Include="RecipeHandlers\RecipeExecutionStepHandler.cs" />
|
||||||
<Compile Include="Routes.cs" />
|
<Compile Include="Routes.cs" />
|
||||||
<Compile Include="Services\BuildContext.cs" />
|
<Compile Include="Services\BuildContext.cs" />
|
||||||
|
<Compile Include="Services\IRecipeExecutionStep.cs" />
|
||||||
<Compile Include="Services\IRecipeExecutor.cs" />
|
<Compile Include="Services\IRecipeExecutor.cs" />
|
||||||
|
<Compile Include="Services\RecipeExecutionContext.cs" />
|
||||||
|
<Compile Include="Services\RecipeExecutionStep.cs" />
|
||||||
<Compile Include="Services\RecipeExecutor.cs" />
|
<Compile Include="Services\RecipeExecutor.cs" />
|
||||||
<Compile Include="Services\IRecipeBuilder.cs" />
|
<Compile Include="Services\IRecipeBuilder.cs" />
|
||||||
<Compile Include="Services\RecipeBuilder.cs" />
|
<Compile Include="Services\RecipeBuilder.cs" />
|
||||||
@@ -152,7 +156,7 @@
|
|||||||
<Content Include="Views\EditorTemplates\ExportSteps\RecipeMetadata.cshtml" />
|
<Content Include="Views\EditorTemplates\ExportSteps\RecipeMetadata.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\EditorTemplates\ExportSteps\SiteSettings.cshtml" />
|
<Content Include="Views\EditorTemplates\ExportSteps\Settings.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
|
|||||||
@@ -104,11 +104,11 @@ namespace Orchard.Recipes.RecipeBuilders {
|
|||||||
partsElement.Add(_contentDefinitionWriter.Export(part));
|
partsElement.Add(_contentDefinitionWriter.Export(part));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new XElement("Metadata", typesElement, partsElement);
|
return new XElement("ContentSchema", typesElement, partsElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
private XElement ExportData(IEnumerable<string> contentTypes, IEnumerable<ContentItem> contentItems, int? batchSize) {
|
private XElement ExportData(IEnumerable<string> contentTypes, IEnumerable<ContentItem> contentItems, int? batchSize) {
|
||||||
var data = new XElement("Data");
|
var data = new XElement("Content");
|
||||||
|
|
||||||
if (batchSize.HasValue && batchSize.Value > 0)
|
if (batchSize.HasValue && batchSize.Value > 0)
|
||||||
data.SetAttributeValue("BatchSize", batchSize);
|
data.SetAttributeValue("BatchSize", batchSize);
|
||||||
|
|||||||
@@ -7,23 +7,23 @@ using Orchard.Recipes.Services;
|
|||||||
using Orchard.Recipes.ViewModels;
|
using Orchard.Recipes.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeBuilders {
|
namespace Orchard.Recipes.RecipeBuilders {
|
||||||
public class SiteSettingsBuilderStep : RecipeBuilderStep {
|
public class SettingsBuilderStep : RecipeBuilderStep {
|
||||||
private readonly IOrchardServices _orchardServices;
|
private readonly IOrchardServices _orchardServices;
|
||||||
|
|
||||||
public SiteSettingsBuilderStep(IOrchardServices orchardServices) {
|
public SettingsBuilderStep(IOrchardServices orchardServices) {
|
||||||
_orchardServices = orchardServices;
|
_orchardServices = orchardServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Name {
|
public override string Name {
|
||||||
get { return "SiteSettings"; }
|
get { return "Settings"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override LocalizedString DisplayName {
|
public override LocalizedString DisplayName {
|
||||||
get { return T("Site Settings"); }
|
get { return T("Settings"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override LocalizedString Description {
|
public override LocalizedString Description {
|
||||||
get { return T("Exports site settings."); }
|
get { return T("Exports settings."); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Priority { get { return 20; } }
|
public override int Priority { get { return 20; } }
|
||||||
@@ -34,7 +34,7 @@ namespace Orchard.Recipes.RecipeBuilders {
|
|||||||
|
|
||||||
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
|
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
|
||||||
var viewModel = new SiteSettingsStepViewModel();
|
var viewModel = new SiteSettingsStepViewModel();
|
||||||
return shapeFactory.EditorTemplate(TemplateName: "ExportSteps/SiteSettings", Model: viewModel, Prefix: Prefix);
|
return shapeFactory.EditorTemplate(TemplateName: "ExportSteps/Settings", Model: viewModel, Prefix: Prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Build(BuildContext context) {
|
public override void Build(BuildContext context) {
|
||||||
@@ -4,25 +4,20 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Orchard.Commands;
|
using Orchard.Commands;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Recipes.Models;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class CommandRecipeHandler : IRecipeHandler {
|
public class CommandStep : RecipeExecutionStep {
|
||||||
private readonly ICommandManager _commandManager;
|
private readonly ICommandManager _commandManager;
|
||||||
private readonly CommandParser _commandParser;
|
private readonly CommandParser _commandParser;
|
||||||
|
|
||||||
public CommandRecipeHandler(ICommandManager commandManager) {
|
public CommandStep(ICommandManager commandManager) {
|
||||||
_commandManager = commandManager;
|
_commandManager = commandManager;
|
||||||
_commandParser = new CommandParser();
|
_commandParser = new CommandParser();
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public override string Name { get { return "Command"; } }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
<Command>
|
<Command>
|
||||||
@@ -31,16 +26,10 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
command3
|
command3
|
||||||
</Command>
|
</Command>
|
||||||
*/
|
*/
|
||||||
// run Orchard commands.
|
// Run Orchard commands.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext context) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Command", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
var commands =
|
var commands =
|
||||||
recipeContext.RecipeStep.Step.Value
|
context.RecipeStep.Step.Value
|
||||||
.Split(new[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries)
|
.Split(new[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Select(commandEntry => commandEntry.Trim());
|
.Select(commandEntry => commandEntry.Trim());
|
||||||
|
|
||||||
@@ -59,9 +48,6 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2,18 +2,18 @@
|
|||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Orchard.ContentManagement.MetaData;
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ContentTypes.Events;
|
using Orchard.ContentTypes.Events;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Recipes.Models;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class MetadataRecipeHandler : IRecipeHandler {
|
public class ContentSchemaStep : RecipeExecutionStep {
|
||||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
private readonly IContentDefinitionReader _contentDefinitionReader;
|
private readonly IContentDefinitionReader _contentDefinitionReader;
|
||||||
private readonly IContentDefinitionEventHandler _contentDefinitonEventHandlers;
|
private readonly IContentDefinitionEventHandler _contentDefinitonEventHandlers;
|
||||||
|
|
||||||
public MetadataRecipeHandler(
|
public override string Name { get { return "ContentSchema"; } }
|
||||||
|
|
||||||
|
public ContentSchemaStep(
|
||||||
IContentDefinitionManager contentDefinitionManager,
|
IContentDefinitionManager contentDefinitionManager,
|
||||||
IContentDefinitionReader contentDefinitionReader,
|
IContentDefinitionReader contentDefinitionReader,
|
||||||
IContentDefinitionEventHandler contentDefinitonEventHandlers) {
|
IContentDefinitionEventHandler contentDefinitonEventHandlers) {
|
||||||
@@ -21,15 +21,10 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
_contentDefinitionManager = contentDefinitionManager;
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
_contentDefinitionReader = contentDefinitionReader;
|
_contentDefinitionReader = contentDefinitionReader;
|
||||||
_contentDefinitonEventHandlers = contentDefinitonEventHandlers;
|
_contentDefinitonEventHandlers = contentDefinitonEventHandlers;
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
<Metadata>
|
<ContentDefinition>
|
||||||
<Types>
|
<Types>
|
||||||
<Blog creatable="true">
|
<Blog creatable="true">
|
||||||
<Body format="abodyformat"/>
|
<Body format="abodyformat"/>
|
||||||
@@ -37,18 +32,12 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
</Types>
|
</Types>
|
||||||
<Parts>
|
<Parts>
|
||||||
</Parts>
|
</Parts>
|
||||||
</Metadata>
|
</ContentDefinition>
|
||||||
*/
|
*/
|
||||||
// Set type settings and attach parts to types.
|
// Set type settings and attach parts to types.
|
||||||
// Create dynamic parts.
|
// Create dynamic parts.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext context) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Metadata", StringComparison.OrdinalIgnoreCase)) {
|
foreach (var metadataElement in context.RecipeStep.Step.Elements()) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
foreach (var metadataElement in recipeContext.RecipeStep.Step.Elements()) {
|
|
||||||
Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName);
|
Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName);
|
||||||
switch (metadataElement.Name.LocalName) {
|
switch (metadataElement.Name.LocalName) {
|
||||||
case "Types":
|
case "Types":
|
||||||
@@ -92,9 +81,6 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,58 +3,47 @@ using System.Collections.Generic;
|
|||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Recipes.Models;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class DataRecipeHandler : IRecipeHandler {
|
public class ContentStep : RecipeExecutionStep {
|
||||||
private readonly IOrchardServices _orchardServices;
|
private readonly IOrchardServices _orchardServices;
|
||||||
private readonly ITransactionManager _transactionManager;
|
private readonly ITransactionManager _transactionManager;
|
||||||
|
|
||||||
public DataRecipeHandler(IOrchardServices orchardServices, ITransactionManager transactionManager) {
|
public ContentStep(IOrchardServices orchardServices, ITransactionManager transactionManager) {
|
||||||
_orchardServices = orchardServices;
|
_orchardServices = orchardServices;
|
||||||
_transactionManager = transactionManager;
|
_transactionManager = transactionManager;
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public override string Name { get { return "Content"; } }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
// <Data />
|
// <Data />
|
||||||
// Import Data
|
// Import Data.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext context) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Data", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
var importContentSession = new ImportContentSession(_orchardServices.ContentManager);
|
var importContentSession = new ImportContentSession(_orchardServices.ContentManager);
|
||||||
|
|
||||||
// Populate local dictionary with elements and their ids
|
// Populate local dictionary with elements and their ids.
|
||||||
var elementDictionary = CreateElementDictionary(recipeContext.RecipeStep.Step);
|
var elementDictionary = CreateElementDictionary(context.RecipeStep.Step);
|
||||||
|
|
||||||
//Populate import session with all identities to be imported
|
// Populate import session with all identities to be imported.
|
||||||
foreach (var identity in elementDictionary.Keys) {
|
foreach (var identity in elementDictionary.Keys) {
|
||||||
importContentSession.Set(identity, elementDictionary[identity].Name.LocalName);
|
importContentSession.Set(identity, elementDictionary[identity].Name.LocalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Determine if the import is to be batched in multiple transactions
|
// Determine if the import is to be batched in multiple transactions.
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
int batchSize = GetBatchSizeForDataStep(recipeContext.RecipeStep.Step);
|
var batchSize = GetBatchSizeForDataStep(context.RecipeStep.Step);
|
||||||
Logger.Debug("Using batch size {0}.", batchSize);
|
Logger.Debug("Using batch size {0}.", batchSize);
|
||||||
|
|
||||||
//Run the import
|
// Run the import.
|
||||||
try {
|
try {
|
||||||
while (startIndex < elementDictionary.Count) {
|
while (startIndex < elementDictionary.Count) {
|
||||||
Logger.Debug("Importing batch starting at index {0}.", startIndex);
|
Logger.Debug("Importing batch starting at index {0}.", startIndex);
|
||||||
importContentSession.InitializeBatch(startIndex, batchSize);
|
importContentSession.InitializeBatch(startIndex, batchSize);
|
||||||
|
|
||||||
//the session determines which items are included in the current batch
|
// The session determines which items are included in the current batch
|
||||||
//so that dependencies can be managed within the same transaction
|
// so that dependencies can be managed within the same transaction.
|
||||||
var nextIdentity = importContentSession.GetNextInBatch();
|
var nextIdentity = importContentSession.GetNextInBatch();
|
||||||
while (nextIdentity != null) {
|
while (nextIdentity != null) {
|
||||||
var itemId = "";
|
var itemId = "";
|
||||||
@@ -76,7 +65,7 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
|
|
||||||
startIndex += batchSize;
|
startIndex += batchSize;
|
||||||
|
|
||||||
//Create a new transaction for each batch
|
// Create a new transaction for each batch.
|
||||||
if (startIndex < elementDictionary.Count) {
|
if (startIndex < elementDictionary.Count) {
|
||||||
_transactionManager.RequireNew();
|
_transactionManager.RequireNew();
|
||||||
}
|
}
|
||||||
@@ -85,13 +74,10 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception) {
|
catch (Exception) {
|
||||||
//Ensure a failed batch is rolled back
|
// Ensure a failed batch is rolled back.
|
||||||
_transactionManager.Cancel();
|
_transactionManager.Cancel();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, XElement> CreateElementDictionary(XElement step) {
|
private Dictionary<string, XElement> CreateElementDictionary(XElement step) {
|
||||||
@@ -2,33 +2,22 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Environment.Features;
|
using Orchard.Environment.Features;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Recipes.Models;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class FeatureRecipeHandler : IRecipeHandler {
|
public class FeatureStep : RecipeExecutionStep {
|
||||||
private readonly IFeatureManager _featureManager;
|
private readonly IFeatureManager _featureManager;
|
||||||
|
|
||||||
public FeatureRecipeHandler(IFeatureManager featureManager) {
|
public FeatureStep(IFeatureManager featureManager) {
|
||||||
_featureManager = featureManager;
|
_featureManager = featureManager;
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public override string Name { get { return "Feature"; } }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
// <Feature enable="f1,f2,f3" disable="f4" />
|
// <Feature enable="f1,f2,f3" disable="f4" />
|
||||||
// Enable/Disable features.
|
// Enable/Disable features.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext recipeContext) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Feature", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
var featuresToEnable = new List<string>();
|
var featuresToEnable = new List<string>();
|
||||||
var featuresToDisable = new List<string>();
|
var featuresToDisable = new List<string>();
|
||||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||||
@@ -64,9 +53,6 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
Logger.Information("Enabling features: {0}", String.Join(";", featuresToEnable));
|
Logger.Information("Enabling features: {0}", String.Join(";", featuresToEnable));
|
||||||
_featureManager.EnableFeatures(featuresToEnable, true);
|
_featureManager.EnableFeatures(featuresToEnable, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<string> ParseFeatures(string csv) {
|
private static List<string> ParseFeatures(string csv) {
|
||||||
@@ -2,37 +2,26 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Recipes.Models;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class MigrationRecipeHandler : IRecipeHandler {
|
public class MigrationStep : RecipeExecutionStep {
|
||||||
private readonly IDataMigrationManager _dataMigrationManager;
|
private readonly IDataMigrationManager _dataMigrationManager;
|
||||||
|
|
||||||
public MigrationRecipeHandler(IDataMigrationManager dataMigrationManager) {
|
public MigrationStep(IDataMigrationManager dataMigrationManager) {
|
||||||
_dataMigrationManager = dataMigrationManager;
|
_dataMigrationManager = dataMigrationManager;
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public override string Name { get { return "Migration"; } }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
// <Migration features="f1, f2" />
|
// <Migration features="f1, f2" />
|
||||||
// <Migration features="*" />
|
// <Migration features="*" />
|
||||||
// Run migration for features.
|
// Run migration for features.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext context) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Migration", StringComparison.OrdinalIgnoreCase)) {
|
var runAll = false;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
bool runAll = false;
|
|
||||||
var features = new List<string>();
|
var features = new List<string>();
|
||||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
foreach (var attribute in context.RecipeStep.Step.Attributes()) {
|
||||||
if (String.Equals(attribute.Name.LocalName, "features", StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(attribute.Name.LocalName, "features", StringComparison.OrdinalIgnoreCase)) {
|
||||||
features = ParseFeatures(attribute.Value);
|
features = ParseFeatures(attribute.Value);
|
||||||
if (features.Contains("*"))
|
if (features.Contains("*"))
|
||||||
@@ -65,9 +54,6 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<string> ParseFeatures(string csv) {
|
private static List<string> ParseFeatures(string csv) {
|
||||||
@@ -3,45 +3,34 @@ using System.Linq;
|
|||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Packaging.Models;
|
using Orchard.Packaging.Models;
|
||||||
using Orchard.Packaging.Services;
|
using Orchard.Packaging.Services;
|
||||||
using Orchard.Recipes.Models;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class ModuleRecipeHandler : IRecipeHandler {
|
public class ModuleStep : RecipeExecutionStep {
|
||||||
private readonly IPackagingSourceManager _packagingSourceManager;
|
private readonly IPackagingSourceManager _packagingSourceManager;
|
||||||
private readonly IPackageManager _packageManager;
|
private readonly IPackageManager _packageManager;
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
|
|
||||||
public ModuleRecipeHandler(
|
public ModuleStep(
|
||||||
IPackagingSourceManager packagingSourceManager,
|
IPackagingSourceManager packagingSourceManager,
|
||||||
IPackageManager packageManager,
|
IPackageManager packageManager,
|
||||||
IExtensionManager extensionManager) {
|
IExtensionManager extensionManager) {
|
||||||
|
|
||||||
_packagingSourceManager = packagingSourceManager;
|
_packagingSourceManager = packagingSourceManager;
|
||||||
_packageManager = packageManager;
|
_packageManager = packageManager;
|
||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
|
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public override string Name { get { return "Module"; } }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
// <Module packageId="module1" [repository="somerepo"] version="1.1" />
|
// <Module packageId="module1" [repository="somerepo"] version="1.1" />
|
||||||
// install modules from feed.
|
// Install modules from feed.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext context) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
string packageId = null, version = null, repository = null;
|
string packageId = null, version = null, repository = null;
|
||||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
foreach (var attribute in context.RecipeStep.Step.Attributes()) {
|
||||||
if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) {
|
||||||
packageId = attribute.Value;
|
packageId = attribute.Value;
|
||||||
}
|
}
|
||||||
@@ -52,7 +41,7 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
repository = attribute.Value;
|
repository = attribute.Value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new InvalidOperationException(string.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName));
|
throw new InvalidOperationException(String.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,8 +50,8 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// download and install module from the orchard feed or a custom feed if repository is specified.
|
// download and install module from the orchard feed or a custom feed if repository is specified.
|
||||||
bool enforceVersion = version != null;
|
var enforceVersion = version != null;
|
||||||
bool installed = false;
|
var installed = false;
|
||||||
PackagingEntry packagingEntry = null;
|
PackagingEntry packagingEntry = null;
|
||||||
|
|
||||||
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
||||||
@@ -94,11 +83,8 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!installed) {
|
if (!installed) {
|
||||||
throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", packageId));
|
throw new InvalidOperationException(String.Format("Module {0} was not found in the specified location.", packageId));
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ModuleAlreadyInstalled(string packageId) {
|
private bool ModuleAlreadyInstalled(string packageId) {
|
||||||
@@ -9,22 +9,19 @@ using Orchard.Recipes.Models;
|
|||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
using Orchard.Settings;
|
using Orchard.Settings;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class SettingsRecipeHandler : IRecipeHandler {
|
public class SettingsStep : RecipeExecutionStep {
|
||||||
private readonly ISiteService _siteService;
|
private readonly ISiteService _siteService;
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
|
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
|
||||||
|
|
||||||
public SettingsRecipeHandler(ISiteService siteService, IContentManager contentManager, Lazy<IEnumerable<IContentHandler>> handlers) {
|
public SettingsStep(ISiteService siteService, IContentManager contentManager, Lazy<IEnumerable<IContentHandler>> handlers) {
|
||||||
_siteService = siteService;
|
_siteService = siteService;
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_handlers = handlers;
|
_handlers = handlers;
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public override string Name { get { return "Settings"; } }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
private IEnumerable<IContentHandler> Handlers { get { return _handlers.Value; } }
|
private IEnumerable<IContentHandler> Handlers { get { return _handlers.Value; } }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -34,24 +31,17 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
</Settings>
|
</Settings>
|
||||||
*/
|
*/
|
||||||
// Set site and part settings.
|
// Set site and part settings.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext context) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Settings", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
var siteContentItem = _siteService.GetSiteSettings().ContentItem;
|
var siteContentItem = _siteService.GetSiteSettings().ContentItem;
|
||||||
|
|
||||||
var importContentSession = new ImportContentSession(_contentManager);
|
var importContentSession = new ImportContentSession(_contentManager);
|
||||||
|
var importContentContext = new ImportContentContext(siteContentItem, context.RecipeStep.Step, importContentSession);
|
||||||
|
|
||||||
var context = new ImportContentContext(siteContentItem, recipeContext.RecipeStep.Step, importContentSession);
|
|
||||||
foreach (var contentHandler in Handlers) {
|
foreach (var contentHandler in Handlers) {
|
||||||
contentHandler.Importing(context);
|
contentHandler.Importing(importContentContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var contentPart in siteContentItem.Parts) {
|
foreach (var contentPart in siteContentItem.Parts) {
|
||||||
var partElement = context.Data.Element(contentPart.PartDefinition.Name);
|
var partElement = importContentContext.Data.Element(contentPart.PartDefinition.Name);
|
||||||
if (partElement == null) {
|
if (partElement == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -67,11 +57,8 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var contentHandler in Handlers) {
|
foreach (var contentHandler in Handlers) {
|
||||||
contentHandler.Imported(context);
|
contentHandler.Imported(importContentContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ImportSettingPart(ContentPart sitePart, XElement element) {
|
private void ImportSettingPart(ContentPart sitePart, XElement element) {
|
||||||
@@ -3,23 +3,21 @@ using System.Linq;
|
|||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Packaging.Models;
|
using Orchard.Packaging.Models;
|
||||||
using Orchard.Packaging.Services;
|
using Orchard.Packaging.Services;
|
||||||
using Orchard.Recipes.Models;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
using Orchard.Themes.Services;
|
using Orchard.Themes.Services;
|
||||||
|
|
||||||
namespace Orchard.Recipes.RecipeHandlers {
|
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||||
public class ThemeRecipeHandler : IRecipeHandler {
|
public class ThemeStep : RecipeExecutionStep {
|
||||||
private readonly IPackagingSourceManager _packagingSourceManager;
|
private readonly IPackagingSourceManager _packagingSourceManager;
|
||||||
private readonly IPackageManager _packageManager;
|
private readonly IPackageManager _packageManager;
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
private readonly IThemeService _themeService;
|
private readonly IThemeService _themeService;
|
||||||
private readonly ISiteThemeService _siteThemeService;
|
private readonly ISiteThemeService _siteThemeService;
|
||||||
|
|
||||||
public ThemeRecipeHandler(
|
public ThemeStep(
|
||||||
IPackagingSourceManager packagingSourceManager,
|
IPackagingSourceManager packagingSourceManager,
|
||||||
IPackageManager packageManager,
|
IPackageManager packageManager,
|
||||||
IExtensionManager extensionManager,
|
IExtensionManager extensionManager,
|
||||||
@@ -31,27 +29,17 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
_themeService = themeService;
|
_themeService = themeService;
|
||||||
_siteThemeService = siteThemeService;
|
_siteThemeService = siteThemeService;
|
||||||
|
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public override string Name { get { return "Theme"; } }
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
// <Theme packageId="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" />
|
// <Theme packageId="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" />
|
||||||
// install themes from feed.
|
// Install themes from feed.
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public override void Execute(RecipeExecutionContext context) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
|
||||||
|
|
||||||
bool enable = false, current = false;
|
bool enable = false, current = false;
|
||||||
string packageId = null, version = null, repository = null;
|
string packageId = null, version = null, repository = null;
|
||||||
|
|
||||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
foreach (var attribute in context.RecipeStep.Step.Attributes()) {
|
||||||
if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||||
enable = Boolean.Parse(attribute.Value);
|
enable = Boolean.Parse(attribute.Value);
|
||||||
}
|
}
|
||||||
@@ -76,9 +64,9 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
throw new InvalidOperationException("The PackageId attribute is required on a Theme declaration in a recipe file.");
|
throw new InvalidOperationException("The PackageId attribute is required on a Theme declaration in a recipe file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// download and install theme from the orchard feed or a custom feed if repository is specified.
|
// Download and install theme from the orchard feed or a custom feed if repository is specified.
|
||||||
bool enforceVersion = version != null;
|
var enforceVersion = version != null;
|
||||||
bool installed = false;
|
var installed = false;
|
||||||
PackagingEntry packagingEntry = null;
|
PackagingEntry packagingEntry = null;
|
||||||
|
|
||||||
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
||||||
@@ -121,11 +109,8 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!installed) {
|
if (!installed) {
|
||||||
throw new InvalidOperationException(string.Format("Theme '{0}' was not found in the specified location.", packageId));
|
throw new InvalidOperationException(String.Format("Theme '{0}' was not found in the specified location.", packageId));
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
|
||||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ThemeAlreadyInstalled(string packageId) {
|
private bool ThemeAlreadyInstalled(string packageId) {
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.Logging;
|
||||||
|
using Orchard.Recipes.Models;
|
||||||
|
using Orchard.Recipes.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Recipes.RecipeHandlers {
|
||||||
|
/// <summary>
|
||||||
|
/// Delegates execution of the step to the appropriate recipe execution step implementation.
|
||||||
|
/// </summary>
|
||||||
|
public class RecipeExecutionStepHandler : Component, IRecipeHandler {
|
||||||
|
private readonly IEnumerable<IRecipeExecutionStep> _recipeExecutionSteps;
|
||||||
|
public RecipeExecutionStepHandler(IEnumerable<IRecipeExecutionStep> recipeExecutionSteps) {
|
||||||
|
_recipeExecutionSteps = recipeExecutionSteps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||||
|
var executionStep = _recipeExecutionSteps.FirstOrDefault(x => x.Name == recipeContext.RecipeStep.Name);
|
||||||
|
var recipeExecutionContext = new RecipeExecutionContext {ExecutionId = recipeContext.ExecutionId, RecipeStep = recipeContext.RecipeStep};
|
||||||
|
|
||||||
|
if (executionStep != null) {
|
||||||
|
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
|
||||||
|
executionStep.Execute(recipeExecutionContext);
|
||||||
|
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
||||||
|
recipeContext.Executed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Orchard.Recipes.Services {
|
||||||
|
public interface IRecipeExecutionStep : IDependency {
|
||||||
|
string Name { get; }
|
||||||
|
void Execute(RecipeExecutionContext context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Orchard.Recipes.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Recipes.Services {
|
||||||
|
public class RecipeExecutionContext {
|
||||||
|
public string ExecutionId { get; set; }
|
||||||
|
public RecipeStep RecipeStep { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Orchard.Recipes.Services {
|
||||||
|
public abstract class RecipeExecutionStep : Component, IRecipeExecutionStep {
|
||||||
|
public abstract string Name { get; }
|
||||||
|
public abstract void Execute(RecipeExecutionContext context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ namespace Orchard.Recipes.Services {
|
|||||||
IRecipeScheduler recipeScheduler,
|
IRecipeScheduler recipeScheduler,
|
||||||
IRecipeExecuteEventHandler recipeExecuteEventHandler,
|
IRecipeExecuteEventHandler recipeExecuteEventHandler,
|
||||||
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
|
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
|
||||||
|
|
||||||
_recipeStepQueue = recipeStepQueue;
|
_recipeStepQueue = recipeStepQueue;
|
||||||
_recipeScheduler = recipeScheduler;
|
_recipeScheduler = recipeScheduler;
|
||||||
_recipeExecuteEventHandler = recipeExecuteEventHandler;
|
_recipeExecuteEventHandler = recipeExecuteEventHandler;
|
||||||
|
|||||||
@@ -2,13 +2,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Recipes.Events;
|
using Orchard.Recipes.Events;
|
||||||
using Orchard.Recipes.Models;
|
using Orchard.Recipes.Models;
|
||||||
|
|
||||||
namespace Orchard.Recipes.Services {
|
namespace Orchard.Recipes.Services {
|
||||||
public class RecipeStepExecutor : IRecipeStepExecutor {
|
public class RecipeStepExecutor : Component, IRecipeStepExecutor {
|
||||||
private readonly IRecipeStepQueue _recipeStepQueue;
|
private readonly IRecipeStepQueue _recipeStepQueue;
|
||||||
private readonly IEnumerable<IRecipeHandler> _recipeHandlers;
|
private readonly IEnumerable<IRecipeHandler> _recipeHandlers;
|
||||||
private readonly IRecipeExecuteEventHandler _recipeExecuteEventHandler;
|
private readonly IRecipeExecuteEventHandler _recipeExecuteEventHandler;
|
||||||
@@ -19,18 +18,13 @@ namespace Orchard.Recipes.Services {
|
|||||||
IEnumerable<IRecipeHandler> recipeHandlers,
|
IEnumerable<IRecipeHandler> recipeHandlers,
|
||||||
IRecipeExecuteEventHandler recipeExecuteEventHandler,
|
IRecipeExecuteEventHandler recipeExecuteEventHandler,
|
||||||
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
|
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
|
||||||
|
|
||||||
_recipeStepQueue = recipeStepQueue;
|
_recipeStepQueue = recipeStepQueue;
|
||||||
_recipeHandlers = recipeHandlers;
|
_recipeHandlers = recipeHandlers;
|
||||||
_recipeExecuteEventHandler = recipeExecuteEventHandler;
|
_recipeExecuteEventHandler = recipeExecuteEventHandler;
|
||||||
_recipeStepResultRecordRepository = recipeStepResultRecordRepository;
|
_recipeStepResultRecordRepository = recipeStepResultRecordRepository;
|
||||||
|
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
public bool ExecuteNextStep(string executionId) {
|
public bool ExecuteNextStep(string executionId) {
|
||||||
var nextRecipeStep = _recipeStepQueue.Dequeue(executionId);
|
var nextRecipeStep = _recipeStepQueue.Dequeue(executionId);
|
||||||
if (nextRecipeStep == null) {
|
if (nextRecipeStep == null) {
|
||||||
@@ -45,9 +39,11 @@ namespace Orchard.Recipes.Services {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
_recipeExecuteEventHandler.RecipeStepExecuting(executionId, recipeContext);
|
_recipeExecuteEventHandler.RecipeStepExecuting(executionId, recipeContext);
|
||||||
|
|
||||||
foreach (var recipeHandler in _recipeHandlers) {
|
foreach (var recipeHandler in _recipeHandlers) {
|
||||||
recipeHandler.ExecuteRecipeStep(recipeContext);
|
recipeHandler.ExecuteRecipeStep(recipeContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateStepResultRecord(executionId, nextRecipeStep.Name, isSuccessful: true);
|
UpdateStepResultRecord(executionId, nextRecipeStep.Name, isSuccessful: true);
|
||||||
_recipeExecuteEventHandler.RecipeStepExecuted(executionId, recipeContext);
|
_recipeExecuteEventHandler.RecipeStepExecuted(executionId, recipeContext);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user