mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Additional intermediate state
--HG-- branch : perf
This commit is contained in:
@@ -29,6 +29,7 @@ using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Modules;
|
||||
using Orchard.Modules.Services;
|
||||
@@ -44,6 +45,7 @@ using Orchard.Themes.Services;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Tests.Modules.Themes.Services {
|
||||
#if REFACTORING
|
||||
[TestFixture, Ignore]
|
||||
public class ThemeServiceTests {
|
||||
private IThemeService _themeService;
|
||||
@@ -51,6 +53,7 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
private IContainer _container;
|
||||
private ISessionFactory _sessionFactory;
|
||||
private ISession _session;
|
||||
private IFeatureManager _featureManager;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void InitFixture() {
|
||||
@@ -85,7 +88,7 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
|
||||
builder.RegisterType<SiteSettingsPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<ThemeSiteSettingsPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<ModuleService>().As<IModuleService>();
|
||||
//builder.RegisterType<ModuleService>().As<IModuleService>();
|
||||
builder.RegisterType<ShellDescriptor>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<StubShellDescriptorManager>().As<IShellDescriptorManager>().InstancePerLifetimeScope();
|
||||
@@ -102,6 +105,7 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
_container = builder.Build();
|
||||
_themeService = _container.Resolve<IThemeService>();
|
||||
_siteThemeService = _container.Resolve<ISiteThemeService>();
|
||||
_featureManager = _container.Resolve<IFeatureManager>();
|
||||
}
|
||||
|
||||
//todo: test theme feature enablement
|
||||
@@ -143,10 +147,10 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
|
||||
[Test]
|
||||
public void CanEnableAndDisableThemes() {
|
||||
_themeService.EnableTheme("ThemeOne");
|
||||
_featureManager.EnableFeature("ThemeOne");
|
||||
Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled);
|
||||
Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));
|
||||
_themeService.DisableTheme("ThemeOne");
|
||||
_featureManager.DisableFeature("ThemeOne");
|
||||
Assert.IsFalse(_themeService.GetThemeByName("ThemeOne").Enabled);
|
||||
Assert.IsFalse(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));
|
||||
}
|
||||
@@ -274,4 +278,5 @@ namespace Orchard.Tests.Modules.Themes.Services {
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -90,11 +90,8 @@ namespace Orchard.Tests.Modules.Widgets.Services {
|
||||
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
|
||||
var theme1 = new ExtensionDescriptor { Zones = ThemeZoneName1 } ;
|
||||
var theme2 = new ExtensionDescriptor { Zones = ThemeZoneName2 } ;
|
||||
Mock<IThemeService> themeServiceMock = new Mock<IThemeService>();
|
||||
themeServiceMock.Setup(x => x.GetInstalledThemes()).Returns(
|
||||
(new ExtensionDescriptor[] { theme1, theme2 }));
|
||||
|
||||
builder.RegisterInstance(themeServiceMock.Object).As<IThemeService>();
|
||||
|
||||
builder.RegisterType<StubWidgetPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<StubLayerPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -83,6 +82,10 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
_availableFeautures = availableFeautures;
|
||||
}
|
||||
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
@@ -94,14 +97,6 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
|
||||
public IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class TestShapeProvider : IShapeTableProvider {
|
||||
|
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
@@ -86,6 +85,10 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
public class StubExtensionManager : IExtensionManager {
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
var ext = new ExtensionDescriptor { Name = "Orchard.Framework" };
|
||||
ext.Features = new[] { new FeatureDescriptor { Extension = ext, Name = ext.Name } };
|
||||
@@ -116,14 +119,6 @@ namespace Orchard.Tests.Environment {
|
||||
};
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Monitor(Action<IVolatileToken> monitor) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Tests.Stubs {
|
||||
public class StubExtensionManager : IExtensionManager {
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
@@ -18,13 +20,5 @@ namespace Orchard.Tests.Stubs {
|
||||
public IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Commands;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
@@ -8,10 +9,12 @@ namespace Orchard.Modules.Commands {
|
||||
public class FeatureCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IModuleService _moduleService;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
|
||||
public FeatureCommands(IModuleService moduleService, INotifier notifier) {
|
||||
public FeatureCommands(IModuleService moduleService, INotifier notifier, IFeatureManager featureManager) {
|
||||
_moduleService = moduleService;
|
||||
_notifier = notifier;
|
||||
_featureManager = featureManager;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
@@ -22,8 +25,8 @@ namespace Orchard.Modules.Commands {
|
||||
[OrchardSwitches("Summary")]
|
||||
public void List() {
|
||||
if (Summary) {
|
||||
foreach (var feature in _moduleService.GetAvailableFeatures().OrderBy(f => f.Descriptor.Name)) {
|
||||
Context.Output.WriteLine(T("{0}, {1}", feature.Descriptor.Name, feature.IsEnabled ? T("Enabled") : T("Disabled")));
|
||||
foreach (var feature in _featureManager.GetAvailableFeatures().OrderBy(f => f.Name)) {
|
||||
Context.Output.WriteLine(T("{0}, {1}", feature.Name, feature.IsEnabled ? T("Enabled") : T("Disabled")));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using JetBrains.Annotations;
|
||||
@@ -119,16 +118,7 @@ namespace Orchard.Setup {
|
||||
};
|
||||
|
||||
public ExtensionDescriptor GetThemeByName(string themeName) { return _theme; }
|
||||
public ExtensionDescriptor GetSiteTheme() { return _theme; }
|
||||
public void SetSiteTheme(string themeName) { }
|
||||
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) { return _theme; }
|
||||
public IEnumerable<ExtensionDescriptor> GetInstalledThemes() { return new[] { _theme }; }
|
||||
public IEnumerable<ExtensionDescriptor> GetEnabledThemes() { return new[] { _theme }; }
|
||||
|
||||
public void InstallTheme(HttpPostedFileBase file) { }
|
||||
public void UninstallTheme(string themeName) { }
|
||||
public void EnableTheme(string themeName) { }
|
||||
public void DisableTheme(string themeName) { }
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
|
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Reports.Services;
|
||||
@@ -20,6 +22,7 @@ namespace Orchard.Themes.Controllers {
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly ISiteThemeService _siteThemeService;
|
||||
private readonly IPreviewTheme _previewTheme;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IDataMigrationManager _dataMigrationManager;
|
||||
private readonly IReportsCoordinator _reportsCoordinator;
|
||||
|
||||
@@ -32,7 +35,8 @@ namespace Orchard.Themes.Controllers {
|
||||
ISiteThemeService siteThemeService,
|
||||
IPreviewTheme previewTheme,
|
||||
IAuthorizer authorizer,
|
||||
INotifier notifier) {
|
||||
INotifier notifier,
|
||||
IExtensionManager extensionManager) {
|
||||
Services = services;
|
||||
_dataMigrationManager = dataMigraitonManager;
|
||||
_reportsCoordinator = reportsCoordinator;
|
||||
@@ -40,6 +44,7 @@ namespace Orchard.Themes.Controllers {
|
||||
_featureManager = featureManager;
|
||||
_siteThemeService = siteThemeService;
|
||||
_previewTheme = previewTheme;
|
||||
_extensionManager = extensionManager;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
@@ -48,7 +53,7 @@ namespace Orchard.Themes.Controllers {
|
||||
|
||||
public ActionResult Index() {
|
||||
try {
|
||||
var themes = _themeService.GetInstalledThemes();
|
||||
var themes = _extensionManager.AvailableExtensions().Where(d => d.ExtensionType == "Theme");
|
||||
var currentTheme = _siteThemeService.GetSiteTheme();
|
||||
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
|
||||
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes, FeaturesThatNeedUpdate = featuresThatNeedUpdate };
|
||||
@@ -144,41 +149,6 @@ namespace Orchard.Themes.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult Install() {
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Install(FormCollection input) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't install theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
foreach (string fileName in Request.Files) {
|
||||
HttpPostedFileBase file = Request.Files[fileName];
|
||||
_themeService.InstallTheme(file);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Installing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Uninstall(string themeName) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't uninstall theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.UninstallTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Uninstalling theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Update(string themeName) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageThemes, T("Couldn't update theme")))
|
||||
|
@@ -85,6 +85,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\SafeModeThemeSelector.cs" />
|
||||
<Compile Include="Services\SiteThemeSelector.cs" />
|
||||
<Compile Include="Services\SiteThemeService.cs" />
|
||||
<Compile Include="Services\ThemeService.cs" />
|
||||
<Compile Include="ViewModels\ThemesIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Themes.ViewModels;
|
||||
|
||||
@@ -10,16 +11,19 @@ namespace Orchard.Themes.Preview {
|
||||
private readonly IPreviewTheme _previewTheme;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly dynamic _shapeFactory;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
|
||||
public PreviewThemeFilter(
|
||||
IThemeService themeService,
|
||||
IPreviewTheme previewTheme,
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
IShapeFactory shapeFactory) {
|
||||
IThemeService themeService,
|
||||
IPreviewTheme previewTheme,
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
IShapeFactory shapeFactory,
|
||||
IFeatureManager featureManager) {
|
||||
_themeService = themeService;
|
||||
_previewTheme = previewTheme;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
_shapeFactory = shapeFactory;
|
||||
_featureManager = featureManager;
|
||||
}
|
||||
|
||||
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||
@@ -27,7 +31,11 @@ namespace Orchard.Themes.Preview {
|
||||
if (string.IsNullOrEmpty(previewThemeName))
|
||||
return;
|
||||
|
||||
var installedThemes = _themeService.GetInstalledThemes();
|
||||
var installedThemes = _featureManager.GetEnabledFeatures()
|
||||
.Select(x => x.Extension)
|
||||
.Where(x => x.ExtensionType == "Theme")
|
||||
.Distinct();
|
||||
|
||||
var themeListItems = installedThemes
|
||||
.Select(theme => new SelectListItem {
|
||||
Text = theme.DisplayName,
|
||||
@@ -36,8 +44,6 @@ namespace Orchard.Themes.Preview {
|
||||
})
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
_workContextAccessor.GetContext(filterContext).Layout.Zones["Body"].Add(_shapeFactory.ThemePreview(Themes: themeListItems), ":before");
|
||||
}
|
||||
|
||||
|
@@ -2,10 +2,8 @@
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Themes.Models;
|
||||
|
||||
namespace Orchard.Themes.Services {
|
||||
@@ -28,34 +26,4 @@ namespace Orchard.Themes.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISiteThemeService : IDependency {
|
||||
ExtensionDescriptor GetSiteTheme();
|
||||
void SetSiteTheme(string themeName);
|
||||
}
|
||||
|
||||
public class SiteThemeService : ISiteThemeService {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
|
||||
public SiteThemeService(IExtensionManager extensionManager) {
|
||||
_extensionManager = extensionManager;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
|
||||
|
||||
public ExtensionDescriptor GetSiteTheme() {
|
||||
string currentThemeName = CurrentSite.As<ThemeSiteSettingsPart>().CurrentThemeName;
|
||||
|
||||
if (string.IsNullOrEmpty(currentThemeName)) {
|
||||
return null;
|
||||
}
|
||||
return _extensionManager.GetExtensionDescriptor(currentThemeName);
|
||||
}
|
||||
|
||||
public void SetSiteTheme(string themeName) {
|
||||
CurrentSite.As<ThemeSiteSettingsPart>().Record.CurrentThemeName = themeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,42 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Themes.Models;
|
||||
|
||||
namespace Orchard.Themes.Services {
|
||||
public interface ISiteThemeService : IDependency {
|
||||
ExtensionDescriptor GetSiteTheme();
|
||||
void SetSiteTheme(string themeName);
|
||||
}
|
||||
|
||||
public class SiteThemeService : ISiteThemeService {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public SiteThemeService(IExtensionManager extensionManager, IWorkContextAccessor workContextAccessor) {
|
||||
_extensionManager = extensionManager;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ExtensionDescriptor GetSiteTheme() {
|
||||
var site = _workContextAccessor.GetContext().CurrentSite;
|
||||
string currentThemeName = site.As<ThemeSiteSettingsPart>().CurrentThemeName;
|
||||
|
||||
if (string.IsNullOrEmpty(currentThemeName)) {
|
||||
return null;
|
||||
}
|
||||
return _extensionManager.GetExtension(currentThemeName);
|
||||
}
|
||||
|
||||
public void SetSiteTheme(string themeName) {
|
||||
var site = _workContextAccessor.GetContext().CurrentSite;
|
||||
site.As<ThemeSiteSettingsPart>().Record.CurrentThemeName = themeName;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Environment.Descriptor;
|
||||
@@ -47,13 +46,7 @@ namespace Orchard.Themes.Services {
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public void EnableTheme(string themeName) {
|
||||
DoEnableTheme(themeName);
|
||||
}
|
||||
|
||||
public void DisableTheme(string themeName) {
|
||||
DisableThemeFeatures(themeName);
|
||||
}
|
||||
|
||||
private bool AllBaseThemesAreInstalled(string baseThemeName) {
|
||||
var themesSeen = new List<string>();
|
||||
@@ -63,7 +56,7 @@ namespace Orchard.Themes.Services {
|
||||
throw new InvalidOperationException(T("The theme \"{0}\" was already seen - looks like we're going around in circles.", baseThemeName).Text);
|
||||
themesSeen.Add(baseThemeName);
|
||||
|
||||
var baseTheme = GetThemeByName(baseThemeName);
|
||||
var baseTheme = _extensionManager.GetExtension(baseThemeName);
|
||||
if (baseTheme == null)
|
||||
return false;
|
||||
baseThemeName = baseTheme.BaseTheme;
|
||||
@@ -77,7 +70,7 @@ namespace Orchard.Themes.Services {
|
||||
while (themeName != null) {
|
||||
if (themes.Contains(themeName))
|
||||
throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName).Text);
|
||||
var theme = GetThemeByName(themeName);
|
||||
var theme = _extensionManager.GetExtension(themeName);
|
||||
if (theme == null)
|
||||
break;
|
||||
themes.Enqueue(themeName);
|
||||
@@ -99,7 +92,7 @@ namespace Orchard.Themes.Services {
|
||||
throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features enabled.", themeName).Text);
|
||||
themes.Push(themeName);
|
||||
|
||||
var theme = GetThemeByName(themeName);
|
||||
var theme = _extensionManager.GetExtension(themeName);
|
||||
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
||||
? theme.BaseTheme
|
||||
: null;
|
||||
@@ -114,7 +107,7 @@ namespace Orchard.Themes.Services {
|
||||
return false;
|
||||
|
||||
//todo: (heskew) need messages given in addition to all of these early returns so something meaningful can be presented to the user
|
||||
var themeToEnable = GetThemeByName(themeName);
|
||||
var themeToEnable = _extensionManager.GetExtension(themeName);
|
||||
if (themeToEnable == null)
|
||||
return false;
|
||||
|
||||
@@ -138,21 +131,12 @@ namespace Orchard.Themes.Services {
|
||||
return null;
|
||||
|
||||
foreach (var theme in requestTheme) {
|
||||
var t = GetThemeByName(theme.ThemeName);
|
||||
var t = _extensionManager.GetExtension(theme.ThemeName);
|
||||
if (t != null)
|
||||
return t;
|
||||
}
|
||||
|
||||
return GetThemeByName("SafeMode");
|
||||
}
|
||||
|
||||
public ExtensionDescriptor GetThemeByName(string name) {
|
||||
foreach (var descriptor in _extensionManager.AvailableExtensions()) {
|
||||
if (string.Equals(descriptor.Name, name, StringComparison.OrdinalIgnoreCase)) {
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return _extensionManager.GetExtension("SafeMode");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -162,13 +146,6 @@ namespace Orchard.Themes.Services {
|
||||
return GetThemes(_extensionManager.AvailableExtensions());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads only enabled themes
|
||||
/// </summary>
|
||||
public IEnumerable<ExtensionDescriptor> GetEnabledThemes() {
|
||||
return GetThemes(_extensionManager.EnabledExtensions(_shellDescriptor));
|
||||
}
|
||||
|
||||
private IEnumerable<ExtensionDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
|
||||
var themes = new List<ExtensionDescriptor>();
|
||||
foreach (var descriptor in extensions) {
|
||||
@@ -186,14 +163,6 @@ namespace Orchard.Themes.Services {
|
||||
return themes;
|
||||
}
|
||||
|
||||
public void InstallTheme(HttpPostedFileBase file) {
|
||||
_extensionManager.InstallExtension("Theme", file);
|
||||
}
|
||||
|
||||
public void UninstallTheme(string themeName) {
|
||||
_extensionManager.UninstallExtension("Theme", themeName);
|
||||
}
|
||||
|
||||
private static string TryLocalize(string key, string original, Localizer localizer) {
|
||||
var localized = localizer(key).Text;
|
||||
|
||||
|
@@ -4,6 +4,7 @@ using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Themes;
|
||||
using Orchard.Widgets.Models;
|
||||
|
||||
@@ -12,14 +13,17 @@ namespace Orchard.Widgets.Services {
|
||||
[UsedImplicitly]
|
||||
public class WidgetsService : IWidgetsService {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public WidgetsService(
|
||||
IContentManager contentManager,
|
||||
IThemeService themeService) {
|
||||
IThemeService themeService,
|
||||
IFeatureManager featureManager) {
|
||||
|
||||
_contentManager = contentManager;
|
||||
_themeService = themeService;
|
||||
_featureManager = featureManager;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetWidgetTypes() {
|
||||
@@ -41,15 +45,12 @@ namespace Orchard.Widgets.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetZones() {
|
||||
HashSet<string> zones = new HashSet<string>();
|
||||
|
||||
foreach (var theme in _themeService.GetEnabledThemes().Where(theme => theme.Zones != null && !theme.Zones.Trim().Equals(string.Empty))) {
|
||||
foreach (string zone in theme.Zones.Split(',').Where(zone => !zones.Contains(zone))) {
|
||||
zones.Add(zone.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
return zones;
|
||||
return _featureManager.GetEnabledFeatures()
|
||||
.Select(x => x.Extension)
|
||||
.Where(x => x.ExtensionType == "Theme")
|
||||
.SelectMany(x => x.Zones.Split(','))
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public IEnumerable<WidgetPart> GetWidgets(int layerId) {
|
||||
|
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Orchard.Environment.Extensions.Folders;
|
||||
using Orchard.Environment.Extensions.Helpers;
|
||||
using Orchard.Environment.Extensions.Loaders;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
@@ -31,6 +28,10 @@ namespace Orchard.Environment.Extensions {
|
||||
|
||||
// This method does not load extension types, simply parses extension manifests from
|
||||
// the filesystem.
|
||||
public ExtensionDescriptor GetExtension(string name) {
|
||||
return AvailableExtensions().FirstOrDefault(x => x.Name == name);
|
||||
}
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
return _folders.SelectMany(folder => folder.AvailableExtensions());
|
||||
}
|
||||
@@ -67,7 +68,7 @@ namespace Orchard.Environment.Extensions {
|
||||
}
|
||||
|
||||
private IEnumerable<ExtensionEntry> LoadedExtensions() {
|
||||
foreach ( var descriptor in AvailableExtensions() ) {
|
||||
foreach (var descriptor in AvailableExtensions()) {
|
||||
ExtensionEntry entry = null;
|
||||
try {
|
||||
entry = BuildEntry(descriptor);
|
||||
@@ -140,65 +141,6 @@ namespace Orchard.Environment.Extensions {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
if (String.IsNullOrEmpty(extensionType)) {
|
||||
throw new ArgumentException(T("extensionType was null or empty").ToString());
|
||||
}
|
||||
string targetFolder;
|
||||
if (String.Equals(extensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Themes");
|
||||
}
|
||||
else if (String.Equals(extensionType, "Module", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Modules");
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException(T("extensionType was not recognized").ToString());
|
||||
}
|
||||
int postedFileLength = extensionBundle.ContentLength;
|
||||
Stream postedFileStream = extensionBundle.InputStream;
|
||||
byte[] postedFileData = new byte[postedFileLength];
|
||||
postedFileStream.Read(postedFileData, 0, postedFileLength);
|
||||
|
||||
using (var memoryStream = new MemoryStream(postedFileData)) {
|
||||
var fileInflater = new ZipInputStream(memoryStream);
|
||||
ZipEntry entry;
|
||||
while ((entry = fileInflater.GetNextEntry()) != null) {
|
||||
string directoryName = Path.GetDirectoryName(entry.Name);
|
||||
if (!Directory.Exists(Path.Combine(targetFolder, directoryName))) {
|
||||
Directory.CreateDirectory(Path.Combine(targetFolder, directoryName));
|
||||
}
|
||||
|
||||
if (!entry.IsDirectory && entry.Name.Length > 0) {
|
||||
var len = Convert.ToInt32(entry.Size);
|
||||
var extractedBytes = new byte[len];
|
||||
fileInflater.Read(extractedBytes, 0, len);
|
||||
File.WriteAllBytes(Path.Combine(targetFolder, entry.Name), extractedBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
if (String.IsNullOrEmpty(extensionType)) {
|
||||
throw new ArgumentException(T("extensionType was null or empty").ToString());
|
||||
}
|
||||
string targetFolder;
|
||||
if (String.Equals(extensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Themes");
|
||||
}
|
||||
else if (String.Equals(extensionType, "Module", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Modules");
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException(T("extensionType was not recognized").ToString());
|
||||
}
|
||||
targetFolder = Path.Combine(targetFolder, extensionName);
|
||||
if (!Directory.Exists(targetFolder)) {
|
||||
throw new ArgumentException(T("extension was not found").ToString());
|
||||
}
|
||||
Directory.Delete(targetFolder, true);
|
||||
}
|
||||
|
||||
private ExtensionEntry BuildEntry(ExtensionDescriptor descriptor) {
|
||||
foreach (var loader in _loaders) {
|
||||
ExtensionEntry entry = loader.Load(descriptor);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
@@ -8,10 +7,10 @@ namespace Orchard.Environment.Extensions {
|
||||
public interface IExtensionManager {
|
||||
IEnumerable<ExtensionDescriptor> AvailableExtensions();
|
||||
IEnumerable<FeatureDescriptor> AvailableFeatures();
|
||||
IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors);
|
||||
|
||||
void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle);
|
||||
void UninstallExtension(string extensionType, string extensionName);
|
||||
ExtensionDescriptor GetExtension(string name);
|
||||
|
||||
IEnumerable<Feature> LoadFeatures(IEnumerable<FeatureDescriptor> featureDescriptors);
|
||||
}
|
||||
|
||||
public static class ExtensionManagerExtensions {
|
||||
@@ -29,13 +28,6 @@ namespace Orchard.Environment.Extensions {
|
||||
.Where(featureDescriptor => IsFeatureEnabledInDescriptor(featureDescriptor, descriptor));
|
||||
}
|
||||
|
||||
public static ExtensionDescriptor GetExtensionDescriptor(this IExtensionManager extensionManager, string name) {
|
||||
return extensionManager.AvailableExtensions().FirstOrDefault(fd => fd.Name == name);
|
||||
}
|
||||
public static FeatureDescriptor GetFeatureDescriptor(this IExtensionManager extensionManager, string name) {
|
||||
return extensionManager.AvailableFeatures().FirstOrDefault(fd => fd.Name == name);
|
||||
}
|
||||
|
||||
private static bool IsFeatureEnabledInDescriptor(FeatureDescriptor featureDescriptor, ShellDescriptor shellDescriptor) {
|
||||
return shellDescriptor.Features.Any(shellDescriptorFeature => shellDescriptorFeature.Name == featureDescriptor.Name);
|
||||
}
|
||||
|
96
src/Orchard/Environment/Features/FeatureManager.cs
Normal file
96
src/Orchard/Environment/Features/FeatureManager.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Environment.Features {
|
||||
public interface IFeatureManager : IDependency {
|
||||
IEnumerable<FeatureInfo> GetFeatures();
|
||||
IEnumerable<FeatureDescriptor> GetAvailableFeatures();
|
||||
IEnumerable<FeatureDescriptor> GetEnabledFeatures();
|
||||
|
||||
void EnableFeature(string name);
|
||||
void DisableFeature(string name);
|
||||
}
|
||||
|
||||
public class FeatureInfo {
|
||||
ExtensionDescriptor Extension { get; set; }
|
||||
FeatureDescriptor Descriptor { get; set; }
|
||||
bool IsEnabled { get; set; }
|
||||
}
|
||||
|
||||
public class FeatureManager : IFeatureManager {
|
||||
public IEnumerable<FeatureDescriptor> GetAvailableFeatures() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<FeatureDescriptor> GetEnabledFeatures() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void EnableFeature(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DisableFeature(string name) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
//private void DisableThemeFeatures(string themeName) {
|
||||
// var themes = new Queue<string>();
|
||||
// while (themeName != null) {
|
||||
// if (themes.Contains(themeName))
|
||||
// throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName).Text);
|
||||
// var theme = GetThemeByName(themeName);
|
||||
// if (theme == null)
|
||||
// break;
|
||||
// themes.Enqueue(themeName);
|
||||
|
||||
// themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
||||
// ? theme.BaseTheme
|
||||
// : null;
|
||||
|
||||
// }
|
||||
|
||||
// while (themes.Count > 0)
|
||||
// _moduleService.DisableFeatures(new[] { themes.Dequeue() });
|
||||
//}
|
||||
|
||||
//private void EnableThemeFeatures(string themeName) {
|
||||
// var themes = new Stack<string>();
|
||||
// while (themeName != null) {
|
||||
// if (themes.Contains(themeName))
|
||||
// throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features enabled.", themeName).Text);
|
||||
// themes.Push(themeName);
|
||||
|
||||
// var theme = GetThemeByName(themeName);
|
||||
// themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
||||
// ? theme.BaseTheme
|
||||
// : null;
|
||||
// }
|
||||
|
||||
// while (themes.Count > 0)
|
||||
// _moduleService.EnableFeatures(new[] { themes.Pop() });
|
||||
//}
|
||||
|
||||
//private bool DoEnableTheme(string themeName) {
|
||||
// if (string.IsNullOrWhiteSpace(themeName))
|
||||
// return false;
|
||||
|
||||
// //todo: (heskew) need messages given in addition to all of these early returns so something meaningful can be presented to the user
|
||||
// var themeToEnable = GetThemeByName(themeName);
|
||||
// if (themeToEnable == null)
|
||||
// return false;
|
||||
|
||||
// // ensure all base themes down the line are present and accounted for
|
||||
// //todo: (heskew) dito on the need of a meaningful message
|
||||
// if (!AllBaseThemesAreInstalled(themeToEnable.BaseTheme))
|
||||
// return false;
|
||||
|
||||
// // enable all theme features
|
||||
// EnableThemeFeatures(themeToEnable.Name);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
@@ -6,7 +6,7 @@ namespace Orchard.Modules {
|
||||
public interface IModuleService : IDependency {
|
||||
[Obsolete]
|
||||
IEnumerable<IModule> GetInstalledModules();
|
||||
[Obsolete]
|
||||
[Obsolete("",true)]
|
||||
IEnumerable<IModuleFeature> GetAvailableFeatures();
|
||||
[Obsolete]
|
||||
void EnableFeatures(IEnumerable<string> featureNames);
|
||||
|
@@ -1,30 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Themes {
|
||||
public interface IThemeService : IDependency {
|
||||
[Obsolete]
|
||||
ExtensionDescriptor GetThemeByName(string themeName);
|
||||
|
||||
[Obsolete]
|
||||
ExtensionDescriptor GetRequestTheme(RequestContext requestContext);
|
||||
|
||||
[Obsolete]
|
||||
void EnableTheme(string themeName);
|
||||
[Obsolete]
|
||||
void DisableTheme(string themeName);
|
||||
|
||||
[Obsolete]
|
||||
IEnumerable<ExtensionDescriptor> GetInstalledThemes();
|
||||
[Obsolete]
|
||||
IEnumerable<ExtensionDescriptor> GetEnabledThemes();
|
||||
|
||||
[Obsolete]
|
||||
void InstallTheme(HttpPostedFileBase file);
|
||||
[Obsolete]
|
||||
void UninstallTheme(string themeName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user