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.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NHibernate;
|
||||
@@ -8,7 +6,6 @@ using NUnit.Framework;
|
||||
using Orchard.Caching;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Core.Settings.Metadata;
|
||||
@@ -86,23 +83,23 @@ namespace Orchard.Tests.Modules.ImportExport.Services {
|
||||
[Test]
|
||||
public void ImportSucceedsWhenRecipeContainsImportSteps() {
|
||||
Assert.DoesNotThrow(() => _importExportService.Import(
|
||||
@"<Orchard>
|
||||
<Recipe>
|
||||
<Name>MyModuleInstaller</Name>
|
||||
</Recipe>
|
||||
<Settings />
|
||||
</Orchard>"));
|
||||
@"<Orchard>
|
||||
<Recipe>
|
||||
<Name>MyModuleInstaller</Name>
|
||||
</Recipe>
|
||||
<Settings />
|
||||
</Orchard>"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ImportDoesntFailsWhenRecipeContainsNonImportSteps() {
|
||||
public void ImportDoesntFailWhenRecipeContainsNonImportSteps() {
|
||||
Assert.DoesNotThrow(() => _importExportService.Import(
|
||||
@"<Orchard>
|
||||
<Recipe>
|
||||
<Name>MyModuleInstaller</Name>
|
||||
</Recipe>
|
||||
<Module name=""MyModule"" />
|
||||
</Orchard>"));
|
||||
@"<Orchard>
|
||||
<Recipe>
|
||||
<Name>MyModuleInstaller</Name>
|
||||
</Recipe>
|
||||
<Module name=""MyModule"" />
|
||||
</Orchard>"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ using Orchard.Recipes.Services;
|
||||
using Orchard.Services;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Recipes.Events;
|
||||
using Orchard.Data;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
|
||||
@@ -164,6 +164,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\EditorTemplates\ExportActions\BuildRecipe.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Orchard.ImportExport.Providers.ExportActions {
|
||||
}
|
||||
|
||||
public override void Execute(ExportActionContext context) {
|
||||
var recipeDocument = _importExportService.ExportXml(RecipeBuilderSteps);
|
||||
var recipeDocument = _importExportService.Export(RecipeBuilderSteps);
|
||||
var recipe = _recipeParser.ParseRecipe(recipeDocument);
|
||||
var exportFileName = GetExportFileName(recipe);
|
||||
var exportFilePath = _importExportService.WriteExportFile(recipeDocument);
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace Orchard.ImportExport.Providers.ImportActions {
|
||||
private string Setup() {
|
||||
var setupContext = new SetupContext {
|
||||
DropExistingTables = true,
|
||||
RecipeText = RecipeDocument.ToString(SaveOptions.DisableFormatting),
|
||||
RecipeDocument = RecipeDocument,
|
||||
AdminPassword = SuperUserPassword,
|
||||
AdminUsername = _orchardServices.WorkContext.CurrentSite.SuperUser,
|
||||
DatabaseConnectionString = _shellSettings.DataConnectionString,
|
||||
@@ -162,7 +162,7 @@ namespace Orchard.ImportExport.Providers.ImportActions {
|
||||
}
|
||||
|
||||
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 {
|
||||
public interface IImportExportService : IDependency {
|
||||
string Import(string recipeText);
|
||||
XDocument ExportXml(IEnumerable<IRecipeBuilderStep> steps);
|
||||
string Export(IEnumerable<IRecipeBuilderStep> steps);
|
||||
string Import(XDocument recipeDocument);
|
||||
XDocument Export(IEnumerable<IRecipeBuilderStep> steps);
|
||||
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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Services;
|
||||
|
||||
namespace Orchard.ImportExport.Services {
|
||||
public class ImportExportService : IImportExportService {
|
||||
public class ImportExportService : Component, IImportExportService {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
private readonly IRecipeBuilder _recipeBuilder;
|
||||
private IRecipeParser _recipeParser;
|
||||
private readonly IRecipeExecutor _recipeExecutor;
|
||||
private readonly IClock _clock;
|
||||
private const string ExportsDirectory = "Exports";
|
||||
@@ -20,51 +18,37 @@ namespace Orchard.ImportExport.Services {
|
||||
public ImportExportService(
|
||||
IOrchardServices orchardServices,
|
||||
IAppDataFolder appDataFolder,
|
||||
IRecipeBuilder recipeBuilder,
|
||||
IRecipeExecutor recipeExecutor,
|
||||
IRecipeBuilder recipeBuilder,
|
||||
IRecipeParser recipeParser,
|
||||
IRecipeExecutor recipeExecutor,
|
||||
IClock clock) {
|
||||
|
||||
_orchardServices = orchardServices;
|
||||
_appDataFolder = appDataFolder;
|
||||
_recipeBuilder = recipeBuilder;
|
||||
_recipeParser = recipeParser;
|
||||
_recipeExecutor = recipeExecutor;
|
||||
_clock = clock;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public string Import(XDocument recipeDocument) {
|
||||
return _recipeExecutor.Execute(recipeDocument);
|
||||
var recipe = _recipeParser.ParseRecipe(recipeDocument);
|
||||
return _recipeExecutor.Execute(recipe);
|
||||
}
|
||||
|
||||
public string Import(string recipeText) {
|
||||
return _recipeExecutor.Execute(recipeText);
|
||||
}
|
||||
|
||||
public XDocument ExportXml(IEnumerable<IRecipeBuilderStep> steps) {
|
||||
public XDocument Export(IEnumerable<IRecipeBuilderStep> steps) {
|
||||
var recipe = _recipeBuilder.Build(steps);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public string Export(IEnumerable<IRecipeBuilderStep> steps) {
|
||||
var recipe = _recipeBuilder.Build(steps);
|
||||
return recipe.ToString();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
var recipeText = recipeDocument.ToString(SaveOptions.None);
|
||||
_appDataFolder.CreateFile(path, recipeText);
|
||||
|
||||
return _appDataFolder.MapPath(path);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Orchard.ImportExport.Services {
|
||||
public class SetupContext {
|
||||
@@ -9,7 +10,7 @@ namespace Orchard.ImportExport.Services {
|
||||
public string DatabaseConnectionString { get; set; }
|
||||
public string DatabaseTablePrefix { get; set; }
|
||||
public IEnumerable<string> EnabledFeatures { get; set; }
|
||||
public string RecipeText { get; set; }
|
||||
public XDocument RecipeDocument { get; set; }
|
||||
public bool DropExistingTables { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ namespace Orchard.ImportExport.Services
|
||||
|
||||
// Execute recipe
|
||||
var recipeParser = environment.Resolve<IRecipeParser>();
|
||||
var recipe = recipeParser.ParseRecipe(context.RecipeText);
|
||||
var recipe = recipeParser.ParseRecipe(context.RecipeDocument);
|
||||
var recipeManager = environment.Resolve<IRecipeManager>();
|
||||
var executionId = recipeManager.Execute(recipe);
|
||||
|
||||
|
||||
@@ -7,21 +7,12 @@ using Orchard.Recipes.Models;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public class RecipeParser : Component, IRecipeParser {
|
||||
|
||||
public Recipe ParseRecipe(XDocument recipeDocument) {
|
||||
return ParseRecipe(recipeDocument.ToString(SaveOptions.DisableFormatting));
|
||||
}
|
||||
|
||||
public Recipe ParseRecipe(string recipeText) {
|
||||
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>();
|
||||
|
||||
foreach (var element in recipeTree.Elements()) {
|
||||
foreach (var element in recipeDocument.Root.Elements()) {
|
||||
// Recipe metadata.
|
||||
if (element.Name.LocalName == "Recipe") {
|
||||
foreach (var metadataElement in element.Elements()) {
|
||||
|
||||
@@ -1037,6 +1037,7 @@
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- 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.
|
||||
|
||||
@@ -3,8 +3,6 @@ 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,6 +4,12 @@ using Orchard.Recipes.Models;
|
||||
namespace Orchard.Recipes.Services {
|
||||
public interface IRecipeParser : IDependency {
|
||||
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;
|
||||
|
||||
namespace Orchard.Recipes.Services {
|
||||
public class RecipeExecutor : Component, IRecipeExecutor {
|
||||
private readonly IRecipeParser _recipeParser;
|
||||
private readonly IRecipeManager _recipeManager;
|
||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
||||
|
||||
@@ -13,21 +11,10 @@ namespace Orchard.Recipes.Services {
|
||||
IRecipeManager recipeManager,
|
||||
IShellDescriptorManager shellDescriptorManager) {
|
||||
|
||||
_recipeParser = recipeParser;
|
||||
_recipeManager = recipeManager;
|
||||
_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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user