Consolidating redundant theme/module services

Breaking off site's "default theme" changing methods
Centralizing enable/disable functionality

--HG--
branch : perf
This commit is contained in:
Louis DeJardin
2010-11-04 20:37:35 -07:00
parent 04bb3d90dc
commit 7b508d72d2
22 changed files with 132 additions and 118 deletions

View File

@@ -45,6 +45,7 @@ namespace Orchard.Tests.Modules.Themes.Services {
[TestFixture] [TestFixture]
public class ThemeServiceTests { public class ThemeServiceTests {
private IThemeService _themeService; private IThemeService _themeService;
private ISiteThemeService _siteThemeService;
private IContainer _container; private IContainer _container;
private ISessionFactory _sessionFactory; private ISessionFactory _sessionFactory;
private ISession _session; private ISession _session;
@@ -97,42 +98,43 @@ namespace Orchard.Tests.Modules.Themes.Services {
builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>(); builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
_container = builder.Build(); _container = builder.Build();
_themeService = _container.Resolve<IThemeService>(); _themeService = _container.Resolve<IThemeService>();
_siteThemeService = _container.Resolve<ISiteThemeService>();
} }
//todo: test theme feature enablement //todo: test theme feature enablement
[Test] [Test]
public void ThemeWithNoBaseThemeCanBeSetAsSiteTheme() { public void ThemeWithNoBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeOne"); _siteThemeService.SetSiteTheme("ThemeOne");
var siteTheme = _themeService.GetSiteTheme(); var siteTheme = _siteThemeService.GetSiteTheme();
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne")); Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
} }
[Test] [Test]
public void ThemeWithAvailableBaseThemeCanBeSetAsSiteTheme() { public void ThemeWithAvailableBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeTwo"); _siteThemeService.SetSiteTheme("ThemeTwo");
var siteTheme = _themeService.GetSiteTheme(); var siteTheme = _siteThemeService.GetSiteTheme();
Assert.That(siteTheme.Name, Is.EqualTo("ThemeTwo")); Assert.That(siteTheme.Name, Is.EqualTo("ThemeTwo"));
Assert.That(siteTheme.Extension.BaseTheme, Is.EqualTo("ThemeOne")); Assert.That(siteTheme.BaseTheme, Is.EqualTo("ThemeOne"));
} }
[Test] [Test]
public void ThemeWithUnavailableBaseThemeCanBeSetAsSiteTheme() { public void ThemeWithUnavailableBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeOne"); _siteThemeService.SetSiteTheme("ThemeOne");
_themeService.SetSiteTheme("ThemeThree"); _siteThemeService.SetSiteTheme("ThemeThree");
var siteTheme = _themeService.GetSiteTheme(); var siteTheme = _siteThemeService.GetSiteTheme();
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne")); Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
} }
[Test] [Test]
public void ThemeWithCircularBaseDepTrowsExceptionOnActivation() { public void ThemeWithCircularBaseDepTrowsExceptionOnActivation() {
_themeService.SetSiteTheme("ThemeOne"); _siteThemeService.SetSiteTheme("ThemeOne");
try { try {
_themeService.SetSiteTheme("ThemeFourBasedOnFive"); _siteThemeService.SetSiteTheme("ThemeFourBasedOnFive");
} catch (InvalidOperationException ex) { } catch (InvalidOperationException ex) {
Assert.That(ex.Message, Is.StringMatching("ThemeFiveBasedOnFour")); Assert.That(ex.Message, Is.StringMatching("ThemeFiveBasedOnFour"));
} }
var siteTheme = _themeService.GetSiteTheme(); var siteTheme = _siteThemeService.GetSiteTheme();
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne")); Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
} }
@@ -148,15 +150,15 @@ namespace Orchard.Tests.Modules.Themes.Services {
[Test] [Test]
public void ActivatingThemeEnablesIt() { public void ActivatingThemeEnablesIt() {
_themeService.SetSiteTheme("ThemeOne"); _siteThemeService.SetSiteTheme("ThemeOne");
Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled); Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled);
Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne")); Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));
} }
[Test] [Test]
public void ActivatingThemeDoesNotDisableOldTheme() { public void ActivatingThemeDoesNotDisableOldTheme() {
_themeService.SetSiteTheme("ThemeOne"); _siteThemeService.SetSiteTheme("ThemeOne");
_themeService.SetSiteTheme("ThemeTwo"); _siteThemeService.SetSiteTheme("ThemeTwo");
Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled); Assert.IsTrue(_themeService.GetThemeByName("ThemeOne").Enabled);
Assert.IsTrue(_themeService.GetThemeByName("ThemeTwo").Enabled); Assert.IsTrue(_themeService.GetThemeByName("ThemeTwo").Enabled);
Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne")); Assert.IsTrue(_container.Resolve<IShellDescriptorManager>().GetShellDescriptor().Features.Any(sf => sf.Name == "ThemeOne"));

View File

@@ -88,11 +88,11 @@ namespace Orchard.Tests.Modules.Widgets.Services {
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>(); builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<WidgetsService>().As<IWidgetsService>(); builder.RegisterType<WidgetsService>().As<IWidgetsService>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>(); builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
var theme1 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = ThemeZoneName1 } }; var theme1 = new ExtensionDescriptor { Zones = ThemeZoneName1 } ;
var theme2 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = ThemeZoneName2 } }; var theme2 = new ExtensionDescriptor { Zones = ThemeZoneName2 } ;
Mock<IThemeService> themeServiceMock = new Mock<IThemeService>(); Mock<IThemeService> themeServiceMock = new Mock<IThemeService>();
themeServiceMock.Setup(x => x.GetInstalledThemes()).Returns( themeServiceMock.Setup(x => x.GetInstalledThemes()).Returns(
(new FeatureDescriptor[] { theme1, theme2 })); (new ExtensionDescriptor[] { theme1, theme2 }));
builder.RegisterInstance(themeServiceMock.Object).As<IThemeService>(); builder.RegisterInstance(themeServiceMock.Object).As<IThemeService>();
builder.RegisterType<StubWidgetPartHandler>().As<IContentHandler>(); builder.RegisterType<StubWidgetPartHandler>().As<IContentHandler>();

