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

View File

@@ -23,7 +23,7 @@ namespace Orchard.Tests.DisplayManagement {
Bindings = new Dictionary<string, ShapeBinding>(StringComparer.OrdinalIgnoreCase)
};
_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
{
CurrentTheme = new FeatureDescriptor { Name = "Hello" }
CurrentTheme = new ExtensionDescriptor { Name = "Hello" }
};
var builder = new ContainerBuilder();

View File

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

View File

@@ -98,6 +98,10 @@
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</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">
<Project>{194D3CCC-1153-474D-8176-FDE8D7D0D0BD}</Project>
<Name>Orchard.Widgets</Name>

View File

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

View File

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

View File

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

View File

@@ -2,6 +2,10 @@
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;
@@ -21,4 +25,35 @@ namespace Orchard.Themes.Services {
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; }
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) {
DoEnableTheme(themeName);
}
@@ -81,7 +65,7 @@ namespace Orchard.Themes.Services {
var baseTheme = GetThemeByName(baseThemeName);
if (baseTheme == null)
return false;
baseThemeName = baseTheme.Extension.BaseTheme;
baseThemeName = baseTheme.BaseTheme;
}
return true;
@@ -97,8 +81,8 @@ namespace Orchard.Themes.Services {
break;
themes.Enqueue(themeName);
themeName = !string.IsNullOrWhiteSpace(theme.Extension.BaseTheme)
? theme.Extension.BaseTheme
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
? theme.BaseTheme
: null;
}
@@ -115,8 +99,8 @@ namespace Orchard.Themes.Services {
themes.Push(themeName);
var theme = GetThemeByName(themeName);
themeName = !string.IsNullOrWhiteSpace(theme.Extension.BaseTheme)
? theme.Extension.BaseTheme
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
? theme.BaseTheme
: null;
}
@@ -135,7 +119,7 @@ namespace Orchard.Themes.Services {
// 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.Extension.BaseTheme))
if (!AllBaseThemesAreInstalled(themeToEnable.BaseTheme))
return false;
// enable all theme features
@@ -143,7 +127,7 @@ namespace Orchard.Themes.Services {
return true;
}
public FeatureDescriptor GetRequestTheme(RequestContext requestContext) {
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) {
var requestTheme = _themeSelectors
.Select(x => x.GetTheme(requestContext))
.Where(x => x != null)
@@ -161,8 +145,8 @@ namespace Orchard.Themes.Services {
return GetThemeByName("SafeMode");
}
public FeatureDescriptor GetThemeByName(string name) {
foreach (var descriptor in _extensionManager.AvailableFeatures()) {
public ExtensionDescriptor GetThemeByName(string name) {
foreach (var descriptor in _extensionManager.AvailableExtensions()) {
if (string.Equals(descriptor.Name, name, StringComparison.OrdinalIgnoreCase)) {
return descriptor;
}
@@ -173,28 +157,28 @@ namespace Orchard.Themes.Services {
/// <summary>
/// Loads only installed themes
/// </summary>
public IEnumerable<FeatureDescriptor> GetInstalledThemes() {
public IEnumerable<ExtensionDescriptor> GetInstalledThemes() {
return GetThemes(_extensionManager.AvailableExtensions());
}
/// <summary>
/// Loads only enabled themes
/// </summary>
public IEnumerable<FeatureDescriptor> GetEnabledThemes() {
public IEnumerable<ExtensionDescriptor> GetEnabledThemes() {
return GetThemes(_extensionManager.EnabledExtensions(_shellDescriptor));
}
private IEnumerable<FeatureDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
var themes = new List<FeatureDescriptor>();
foreach (var descriptor in extensions.SelectMany(x=>x.Features)) {
private IEnumerable<ExtensionDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
var themes = new List<ExtensionDescriptor>();
foreach (var descriptor in extensions) {
if (!string.Equals(descriptor.Extension.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
if (!string.Equals(descriptor.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
continue;
}
FeatureDescriptor theme = descriptor;
ExtensionDescriptor theme = descriptor;
if (!theme.Extension.Tags.Contains("hidden")) {
if (!theme.Tags.Contains("hidden")) {
themes.Add(theme);
}
}

View File

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

View File

@@ -43,8 +43,8 @@ namespace Orchard.Widgets.Services {
public IEnumerable<string> GetZones() {
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 (string zone in theme.Extension.Zones.Split(',').Where(zone => !zones.Contains(zone))) {
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());
}
}

View File

@@ -29,6 +29,13 @@ 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);
}

View File

@@ -31,5 +31,8 @@ namespace Orchard.Environment.Extensions.Models {
public string BaseTheme { 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 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);
}
public static string ThemePath(this HtmlHelper helper, FeatureDescriptor theme, string path) {
return theme.Extension.Location + "/" + theme.Extension.Name + path;
public static string ThemePath(this HtmlHelper helper, ExtensionDescriptor theme, string 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())));
}
private IViewEngine ShallowEngines(FeatureDescriptor theme) {
private IViewEngine ShallowEngines(ExtensionDescriptor theme) {
//return _configuredEnginesCache.BindShallowEngines(theme.ThemeName, () => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine())));
return DeepEngines(theme);
}
private IViewEngine DeepEngines(FeatureDescriptor theme) {
private IViewEngine DeepEngines(ExtensionDescriptor theme) {
return _configuredEnginesCache.BindDeepEngines(theme.Name, () => {
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 };
engines = engines.Concat(_viewEngineProviders.Select(vep => vep.CreateThemeViewEngine(themeParams)));

View File

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

View File

@@ -7,15 +7,10 @@ using Orchard.Environment.Extensions.Models;
namespace Orchard.Themes {
public interface IThemeService : IDependency {
[Obsolete]
FeatureDescriptor GetThemeByName(string themeName);
ExtensionDescriptor GetThemeByName(string themeName);
[Obsolete]
FeatureDescriptor GetSiteTheme();
[Obsolete]
void SetSiteTheme(string themeName);
[Obsolete]
FeatureDescriptor GetRequestTheme(RequestContext requestContext);
ExtensionDescriptor GetRequestTheme(RequestContext requestContext);
[Obsolete]
void EnableTheme(string themeName);
@@ -23,9 +18,9 @@ namespace Orchard.Themes {
void DisableTheme(string themeName);
[Obsolete]
IEnumerable<FeatureDescriptor> GetInstalledThemes();
IEnumerable<ExtensionDescriptor> GetInstalledThemes();
[Obsolete]
IEnumerable<FeatureDescriptor> GetEnabledThemes();
IEnumerable<ExtensionDescriptor> GetEnabledThemes();
[Obsolete]
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); }
}
public FeatureDescriptor CurrentTheme {
get { return GetState<FeatureDescriptor>("CurrentTheme"); }
public ExtensionDescriptor CurrentTheme {
get { return GetState<ExtensionDescriptor>("CurrentTheme"); }
set { SetState("CurrentTheme", value); }
}
}