mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Refactored CustomElements import/export step.
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.Layouts.ImportExport {
|
||||
public interface ICustomExportStep : IEventHandler {
|
||||
void Register(IList<string> steps);
|
||||
}
|
||||
|
||||
public class ElementsExportStep : ICustomExportStep {
|
||||
public void Register(IList<string> steps) {
|
||||
steps.Add("LayoutElements");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -367,9 +367,8 @@
|
||||
<Compile Include="Helpers\PrefixHelper.cs" />
|
||||
<Compile Include="Helpers\JsonHelper.cs" />
|
||||
<Compile Include="Helpers\StringHelper.cs" />
|
||||
<Compile Include="ImportExport\ElementsExportHandler.cs" />
|
||||
<Compile Include="ImportExport\ElementsExportStep.cs" />
|
||||
<Compile Include="ImportExport\ElementsImportHandler.cs" />
|
||||
<Compile Include="Recipes\Builders\CustomElementsStep.cs" />
|
||||
<Compile Include="Recipes\Executors\CustomElementsStep.cs" />
|
||||
<Compile Include="Providers\BlueprintElementHarvester.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Services\CurrentControllerAccessor.cs" />
|
||||
|
||||
@@ -1,40 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Events;
|
||||
using Orchard.Layouts.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Layouts.ImportExport {
|
||||
public interface IExportEventHandler : IEventHandler {
|
||||
void Exporting(dynamic context);
|
||||
void Exported(dynamic context);
|
||||
}
|
||||
|
||||
public class ElementsExportHandler : IExportEventHandler {
|
||||
namespace Orchard.Layouts.Recipes.Builders {
|
||||
|
||||
public class CustomElementsStep : RecipeBuilderStep {
|
||||
private readonly IRepository<ElementBlueprint> _repository;
|
||||
|
||||
public ElementsExportHandler(IRepository<ElementBlueprint> repository) {
|
||||
public CustomElementsStep(IRepository<ElementBlueprint> repository) {
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public void Exporting(dynamic context) {
|
||||
public override string Name
|
||||
{
|
||||
get { return "CustomElements"; }
|
||||
}
|
||||
|
||||
public void Exported(dynamic context) {
|
||||
public override LocalizedString DisplayName
|
||||
{
|
||||
get { return T("Custom Elements"); }
|
||||
}
|
||||
|
||||
if (!((IEnumerable<string>)context.ExportOptions.CustomSteps).Contains("LayoutElements")) {
|
||||
return;
|
||||
}
|
||||
public override LocalizedString Description
|
||||
{
|
||||
get { return T("Exports custom defined elements."); }
|
||||
}
|
||||
|
||||
public override void Build(BuildContext context) {
|
||||
var elements = _repository.Table.OrderBy(x => x.ElementTypeName).ToList();
|
||||
|
||||
if (!elements.Any()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var root = new XElement("LayoutElements");
|
||||
context.Document.Element("Orchard").Add(root);
|
||||
var root = new XElement("CustomElements");
|
||||
context.RecipeDocument.Element("Orchard").Add(root);
|
||||
|
||||
foreach (var element in elements) {
|
||||
root.Add(new XElement("Element",
|
||||
@@ -1,23 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Data;
|
||||
using Orchard.Layouts.Models;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Layouts.ImportExport {
|
||||
public class ElementsImportHandler : Component, IRecipeHandler {
|
||||
namespace Orchard.Layouts.Recipes.Executors {
|
||||
public class CustomElementsStep : RecipeExecutionStep {
|
||||
private readonly IRepository<ElementBlueprint> _repository;
|
||||
|
||||
public ElementsImportHandler(IRepository<ElementBlueprint> repository) {
|
||||
public CustomElementsStep(IRepository<ElementBlueprint> repository) {
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||
if (!String.Equals(recipeContext.RecipeStep.Name, "LayoutElements", StringComparison.OrdinalIgnoreCase)) {
|
||||
return;
|
||||
}
|
||||
public override string Name {
|
||||
get { return "CustomElements"; }
|
||||
}
|
||||
|
||||
foreach (var elementElement in recipeContext.RecipeStep.Step.Elements()) {
|
||||
public override IEnumerable<string> Names {
|
||||
get { return new[] { Name, "LayoutElements" }; }
|
||||
}
|
||||
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
foreach (var elementElement in context.RecipeStep.Step.Elements()) {
|
||||
var typeName = elementElement.Attribute("ElementTypeName").Value;
|
||||
var element = GetOrCreateElement(typeName);
|
||||
|
||||
@@ -27,10 +31,8 @@ namespace Orchard.Layouts.ImportExport {
|
||||
element.ElementCategory = elementElement.Attribute("ElementCategory").Value;
|
||||
element.BaseElementState = elementElement.Element("BaseElementState").Value;
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
}
|
||||
|
||||
|
||||
private ElementBlueprint GetOrCreateElement(string typeName) {
|
||||
var element = _repository.Get(x => x.ElementTypeName == typeName);
|
||||
|
||||
Reference in New Issue
Block a user