View File

@@ -23,7 +23,7 @@ namespace Orchard.Tests.DisplayManagement {
Bindings = new Dictionary<string, ShapeBinding>(StringComparer.OrdinalIgnoreCase) Bindings = new Dictionary<string, ShapeBinding>(StringComparer.OrdinalIgnoreCase)
}; };
_workContext = new TestWorkContext { _workContext = new TestWorkContext {
CurrentTheme = new FeatureDescriptor { Name = "Hello" } CurrentTheme = new ExtensionDescriptor { Name = "Hello" }
}; };

View File

@@ -35,7 +35,7 @@ namespace Orchard.Tests.DisplayManagement {
var workContext = new DefaultDisplayManagerTests.TestWorkContext var workContext = new DefaultDisplayManagerTests.TestWorkContext
{ {
CurrentTheme = new FeatureDescriptor { Name = "Hello" } CurrentTheme = new ExtensionDescriptor { Name = "Hello" }
}; };
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();

View File

@@ -29,7 +29,7 @@ namespace Orchard.Tests.Mvc {
var workContext = new DefaultDisplayManagerTests.TestWorkContext var workContext = new DefaultDisplayManagerTests.TestWorkContext
{ {
CurrentTheme = new FeatureDescriptor { Name = "Hello" }, CurrentTheme = new ExtensionDescriptor { Name = "Hello" },
ContainerProvider = _containerProvider ContainerProvider = _containerProvider
}; };
_workContextAccessor = new DefaultDisplayManagerTests.TestWorkContextAccessor(workContext); _workContextAccessor = new DefaultDisplayManagerTests.TestWorkContextAccessor(workContext);

View File

@@ -98,6 +98,10 @@
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project> <Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name> <Name>Orchard.Core</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Orchard.Themes\Orchard.Themes.csproj">
<Project>{CDE24A24-01D3-403C-84B9-37722E18DFB7}</Project>
<Name>Orchard.Themes</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Widgets\Orchard.Widgets.csproj"> <ProjectReference Include="..\Orchard.Widgets\Orchard.Widgets.csproj">
<Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project> <Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project>
<Name>Orchard.Widgets</Name> <Name>Orchard.Widgets</Name>

View File

@@ -28,6 +28,7 @@ using Orchard.Settings;
using Orchard.Themes; using Orchard.Themes;
using Orchard.Environment.State; using Orchard.Environment.State;
using Orchard.Data.Migration; using Orchard.Data.Migration;
using Orchard.Themes.Services;
using Orchard.Widgets.Models; using Orchard.Widgets.Models;
using Orchard.Widgets; using Orchard.Widgets;
@@ -197,7 +198,7 @@ namespace Orchard.Setup.Services {
siteSettings.Record.SiteCulture = "en-US"; siteSettings.Record.SiteCulture = "en-US";
// set site theme // set site theme
var themeService = environment.Resolve<IThemeService>(); var themeService = environment.Resolve<ISiteThemeService>();
themeService.SetSiteTheme("TheThemeMachine"); themeService.SetSiteTheme("TheThemeMachine");
// add default culture // add default culture

View File

@@ -113,18 +113,17 @@ namespace Orchard.Setup {
public string BaseTheme { get; set; } public string BaseTheme { get; set; }
} }
private readonly FeatureDescriptor _theme = new FeatureDescriptor { private readonly ExtensionDescriptor _theme = new ExtensionDescriptor {
Name = "SafeMode", Name = "SafeMode",
DisplayName = "SafeMode", DisplayName = "SafeMode",
Extension = new ExtensionDescriptor { Name = "SafeMode" },
}; };
public FeatureDescriptor GetThemeByName(string themeName) { return _theme; } public ExtensionDescriptor GetThemeByName(string themeName) { return _theme; }
public FeatureDescriptor GetSiteTheme() { return _theme; } public ExtensionDescriptor GetSiteTheme() { return _theme; }
public void SetSiteTheme(string themeName) { } public void SetSiteTheme(string themeName) { }
public FeatureDescriptor GetRequestTheme(RequestContext requestContext) { return _theme; } public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) { return _theme; }
public IEnumerable<FeatureDescriptor> GetInstalledThemes() { return new[] { _theme }; } public IEnumerable<ExtensionDescriptor> GetInstalledThemes() { return new[] { _theme }; }
public IEnumerable<FeatureDescriptor> GetEnabledThemes() { return new[] { _theme }; } public IEnumerable<ExtensionDescriptor> GetEnabledThemes() { return new[] { _theme }; }
public void InstallTheme(HttpPostedFileBase file) { } public void InstallTheme(HttpPostedFileBase file) { }
public void UninstallTheme(string themeName) { } public void UninstallTheme(string themeName) { }

View File

@@ -4,10 +4,12 @@ using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Data.Migration; using Orchard.Data.Migration;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
using Orchard.Environment.Features;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Reports.Services; using Orchard.Reports.Services;
using Orchard.Security; using Orchard.Security;
using Orchard.Themes.Preview; using Orchard.Themes.Preview;
using Orchard.Themes.Services;
using Orchard.Themes.ViewModels; using Orchard.Themes.ViewModels;
using Orchard.UI.Notify; using Orchard.UI.Notify;
@@ -15,6 +17,8 @@ namespace Orchard.Themes.Controllers {
[ValidateInput(false)] [ValidateInput(false)]
public class AdminController : Controller { public class AdminController : Controller {
private readonly IThemeService _themeService; private readonly IThemeService _themeService;
private readonly IFeatureManager _featureManager;
private readonly ISiteThemeService _siteThemeService;
private readonly IPreviewTheme _previewTheme; private readonly IPreviewTheme _previewTheme;
private readonly IDataMigrationManager _dataMigrationManager; private readonly IDataMigrationManager _dataMigrationManager;
private readonly IReportsCoordinator _reportsCoordinator; private readonly IReportsCoordinator _reportsCoordinator;
@@ -24,6 +28,8 @@ namespace Orchard.Themes.Controllers {
IReportsCoordinator reportsCoordinator, IReportsCoordinator reportsCoordinator,
IOrchardServices services, IOrchardServices services,
IThemeService themeService, IThemeService themeService,
IFeatureManager featureManager,
ISiteThemeService siteThemeService,
IPreviewTheme previewTheme, IPreviewTheme previewTheme,
IAuthorizer authorizer, IAuthorizer authorizer,
INotifier notifier) { INotifier notifier) {
@@ -31,6 +37,8 @@ namespace Orchard.Themes.Controllers {
_dataMigrationManager = dataMigraitonManager; _dataMigrationManager = dataMigraitonManager;
_reportsCoordinator = reportsCoordinator; _reportsCoordinator = reportsCoordinator;
_themeService = themeService; _themeService = themeService;
_featureManager = featureManager;
_siteThemeService = siteThemeService;
_previewTheme = previewTheme; _previewTheme = previewTheme;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -41,7 +49,7 @@ namespace Orchard.Themes.Controllers {
public ActionResult Index() { public ActionResult Index() {
try { try {
var themes = _themeService.GetInstalledThemes(); var themes = _themeService.GetInstalledThemes();
var currentTheme = _themeService.GetSiteTheme(); var currentTheme = _siteThemeService.GetSiteTheme();
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate(); var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes, FeaturesThatNeedUpdate = featuresThatNeedUpdate }; var model = new ThemesIndexViewModel { CurrentTheme = currentTheme, Themes = themes, FeaturesThatNeedUpdate = featuresThatNeedUpdate };
return View(model); return View(model);
@@ -72,7 +80,7 @@ namespace Orchard.Themes.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme"))) if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_previewTheme.SetPreviewTheme(null); _previewTheme.SetPreviewTheme(null);
_themeService.SetSiteTheme(themeName); _siteThemeService.SetSiteTheme(themeName);
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Previewing theme failed: " + exception.Message)); Services.Notifier.Error(T("Previewing theme failed: " + exception.Message));
@@ -98,7 +106,9 @@ namespace Orchard.Themes.Controllers {
try { try {
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't enable the theme"))) if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't enable the theme")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_themeService.EnableTheme(themeName);
// feature id always == extension id, in this case
_featureManager.EnableFeature(themeName);
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Enabling theme failed: " + exception.Message)); Services.Notifier.Error(T("Enabling theme failed: " + exception.Message));
@@ -111,7 +121,9 @@ namespace Orchard.Themes.Controllers {
try { try {
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't disable the current theme"))) if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't disable the current theme")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_themeService.DisableTheme(themeName);
// feature id always == extension id, in this case
_featureManager.DisableFeature(themeName);
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Disabling theme failed: " + exception.Message)); Services.Notifier.Error(T("Disabling theme failed: " + exception.Message));
@@ -124,7 +136,7 @@ namespace Orchard.Themes.Controllers {
try { try {
if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't set the current theme"))) if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't set the current theme")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_themeService.SetSiteTheme(themeName); _siteThemeService.SetSiteTheme(themeName);
} }
catch (Exception exception) { catch (Exception exception) {
Services.Notifier.Error(T("Activating theme failed: " + exception.Message)); Services.Notifier.Error(T("Activating theme failed: " + exception.Message));

View File

@@ -2,6 +2,10 @@
using System.Web.Routing; using System.Web.Routing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Settings; using Orchard.Settings;
using Orchard.Themes.Models; using Orchard.Themes.Models;
@@ -21,4 +25,35 @@ namespace Orchard.Themes.Services {
return new ThemeSelectorResult { Priority = -5, ThemeName = currentThemeName }; return new ThemeSelectorResult { Priority = -5, ThemeName = currentThemeName };
} }
} }
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;
}
}
} }

View File

@@ -46,22 +46,6 @@ namespace Orchard.Themes.Services {
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public FeatureDescriptor GetSiteTheme() {
string currentThemeName = CurrentSite.As<ThemeSiteSettingsPart>().CurrentThemeName;
if (string.IsNullOrEmpty(currentThemeName)) {
return null;
}
return GetThemeByName(currentThemeName);
}
public void SetSiteTheme(string themeName) {
if (DoEnableTheme(themeName)) {
CurrentSite.As<ThemeSiteSettingsPart>().Record.CurrentThemeName = themeName;
}
}
public void EnableTheme(string themeName) { public void EnableTheme(string themeName) {
DoEnableTheme(themeName); DoEnableTheme(themeName);
} }
@@ -81,7 +65,7 @@ namespace Orchard.Themes.Services {
var baseTheme = GetThemeByName(baseThemeName); var baseTheme = GetThemeByName(baseThemeName);
if (baseTheme == null) if (baseTheme == null)
return false; return false;
baseThemeName = baseTheme.Extension.BaseTheme; baseThemeName = baseTheme.BaseTheme;
} }
return true; return true;
@@ -97,8 +81,8 @@ namespace Orchard.Themes.Services {
break; break;
themes.Enqueue(themeName); themes.Enqueue(themeName);
themeName = !string.IsNullOrWhiteSpace(theme.Extension.BaseTheme) themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
? theme.Extension.BaseTheme ? theme.BaseTheme
: null; : null;
} }
@@ -115,8 +99,8 @@ namespace Orchard.Themes.Services {
themes.Push(themeName); themes.Push(themeName);
var theme = GetThemeByName(themeName); var theme = GetThemeByName(themeName);
themeName = !string.IsNullOrWhiteSpace(theme.Extension.BaseTheme) themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
? theme.Extension.BaseTheme ? theme.BaseTheme
: null; : null;
} }
@@ -135,7 +119,7 @@ namespace Orchard.Themes.Services {
// ensure all base themes down the line are present and accounted for // ensure all base themes down the line are present and accounted for
//todo: (heskew) dito on the need of a meaningful message //todo: (heskew) dito on the need of a meaningful message
if (!AllBaseThemesAreInstalled(themeToEnable.Extension.BaseTheme)) if (!AllBaseThemesAreInstalled(themeToEnable.BaseTheme))
return false; return false;
// enable all theme features // enable all theme features
@@ -143,7 +127,7 @@ namespace Orchard.Themes.Services {
return true; return true;
} }
public FeatureDescriptor GetRequestTheme(RequestContext requestContext) { public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) {
var requestTheme = _themeSelectors var requestTheme = _themeSelectors
.Select(x => x.GetTheme(requestContext)) .Select(x => x.GetTheme(requestContext))
.Where(x => x != null) .Where(x => x != null)
@@ -161,8 +145,8 @@ namespace Orchard.Themes.Services {
return GetThemeByName("SafeMode"); return GetThemeByName("SafeMode");
} }
public FeatureDescriptor GetThemeByName(string name) { public ExtensionDescriptor GetThemeByName(string name) {
foreach (var descriptor in _extensionManager.AvailableFeatures()) { foreach (var descriptor in _extensionManager.AvailableExtensions()) {
if (string.Equals(descriptor.Name, name, StringComparison.OrdinalIgnoreCase)) { if (string.Equals(descriptor.Name, name, StringComparison.OrdinalIgnoreCase)) {
return descriptor; return descriptor;
} }
@@ -173,28 +157,28 @@ namespace Orchard.Themes.Services {
/// <summary> /// <summary>
/// Loads only installed themes /// Loads only installed themes
/// </summary> /// </summary>
public IEnumerable<FeatureDescriptor> GetInstalledThemes() { public IEnumerable<ExtensionDescriptor> GetInstalledThemes() {
return GetThemes(_extensionManager.AvailableExtensions()); return GetThemes(_extensionManager.AvailableExtensions());
} }
/// <summary> /// <summary>
/// Loads only enabled themes /// Loads only enabled themes
/// </summary> /// </summary>
public IEnumerable<FeatureDescriptor> GetEnabledThemes() { public IEnumerable<ExtensionDescriptor> GetEnabledThemes() {
return GetThemes(_extensionManager.EnabledExtensions(_shellDescriptor)); return GetThemes(_extensionManager.EnabledExtensions(_shellDescriptor));
} }
private IEnumerable<FeatureDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) { private IEnumerable<ExtensionDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
var themes = new List<FeatureDescriptor>(); var themes = new List<ExtensionDescriptor>();
foreach (var descriptor in extensions.SelectMany(x=>x.Features)) { foreach (var descriptor in extensions) {
if (!string.Equals(descriptor.Extension.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) { if (!string.Equals(descriptor.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
continue; continue;
} }
FeatureDescriptor theme = descriptor; ExtensionDescriptor theme = descriptor;
if (!theme.Extension.Tags.Contains("hidden")) { if (!theme.Tags.Contains("hidden")) {
themes.Add(theme); themes.Add(theme);
} }
} }

View File

@@ -3,8 +3,8 @@ using Orchard.Environment.Extensions.Models;
namespace Orchard.Themes.ViewModels { namespace Orchard.Themes.ViewModels {
public class ThemesIndexViewModel { public class ThemesIndexViewModel {
public FeatureDescriptor CurrentTheme { get; set; } public ExtensionDescriptor CurrentTheme { get; set; }
public IEnumerable<FeatureDescriptor> Themes { get; set; } public IEnumerable<ExtensionDescriptor> Themes { get; set; }
public IEnumerable<string> FeaturesThatNeedUpdate { get; set; } public IEnumerable<string> FeaturesThatNeedUpdate { get; set; }
} }
} }

View File

@@ -43,8 +43,8 @@ namespace Orchard.Widgets.Services {
public IEnumerable<string> GetZones() { public IEnumerable<string> GetZones() {
HashSet<string> zones = new HashSet<string>(); HashSet<string> zones = new HashSet<string>();
foreach (var theme in _themeService.GetEnabledThemes().Where(theme => theme.Extension.Zones != null && !theme.Extension.Zones.Trim().Equals(string.Empty))) { foreach (var theme in _themeService.GetEnabledThemes().Where(theme => theme.Zones != null && !theme.Zones.Trim().Equals(string.Empty))) {
foreach (string zone in theme.Extension.Zones.Split(',').Where(zone => !zones.Contains(zone))) { foreach (string zone in theme.Zones.Split(',').Where(zone => !zones.Contains(zone))) {
zones.Add(zone.Trim()); zones.Add(zone.Trim());
} }
} }

View File

@@ -29,6 +29,13 @@ namespace Orchard.Environment.Extensions {
.Where(featureDescriptor => IsFeatureEnabledInDescriptor(featureDescriptor, descriptor)); .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) { private static bool IsFeatureEnabledInDescriptor(FeatureDescriptor featureDescriptor, ShellDescriptor shellDescriptor) {
return shellDescriptor.Features.Any(shellDescriptorFeature => shellDescriptorFeature.Name == featureDescriptor.Name); return shellDescriptor.Features.Any(shellDescriptorFeature => shellDescriptorFeature.Name == featureDescriptor.Name);
} }

View File

@@ -31,5 +31,8 @@ namespace Orchard.Environment.Extensions.Models {
public string BaseTheme { get; set; } public string BaseTheme { get; set; }
public IEnumerable<FeatureDescriptor> Features { get; set; } public IEnumerable<FeatureDescriptor> Features { get; set; }
[Obsolete("Temporary property - added for theme transition")]
public bool Enabled { get; set; }
} }
} }

View File

@@ -16,7 +16,6 @@ namespace Orchard.Environment.Extensions.Models {
public string Category { get; set; } public string Category { get; set; }
public IEnumerable<string> Dependencies { get; set; } public IEnumerable<string> Dependencies { get; set; }
[Obsolete("Temporary property - added for theme transition")]
public bool Enabled { get; set; }
} }
} }

View File

@@ -22,8 +22,8 @@ namespace Orchard.Mvc.Html {
return helper.ThemePath(helper.Resolve<IThemeService>().GetRequestTheme(helper.ViewContext.RequestContext), path); return helper.ThemePath(helper.Resolve<IThemeService>().GetRequestTheme(helper.ViewContext.RequestContext), path);
} }
public static string ThemePath(this HtmlHelper helper, FeatureDescriptor theme, string path) { public static string ThemePath(this HtmlHelper helper, ExtensionDescriptor theme, string path) {
return theme.Extension.Location + "/" + theme.Extension.Name + path; return theme.Location + "/" + theme.Name + path;
} }
} }
} }

View File

@@ -65,15 +65,15 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
return _configuredEnginesCache.BindBareEngines(() => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine()))); return _configuredEnginesCache.BindBareEngines(() => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine())));
} }
private IViewEngine ShallowEngines(FeatureDescriptor theme) { private IViewEngine ShallowEngines(ExtensionDescriptor theme) {
//return _configuredEnginesCache.BindShallowEngines(theme.ThemeName, () => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine()))); //return _configuredEnginesCache.BindShallowEngines(theme.ThemeName, () => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine())));
return DeepEngines(theme); return DeepEngines(theme);
} }
private IViewEngine DeepEngines(FeatureDescriptor theme) { private IViewEngine DeepEngines(ExtensionDescriptor theme) {
return _configuredEnginesCache.BindDeepEngines(theme.Name, () => { return _configuredEnginesCache.BindDeepEngines(theme.Name, () => {
var engines = Enumerable.Empty<IViewEngine>(); var engines = Enumerable.Empty<IViewEngine>();
var themeLocation = theme.Extension.Location + "/" + theme.Extension.Name; var themeLocation = theme.Location + "/" + theme.Name;
var themeParams = new CreateThemeViewEngineParams { VirtualPath = themeLocation }; var themeParams = new CreateThemeViewEngineParams { VirtualPath = themeLocation };
engines = engines.Concat(_viewEngineProviders.Select(vep => vep.CreateThemeViewEngine(themeParams))); engines = engines.Concat(_viewEngineProviders.Select(vep => vep.CreateThemeViewEngine(themeParams)));

View File

@@ -174,6 +174,7 @@
<Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" /> <Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" />
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" /> <Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
<Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" /> <Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" />
<Compile Include="Environment\Features\FeatureManager.cs" />
<Compile Include="Localization\Services\DefaultLocalizedStringManager.cs" /> <Compile Include="Localization\Services\DefaultLocalizedStringManager.cs" />
<Compile Include="Localization\Services\ILocalizedStringManager.cs" /> <Compile Include="Localization\Services\ILocalizedStringManager.cs" />
<Compile Include="Mvc\IOrchardViewPage.cs" /> <Compile Include="Mvc\IOrchardViewPage.cs" />
@@ -781,7 +782,6 @@
<Compile Include="Tasks\SweepGenerator.cs" /> <Compile Include="Tasks\SweepGenerator.cs" />
<Compile Include="Themes\IThemeSelector.cs" /> <Compile Include="Themes\IThemeSelector.cs" />
<Compile Include="Themes\IThemeService.cs" /> <Compile Include="Themes\IThemeService.cs" />
<Compile Include="Themes\ThemesModule.cs" />
<Compile Include="UI\Navigation\MenuFilter.cs" /> <Compile Include="UI\Navigation\MenuFilter.cs" />
<Compile Include="UI\Navigation\NavigationBuilder.cs" /> <Compile Include="UI\Navigation\NavigationBuilder.cs" />
<Compile Include="UI\Navigation\INavigationProvider.cs" /> <Compile Include="UI\Navigation\INavigationProvider.cs" />

View File

@@ -7,15 +7,10 @@ using Orchard.Environment.Extensions.Models;
namespace Orchard.Themes { namespace Orchard.Themes {
public interface IThemeService : IDependency { public interface IThemeService : IDependency {
[Obsolete] [Obsolete]
FeatureDescriptor GetThemeByName(string themeName); ExtensionDescriptor GetThemeByName(string themeName);
[Obsolete] [Obsolete]
FeatureDescriptor GetSiteTheme(); ExtensionDescriptor GetRequestTheme(RequestContext requestContext);
[Obsolete]
void SetSiteTheme(string themeName);
[Obsolete]
FeatureDescriptor GetRequestTheme(RequestContext requestContext);
[Obsolete] [Obsolete]
void EnableTheme(string themeName); void EnableTheme(string themeName);
@@ -23,9 +18,9 @@ namespace Orchard.Themes {
void DisableTheme(string themeName); void DisableTheme(string themeName);
[Obsolete] [Obsolete]
IEnumerable<FeatureDescriptor> GetInstalledThemes(); IEnumerable<ExtensionDescriptor> GetInstalledThemes();
[Obsolete] [Obsolete]
IEnumerable<FeatureDescriptor> GetEnabledThemes(); IEnumerable<ExtensionDescriptor> GetEnabledThemes();
[Obsolete] [Obsolete]
void InstallTheme(HttpPostedFileBase file); void InstallTheme(HttpPostedFileBase file);

View File

@@ -1,27 +0,0 @@
using System;
using System.Reflection;
using Autofac;
using Autofac.Core;
using Orchard.Environment.Extensions.Models;
using Module = Autofac.Module;
namespace Orchard.Themes {
public class ThemesModule : Module {
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) {
var themeProperty = FindThemeProperty(registration.Activator.LimitType);
if (themeProperty != null) {
registration.Activated += (sender, e) => {
var themeService = e.Context.Resolve<IThemeService>();
var currentTheme = themeService.GetSiteTheme();
themeProperty.SetValue(e.Instance, currentTheme, null);
};
}
}
private static PropertyInfo FindThemeProperty(Type type) {
return type.GetProperty("CurrentTheme", typeof(FeatureDescriptor));
}
}
}

View File

@@ -32,8 +32,8 @@ namespace Orchard {
set { SetState("CurrentUser", value); } set { SetState("CurrentUser", value); }
} }
public FeatureDescriptor CurrentTheme { public ExtensionDescriptor CurrentTheme {
get { return GetState<FeatureDescriptor>("CurrentTheme"); } get { return GetState<ExtensionDescriptor>("CurrentTheme"); }
set { SetState("CurrentTheme", value); } set { SetState("CurrentTheme", value); }
} }
} }