Simplifying recipe step API for implementers.

This commit is contained in:
Sipke Schoorstra
2015-07-15 12:53:19 +01:00
parent de58b4253d
commit 901c11a1ea
22 changed files with 1178 additions and 1239 deletions

View File

@@ -159,7 +159,7 @@
<Compile Include="Packaging\Services\FileBasedProjectSystemTests.cs" />
<Compile Include="Packaging\Services\FolderUpdaterTests.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\Services\RecipeManagerTests.cs" />
<Compile Include="Scripting.Dlr\EvaluatorTests.cs" />

View File

@@ -23,17 +23,16 @@ using Orchard.Packaging.GalleryServer;
using Orchard.Packaging.Models;
using Orchard.Packaging.Services;
using Orchard.Recipes.Models;
using Orchard.Recipes.RecipeHandlers;
using Orchard.Recipes.RecipeExecutionSteps;
using Orchard.Recipes.Services;
using Orchard.Tests.Environment.Extensions;
using Orchard.Tests.Environment.Features;
using Orchard.Tests.Stubs;
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
using Orchard.Tests.Modules.Recipes.Services;
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
[TestFixture]
public class ModuleRecipeHandlerTest : DatabaseEnabledTestsBase {
public class ModuleStepTest : DatabaseEnabledTestsBase {
private ExtensionManagerTests.StubFolders _folders;
private StubPackagingSourceManager _packagesInRepository;
private StubPackageManager _packageManager;
@@ -66,7 +65,7 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
builder.RegisterInstance(_packageManager).As<IPackageManager>();
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
builder.RegisterType<ModuleRecipeHandler>();
builder.RegisterType<ModuleStep>();
builder.RegisterSource(new EventsRegistrationSource());
}
@@ -94,16 +93,16 @@ Features:
Enumerable.Empty<ShellFeature>(),
Enumerable.Empty<ShellParameter>());
ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
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.RecipeStep.Step.Add(new XAttribute("packageId", "Orchard.Module.SuperWiki"));
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
IFeatureManager featureManager = _container.Resolve<IFeatureManager>();
IEnumerable<FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();
Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
moduleRecipeHandler.ExecuteRecipeStep(recipeContext);
moduleStep.Execute(recipeExecutionContext);
var availableFeatures = featureManager.GetAvailableFeatures().Where(x => x.Id == "SuperWiki").FirstOrDefault();
@@ -122,12 +121,12 @@ Features:
Description: My super wiki module for Orchard.
");
ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();
RecipeContext recipeContext = new RecipeContext { RecipeStep = new RecipeStep { Name = "Module", Step = new XElement("SuperWiki") } };
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.RecipeStep.Step.Add(new XAttribute("repository", "test"));
Assert.Throws(typeof (InvalidOperationException), () => moduleRecipeHandler.ExecuteRecipeStep(recipeContext));
Assert.Throws(typeof (InvalidOperationException), () => moduleStep.Execute(recipeExecutionContext));
}
[Test]
@@ -147,14 +146,15 @@ Features:
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("repository", "test"));
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");
Assert.That(installedPackage, Is.Not.Null);
@@ -163,7 +163,7 @@ Features:
}
internal class StubPackagingSourceManager : IPackagingSourceManager {
private List<PublishedPackage> _publishedPackages = new List<PublishedPackage>();
private readonly List<PublishedPackage> _publishedPackages = new List<PublishedPackage>();
public IEnumerable<PackagingSource> GetSources() {
return Enumerable.Empty<PackagingSource>();
@@ -199,7 +199,7 @@ Features:
}
internal class StubPackageManager : IPackageManager {
private IList<PackageInfo> _installedPackages = new List<PackageInfo>();
private readonly IList<PackageInfo> _installedPackages = new List<PackageInfo>();
public IEnumerable<PackageInfo> GetInstalledPackages() {
return _installedPackages;

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Hosting;
using System.Xml.Linq;
using Autofac;
using NUnit.Framework;
@@ -23,21 +22,21 @@ using Orchard.FileSystems.VirtualPath;
using Orchard.Packaging.GalleryServer;
using Orchard.Packaging.Services;
using Orchard.Recipes.Models;
using Orchard.Recipes.RecipeHandlers;
using Orchard.Recipes.RecipeExecutionSteps;
using Orchard.Recipes.Services;
using Orchard.Tests.DisplayManagement.Descriptors;
using Orchard.Tests.Environment.Extensions;
using Orchard.Tests.Environment.Features;
using Orchard.Tests.Stubs;
using Orchard.Tests.UI.Navigation;
using Orchard.Themes.Services;
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
[TestFixture]
public class ThemeRecipeHandlerTest : DatabaseEnabledTestsBase {
private ExtensionManagerTests.StubFolders _folders;
private ModuleRecipeHandlerTest.StubPackagingSourceManager _packagesInRepository;
private ModuleRecipeHandlerTest.StubPackageManager _packageManager;
private ModuleStepTest.StubPackagingSourceManager _packagesInRepository;
private ModuleStepTest.StubPackageManager _packageManager;
protected override IEnumerable<Type> DatabaseTypes {
get {
@@ -50,13 +49,13 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
}
public override void Register(ContainerBuilder builder) {
var _testVirtualPathProvider = new StylesheetBindingStrategyTests.TestVirtualPathProvider();
var testVirtualPathProvider = new StylesheetBindingStrategyTests.TestVirtualPathProvider();
builder.RegisterInstance(new ShellSettings { Name = "Default" });
_folders = new ExtensionManagerTests.StubFolders();
_packagesInRepository = new ModuleRecipeHandlerTest.StubPackagingSourceManager();
_packageManager = new ModuleRecipeHandlerTest.StubPackageManager();
_packagesInRepository = new ModuleStepTest.StubPackagingSourceManager();
_packageManager = new ModuleStepTest.StubPackageManager();
builder.RegisterInstance(_folders).As<IExtensionFolders>();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<FeatureManager>().As<IFeatureManager>();
@@ -64,16 +63,16 @@ namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
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(_packageManager).As<IPackageManager>();
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
builder.RegisterInstance(_testVirtualPathProvider).As<IVirtualPathProvider>();
builder.RegisterInstance(testVirtualPathProvider).As<IVirtualPathProvider>();
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
builder.RegisterType<ThemeService>().As<IThemeService>();
builder.RegisterType<StubOrchardServices>().As<IOrchardServices>();
builder.RegisterType<StubSiteThemeService>().As<ISiteThemeService>();
builder.RegisterType<ThemeRecipeHandler>();
builder.RegisterType<ThemeStep>();
builder.RegisterSource(new EventsRegistrationSource());
}
@@ -101,16 +100,17 @@ Features:
Enumerable.Empty<ShellFeature>(),
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("repository", "test"));
IFeatureManager featureManager = _container.Resolve<IFeatureManager>();
IEnumerable<FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();
var featureManager = _container.Resolve<IFeatureManager>();
var enabledFeatures = featureManager.GetEnabledFeatures();
Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
themeRecipeHandler.ExecuteRecipeStep(recipeContext);
themeStep.Execute(recipeExecutionContext);
// without setting enable no feature should be activated...
featureManager.GetEnabledFeatures();
@@ -118,7 +118,7 @@ Features:
// Adding enable the feature should get active
recipeContext.RecipeStep.Step.Add(new XAttribute("enable", true));
themeRecipeHandler.ExecuteRecipeStep(recipeContext);
themeStep.Execute(recipeExecutionContext);
enabledFeatures = featureManager.GetEnabledFeatures();
Assert.That(enabledFeatures.FirstOrDefault(feature => feature.Id.Equals("SuperWiki")), Is.Not.Null);
@@ -137,12 +137,12 @@ Features:
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"));
Assert.Throws(typeof (InvalidOperationException), () => themeRecipeHandler.ExecuteRecipeStep(recipeContext));
Assert.Throws(typeof (InvalidOperationException), () => themeStep.Execute(recipeExecutionContext));
}
[Test]
@@ -162,14 +162,15 @@ Features:
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("repository", "test"));
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");
Assert.That(installedPackage, Is.Not.Null);

View File

@@ -113,7 +113,7 @@ namespace Orchard.ImportExport.Commands {
}
if (SiteSettings) {
var siteSettingsStep = _orchardServices.WorkContext.Resolve<SiteSettingsBuilderStep>();
var siteSettingsStep = _orchardServices.WorkContext.Resolve<SettingsBuilderStep>();
recipeBuilderSteps.Add(siteSettingsStep);
}

View File

@@ -84,18 +84,22 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecipeBuilders\ContentRecipeBuilderStep.cs" />
<Compile Include="RecipeBuilders\RecipeMetadataBuilderStep.cs" />
<Compile Include="RecipeBuilders\SiteSettingsBuilderStep.cs" />
<Compile Include="RecipeHandlers\CommandRecipeHandler.cs" />
<Compile Include="RecipeHandlers\DataRecipeHandler.cs" />
<Compile Include="RecipeHandlers\FeatureRecipeHandler.cs" />
<Compile Include="RecipeHandlers\MetadataRecipeHandler.cs" />
<Compile Include="RecipeHandlers\MigrationRecipeHandler.cs" />
<Compile Include="RecipeHandlers\ModuleRecipeHandler.cs" />
<Compile Include="RecipeHandlers\SettingsRecipeHandler.cs" />
<Compile Include="RecipeHandlers\ThemeRecipeHandler.cs" />
<Compile Include="RecipeBuilders\SettingsBuilderStep.cs" />
<Compile Include="RecipeExecutionSteps\CommandStep.cs" />
<Compile Include="RecipeExecutionSteps\ContentStep.cs" />
<Compile Include="RecipeExecutionSteps\FeatureStep.cs" />
<Compile Include="RecipeExecutionSteps\ContentSchemaStep.cs" />
<Compile Include="RecipeExecutionSteps\MigrationStep.cs" />
<Compile Include="RecipeExecutionSteps\ModuleStep.cs" />
<Compile Include="RecipeExecutionSteps\SettingsStep.cs" />
<Compile Include="RecipeExecutionSteps\ThemeStep.cs" />
<Compile Include="RecipeHandlers\RecipeExecutionStepHandler.cs" />
<Compile Include="Routes.cs" />
<Compile Include="Services\BuildContext.cs" />
<Compile Include="Services\IRecipeExecutionStep.cs" />
<Compile Include="Services\IRecipeExecutor.cs" />
<Compile Include="Services\RecipeExecutionContext.cs" />
<Compile Include="Services\RecipeExecutionStep.cs" />
<Compile Include="Services\RecipeExecutor.cs" />
<Compile Include="Services\IRecipeBuilder.cs" />
<Compile Include="Services\RecipeBuilder.cs" />
@@ -152,7 +156,7 @@
<Content Include="Views\EditorTemplates\ExportSteps\RecipeMetadata.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\EditorTemplates\ExportSteps\SiteSettings.cshtml" />
<Content Include="Views\EditorTemplates\ExportSteps\Settings.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

View File

@@ -104,11 +104,11 @@ namespace Orchard.Recipes.RecipeBuilders {
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) {
var data = new XElement("Data");
var data = new XElement("Content");
if (batchSize.HasValue && batchSize.Value > 0)
data.SetAttributeValue("BatchSize", batchSize);

View File

@@ -7,23 +7,23 @@ using Orchard.Recipes.Services;
using Orchard.Recipes.ViewModels;
namespace Orchard.Recipes.RecipeBuilders {
public class SiteSettingsBuilderStep : RecipeBuilderStep {
public class SettingsBuilderStep : RecipeBuilderStep {
private readonly IOrchardServices _orchardServices;
public SiteSettingsBuilderStep(IOrchardServices orchardServices) {
public SettingsBuilderStep(IOrchardServices orchardServices) {
_orchardServices = orchardServices;
}
public override string Name {
get { return "SiteSettings"; }
get { return "Settings"; }
}
public override LocalizedString DisplayName {
get { return T("Site Settings"); }
get { return T("Settings"); }
}
public override LocalizedString Description {
get { return T("Exports site settings."); }
get { return T("Exports settings."); }
}
public override int Priority { get { return 20; } }
@@ -34,7 +34,7 @@ namespace Orchard.Recipes.RecipeBuilders {
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
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) {

View File

@@ -4,25 +4,20 @@ using System.IO;
using System.Linq;
using System.Text;
using Orchard.Commands;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class CommandRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class CommandStep : RecipeExecutionStep {
private readonly ICommandManager _commandManager;
private readonly CommandParser _commandParser;
public CommandRecipeHandler(ICommandManager commandManager) {
public CommandStep(ICommandManager commandManager) {
_commandManager = commandManager;
_commandParser = new CommandParser();
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public override string Name { get { return "Command"; } }
/*
<Command>
@@ -31,16 +26,10 @@ namespace Orchard.Recipes.RecipeHandlers {
command3
</Command>
*/
// run Orchard commands.
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Command", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
// Run Orchard commands.
public override void Execute(RecipeExecutionContext context) {
var commands =
recipeContext.RecipeStep.Step.Value
context.RecipeStep.Step.Value
.Split(new[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries)
.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);
}
}

View File

@@ -2,18 +2,18 @@
using System.Xml;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentTypes.Events;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class MetadataRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class ContentSchemaStep : RecipeExecutionStep {
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly IContentDefinitionReader _contentDefinitionReader;
private readonly IContentDefinitionEventHandler _contentDefinitonEventHandlers;
public MetadataRecipeHandler(
public override string Name { get { return "ContentSchema"; } }
public ContentSchemaStep(
IContentDefinitionManager contentDefinitionManager,
IContentDefinitionReader contentDefinitionReader,
IContentDefinitionEventHandler contentDefinitonEventHandlers) {
@@ -21,15 +21,10 @@ namespace Orchard.Recipes.RecipeHandlers {
_contentDefinitionManager = contentDefinitionManager;
_contentDefinitionReader = contentDefinitionReader;
_contentDefinitonEventHandlers = contentDefinitonEventHandlers;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
/*
<Metadata>
<ContentDefinition>
<Types>
<Blog creatable="true">
<Body format="abodyformat"/>
@@ -37,18 +32,12 @@ namespace Orchard.Recipes.RecipeHandlers {
</Types>
<Parts>
</Parts>
</Metadata>
</ContentDefinition>
*/
// Set type settings and attach parts to types.
// Create dynamic parts.
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Metadata", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
foreach (var metadataElement in recipeContext.RecipeStep.Step.Elements()) {
public override void Execute(RecipeExecutionContext context) {
foreach (var metadataElement in context.RecipeStep.Step.Elements()) {
Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName);
switch (metadataElement.Name.LocalName) {
case "Types":
@@ -92,9 +81,6 @@ namespace Orchard.Recipes.RecipeHandlers {
break;
}
}
recipeContext.Executed = true;
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
}
}
}

View File

@@ -3,58 +3,47 @@ using System.Collections.Generic;
using System.Xml.Linq;
using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class DataRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class ContentStep : RecipeExecutionStep {
private readonly IOrchardServices _orchardServices;
private readonly ITransactionManager _transactionManager;
public DataRecipeHandler(IOrchardServices orchardServices, ITransactionManager transactionManager) {
public ContentStep(IOrchardServices orchardServices, ITransactionManager transactionManager) {
_orchardServices = orchardServices;
_transactionManager = transactionManager;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public override string Name { get { return "Content"; } }
// <Data />
// Import Data
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Data", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
// Import Data.
public override void Execute(RecipeExecutionContext context) {
var importContentSession = new ImportContentSession(_orchardServices.ContentManager);
// Populate local dictionary with elements and their ids
var elementDictionary = CreateElementDictionary(recipeContext.RecipeStep.Step);
// Populate local dictionary with elements and their ids.
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) {
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;
int batchSize = GetBatchSizeForDataStep(recipeContext.RecipeStep.Step);
var batchSize = GetBatchSizeForDataStep(context.RecipeStep.Step);
Logger.Debug("Using batch size {0}.", batchSize);
//Run the import
// Run the import.
try {
while (startIndex < elementDictionary.Count) {
Logger.Debug("Importing batch starting at index {0}.", startIndex);
importContentSession.InitializeBatch(startIndex, batchSize);
//the session determines which items are included in the current batch
//so that dependencies can be managed within the same transaction
// The session determines which items are included in the current batch
// so that dependencies can be managed within the same transaction.
var nextIdentity = importContentSession.GetNextInBatch();
while (nextIdentity != null) {
var itemId = "";
@@ -76,7 +65,7 @@ namespace Orchard.Recipes.RecipeHandlers {
startIndex += batchSize;
//Create a new transaction for each batch
// Create a new transaction for each batch.
if (startIndex < elementDictionary.Count) {
_transactionManager.RequireNew();
}
@@ -85,13 +74,10 @@ namespace Orchard.Recipes.RecipeHandlers {
}
}
catch (Exception) {
//Ensure a failed batch is rolled back
// Ensure a failed batch is rolled back.
_transactionManager.Cancel();
throw;
}
recipeContext.Executed = true;
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
}
private Dictionary<string, XElement> CreateElementDictionary(XElement step) {

View File

@@ -2,33 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using Orchard.Environment.Features;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class FeatureRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class FeatureStep : RecipeExecutionStep {
private readonly IFeatureManager _featureManager;
public FeatureRecipeHandler(IFeatureManager featureManager) {
public FeatureStep(IFeatureManager featureManager) {
_featureManager = featureManager;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public override string Name { get { return "Feature"; } }
// <Feature enable="f1,f2,f3" disable="f4" />
// Enable/Disable features.
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Feature", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
public override void Execute(RecipeExecutionContext recipeContext) {
var featuresToEnable = new List<string>();
var featuresToDisable = new List<string>();
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
@@ -64,9 +53,6 @@ namespace Orchard.Recipes.RecipeHandlers {
Logger.Information("Enabling features: {0}", String.Join(";", featuresToEnable));
_featureManager.EnableFeatures(featuresToEnable, true);
}
recipeContext.Executed = true;
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
}
private static List<string> ParseFeatures(string csv) {

View File

@@ -2,37 +2,26 @@
using System.Collections.Generic;
using System.Linq;
using Orchard.Data.Migration;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class MigrationRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class MigrationStep : RecipeExecutionStep {
private readonly IDataMigrationManager _dataMigrationManager;
public MigrationRecipeHandler(IDataMigrationManager dataMigrationManager) {
public MigrationStep(IDataMigrationManager dataMigrationManager) {
_dataMigrationManager = dataMigrationManager;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public override string Name { get { return "Migration"; } }
// <Migration features="f1, f2" />
// <Migration features="*" />
// Run migration for features.
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Migration", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
bool runAll = false;
public override void Execute(RecipeExecutionContext context) {
var runAll = false;
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)) {
features = ParseFeatures(attribute.Value);
if (features.Contains("*"))
@@ -65,9 +54,6 @@ namespace Orchard.Recipes.RecipeHandlers {
throw;
}
}
recipeContext.Executed = true;
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
}
private static List<string> ParseFeatures(string csv) {

View File

@@ -3,45 +3,34 @@ using System.Linq;
using System.Web.Hosting;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Packaging.Models;
using Orchard.Packaging.Services;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class ModuleRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class ModuleStep : RecipeExecutionStep {
private readonly IPackagingSourceManager _packagingSourceManager;
private readonly IPackageManager _packageManager;
private readonly IExtensionManager _extensionManager;
public ModuleRecipeHandler(
public ModuleStep(
IPackagingSourceManager packagingSourceManager,
IPackageManager packageManager,
IExtensionManager extensionManager) {
_packagingSourceManager = packagingSourceManager;
_packageManager = packageManager;
_extensionManager = extensionManager;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public override string Name { get { return "Module"; } }
// <Module packageId="module1" [repository="somerepo"] version="1.1" />
// install modules from feed.
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
// Install modules from feed.
public override void Execute(RecipeExecutionContext context) {
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)) {
packageId = attribute.Value;
}
@@ -52,7 +41,7 @@ namespace Orchard.Recipes.RecipeHandlers {
repository = attribute.Value;
}
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.
bool enforceVersion = version != null;
bool installed = false;
var enforceVersion = version != null;
var installed = false;
PackagingEntry packagingEntry = null;
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
@@ -94,11 +83,8 @@ namespace Orchard.Recipes.RecipeHandlers {
}
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) {

View File

@@ -9,22 +9,19 @@ using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
using Orchard.Settings;
namespace Orchard.Recipes.RecipeHandlers {
public class SettingsRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class SettingsStep : RecipeExecutionStep {
private readonly ISiteService _siteService;
private readonly IContentManager _contentManager;
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;
_contentManager = contentManager;
_handlers = handlers;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public override string Name { get { return "Settings"; } }
private IEnumerable<IContentHandler> Handlers { get { return _handlers.Value; } }
/*
@@ -34,24 +31,17 @@ namespace Orchard.Recipes.RecipeHandlers {
</Settings>
*/
// Set site and part settings.
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Settings", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
public override void Execute(RecipeExecutionContext context) {
var siteContentItem = _siteService.GetSiteSettings().ContentItem;
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) {
contentHandler.Importing(context);
contentHandler.Importing(importContentContext);
}
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) {
continue;
}
@@ -67,11 +57,8 @@ namespace Orchard.Recipes.RecipeHandlers {
}
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) {

View File

@@ -3,23 +3,21 @@ using System.Linq;
using System.Web.Hosting;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Packaging.Models;
using Orchard.Packaging.Services;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
using Orchard.Themes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class ThemeRecipeHandler : IRecipeHandler {
namespace Orchard.Recipes.RecipeExecutionSteps {
public class ThemeStep : RecipeExecutionStep {
private readonly IPackagingSourceManager _packagingSourceManager;
private readonly IPackageManager _packageManager;
private readonly IExtensionManager _extensionManager;
private readonly IThemeService _themeService;
private readonly ISiteThemeService _siteThemeService;
public ThemeRecipeHandler(
public ThemeStep(
IPackagingSourceManager packagingSourceManager,
IPackageManager packageManager,
IExtensionManager extensionManager,
@@ -31,27 +29,17 @@ namespace Orchard.Recipes.RecipeHandlers {
_extensionManager = extensionManager;
_themeService = themeService;
_siteThemeService = siteThemeService;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public override string Name { get { return "Theme"; } }
// <Theme packageId="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" />
// install themes from feed.
public void ExecuteRecipeStep(RecipeContext recipeContext) {
if (!String.Equals(recipeContext.RecipeStep.Name, "Theme", StringComparison.OrdinalIgnoreCase)) {
return;
}
Logger.Information("Executing recipe step '{0}'; ExecutionId={1}", recipeContext.RecipeStep.Name, recipeContext.ExecutionId);
// Install themes from feed.
public override void Execute(RecipeExecutionContext context) {
bool enable = false, current = false;
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)) {
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.");
}
// download and install theme from the orchard feed or a custom feed if repository is specified.
bool enforceVersion = version != null;
bool installed = false;
// Download and install theme from the orchard feed or a custom feed if repository is specified.
var enforceVersion = version != null;
var installed = false;
PackagingEntry packagingEntry = null;
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
@@ -121,11 +109,8 @@ namespace Orchard.Recipes.RecipeHandlers {
}
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) {

View File

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

View File

@@ -0,0 +1,6 @@
namespace Orchard.Recipes.Services {
public interface IRecipeExecutionStep : IDependency {
string Name { get; }
void Execute(RecipeExecutionContext context);
}
}

View File

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

View File

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

View File

@@ -17,6 +17,7 @@ namespace Orchard.Recipes.Services {
IRecipeScheduler recipeScheduler,
IRecipeExecuteEventHandler recipeExecuteEventHandler,
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
_recipeStepQueue = recipeStepQueue;
_recipeScheduler = recipeScheduler;
_recipeExecuteEventHandler = recipeExecuteEventHandler;

View File

@@ -2,13 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using Orchard.Data;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Events;
using Orchard.Recipes.Models;
namespace Orchard.Recipes.Services {
public class RecipeStepExecutor : IRecipeStepExecutor {
public class RecipeStepExecutor : Component, IRecipeStepExecutor {
private readonly IRecipeStepQueue _recipeStepQueue;
private readonly IEnumerable<IRecipeHandler> _recipeHandlers;
private readonly IRecipeExecuteEventHandler _recipeExecuteEventHandler;
@@ -19,18 +18,13 @@ namespace Orchard.Recipes.Services {
IEnumerable<IRecipeHandler> recipeHandlers,
IRecipeExecuteEventHandler recipeExecuteEventHandler,
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
_recipeStepQueue = recipeStepQueue;
_recipeHandlers = recipeHandlers;
_recipeExecuteEventHandler = recipeExecuteEventHandler;
_recipeStepResultRecordRepository = recipeStepResultRecordRepository;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public bool ExecuteNextStep(string executionId) {
var nextRecipeStep = _recipeStepQueue.Dequeue(executionId);
if (nextRecipeStep == null) {
@@ -45,9 +39,11 @@ namespace Orchard.Recipes.Services {
try {
_recipeExecuteEventHandler.RecipeStepExecuting(executionId, recipeContext);
foreach (var recipeHandler in _recipeHandlers) {
recipeHandler.ExecuteRecipeStep(recipeContext);
}
UpdateStepResultRecord(executionId, nextRecipeStep.Name, isSuccessful: true);
_recipeExecuteEventHandler.RecipeStepExecuted(executionId, recipeContext);
}