mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +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\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" />
|
||||
|
@@ -1,252 +1,252 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Autofac;
|
||||
using NuGet;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Core.Settings.Descriptor;
|
||||
using Orchard.Core.Settings.Descriptor.Records;
|
||||
using Orchard.Core.Settings.State;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Folders;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Environment.State;
|
||||
using Orchard.Events;
|
||||
using Orchard.Packaging.GalleryServer;
|
||||
using Orchard.Packaging.Models;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.RecipeHandlers;
|
||||
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 {
|
||||
private ExtensionManagerTests.StubFolders _folders;
|
||||
private StubPackagingSourceManager _packagesInRepository;
|
||||
private StubPackageManager _packageManager;
|
||||
|
||||
protected override IEnumerable<Type> DatabaseTypes {
|
||||
get {
|
||||
return new[] {
|
||||
typeof (ShellDescriptorRecord),
|
||||
typeof (ShellFeatureRecord),
|
||||
typeof (ShellParameterRecord),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterInstance(new ShellSettings { Name = "Default" });
|
||||
|
||||
_folders = new ExtensionManagerTests.StubFolders();
|
||||
_packagesInRepository = new StubPackagingSourceManager();
|
||||
_packageManager = new StubPackageManager();
|
||||
builder.RegisterInstance(_folders).As<IExtensionFolders>();
|
||||
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
|
||||
builder.RegisterType<FeatureManager>().As<IFeatureManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
|
||||
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
|
||||
builder.RegisterType<ShellDescriptorManager>().As<IShellDescriptorManager>().SingleInstance();
|
||||
builder.RegisterType<StubDataMigrationManager>().As<IDataMigrationManager>();
|
||||
builder.RegisterInstance(_packagesInRepository).As<IPackagingSourceManager>();
|
||||
builder.RegisterInstance(_packageManager).As<IPackageManager>();
|
||||
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
|
||||
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
|
||||
builder.RegisterType<ModuleRecipeHandler>();
|
||||
builder.RegisterSource(new EventsRegistrationSource());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteRecipeStepTest() {
|
||||
_folders.Manifests.Add("SuperWiki", @"
|
||||
Name: SuperWiki
|
||||
Version: 1.0.3
|
||||
OrchardVersion: 1
|
||||
Features:
|
||||
SuperWiki:
|
||||
Description: My super wiki module for Orchard.
|
||||
");
|
||||
_packagesInRepository.AddPublishedPackage(new PublishedPackage {
|
||||
Id = "Orchard.Module.SuperWiki",
|
||||
PackageType = DefaultExtensionTypes.Module,
|
||||
Title = "SuperWiki",
|
||||
Version = "1.0.3",
|
||||
IsLatestVersion = true,
|
||||
});
|
||||
|
||||
IShellDescriptorManager shellDescriptorManager = _container.Resolve<IShellDescriptorManager>();
|
||||
// No features enabled
|
||||
shellDescriptorManager.UpdateShellDescriptor(0,
|
||||
Enumerable.Empty<ShellFeature>(),
|
||||
Enumerable.Empty<ShellParameter>());
|
||||
|
||||
ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();
|
||||
|
||||
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"));
|
||||
|
||||
IFeatureManager featureManager = _container.Resolve<IFeatureManager>();
|
||||
IEnumerable<FeatureDescriptor> enabledFeatures = featureManager.GetEnabledFeatures();
|
||||
Assert.That(enabledFeatures.Count(), Is.EqualTo(0));
|
||||
moduleRecipeHandler.ExecuteRecipeStep(recipeContext);
|
||||
|
||||
|
||||
var availableFeatures = featureManager.GetAvailableFeatures().Where(x => x.Id == "SuperWiki").FirstOrDefault();
|
||||
Assert.That(availableFeatures.Id, Is.EqualTo("SuperWiki"));
|
||||
Assert.That(recipeContext.Executed, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteRecipeStepNeedsNameTest() {
|
||||
_folders.Manifests.Add("SuperWiki", @"
|
||||
Name: SuperWiki
|
||||
Version: 1.0.3
|
||||
OrchardVersion: 1
|
||||
Features:
|
||||
SuperWiki:
|
||||
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") } };
|
||||
recipeContext.RecipeStep.Step.Add(new XAttribute("repository", "test"));
|
||||
|
||||
Assert.Throws(typeof (InvalidOperationException), () => moduleRecipeHandler.ExecuteRecipeStep(recipeContext));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteRecipeStepWithRepositoryAndVersionNotLatestTest() {
|
||||
_packagesInRepository.AddPublishedPackage(new PublishedPackage {
|
||||
Id = "Orchard.Module.SuperWiki",
|
||||
PackageType = DefaultExtensionTypes.Module,
|
||||
Title = "SuperWiki",
|
||||
Version = "1.0.3",
|
||||
IsLatestVersion = true,
|
||||
});
|
||||
_packagesInRepository.AddPublishedPackage(new PublishedPackage {
|
||||
Id = "Orchard.Module.SuperWiki",
|
||||
PackageType = DefaultExtensionTypes.Module,
|
||||
Title = "SuperWiki",
|
||||
Version = "1.0.2",
|
||||
IsLatestVersion = false,
|
||||
});
|
||||
|
||||
ModuleRecipeHandler moduleRecipeHandler = _container.Resolve<ModuleRecipeHandler>();
|
||||
|
||||
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);
|
||||
|
||||
var installedPackage = _packageManager.GetInstalledPackages().FirstOrDefault(info => info.ExtensionName == "Orchard.Module.SuperWiki");
|
||||
Assert.That(installedPackage, Is.Not.Null);
|
||||
Assert.That(installedPackage.ExtensionVersion, Is.EqualTo("1.0.2"));
|
||||
Assert.That(recipeContext.Executed, Is.True);
|
||||
}
|
||||
|
||||
internal class StubPackagingSourceManager : IPackagingSourceManager {
|
||||
private List<PublishedPackage> _publishedPackages = new List<PublishedPackage>();
|
||||
|
||||
public IEnumerable<PackagingSource> GetSources() {
|
||||
return Enumerable.Empty<PackagingSource>();
|
||||
}
|
||||
|
||||
public int AddSource(string feedTitle, string feedUrl) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RemoveSource(int id) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<PackagingEntry> GetExtensionList(bool includeScreenshots, PackagingSource packagingSource = null, Func<IQueryable<PublishedPackage>, IQueryable<PublishedPackage>> query = null) {
|
||||
return query(_publishedPackages.AsQueryable()).Select(package => CreatePackagingEntry(package));
|
||||
}
|
||||
|
||||
public int GetExtensionCount(PackagingSource packagingSource = null, Func<IQueryable<PublishedPackage>, IQueryable<PublishedPackage>> query = null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void AddPublishedPackage(PublishedPackage package) {
|
||||
_publishedPackages.Add(package);
|
||||
}
|
||||
|
||||
private static PackagingEntry CreatePackagingEntry(PublishedPackage package) {
|
||||
return new PackagingEntry {
|
||||
PackageId = package.Id,
|
||||
Title = package.Title,
|
||||
Version = package.Version,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal class StubPackageManager : IPackageManager {
|
||||
private IList<PackageInfo> _installedPackages = new List<PackageInfo>();
|
||||
|
||||
public IEnumerable<PackageInfo> GetInstalledPackages() {
|
||||
return _installedPackages;
|
||||
}
|
||||
|
||||
public PackageData Harvest(string extensionName) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public PackageInfo Install(IPackage package, string location, string applicationPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PackageInfo Install(string packageId, string version, string location, string applicationPath) {
|
||||
var package = new PackageInfo {
|
||||
ExtensionName = packageId,
|
||||
ExtensionVersion = version,
|
||||
};
|
||||
_installedPackages.Add(package);
|
||||
return package;
|
||||
}
|
||||
|
||||
public void Uninstall(string packageId, string applicationPath) {
|
||||
}
|
||||
|
||||
public ExtensionDescriptor GetExtensionDescriptor(IPackage package, string extensionType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal class StubDataMigrationManager : IDataMigrationManager {
|
||||
public bool IsFeatureAlreadyInstalled(string feature) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetFeaturesThatNeedUpdate() {
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
public void Update(string feature) {
|
||||
}
|
||||
|
||||
public void Update(IEnumerable<string> features) {
|
||||
}
|
||||
|
||||
public void Uninstall(string feature) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Autofac;
|
||||
using NuGet;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Core.Settings.Descriptor;
|
||||
using Orchard.Core.Settings.Descriptor.Records;
|
||||
using Orchard.Core.Settings.State;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Folders;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Environment.State;
|
||||
using Orchard.Events;
|
||||
using Orchard.Packaging.GalleryServer;
|
||||
using Orchard.Packaging.Models;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Recipes.Models;
|
||||
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;
|
||||
|
||||
namespace Orchard.Tests.Modules.Recipes.RecipeHandlers {
|
||||
[TestFixture]
|
||||
public class ModuleStepTest : DatabaseEnabledTestsBase {
|
||||
private ExtensionManagerTests.StubFolders _folders;
|
||||
private StubPackagingSourceManager _packagesInRepository;
|
||||
private StubPackageManager _packageManager;
|
||||
|
||||
protected override IEnumerable<Type> DatabaseTypes {
|
||||
get {
|
||||
return new[] {
|
||||
typeof (ShellDescriptorRecord),
|
||||
typeof (ShellFeatureRecord),
|
||||
typeof (ShellParameterRecord),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterInstance(new ShellSettings { Name = "Default" });
|
||||
|
||||
_folders = new ExtensionManagerTests.StubFolders();
|
||||
_packagesInRepository = new StubPackagingSourceManager();
|
||||
_packageManager = new StubPackageManager();
|
||||
builder.RegisterInstance(_folders).As<IExtensionFolders>();
|
||||
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
|
||||
builder.RegisterType<FeatureManager>().As<IFeatureManager>();
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
|
||||
builder.RegisterType<StubAsyncTokenProvider>().As<IAsyncTokenProvider>();
|
||||
builder.RegisterType<ShellDescriptorManager>().As<IShellDescriptorManager>().SingleInstance();
|
||||
builder.RegisterType<StubDataMigrationManager>().As<IDataMigrationManager>();
|
||||
builder.RegisterInstance(_packagesInRepository).As<IPackagingSourceManager>();
|
||||
builder.RegisterInstance(_packageManager).As<IPackageManager>();
|
||||
builder.RegisterType<ShellStateManager>().As<IShellStateManager>().SingleInstance();
|
||||
builder.RegisterType<StubEventBus>().As<IEventBus>().SingleInstance();
|
||||
builder.RegisterType<ModuleStep>();
|
||||
builder.RegisterSource(new EventsRegistrationSource());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteRecipeStepTest() {
|
||||
_folders.Manifests.Add("SuperWiki", @"
|
||||
Name: SuperWiki
|
||||
Version: 1.0.3
|
||||
OrchardVersion: 1
|
||||
Features:
|
||||
SuperWiki:
|
||||
Description: My super wiki module for Orchard.
|
||||
");
|
||||
_packagesInRepository.AddPublishedPackage(new PublishedPackage {
|
||||
Id = "Orchard.Module.SuperWiki",
|
||||
PackageType = DefaultExtensionTypes.Module,
|
||||
Title = "SuperWiki",
|
||||
Version = "1.0.3",
|
||||
IsLatestVersion = true,
|
||||
});
|
||||
|
||||
IShellDescriptorManager shellDescriptorManager = _container.Resolve<IShellDescriptorManager>();
|
||||
// No features enabled
|
||||
shellDescriptorManager.UpdateShellDescriptor(0,
|
||||
Enumerable.Empty<ShellFeature>(),
|
||||
Enumerable.Empty<ShellParameter>());
|
||||
|
||||
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));
|
||||
moduleStep.Execute(recipeExecutionContext);
|
||||
|
||||
|
||||
var availableFeatures = featureManager.GetAvailableFeatures().Where(x => x.Id == "SuperWiki").FirstOrDefault();
|
||||
Assert.That(availableFeatures.Id, Is.EqualTo("SuperWiki"));
|
||||
Assert.That(recipeContext.Executed, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteRecipeStepNeedsNameTest() {
|
||||
_folders.Manifests.Add("SuperWiki", @"
|
||||
Name: SuperWiki
|
||||
Version: 1.0.3
|
||||
OrchardVersion: 1
|
||||
Features:
|
||||
SuperWiki:
|
||||
Description: My super wiki module for Orchard.
|
||||
");
|
||||
|
||||
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), () => moduleStep.Execute(recipeExecutionContext));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteRecipeStepWithRepositoryAndVersionNotLatestTest() {
|
||||
_packagesInRepository.AddPublishedPackage(new PublishedPackage {
|
||||
Id = "Orchard.Module.SuperWiki",
|
||||
PackageType = DefaultExtensionTypes.Module,
|
||||
Title = "SuperWiki",
|
||||
Version = "1.0.3",
|
||||
IsLatestVersion = true,
|
||||
});
|
||||
_packagesInRepository.AddPublishedPackage(new PublishedPackage {
|
||||
Id = "Orchard.Module.SuperWiki",
|
||||
PackageType = DefaultExtensionTypes.Module,
|
||||
Title = "SuperWiki",
|
||||
Version = "1.0.2",
|
||||
IsLatestVersion = false,
|
||||
});
|
||||
|
||||
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"));
|
||||
recipeContext.RecipeStep.Step.Add(new XAttribute("version", "1.0.2"));
|
||||
|
||||
moduleStep.Execute(recipeExecutionContext);
|
||||
|
||||
var installedPackage = _packageManager.GetInstalledPackages().FirstOrDefault(info => info.ExtensionName == "Orchard.Module.SuperWiki");
|
||||
Assert.That(installedPackage, Is.Not.Null);
|
||||
Assert.That(installedPackage.ExtensionVersion, Is.EqualTo("1.0.2"));
|
||||
Assert.That(recipeContext.Executed, Is.True);
|
||||
}
|
||||
|
||||
internal class StubPackagingSourceManager : IPackagingSourceManager {
|
||||
private readonly List<PublishedPackage> _publishedPackages = new List<PublishedPackage>();
|
||||
|
||||
public IEnumerable<PackagingSource> GetSources() {
|
||||
return Enumerable.Empty<PackagingSource>();
|
||||
}
|
||||
|
||||
public int AddSource(string feedTitle, string feedUrl) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RemoveSource(int id) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<PackagingEntry> GetExtensionList(bool includeScreenshots, PackagingSource packagingSource = null, Func<IQueryable<PublishedPackage>, IQueryable<PublishedPackage>> query = null) {
|
||||
return query(_publishedPackages.AsQueryable()).Select(package => CreatePackagingEntry(package));
|
||||
}
|
||||
|
||||
public int GetExtensionCount(PackagingSource packagingSource = null, Func<IQueryable<PublishedPackage>, IQueryable<PublishedPackage>> query = null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void AddPublishedPackage(PublishedPackage package) {
|
||||
_publishedPackages.Add(package);
|
||||
}
|
||||
|
||||
private static PackagingEntry CreatePackagingEntry(PublishedPackage package) {
|
||||
return new PackagingEntry {
|
||||
PackageId = package.Id,
|
||||
Title = package.Title,
|
||||
Version = package.Version,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal class StubPackageManager : IPackageManager {
|
||||
private readonly IList<PackageInfo> _installedPackages = new List<PackageInfo>();
|
||||
|
||||
public IEnumerable<PackageInfo> GetInstalledPackages() {
|
||||
return _installedPackages;
|
||||
}
|
||||
|
||||
public PackageData Harvest(string extensionName) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public PackageInfo Install(IPackage package, string location, string applicationPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PackageInfo Install(string packageId, string version, string location, string applicationPath) {
|
||||
var package = new PackageInfo {
|
||||
ExtensionName = packageId,
|
||||
ExtensionVersion = version,
|
||||
};
|
||||
_installedPackages.Add(package);
|
||||
return package;
|
||||
}
|
||||
|
||||
public void Uninstall(string packageId, string applicationPath) {
|
||||
}
|
||||
|
||||
public ExtensionDescriptor GetExtensionDescriptor(IPackage package, string extensionType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
internal class StubDataMigrationManager : IDataMigrationManager {
|
||||
public bool IsFeatureAlreadyInstalled(string feature) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetFeaturesThatNeedUpdate() {
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
public void Update(string feature) {
|
||||
}
|
||||
|
||||
public void Update(IEnumerable<string> features) {
|
||||
}
|
||||
|
||||
public void Uninstall(string feature) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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>
|
||||
|
@@ -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);
|
||||
|
@@ -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) {
|
@@ -1,212 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 {
|
||||
private readonly ICommandManager _commandManager;
|
||||
private readonly CommandParser _commandParser;
|
||||
|
||||
public CommandRecipeHandler(ICommandManager commandManager) {
|
||||
_commandManager = commandManager;
|
||||
_commandParser = new CommandParser();
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
/*
|
||||
<Command>
|
||||
command1
|
||||
command2
|
||||
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);
|
||||
|
||||
var commands =
|
||||
recipeContext.RecipeStep.Step.Value
|
||||
.Split(new[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(commandEntry => commandEntry.Trim());
|
||||
|
||||
foreach (var command in commands) {
|
||||
if (!String.IsNullOrEmpty(command)) {
|
||||
Logger.Information("Executing command: {0}", command);
|
||||
try {
|
||||
var commandParameters = _commandParser.ParseCommandParameters(command);
|
||||
var input = new StringReader("");
|
||||
var output = new StringWriter();
|
||||
_commandManager.Execute(new CommandParameters { Arguments = commandParameters.Arguments, Input = input, Output = output, Switches = commandParameters.Switches });
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while executing command: {0}", command);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
||||
}
|
||||
}
|
||||
|
||||
// Utility class for parsing lines of commands.
|
||||
// Note: This lexer handles double quotes pretty harshly by design.
|
||||
// In case you needed them in your arguments, hopefully single quotes work for you as a replacement on the receiving end.
|
||||
class CommandParser {
|
||||
public CommandParameters ParseCommandParameters(string command) {
|
||||
var args = SplitArgs(command);
|
||||
var arguments = new List<string>();
|
||||
var result = new CommandParameters {
|
||||
Switches = new Dictionary<string, string>()
|
||||
};
|
||||
|
||||
foreach (var arg in args) {
|
||||
if (arg.StartsWith("/")) {
|
||||
//If arg is not empty and starts with '/'
|
||||
|
||||
int index = arg.IndexOf(':');
|
||||
var switchName = (index < 0 ? arg.Substring(1) : arg.Substring(1, index - 1));
|
||||
var switchValue = (index < 0 || index >= arg.Length ? string.Empty : arg.Substring(index + 1));
|
||||
|
||||
if (string.IsNullOrEmpty(switchName))
|
||||
{
|
||||
throw new ArgumentException(string.Format("Invalid switch syntax: \"{0}\". Valid syntax is /<switchName>[:<switchValue>].", arg));
|
||||
}
|
||||
|
||||
result.Switches.Add(switchName, switchValue);
|
||||
}
|
||||
else {
|
||||
arguments.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
result.Arguments = arguments;
|
||||
return result;
|
||||
}
|
||||
|
||||
class State {
|
||||
private readonly string _commandLine;
|
||||
private readonly StringBuilder _stringBuilder;
|
||||
private readonly List<string> _arguments;
|
||||
private int _index;
|
||||
|
||||
public State(string commandLine) {
|
||||
_commandLine = commandLine;
|
||||
_stringBuilder = new StringBuilder();
|
||||
_arguments = new List<string>();
|
||||
}
|
||||
|
||||
public StringBuilder StringBuilder { get { return _stringBuilder; } }
|
||||
public bool EOF { get { return _index >= _commandLine.Length; } }
|
||||
public char Current { get { return _commandLine[_index]; } }
|
||||
public IEnumerable<string> Arguments { get { return _arguments; } }
|
||||
|
||||
public void AddArgument() {
|
||||
_arguments.Add(StringBuilder.ToString());
|
||||
StringBuilder.Clear();
|
||||
}
|
||||
|
||||
public void AppendCurrent() {
|
||||
StringBuilder.Append(Current);
|
||||
}
|
||||
|
||||
public void Append(char ch) {
|
||||
StringBuilder.Append(ch);
|
||||
}
|
||||
|
||||
public void MoveNext() {
|
||||
if (!EOF)
|
||||
_index++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implement the same logic as found at
|
||||
/// http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
|
||||
/// The 3 special characters are quote, backslash and whitespaces, in order
|
||||
/// of priority.
|
||||
/// The semantics of a quote is: whatever the state of the lexer, copy
|
||||
/// all characters verbatim until the next quote or EOF.
|
||||
/// The semantics of backslash is: If the next character is a backslash or a quote,
|
||||
/// copy the next character. Otherwise, copy the backslash and the next character.
|
||||
/// The semantics of whitespace is: end the current argument and move on to the next one.
|
||||
/// </summary>
|
||||
private static IEnumerable<string> SplitArgs(string commandLine) {
|
||||
var state = new State(commandLine);
|
||||
while (!state.EOF) {
|
||||
switch (state.Current) {
|
||||
case '"':
|
||||
ProcessQuote(state);
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
ProcessBackslash(state);
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
case '\t':
|
||||
if (state.StringBuilder.Length > 0)
|
||||
state.AddArgument();
|
||||
state.MoveNext();
|
||||
break;
|
||||
|
||||
default:
|
||||
state.AppendCurrent();
|
||||
state.MoveNext();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state.StringBuilder.Length > 0)
|
||||
state.AddArgument();
|
||||
return state.Arguments;
|
||||
}
|
||||
|
||||
private static void ProcessQuote(State state) {
|
||||
state.MoveNext();
|
||||
while (!state.EOF) {
|
||||
if (state.Current == '"') {
|
||||
state.MoveNext();
|
||||
break;
|
||||
}
|
||||
state.AppendCurrent();
|
||||
state.MoveNext();
|
||||
}
|
||||
|
||||
state.AddArgument();
|
||||
}
|
||||
|
||||
private static void ProcessBackslash(State state) {
|
||||
state.MoveNext();
|
||||
if (state.EOF) {
|
||||
state.Append('\\');
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.Current == '"') {
|
||||
state.Append('"');
|
||||
state.MoveNext();
|
||||
}
|
||||
else {
|
||||
state.Append('\\');
|
||||
state.AppendCurrent();
|
||||
state.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Orchard.Commands;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||
public class CommandStep : RecipeExecutionStep {
|
||||
private readonly ICommandManager _commandManager;
|
||||
private readonly CommandParser _commandParser;
|
||||
|
||||
public CommandStep(ICommandManager commandManager) {
|
||||
_commandManager = commandManager;
|
||||
_commandParser = new CommandParser();
|
||||
}
|
||||
|
||||
public override string Name { get { return "Command"; } }
|
||||
|
||||
/*
|
||||
<Command>
|
||||
command1
|
||||
command2
|
||||
command3
|
||||
</Command>
|
||||
*/
|
||||
// Run Orchard commands.
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
var commands =
|
||||
context.RecipeStep.Step.Value
|
||||
.Split(new[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(commandEntry => commandEntry.Trim());
|
||||
|
||||
foreach (var command in commands) {
|
||||
if (!String.IsNullOrEmpty(command)) {
|
||||
Logger.Information("Executing command: {0}", command);
|
||||
try {
|
||||
var commandParameters = _commandParser.ParseCommandParameters(command);
|
||||
var input = new StringReader("");
|
||||
var output = new StringWriter();
|
||||
_commandManager.Execute(new CommandParameters { Arguments = commandParameters.Arguments, Input = input, Output = output, Switches = commandParameters.Switches });
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while executing command: {0}", command);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utility class for parsing lines of commands.
|
||||
// Note: This lexer handles double quotes pretty harshly by design.
|
||||
// In case you needed them in your arguments, hopefully single quotes work for you as a replacement on the receiving end.
|
||||
class CommandParser {
|
||||
public CommandParameters ParseCommandParameters(string command) {
|
||||
var args = SplitArgs(command);
|
||||
var arguments = new List<string>();
|
||||
var result = new CommandParameters {
|
||||
Switches = new Dictionary<string, string>()
|
||||
};
|
||||
|
||||
foreach (var arg in args) {
|
||||
if (arg.StartsWith("/")) {
|
||||
//If arg is not empty and starts with '/'
|
||||
|
||||
int index = arg.IndexOf(':');
|
||||
var switchName = (index < 0 ? arg.Substring(1) : arg.Substring(1, index - 1));
|
||||
var switchValue = (index < 0 || index >= arg.Length ? string.Empty : arg.Substring(index + 1));
|
||||
|
||||
if (string.IsNullOrEmpty(switchName))
|
||||
{
|
||||
throw new ArgumentException(string.Format("Invalid switch syntax: \"{0}\". Valid syntax is /<switchName>[:<switchValue>].", arg));
|
||||
}
|
||||
|
||||
result.Switches.Add(switchName, switchValue);
|
||||
}
|
||||
else {
|
||||
arguments.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
result.Arguments = arguments;
|
||||
return result;
|
||||
}
|
||||
|
||||
class State {
|
||||
private readonly string _commandLine;
|
||||
private readonly StringBuilder _stringBuilder;
|
||||
private readonly List<string> _arguments;
|
||||
private int _index;
|
||||
|
||||
public State(string commandLine) {
|
||||
_commandLine = commandLine;
|
||||
_stringBuilder = new StringBuilder();
|
||||
_arguments = new List<string>();
|
||||
}
|
||||
|
||||
public StringBuilder StringBuilder { get { return _stringBuilder; } }
|
||||
public bool EOF { get { return _index >= _commandLine.Length; } }
|
||||
public char Current { get { return _commandLine[_index]; } }
|
||||
public IEnumerable<string> Arguments { get { return _arguments; } }
|
||||
|
||||
public void AddArgument() {
|
||||
_arguments.Add(StringBuilder.ToString());
|
||||
StringBuilder.Clear();
|
||||
}
|
||||
|
||||
public void AppendCurrent() {
|
||||
StringBuilder.Append(Current);
|
||||
}
|
||||
|
||||
public void Append(char ch) {
|
||||
StringBuilder.Append(ch);
|
||||
}
|
||||
|
||||
public void MoveNext() {
|
||||
if (!EOF)
|
||||
_index++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implement the same logic as found at
|
||||
/// http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
|
||||
/// The 3 special characters are quote, backslash and whitespaces, in order
|
||||
/// of priority.
|
||||
/// The semantics of a quote is: whatever the state of the lexer, copy
|
||||
/// all characters verbatim until the next quote or EOF.
|
||||
/// The semantics of backslash is: If the next character is a backslash or a quote,
|
||||
/// copy the next character. Otherwise, copy the backslash and the next character.
|
||||
/// The semantics of whitespace is: end the current argument and move on to the next one.
|
||||
/// </summary>
|
||||
private static IEnumerable<string> SplitArgs(string commandLine) {
|
||||
var state = new State(commandLine);
|
||||
while (!state.EOF) {
|
||||
switch (state.Current) {
|
||||
case '"':
|
||||
ProcessQuote(state);
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
ProcessBackslash(state);
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
case '\t':
|
||||
if (state.StringBuilder.Length > 0)
|
||||
state.AddArgument();
|
||||
state.MoveNext();
|
||||
break;
|
||||
|
||||
default:
|
||||
state.AppendCurrent();
|
||||
state.MoveNext();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state.StringBuilder.Length > 0)
|
||||
state.AddArgument();
|
||||
return state.Arguments;
|
||||
}
|
||||
|
||||
private static void ProcessQuote(State state) {
|
||||
state.MoveNext();
|
||||
while (!state.EOF) {
|
||||
if (state.Current == '"') {
|
||||
state.MoveNext();
|
||||
break;
|
||||
}
|
||||
state.AppendCurrent();
|
||||
state.MoveNext();
|
||||
}
|
||||
|
||||
state.AddArgument();
|
||||
}
|
||||
|
||||
private static void ProcessBackslash(State state) {
|
||||
state.MoveNext();
|
||||
if (state.EOF) {
|
||||
state.Append('\\');
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.Current == '"') {
|
||||
state.Append('"');
|
||||
state.MoveNext();
|
||||
}
|
||||
else {
|
||||
state.Append('\\');
|
||||
state.AppendCurrent();
|
||||
state.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,100 +1,86 @@
|
||||
using System;
|
||||
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 {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly IContentDefinitionReader _contentDefinitionReader;
|
||||
private readonly IContentDefinitionEventHandler _contentDefinitonEventHandlers;
|
||||
|
||||
public MetadataRecipeHandler(
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
IContentDefinitionReader contentDefinitionReader,
|
||||
IContentDefinitionEventHandler contentDefinitonEventHandlers) {
|
||||
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
_contentDefinitionReader = contentDefinitionReader;
|
||||
_contentDefinitonEventHandlers = contentDefinitonEventHandlers;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
/*
|
||||
<Metadata>
|
||||
<Types>
|
||||
<Blog creatable="true">
|
||||
<Body format="abodyformat"/>
|
||||
</Blog>
|
||||
</Types>
|
||||
<Parts>
|
||||
</Parts>
|
||||
</Metadata>
|
||||
*/
|
||||
// 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()) {
|
||||
Logger.Debug("Processing element '{0}'.", metadataElement.Name.LocalName);
|
||||
switch (metadataElement.Name.LocalName) {
|
||||
case "Types":
|
||||
foreach (var element in metadataElement.Elements()) {
|
||||
var typeElement = element;
|
||||
var typeName = XmlConvert.DecodeName(element.Name.LocalName);
|
||||
|
||||
Logger.Information("Importing content type '{0}'.", typeName);
|
||||
try {
|
||||
_contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName });
|
||||
_contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration));
|
||||
_contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName) });
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing content type '{0}'.", typeName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "Parts":
|
||||
foreach (var element in metadataElement.Elements()) {
|
||||
var partElement = element;
|
||||
var partName = XmlConvert.DecodeName(element.Name.LocalName);
|
||||
|
||||
Logger.Information("Importing content part '{0}'.", partName);
|
||||
try {
|
||||
_contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName });
|
||||
_contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration));
|
||||
_contentDefinitonEventHandlers.ContentPartImported(new ContentPartImportedContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName)});
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing content part '{0}'.", partName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Logger.Warning("Unrecognized element '{0}' encountered; skipping", metadataElement.Name.LocalName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Xml;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentTypes.Events;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||
public class ContentSchemaStep : RecipeExecutionStep {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly IContentDefinitionReader _contentDefinitionReader;
|
||||
private readonly IContentDefinitionEventHandler _contentDefinitonEventHandlers;
|
||||
|
||||
public override string Name { get { return "ContentSchema"; } }
|
||||
|
||||
public ContentSchemaStep(
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
IContentDefinitionReader contentDefinitionReader,
|
||||
IContentDefinitionEventHandler contentDefinitonEventHandlers) {
|
||||
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
_contentDefinitionReader = contentDefinitionReader;
|
||||
_contentDefinitonEventHandlers = contentDefinitonEventHandlers;
|
||||
}
|
||||
|
||||
/*
|
||||
<ContentDefinition>
|
||||
<Types>
|
||||
<Blog creatable="true">
|
||||
<Body format="abodyformat"/>
|
||||
</Blog>
|
||||
</Types>
|
||||
<Parts>
|
||||
</Parts>
|
||||
</ContentDefinition>
|
||||
*/
|
||||
// Set type settings and attach parts to types.
|
||||
// Create dynamic parts.
|
||||
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":
|
||||
foreach (var element in metadataElement.Elements()) {
|
||||
var typeElement = element;
|
||||
var typeName = XmlConvert.DecodeName(element.Name.LocalName);
|
||||
|
||||
Logger.Information("Importing content type '{0}'.", typeName);
|
||||
try {
|
||||
_contentDefinitonEventHandlers.ContentTypeImporting(new ContentTypeImportingContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName), ContentTypeName = typeName });
|
||||
_contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration));
|
||||
_contentDefinitonEventHandlers.ContentTypeImported(new ContentTypeImportedContext { ContentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName) });
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing content type '{0}'.", typeName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "Parts":
|
||||
foreach (var element in metadataElement.Elements()) {
|
||||
var partElement = element;
|
||||
var partName = XmlConvert.DecodeName(element.Name.LocalName);
|
||||
|
||||
Logger.Information("Importing content part '{0}'.", partName);
|
||||
try {
|
||||
_contentDefinitonEventHandlers.ContentPartImporting(new ContentPartImportingContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName), ContentPartName = partName });
|
||||
_contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration));
|
||||
_contentDefinitonEventHandlers.ContentPartImported(new ContentPartImportedContext { ContentPartDefinition = _contentDefinitionManager.GetPartDefinition(partName)});
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing content part '{0}'.", partName);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Logger.Warning("Unrecognized element '{0}' encountered; skipping", metadataElement.Name.LocalName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,120 +1,106 @@
|
||||
using System;
|
||||
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 {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly ITransactionManager _transactionManager;
|
||||
|
||||
public DataRecipeHandler(IOrchardServices orchardServices, ITransactionManager transactionManager) {
|
||||
_orchardServices = orchardServices;
|
||||
_transactionManager = transactionManager;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
// <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);
|
||||
|
||||
var importContentSession = new ImportContentSession(_orchardServices.ContentManager);
|
||||
|
||||
// Populate local dictionary with elements and their ids
|
||||
var elementDictionary = CreateElementDictionary(recipeContext.RecipeStep.Step);
|
||||
|
||||
//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
|
||||
var startIndex = 0;
|
||||
int batchSize = GetBatchSizeForDataStep(recipeContext.RecipeStep.Step);
|
||||
Logger.Debug("Using batch size {0}.", batchSize);
|
||||
|
||||
//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
|
||||
var nextIdentity = importContentSession.GetNextInBatch();
|
||||
while (nextIdentity != null) {
|
||||
var itemId = "";
|
||||
if (elementDictionary[nextIdentity.ToString()].HasAttributes) {
|
||||
itemId = elementDictionary[nextIdentity.ToString()].FirstAttribute.Value;
|
||||
}
|
||||
Logger.Information("Importing data item '{0}'.", itemId);
|
||||
try {
|
||||
_orchardServices.ContentManager.Import(
|
||||
elementDictionary[nextIdentity.ToString()],
|
||||
importContentSession);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing data item '{0}'.", itemId);
|
||||
throw;
|
||||
}
|
||||
nextIdentity = importContentSession.GetNextInBatch();
|
||||
}
|
||||
|
||||
startIndex += batchSize;
|
||||
|
||||
//Create a new transaction for each batch
|
||||
if (startIndex < elementDictionary.Count) {
|
||||
_transactionManager.RequireNew();
|
||||
}
|
||||
|
||||
Logger.Debug("Finished importing batch starting at index {0}.", startIndex);
|
||||
}
|
||||
}
|
||||
catch (Exception) {
|
||||
//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) {
|
||||
var elementDictionary = new Dictionary<string, XElement>();
|
||||
foreach (var element in step.Elements()) {
|
||||
if (element.Attribute("Id") == null
|
||||
|| string.IsNullOrEmpty(element.Attribute("Id").Value))
|
||||
continue;
|
||||
|
||||
var identity = new ContentIdentity(element.Attribute("Id").Value).ToString();
|
||||
elementDictionary[identity] = element;
|
||||
}
|
||||
return elementDictionary;
|
||||
}
|
||||
|
||||
private int GetBatchSizeForDataStep(XElement step) {
|
||||
int batchSize;
|
||||
if (step.Attribute("BatchSize") == null ||
|
||||
!int.TryParse(step.Attribute("BatchSize").Value, out batchSize) ||
|
||||
batchSize <= 0) {
|
||||
batchSize = int.MaxValue;
|
||||
}
|
||||
return batchSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||
public class ContentStep : RecipeExecutionStep {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly ITransactionManager _transactionManager;
|
||||
|
||||
public ContentStep(IOrchardServices orchardServices, ITransactionManager transactionManager) {
|
||||
_orchardServices = orchardServices;
|
||||
_transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Content"; } }
|
||||
|
||||
// <Data />
|
||||
// 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(context.RecipeStep.Step);
|
||||
|
||||
// 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.
|
||||
var startIndex = 0;
|
||||
var batchSize = GetBatchSizeForDataStep(context.RecipeStep.Step);
|
||||
Logger.Debug("Using batch size {0}.", batchSize);
|
||||
|
||||
// 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.
|
||||
var nextIdentity = importContentSession.GetNextInBatch();
|
||||
while (nextIdentity != null) {
|
||||
var itemId = "";
|
||||
if (elementDictionary[nextIdentity.ToString()].HasAttributes) {
|
||||
itemId = elementDictionary[nextIdentity.ToString()].FirstAttribute.Value;
|
||||
}
|
||||
Logger.Information("Importing data item '{0}'.", itemId);
|
||||
try {
|
||||
_orchardServices.ContentManager.Import(
|
||||
elementDictionary[nextIdentity.ToString()],
|
||||
importContentSession);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing data item '{0}'.", itemId);
|
||||
throw;
|
||||
}
|
||||
nextIdentity = importContentSession.GetNextInBatch();
|
||||
}
|
||||
|
||||
startIndex += batchSize;
|
||||
|
||||
// Create a new transaction for each batch.
|
||||
if (startIndex < elementDictionary.Count) {
|
||||
_transactionManager.RequireNew();
|
||||
}
|
||||
|
||||
Logger.Debug("Finished importing batch starting at index {0}.", startIndex);
|
||||
}
|
||||
}
|
||||
catch (Exception) {
|
||||
// Ensure a failed batch is rolled back.
|
||||
_transactionManager.Cancel();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, XElement> CreateElementDictionary(XElement step) {
|
||||
var elementDictionary = new Dictionary<string, XElement>();
|
||||
foreach (var element in step.Elements()) {
|
||||
if (element.Attribute("Id") == null
|
||||
|| string.IsNullOrEmpty(element.Attribute("Id").Value))
|
||||
continue;
|
||||
|
||||
var identity = new ContentIdentity(element.Attribute("Id").Value).ToString();
|
||||
elementDictionary[identity] = element;
|
||||
}
|
||||
return elementDictionary;
|
||||
}
|
||||
|
||||
private int GetBatchSizeForDataStep(XElement step) {
|
||||
int batchSize;
|
||||
if (step.Attribute("BatchSize") == null ||
|
||||
!int.TryParse(step.Attribute("BatchSize").Value, out batchSize) ||
|
||||
batchSize <= 0) {
|
||||
batchSize = int.MaxValue;
|
||||
}
|
||||
return batchSize;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,79 +1,65 @@
|
||||
using System;
|
||||
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 {
|
||||
private readonly IFeatureManager _featureManager;
|
||||
|
||||
public FeatureRecipeHandler(IFeatureManager featureManager) {
|
||||
_featureManager = featureManager;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
// <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);
|
||||
|
||||
var featuresToEnable = new List<string>();
|
||||
var featuresToDisable = new List<string>();
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "disable", StringComparison.OrdinalIgnoreCase)) {
|
||||
featuresToDisable = ParseFeatures(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||
featuresToEnable = ParseFeatures(attribute.Value);
|
||||
}
|
||||
else {
|
||||
Logger.Warning("Unrecognized attribute '{0}' encountered; skipping", attribute.Name.LocalName);
|
||||
}
|
||||
}
|
||||
|
||||
var availableFeatures = _featureManager.GetAvailableFeatures().Select(x => x.Id).ToArray();
|
||||
foreach (var featureName in featuresToDisable) {
|
||||
if (!availableFeatures.Contains(featureName)) {
|
||||
throw new InvalidOperationException(string.Format("Could not disable feature {0} because it was not found.", featureName));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var featureName in featuresToEnable) {
|
||||
if (!availableFeatures.Contains(featureName)) {
|
||||
throw new InvalidOperationException(string.Format("Could not enable feature {0} because it was not found.", featureName));
|
||||
}
|
||||
}
|
||||
|
||||
if (featuresToDisable.Any()) {
|
||||
Logger.Information("Disabling features: {0}", String.Join(";", featuresToDisable));
|
||||
_featureManager.DisableFeatures(featuresToDisable, true);
|
||||
}
|
||||
if (featuresToEnable.Any()) {
|
||||
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) {
|
||||
return csv.Split(',')
|
||||
.Select(value => value.Trim())
|
||||
.Where(sanitizedValue => !String.IsNullOrEmpty(sanitizedValue))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||
public class FeatureStep : RecipeExecutionStep {
|
||||
private readonly IFeatureManager _featureManager;
|
||||
|
||||
public FeatureStep(IFeatureManager featureManager) {
|
||||
_featureManager = featureManager;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Feature"; } }
|
||||
|
||||
// <Feature enable="f1,f2,f3" disable="f4" />
|
||||
// Enable/Disable features.
|
||||
public override void Execute(RecipeExecutionContext recipeContext) {
|
||||
var featuresToEnable = new List<string>();
|
||||
var featuresToDisable = new List<string>();
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "disable", StringComparison.OrdinalIgnoreCase)) {
|
||||
featuresToDisable = ParseFeatures(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||
featuresToEnable = ParseFeatures(attribute.Value);
|
||||
}
|
||||
else {
|
||||
Logger.Warning("Unrecognized attribute '{0}' encountered; skipping", attribute.Name.LocalName);
|
||||
}
|
||||
}
|
||||
|
||||
var availableFeatures = _featureManager.GetAvailableFeatures().Select(x => x.Id).ToArray();
|
||||
foreach (var featureName in featuresToDisable) {
|
||||
if (!availableFeatures.Contains(featureName)) {
|
||||
throw new InvalidOperationException(string.Format("Could not disable feature {0} because it was not found.", featureName));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var featureName in featuresToEnable) {
|
||||
if (!availableFeatures.Contains(featureName)) {
|
||||
throw new InvalidOperationException(string.Format("Could not enable feature {0} because it was not found.", featureName));
|
||||
}
|
||||
}
|
||||
|
||||
if (featuresToDisable.Any()) {
|
||||
Logger.Information("Disabling features: {0}", String.Join(";", featuresToDisable));
|
||||
_featureManager.DisableFeatures(featuresToDisable, true);
|
||||
}
|
||||
if (featuresToEnable.Any()) {
|
||||
Logger.Information("Enabling features: {0}", String.Join(";", featuresToEnable));
|
||||
_featureManager.EnableFeatures(featuresToEnable, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> ParseFeatures(string csv) {
|
||||
return csv.Split(',')
|
||||
.Select(value => value.Trim())
|
||||
.Where(sanitizedValue => !String.IsNullOrEmpty(sanitizedValue))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,80 +1,66 @@
|
||||
using System;
|
||||
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 {
|
||||
private readonly IDataMigrationManager _dataMigrationManager;
|
||||
|
||||
public MigrationRecipeHandler(IDataMigrationManager dataMigrationManager) {
|
||||
_dataMigrationManager = dataMigrationManager;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
// <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;
|
||||
var features = new List<string>();
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "features", StringComparison.OrdinalIgnoreCase)) {
|
||||
features = ParseFeatures(attribute.Value);
|
||||
if (features.Contains("*"))
|
||||
runAll = true;
|
||||
}
|
||||
else {
|
||||
Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName);
|
||||
}
|
||||
}
|
||||
|
||||
if (runAll) {
|
||||
foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) {
|
||||
Logger.Information("Updating feature '{0}'.", feature);
|
||||
try {
|
||||
_dataMigrationManager.Update(feature);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while updating feature '{0}'", feature);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger.Information("Updating features: {0}", String.Join(";", features));
|
||||
try {
|
||||
_dataMigrationManager.Update(features);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while updating features: {0}", String.Join(";", features));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
||||
}
|
||||
|
||||
private static List<string> ParseFeatures(string csv) {
|
||||
return csv.Split(',')
|
||||
.Select(value => value.Trim())
|
||||
.Where(sanitizedValue => !String.IsNullOrEmpty(sanitizedValue))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||
public class MigrationStep : RecipeExecutionStep {
|
||||
private readonly IDataMigrationManager _dataMigrationManager;
|
||||
|
||||
public MigrationStep(IDataMigrationManager dataMigrationManager) {
|
||||
_dataMigrationManager = dataMigrationManager;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Migration"; } }
|
||||
|
||||
// <Migration features="f1, f2" />
|
||||
// <Migration features="*" />
|
||||
// Run migration for features.
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
var runAll = false;
|
||||
var features = new List<string>();
|
||||
foreach (var attribute in context.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "features", StringComparison.OrdinalIgnoreCase)) {
|
||||
features = ParseFeatures(attribute.Value);
|
||||
if (features.Contains("*"))
|
||||
runAll = true;
|
||||
}
|
||||
else {
|
||||
Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName);
|
||||
}
|
||||
}
|
||||
|
||||
if (runAll) {
|
||||
foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) {
|
||||
Logger.Information("Updating feature '{0}'.", feature);
|
||||
try {
|
||||
_dataMigrationManager.Update(feature);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while updating feature '{0}'", feature);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger.Information("Updating features: {0}", String.Join(";", features));
|
||||
try {
|
||||
_dataMigrationManager.Update(features);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while updating features: {0}", String.Join(";", features));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> ParseFeatures(string csv) {
|
||||
return csv.Split(',')
|
||||
.Select(value => value.Trim())
|
||||
.Where(sanitizedValue => !String.IsNullOrEmpty(sanitizedValue))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,111 +1,97 @@
|
||||
using System;
|
||||
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 {
|
||||
private readonly IPackagingSourceManager _packagingSourceManager;
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
|
||||
public ModuleRecipeHandler(
|
||||
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; }
|
||||
|
||||
// <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);
|
||||
|
||||
string packageId = null, version = null, repository = null;
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) {
|
||||
packageId = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase)) {
|
||||
version = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase)) {
|
||||
repository = attribute.Value;
|
||||
}
|
||||
else {
|
||||
throw new InvalidOperationException(string.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName));
|
||||
}
|
||||
}
|
||||
|
||||
if (packageId == null) {
|
||||
throw new InvalidOperationException("PackageId is required in a Module declaration in a recipe file.");
|
||||
}
|
||||
|
||||
// download and install module from the orchard feed or a custom feed if repository is specified.
|
||||
bool enforceVersion = version != null;
|
||||
bool installed = false;
|
||||
PackagingEntry packagingEntry = null;
|
||||
|
||||
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
||||
if (repository != null) {
|
||||
packagingSource = new PackagingSource {FeedTitle = repository, FeedUrl = repository};
|
||||
}
|
||||
|
||||
if (enforceVersion) {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Module) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
|
||||
}
|
||||
else {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Module) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.IsLatestVersion)).FirstOrDefault();
|
||||
}
|
||||
|
||||
if (packagingEntry != null) {
|
||||
if (!ModuleAlreadyInstalled(packagingEntry.PackageId)) {
|
||||
Logger.Information("Installing module {0}.", packagingEntry.Title);
|
||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||
}
|
||||
installed = true;
|
||||
}
|
||||
|
||||
if (!installed) {
|
||||
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) {
|
||||
return _extensionManager.AvailableExtensions().Where(m => DefaultExtensionTypes.IsModule(m.ExtensionType))
|
||||
.Any(module => module.Id.Equals(
|
||||
packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Module).Length),
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Packaging.Models;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||
public class ModuleStep : RecipeExecutionStep {
|
||||
private readonly IPackagingSourceManager _packagingSourceManager;
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
|
||||
public ModuleStep(
|
||||
IPackagingSourceManager packagingSourceManager,
|
||||
IPackageManager packageManager,
|
||||
IExtensionManager extensionManager) {
|
||||
|
||||
_packagingSourceManager = packagingSourceManager;
|
||||
_packageManager = packageManager;
|
||||
_extensionManager = extensionManager;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Module"; } }
|
||||
|
||||
// <Module packageId="module1" [repository="somerepo"] version="1.1" />
|
||||
// Install modules from feed.
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
string packageId = null, version = null, repository = null;
|
||||
foreach (var attribute in context.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) {
|
||||
packageId = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase)) {
|
||||
version = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase)) {
|
||||
repository = attribute.Value;
|
||||
}
|
||||
else {
|
||||
throw new InvalidOperationException(String.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName));
|
||||
}
|
||||
}
|
||||
|
||||
if (packageId == null) {
|
||||
throw new InvalidOperationException("PackageId is required in a Module declaration in a recipe file.");
|
||||
}
|
||||
|
||||
// download and install module 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();
|
||||
if (repository != null) {
|
||||
packagingSource = new PackagingSource {FeedTitle = repository, FeedUrl = repository};
|
||||
}
|
||||
|
||||
if (enforceVersion) {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Module) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
|
||||
}
|
||||
else {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Module) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.IsLatestVersion)).FirstOrDefault();
|
||||
}
|
||||
|
||||
if (packagingEntry != null) {
|
||||
if (!ModuleAlreadyInstalled(packagingEntry.PackageId)) {
|
||||
Logger.Information("Installing module {0}.", packagingEntry.Title);
|
||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||
}
|
||||
installed = true;
|
||||
}
|
||||
|
||||
if (!installed) {
|
||||
throw new InvalidOperationException(String.Format("Module {0} was not found in the specified location.", packageId));
|
||||
}
|
||||
}
|
||||
|
||||
private bool ModuleAlreadyInstalled(string packageId) {
|
||||
return _extensionManager.AvailableExtensions().Where(m => DefaultExtensionTypes.IsModule(m.ExtensionType))
|
||||
.Any(module => module.Id.Equals(
|
||||
packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Module).Length),
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,101 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Recipes.RecipeHandlers {
|
||||
public class SettingsRecipeHandler : IRecipeHandler {
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
|
||||
|
||||
public SettingsRecipeHandler(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; }
|
||||
private IEnumerable<IContentHandler> Handlers { get { return _handlers.Value; } }
|
||||
|
||||
/*
|
||||
<Settings>
|
||||
<SiteSettingsPart PageSize="30" />
|
||||
<CommentSettingsPart ModerateComments="true" />
|
||||
</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);
|
||||
|
||||
var siteContentItem = _siteService.GetSiteSettings().ContentItem;
|
||||
|
||||
var importContentSession = new ImportContentSession(_contentManager);
|
||||
|
||||
var context = new ImportContentContext(siteContentItem, recipeContext.RecipeStep.Step, importContentSession);
|
||||
foreach (var contentHandler in Handlers) {
|
||||
contentHandler.Importing(context);
|
||||
}
|
||||
|
||||
foreach (var contentPart in siteContentItem.Parts) {
|
||||
var partElement = context.Data.Element(contentPart.PartDefinition.Name);
|
||||
if (partElement == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger.Information("Importing settings part '{0}'.", contentPart.PartDefinition.Name);
|
||||
try {
|
||||
ImportSettingPart(contentPart, partElement);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing settings part '{0}'.", contentPart.PartDefinition.Name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var contentHandler in Handlers) {
|
||||
contentHandler.Imported(context);
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
Logger.Information("Finished executing recipe step '{0}'.", recipeContext.RecipeStep.Name);
|
||||
}
|
||||
|
||||
private void ImportSettingPart(ContentPart sitePart, XElement element) {
|
||||
|
||||
foreach (var attribute in element.Attributes()) {
|
||||
var attributeName = attribute.Name.LocalName;
|
||||
var attributeValue = attribute.Value;
|
||||
|
||||
var property = sitePart.GetType().GetProperty(attributeName);
|
||||
if (property == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyType = property.PropertyType;
|
||||
if (propertyType == typeof(string)) {
|
||||
property.SetValue(sitePart, attributeValue, null);
|
||||
}
|
||||
else if (propertyType == typeof(bool)) {
|
||||
property.SetValue(sitePart, Boolean.Parse(attributeValue), null);
|
||||
}
|
||||
else if (propertyType == typeof(int)) {
|
||||
property.SetValue(sitePart, Int32.Parse(attributeValue), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Settings;
|
||||
|
||||
namespace Orchard.Recipes.RecipeExecutionSteps {
|
||||
public class SettingsStep : RecipeExecutionStep {
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly Lazy<IEnumerable<IContentHandler>> _handlers;
|
||||
|
||||
public SettingsStep(ISiteService siteService, IContentManager contentManager, Lazy<IEnumerable<IContentHandler>> handlers) {
|
||||
_siteService = siteService;
|
||||
_contentManager = contentManager;
|
||||
_handlers = handlers;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Settings"; } }
|
||||
private IEnumerable<IContentHandler> Handlers { get { return _handlers.Value; } }
|
||||
|
||||
/*
|
||||
<Settings>
|
||||
<SiteSettingsPart PageSize="30" />
|
||||
<CommentSettingsPart ModerateComments="true" />
|
||||
</Settings>
|
||||
*/
|
||||
// Set site and part settings.
|
||||
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);
|
||||
|
||||
foreach (var contentHandler in Handlers) {
|
||||
contentHandler.Importing(importContentContext);
|
||||
}
|
||||
|
||||
foreach (var contentPart in siteContentItem.Parts) {
|
||||
var partElement = importContentContext.Data.Element(contentPart.PartDefinition.Name);
|
||||
if (partElement == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger.Information("Importing settings part '{0}'.", contentPart.PartDefinition.Name);
|
||||
try {
|
||||
ImportSettingPart(contentPart, partElement);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing settings part '{0}'.", contentPart.PartDefinition.Name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var contentHandler in Handlers) {
|
||||
contentHandler.Imported(importContentContext);
|
||||
}
|
||||
}
|
||||
|
||||
private void ImportSettingPart(ContentPart sitePart, XElement element) {
|
||||
|
||||
foreach (var attribute in element.Attributes()) {
|
||||
var attributeName = attribute.Name.LocalName;
|
||||
var attributeValue = attribute.Value;
|
||||
|
||||
var property = sitePart.GetType().GetProperty(attributeName);
|
||||
if (property == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyType = property.PropertyType;
|
||||
if (propertyType == typeof(string)) {
|
||||
property.SetValue(sitePart, attributeValue, null);
|
||||
}
|
||||
else if (propertyType == typeof(bool)) {
|
||||
property.SetValue(sitePart, Boolean.Parse(attributeValue), null);
|
||||
}
|
||||
else if (propertyType == typeof(int)) {
|
||||
property.SetValue(sitePart, Int32.Parse(attributeValue), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,138 +1,123 @@
|
||||
using System;
|
||||
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 {
|
||||
private readonly IPackagingSourceManager _packagingSourceManager;
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly ISiteThemeService _siteThemeService;
|
||||
|
||||
public ThemeRecipeHandler(
|
||||
IPackagingSourceManager packagingSourceManager,
|
||||
IPackageManager packageManager,
|
||||
IExtensionManager extensionManager,
|
||||
IThemeService themeService,
|
||||
ISiteThemeService siteThemeService) {
|
||||
|
||||
_packagingSourceManager = packagingSourceManager;
|
||||
_packageManager = packageManager;
|
||||
_extensionManager = extensionManager;
|
||||
_themeService = themeService;
|
||||
_siteThemeService = siteThemeService;
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
// <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);
|
||||
|
||||
bool enable = false, current = false;
|
||||
string packageId = null, version = null, repository = null;
|
||||
|
||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||
enable = Boolean.Parse(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "current", StringComparison.OrdinalIgnoreCase)) {
|
||||
current = Boolean.Parse(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) {
|
||||
packageId = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase)) {
|
||||
version = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase)) {
|
||||
repository = attribute.Value;
|
||||
}
|
||||
else {
|
||||
Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName);
|
||||
}
|
||||
}
|
||||
|
||||
if (packageId == null) {
|
||||
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;
|
||||
PackagingEntry packagingEntry = null;
|
||||
|
||||
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
||||
if (repository != null) {
|
||||
packagingSource = new PackagingSource { FeedTitle = repository, FeedUrl = repository };
|
||||
}
|
||||
|
||||
if (enforceVersion) {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Theme) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
|
||||
}
|
||||
else {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Theme) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.IsLatestVersion)).FirstOrDefault();
|
||||
}
|
||||
|
||||
if (packagingEntry != null) {
|
||||
if (!ThemeAlreadyInstalled(packagingEntry.PackageId)) {
|
||||
Logger.Information("Installing theme package '{0}'.", packagingEntry.PackageId);
|
||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||
}
|
||||
if (current) {
|
||||
Logger.Information("Enabling theme '{0}'.", packagingEntry.Title);
|
||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||
Logger.Information("Setting theme '{0}' as the site theme.", packagingEntry.Title);
|
||||
_siteThemeService.SetSiteTheme(packagingEntry.Title);
|
||||
}
|
||||
else if (enable) {
|
||||
Logger.Information("Enabling theme '{0}'.", packagingEntry.Title);
|
||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||
}
|
||||
|
||||
installed = true;
|
||||
}
|
||||
|
||||
if (!installed) {
|
||||
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) {
|
||||
return _extensionManager.AvailableExtensions().Where(t => DefaultExtensionTypes.IsTheme(t.ExtensionType))
|
||||
.Any(theme => theme.Id.Equals(
|
||||
packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Theme).Length),
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Packaging.Models;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Themes.Services;
|
||||
|
||||
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 ThemeStep(
|
||||
IPackagingSourceManager packagingSourceManager,
|
||||
IPackageManager packageManager,
|
||||
IExtensionManager extensionManager,
|
||||
IThemeService themeService,
|
||||
ISiteThemeService siteThemeService) {
|
||||
|
||||
_packagingSourceManager = packagingSourceManager;
|
||||
_packageManager = packageManager;
|
||||
_extensionManager = extensionManager;
|
||||
_themeService = themeService;
|
||||
_siteThemeService = siteThemeService;
|
||||
}
|
||||
|
||||
public override string Name { get { return "Theme"; } }
|
||||
|
||||
// <Theme packageId="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" />
|
||||
// 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 context.RecipeStep.Step.Attributes()) {
|
||||
if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||
enable = Boolean.Parse(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "current", StringComparison.OrdinalIgnoreCase)) {
|
||||
current = Boolean.Parse(attribute.Value);
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase)) {
|
||||
packageId = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase)) {
|
||||
version = attribute.Value;
|
||||
}
|
||||
else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase)) {
|
||||
repository = attribute.Value;
|
||||
}
|
||||
else {
|
||||
Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName);
|
||||
}
|
||||
}
|
||||
|
||||
if (packageId == null) {
|
||||
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.
|
||||
var enforceVersion = version != null;
|
||||
var installed = false;
|
||||
PackagingEntry packagingEntry = null;
|
||||
|
||||
var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
||||
if (repository != null) {
|
||||
packagingSource = new PackagingSource { FeedTitle = repository, FeedUrl = repository };
|
||||
}
|
||||
|
||||
if (enforceVersion) {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Theme) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
|
||||
}
|
||||
else {
|
||||
packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
|
||||
packages => packages.Where(package =>
|
||||
package.PackageType.Equals(DefaultExtensionTypes.Theme) &&
|
||||
package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
|
||||
package.IsLatestVersion)).FirstOrDefault();
|
||||
}
|
||||
|
||||
if (packagingEntry != null) {
|
||||
if (!ThemeAlreadyInstalled(packagingEntry.PackageId)) {
|
||||
Logger.Information("Installing theme package '{0}'.", packagingEntry.PackageId);
|
||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||
}
|
||||
if (current) {
|
||||
Logger.Information("Enabling theme '{0}'.", packagingEntry.Title);
|
||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||
Logger.Information("Setting theme '{0}' as the site theme.", packagingEntry.Title);
|
||||
_siteThemeService.SetSiteTheme(packagingEntry.Title);
|
||||
}
|
||||
else if (enable) {
|
||||
Logger.Information("Enabling theme '{0}'.", packagingEntry.Title);
|
||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||
}
|
||||
|
||||
installed = true;
|
||||
}
|
||||
|
||||
if (!installed) {
|
||||
throw new InvalidOperationException(String.Format("Theme '{0}' was not found in the specified location.", packageId));
|
||||
}
|
||||
}
|
||||
|
||||
private bool ThemeAlreadyInstalled(string packageId) {
|
||||
return _extensionManager.AvailableExtensions().Where(t => DefaultExtensionTypes.IsTheme(t.ExtensionType))
|
||||
.Any(theme => theme.Id.Equals(
|
||||
packageId.Substring(PackagingSourceManager.GetExtensionPrefix(DefaultExtensionTypes.Theme).Length),
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
}
|
@@ -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,
|
||||
IRecipeExecuteEventHandler recipeExecuteEventHandler,
|
||||
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
|
||||
|
||||
_recipeStepQueue = recipeStepQueue;
|
||||
_recipeScheduler = recipeScheduler;
|
||||
_recipeExecuteEventHandler = recipeExecuteEventHandler;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user