mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Refactored CurrentTheme import/export step.
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Events;
|
||||
using Orchard.Themes.Services;
|
||||
|
||||
namespace Orchard.Themes.ImportExport {
|
||||
public interface IExportEventHandler : IEventHandler {
|
||||
void Exporting(dynamic context);
|
||||
void Exported(dynamic context);
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Themes.ImportExportCurrentTheme")]
|
||||
public class CurrentThemeExportHandler : IExportEventHandler {
|
||||
private readonly ISiteThemeService _siteThemeService;
|
||||
|
||||
public CurrentThemeExportHandler(ISiteThemeService siteThemeService) {
|
||||
_siteThemeService = siteThemeService;
|
||||
}
|
||||
|
||||
public void Exporting(dynamic context) { }
|
||||
|
||||
public void Exported(dynamic context) {
|
||||
if (!((IEnumerable<string>)context.ExportOptions.CustomSteps).Contains("CurrentTheme")) {
|
||||
return;
|
||||
}
|
||||
|
||||
var currentThemeId = _siteThemeService.GetCurrentThemeName();
|
||||
var root = new XElement("CurrentTheme", new XAttribute("id", currentThemeId));
|
||||
context.Document.Element("Orchard").Add(root);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.Themes.ImportExport {
|
||||
public interface ICustomExportStep : IEventHandler {
|
||||
void Register(IList<string> steps);
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Themes.ImportExportCurrentTheme")]
|
||||
public class CurrentThemeStep : ICustomExportStep {
|
||||
|
||||
void ICustomExportStep.Register(IList<string> steps) {
|
||||
steps.Add("CurrentTheme");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,4 +16,3 @@ Features:
|
||||
Name: Import Export Current Theme
|
||||
Description: Provides the capability to import and export the current theme.
|
||||
Category: Deployment
|
||||
Dependencies: Orchard.ImportExport
|
||||
|
@@ -69,12 +69,11 @@
|
||||
<Compile Include="Commands\ThemeCommands.cs" />
|
||||
<Compile Include="Drivers\DisableThemePartDriver.cs" />
|
||||
<Compile Include="Events\IExtensionDisplayEventHandler.cs" />
|
||||
<Compile Include="ImportExport\CurrentThemeRecipeHandler.cs" />
|
||||
<Compile Include="ImportExport\CurrentThemeExportHandler.cs" />
|
||||
<Compile Include="ImportExport\CurrentThemeStep.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Models\ThemeEntry.cs" />
|
||||
<Compile Include="Models\DisableThemePart.cs" />
|
||||
<Compile Include="Recipes\Executors\CurrentThemeStep.cs" />
|
||||
<Compile Include="Recipes\Builders\CurrentThemeStep.cs" />
|
||||
<Compile Include="Recipes\Executors\ThemeStep.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
|
@@ -0,0 +1,34 @@
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Themes.Services;
|
||||
|
||||
namespace Orchard.Themes.Recipes.Builders {
|
||||
[OrchardFeature("Orchard.Themes.ImportExportCurrentTheme")]
|
||||
public class CurrentThemeStep : RecipeBuilderStep {
|
||||
private readonly ISiteThemeService _siteThemeService;
|
||||
|
||||
public CurrentThemeStep(ISiteThemeService siteThemeService) {
|
||||
_siteThemeService = siteThemeService;
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get { return "CurrentTheme"; }
|
||||
}
|
||||
|
||||
public override LocalizedString DisplayName {
|
||||
get { return T("Current Theme"); }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("Adds information to the recipe that indicates the current theme."); }
|
||||
}
|
||||
|
||||
public override void Build(BuildContext context) {
|
||||
var currentThemeId = _siteThemeService.GetCurrentThemeName();
|
||||
var root = new XElement("CurrentTheme", new XAttribute("id", currentThemeId));
|
||||
context.RecipeDocument.Element("Orchard").Add(root);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,27 +1,25 @@
|
||||
using System;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Themes.Services;
|
||||
|
||||
namespace Orchard.Themes.ImportExport {
|
||||
namespace Orchard.Themes.Recipes.Executors {
|
||||
|
||||
[OrchardFeature("Orchard.Themes.ImportExportCurrentTheme")]
|
||||
public class CurrentThemeRecipeHandler : IRecipeHandler {
|
||||
public class CurrentThemeStep : RecipeExecutionStep {
|
||||
private readonly ISiteThemeService _siteThemeService;
|
||||
|
||||
public CurrentThemeRecipeHandler(ISiteThemeService siteThemeService) {
|
||||
|
||||
public override string Name {
|
||||
get { return "CurrentTheme"; }
|
||||
}
|
||||
|
||||
public CurrentThemeStep(ISiteThemeService siteThemeService) {
|
||||
_siteThemeService = siteThemeService;
|
||||
}
|
||||
|
||||
public void ExecuteRecipeStep(RecipeContext context) {
|
||||
if (!String.Equals(context.RecipeStep.Name, "CurrentTheme", StringComparison.OrdinalIgnoreCase)) {
|
||||
return;
|
||||
}
|
||||
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
var themeId = context.RecipeStep.Step.Attribute("id").Value;
|
||||
_siteThemeService.SetSiteTheme(themeId);
|
||||
context.Executed = true;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user