mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Cleaned up interfaces by moving out convenience methods to extension classes.
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
@@ -8,7 +6,6 @@ using NUnit.Framework;
|
|||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.MetaData;
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ContentManagement.MetaData.Models;
|
|
||||||
using Orchard.ContentManagement.MetaData.Services;
|
using Orchard.ContentManagement.MetaData.Services;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Core.Settings.Metadata;
|
using Orchard.Core.Settings.Metadata;
|
||||||
@@ -95,7 +92,7 @@ namespace Orchard.Tests.Modules.ImportExport.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ImportDoesntFailsWhenRecipeContainsNonImportSteps() {
|
public void ImportDoesntFailWhenRecipeContainsNonImportSteps() {
|
||||||
Assert.DoesNotThrow(() => _importExportService.Import(
|
Assert.DoesNotThrow(() => _importExportService.Import(
|
||||||
@"<Orchard>
|
@"<Orchard>
|
||||||
<Recipe>
|
<Recipe>
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ using Orchard.Recipes.Services;
|
|||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
using Orchard.Tests.Stubs;
|
using Orchard.Tests.Stubs;
|
||||||
using Orchard.Recipes.Events;
|
using Orchard.Recipes.Events;
|
||||||
using Orchard.Data;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\EditorTemplates\ExportActions\BuildRecipe.cshtml" />
|
<Content Include="Views\EditorTemplates\ExportActions\BuildRecipe.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace Orchard.ImportExport.Providers.ExportActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Execute(ExportActionContext context) {
|
public override void Execute(ExportActionContext context) {
|
||||||
var recipeDocument = _importExportService.ExportXml(RecipeBuilderSteps);
|
var recipeDocument = _importExportService.Export(RecipeBuilderSteps);
|
||||||
var recipe = _recipeParser.ParseRecipe(recipeDocument);
|
var recipe = _recipeParser.ParseRecipe(recipeDocument);
|
||||||
var exportFileName = GetExportFileName(recipe);
|
var exportFileName = GetExportFileName(recipe);
|
||||||
var exportFilePath = _importExportService.WriteExportFile(recipeDocument);
|
var exportFilePath = _importExportService.WriteExportFile(recipeDocument);
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace Orchard.ImportExport.Providers.ImportActions {
|
|||||||
private string Setup() {
|
private string Setup() {
|
||||||
var setupContext = new SetupContext {
|
var setupContext = new SetupContext {
|
||||||
DropExistingTables = true,
|
DropExistingTables = true,
|
||||||
RecipeText = RecipeDocument.ToString(SaveOptions.DisableFormatting),
|
RecipeDocument = RecipeDocument,
|
||||||
AdminPassword = SuperUserPassword,
|
AdminPassword = SuperUserPassword,
|
||||||
AdminUsername = _orchardServices.WorkContext.CurrentSite.SuperUser,
|
AdminUsername = _orchardServices.WorkContext.CurrentSite.SuperUser,
|
||||||
DatabaseConnectionString = _shellSettings.DataConnectionString,
|
DatabaseConnectionString = _shellSettings.DataConnectionString,
|
||||||
@@ -162,7 +162,7 @@ namespace Orchard.ImportExport.Providers.ImportActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private string ExecuteRecipe() {
|
private string ExecuteRecipe() {
|
||||||
return _importExportService.Import(RecipeDocument.ToString(SaveOptions.DisableFormatting));
|
return _importExportService.Import(RecipeDocument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,15 @@ using Orchard.Recipes.Services;
|
|||||||
|
|
||||||
namespace Orchard.ImportExport.Services {
|
namespace Orchard.ImportExport.Services {
|
||||||
public interface IImportExportService : IDependency {
|
public interface IImportExportService : IDependency {
|
||||||
string Import(string recipeText);
|
string Import(XDocument recipeDocument);
|
||||||
XDocument ExportXml(IEnumerable<IRecipeBuilderStep> steps);
|
XDocument Export(IEnumerable<IRecipeBuilderStep> steps);
|
||||||
string Export(IEnumerable<IRecipeBuilderStep> steps);
|
|
||||||
string WriteExportFile(XDocument recipeDocument);
|
string WriteExportFile(XDocument recipeDocument);
|
||||||
string WriteExportFile(string recipeText);
|
}
|
||||||
|
|
||||||
|
public static class ImportExportServiceExtensions {
|
||||||
|
public static string Import(this IImportExportService service, string recipeText) {
|
||||||
|
var recipeDocument = XDocument.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
||||||
|
return service.Import(recipeDocument);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Orchard.FileSystems.AppData;
|
using Orchard.FileSystems.AppData;
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
|
||||||
using Orchard.Recipes.Services;
|
using Orchard.Recipes.Services;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
|
||||||
namespace Orchard.ImportExport.Services {
|
namespace Orchard.ImportExport.Services {
|
||||||
public class ImportExportService : IImportExportService {
|
public class ImportExportService : Component, IImportExportService {
|
||||||
private readonly IOrchardServices _orchardServices;
|
private readonly IOrchardServices _orchardServices;
|
||||||
private readonly IAppDataFolder _appDataFolder;
|
private readonly IAppDataFolder _appDataFolder;
|
||||||
private readonly IRecipeBuilder _recipeBuilder;
|
private readonly IRecipeBuilder _recipeBuilder;
|
||||||
|
private IRecipeParser _recipeParser;
|
||||||
private readonly IRecipeExecutor _recipeExecutor;
|
private readonly IRecipeExecutor _recipeExecutor;
|
||||||
private readonly IClock _clock;
|
private readonly IClock _clock;
|
||||||
private const string ExportsDirectory = "Exports";
|
private const string ExportsDirectory = "Exports";
|
||||||
@@ -21,50 +19,36 @@ namespace Orchard.ImportExport.Services {
|
|||||||
IOrchardServices orchardServices,
|
IOrchardServices orchardServices,
|
||||||
IAppDataFolder appDataFolder,
|
IAppDataFolder appDataFolder,
|
||||||
IRecipeBuilder recipeBuilder,
|
IRecipeBuilder recipeBuilder,
|
||||||
|
IRecipeParser recipeParser,
|
||||||
IRecipeExecutor recipeExecutor,
|
IRecipeExecutor recipeExecutor,
|
||||||
IClock clock) {
|
IClock clock) {
|
||||||
|
|
||||||
_orchardServices = orchardServices;
|
_orchardServices = orchardServices;
|
||||||
_appDataFolder = appDataFolder;
|
_appDataFolder = appDataFolder;
|
||||||
_recipeBuilder = recipeBuilder;
|
_recipeBuilder = recipeBuilder;
|
||||||
|
_recipeParser = recipeParser;
|
||||||
_recipeExecutor = recipeExecutor;
|
_recipeExecutor = recipeExecutor;
|
||||||
_clock = clock;
|
_clock = clock;
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
public string Import(XDocument recipeDocument) {
|
public string Import(XDocument recipeDocument) {
|
||||||
return _recipeExecutor.Execute(recipeDocument);
|
var recipe = _recipeParser.ParseRecipe(recipeDocument);
|
||||||
|
return _recipeExecutor.Execute(recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Import(string recipeText) {
|
public XDocument Export(IEnumerable<IRecipeBuilderStep> steps) {
|
||||||
return _recipeExecutor.Execute(recipeText);
|
|
||||||
}
|
|
||||||
|
|
||||||
public XDocument ExportXml(IEnumerable<IRecipeBuilderStep> steps) {
|
|
||||||
var recipe = _recipeBuilder.Build(steps);
|
var recipe = _recipeBuilder.Build(steps);
|
||||||
return recipe;
|
return recipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Export(IEnumerable<IRecipeBuilderStep> steps) {
|
|
||||||
var recipe = _recipeBuilder.Build(steps);
|
|
||||||
return recipe.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string WriteExportFile(XDocument recipeDocument) {
|
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);
|
var exportFile = String.Format("Export-{0}-{1}.xml", _orchardServices.WorkContext.CurrentUser.UserName, _clock.UtcNow.Ticks);
|
||||||
if (!_appDataFolder.DirectoryExists(ExportsDirectory)) {
|
if (!_appDataFolder.DirectoryExists(ExportsDirectory)) {
|
||||||
_appDataFolder.CreateDirectory(ExportsDirectory);
|
_appDataFolder.CreateDirectory(ExportsDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = _appDataFolder.Combine(ExportsDirectory, exportFile);
|
var path = _appDataFolder.Combine(ExportsDirectory, exportFile);
|
||||||
|
var recipeText = recipeDocument.ToString(SaveOptions.None);
|
||||||
_appDataFolder.CreateFile(path, recipeText);
|
_appDataFolder.CreateFile(path, recipeText);
|
||||||
|
|
||||||
return _appDataFolder.MapPath(path);
|
return _appDataFolder.MapPath(path);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace Orchard.ImportExport.Services {
|
namespace Orchard.ImportExport.Services {
|
||||||
public class SetupContext {
|
public class SetupContext {
|
||||||
@@ -9,7 +10,7 @@ namespace Orchard.ImportExport.Services {
|
|||||||
public string DatabaseConnectionString { get; set; }
|
public string DatabaseConnectionString { get; set; }
|
||||||
public string DatabaseTablePrefix { get; set; }
|
public string DatabaseTablePrefix { get; set; }
|
||||||
public IEnumerable<string> EnabledFeatures { get; set; }
|
public IEnumerable<string> EnabledFeatures { get; set; }
|
||||||
public string RecipeText { get; set; }
|
public XDocument RecipeDocument { get; set; }
|
||||||
public bool DropExistingTables { get; set; }
|
public bool DropExistingTables { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ namespace Orchard.ImportExport.Services
|
|||||||
|
|
||||||
// Execute recipe
|
// Execute recipe
|
||||||
var recipeParser = environment.Resolve<IRecipeParser>();
|
var recipeParser = environment.Resolve<IRecipeParser>();
|
||||||
var recipe = recipeParser.ParseRecipe(context.RecipeText);
|
var recipe = recipeParser.ParseRecipe(context.RecipeDocument);
|
||||||
var recipeManager = environment.Resolve<IRecipeManager>();
|
var recipeManager = environment.Resolve<IRecipeManager>();
|
||||||
var executionId = recipeManager.Execute(recipe);
|
var executionId = recipeManager.Execute(recipe);
|
||||||
|
|
||||||
|
|||||||
@@ -7,21 +7,12 @@ using Orchard.Recipes.Models;
|
|||||||
|
|
||||||
namespace Orchard.Recipes.Services {
|
namespace Orchard.Recipes.Services {
|
||||||
public class RecipeParser : Component, IRecipeParser {
|
public class RecipeParser : Component, IRecipeParser {
|
||||||
|
|
||||||
public Recipe ParseRecipe(XDocument recipeDocument) {
|
public Recipe ParseRecipe(XDocument recipeDocument) {
|
||||||
return ParseRecipe(recipeDocument.ToString(SaveOptions.DisableFormatting));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Recipe ParseRecipe(string recipeText) {
|
|
||||||
var recipe = new Recipe();
|
var recipe = new Recipe();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(recipeText)) {
|
|
||||||
throw new Exception("Recipe is empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
var recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
|
||||||
var recipeSteps = new List<RecipeStep>();
|
var recipeSteps = new List<RecipeStep>();
|
||||||
|
|
||||||
foreach (var element in recipeTree.Elements()) {
|
foreach (var element in recipeDocument.Root.Elements()) {
|
||||||
// Recipe metadata.
|
// Recipe metadata.
|
||||||
if (element.Name.LocalName == "Recipe") {
|
if (element.Name.LocalName == "Recipe") {
|
||||||
foreach (var metadataElement in element.Elements()) {
|
foreach (var metadataElement in element.Elements()) {
|
||||||
|
|||||||
@@ -1037,6 +1037,7 @@
|
|||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ using Orchard.Recipes.Models;
|
|||||||
|
|
||||||
namespace Orchard.Recipes.Services {
|
namespace Orchard.Recipes.Services {
|
||||||
public interface IRecipeExecutor : IDependency {
|
public interface IRecipeExecutor : IDependency {
|
||||||
string Execute(XDocument recipeDocument);
|
|
||||||
string Execute(string recipeText);
|
|
||||||
string Execute(Recipe recipe);
|
string Execute(Recipe recipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,12 @@ using Orchard.Recipes.Models;
|
|||||||
namespace Orchard.Recipes.Services {
|
namespace Orchard.Recipes.Services {
|
||||||
public interface IRecipeParser : IDependency {
|
public interface IRecipeParser : IDependency {
|
||||||
Recipe ParseRecipe(XDocument recipeDocument);
|
Recipe ParseRecipe(XDocument recipeDocument);
|
||||||
Recipe ParseRecipe(string recipeText);
|
}
|
||||||
|
|
||||||
|
public static class RecipeParserExtensions {
|
||||||
|
public static Recipe ParseRecipe(this IRecipeParser recipeParser, string recipeText) {
|
||||||
|
var recipeDocument = XDocument.Parse(recipeText, LoadOptions.PreserveWhitespace);
|
||||||
|
return recipeParser.ParseRecipe(recipeDocument);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
using System.Xml.Linq;
|
using Orchard.Environment.Descriptor;
|
||||||
using Orchard.Environment.Descriptor;
|
|
||||||
using Orchard.Recipes.Models;
|
using Orchard.Recipes.Models;
|
||||||
|
|
||||||
namespace Orchard.Recipes.Services {
|
namespace Orchard.Recipes.Services {
|
||||||
public class RecipeExecutor : Component, IRecipeExecutor {
|
public class RecipeExecutor : Component, IRecipeExecutor {
|
||||||
private readonly IRecipeParser _recipeParser;
|
|
||||||
private readonly IRecipeManager _recipeManager;
|
private readonly IRecipeManager _recipeManager;
|
||||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
private readonly IShellDescriptorManager _shellDescriptorManager;
|
||||||
|
|
||||||
@@ -13,21 +11,10 @@ namespace Orchard.Recipes.Services {
|
|||||||
IRecipeManager recipeManager,
|
IRecipeManager recipeManager,
|
||||||
IShellDescriptorManager shellDescriptorManager) {
|
IShellDescriptorManager shellDescriptorManager) {
|
||||||
|
|
||||||
_recipeParser = recipeParser;
|
|
||||||
_recipeManager = recipeManager;
|
_recipeManager = recipeManager;
|
||||||
_shellDescriptorManager = shellDescriptorManager;
|
_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) {
|
public string Execute(Recipe recipe) {
|
||||||
var executionId = _recipeManager.Execute(recipe);
|
var executionId = _recipeManager.Execute(recipe);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user