mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added additional overloads to handle various representations of recipe documents more consistently.
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.ImportExport.Services {
|
||||
public interface IImportExportService : IDependency {
|
||||
string Import(string recipeText);
|
||||
XDocument ExportXml(IEnumerable<IRecipeBuilderStep> steps);
|
||||
string Export(IEnumerable<IRecipeBuilderStep> steps);
|
||||
string WriteExportFile(XDocument recipeDocument);
|
||||
string WriteExportFile(string recipeText);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
@@ -34,23 +35,36 @@ namespace Orchard.ImportExport.Services {
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public string Import(XDocument recipeDocument) {
|
||||
return _recipeExecutor.Execute(recipeDocument);
|
||||
}
|
||||
|
||||
public string Import(string recipeText) {
|
||||
return _recipeExecutor.Execute(recipeText);
|
||||
}
|
||||
|
||||
public XDocument ExportXml(IEnumerable<IRecipeBuilderStep> steps) {
|
||||
var recipe = _recipeBuilder.Build(steps);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public string Export(IEnumerable<IRecipeBuilderStep> steps) {
|
||||
var recipe = _recipeBuilder.Build(steps);
|
||||
return WriteExportFile(recipe);
|
||||
return recipe.ToString();
|
||||
}
|
||||
|
||||
private string WriteExportFile(string exportDocument) {
|
||||
|
||||
public string WriteExportFile(XDocument recipeDocument) {
|
||||
return WriteExportFile(recipeDocument.ToString());
|
||||
}
|
||||
|
||||
public string WriteExportFile(string recipeText) {
|
||||
var exportFile = String.Format("Export-{0}-{1}.xml", _orchardServices.WorkContext.CurrentUser.UserName, _clock.UtcNow.Ticks);
|
||||
if (!_appDataFolder.DirectoryExists(ExportsDirectory)) {
|
||||
_appDataFolder.CreateDirectory(ExportsDirectory);
|
||||
}
|
||||
|
||||
var path = _appDataFolder.Combine(ExportsDirectory, exportFile);
|
||||
_appDataFolder.CreateFile(path, exportDocument);
|
||||
_appDataFolder.CreateFile(path, recipeText);
|
||||
|
||||
return _appDataFolder.MapPath(path);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public interface IRecipeBuilder : IDependency {
|
||||
string Build(IEnumerable<IRecipeBuilderStep> steps);
|
||||
XDocument Build(IEnumerable<IRecipeBuilderStep> steps);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
namespace Orchard.Recipes.Services {
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Recipes.Models;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public interface IRecipeExecutor : IDependency {
|
||||
string Execute(XDocument recipeDocument);
|
||||
string Execute(string recipeText);
|
||||
string Execute(Recipe recipe);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Xml.Linq;
|
||||
namespace Orchard.Recipes.Services {
|
||||
public class RecipeBuilder : Component, IRecipeBuilder {
|
||||
|
||||
public string Build(IEnumerable<IRecipeBuilderStep> steps) {
|
||||
public XDocument Build(IEnumerable<IRecipeBuilderStep> steps) {
|
||||
var context = new BuildContext {
|
||||
RecipeDocument = CreateRecipeRoot()
|
||||
};
|
||||
@@ -13,7 +13,7 @@ namespace Orchard.Recipes.Services {
|
||||
step.Build(context);
|
||||
}
|
||||
|
||||
return context.RecipeDocument.ToString();
|
||||
return context.RecipeDocument;
|
||||
}
|
||||
|
||||
private XDocument CreateRecipeRoot() {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Orchard.Environment.Descriptor;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Recipes.Models;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public class RecipeExecutor : Component, IRecipeExecutor {
|
||||
@@ -16,13 +18,22 @@ namespace Orchard.Recipes.Services {
|
||||
_shellDescriptorManager = shellDescriptorManager;
|
||||
}
|
||||
|
||||
public string Execute(XDocument recipeDocument) {
|
||||
var recipeText = recipeDocument.ToString();
|
||||
return Execute(recipeText);
|
||||
}
|
||||
|
||||
public string Execute(string recipeText) {
|
||||
var recipe = _recipeParser.ParseRecipe(recipeText);
|
||||
return Execute(recipe);
|
||||
}
|
||||
|
||||
public string Execute(Recipe recipe) {
|
||||
var executionId = _recipeManager.Execute(recipe);
|
||||
UpdateShell();
|
||||
return executionId;
|
||||
}
|
||||
|
||||
|
||||
private void UpdateShell() {
|
||||
var descriptor = _shellDescriptorManager.GetShellDescriptor();
|
||||
_shellDescriptorManager.UpdateShellDescriptor(descriptor.SerialNumber, descriptor.Features, descriptor.Parameters);
|
||||
|
||||
@@ -2,29 +2,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Models;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public class RecipeParser : IRecipeParser {
|
||||
public RecipeParser() {
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
public class RecipeParser : Component, IRecipeParser {
|
||||
public Recipe ParseRecipe(XDocument recipeDocument) {
|
||||
return ParseRecipe(recipeDocument.ToString(SaveOptions.DisableFormatting));
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public Recipe ParseRecipe(string recipeText) {
|
||||
var recipe = new Recipe();
|
||||
|
||||
if (string.IsNullOrEmpty(recipeText)) {
|
||||
if (String.IsNullOrEmpty(recipeText)) {
|
||||
throw new Exception("Recipe is empty");
|
||||
}
|
||||
|
||||
XElement recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
||||
|
||||
var recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
||||
var recipeSteps = new List<RecipeStep>();
|
||||
|
||||
foreach (var element in recipeTree.Elements()) {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Orchard.Recipes.Models;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Recipes.Models;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public interface IRecipeParser : IDependency {
|
||||
Recipe ParseRecipe(XDocument recipeDocument);
|
||||
Recipe ParseRecipe(string recipeText);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user