Refactoring IModule and ITheme related services

Changing component layering to allow more efficient dependencies
Marking several interfaces and services obsolete to produce warnings
Changing ITheme to FeatureDescriptor as a first step

--HG--
branch : perf
extra : rebase_source : 905b69eb1cc6ed05750908e41a2d0846dde22001
This commit is contained in:
Louis DeJardin
2010-11-04 16:04:50 -07:00
parent 035c60fb90
commit 04bb3d90dc
30 changed files with 153 additions and 225 deletions

View File

@@ -105,15 +105,15 @@ namespace Orchard.Tests.Modules.Themes.Services {
public void ThemeWithNoBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeOne");
var siteTheme = _themeService.GetSiteTheme();
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
}
[Test]
public void ThemeWithAvailableBaseThemeCanBeSetAsSiteTheme() {
_themeService.SetSiteTheme("ThemeTwo");
var siteTheme = _themeService.GetSiteTheme();
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeTwo"));
Assert.That(siteTheme.BaseTheme, Is.EqualTo("ThemeOne"));
Assert.That(siteTheme.Name, Is.EqualTo("ThemeTwo"));
Assert.That(siteTheme.Extension.BaseTheme, Is.EqualTo("ThemeOne"));
}
[Test]
@@ -121,7 +121,7 @@ namespace Orchard.Tests.Modules.Themes.Services {
_themeService.SetSiteTheme("ThemeOne");
_themeService.SetSiteTheme("ThemeThree");
var siteTheme = _themeService.GetSiteTheme();
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
}
[Test]
@@ -133,7 +133,7 @@ namespace Orchard.Tests.Modules.Themes.Services {
Assert.That(ex.Message, Is.StringMatching("ThemeFiveBasedOnFour"));
}
var siteTheme = _themeService.GetSiteTheme();
Assert.That(siteTheme.ThemeName, Is.EqualTo("ThemeOne"));
Assert.That(siteTheme.Name, Is.EqualTo("ThemeOne"));
}
[Test]

View File

@@ -16,6 +16,7 @@ using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Security;
using Orchard.Tests.Stubs;
using Orchard.Themes;
@@ -25,7 +26,7 @@ using Orchard.Widgets.Models;
using Orchard.Widgets.Services;
namespace Orchard.Tests.Modules.Widgets.Services {
[TestFixture]
public class WidgetsServiceTest : DatabaseEnabledTestsBase {
@@ -87,11 +88,11 @@ namespace Orchard.Tests.Modules.Widgets.Services {
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<WidgetsService>().As<IWidgetsService>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
Theme theme1 = new Theme { Zones = ThemeZoneName1 };
Theme theme2 = new Theme { Zones = ThemeZoneName2 };
var theme1 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = ThemeZoneName1 } };
var theme2 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = ThemeZoneName2 } };
Mock<IThemeService> themeServiceMock = new Mock<IThemeService>();
themeServiceMock.Setup(x => x.GetInstalledThemes()).Returns(
(new ITheme[] { theme1, theme2 }));
(new FeatureDescriptor[] { theme1, theme2 }));
builder.RegisterInstance(themeServiceMock.Object).As<IThemeService>();
builder.RegisterType<StubWidgetPartHandler>().As<IContentHandler>();
@@ -153,7 +154,7 @@ namespace Orchard.Tests.Modules.Widgets.Services {
WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", "");
Assert.That(widgetPart, Is.Not.Null);
widgetResult = _widgetService.GetWidget(0);
Assert.That(widgetResult, Is.Null, "Still yields null on an invalid identifier");
@@ -225,7 +226,7 @@ namespace Orchard.Tests.Modules.Widgets.Services {
widgetPart1 = _widgetService.GetWidget(widgetPart1.Id);
Assert.That(widgetPart1.Position, Is.EqualTo(Position2), "First widget moved to second widget position");
widgetPart2 = _widgetService.GetWidget(widgetPart2.Id);
Assert.That(widgetPart2.Position, Is.EqualTo(Position1), "Second widget moved to first widget position");

View File

@@ -8,6 +8,7 @@ using NUnit.Framework;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
using Orchard.DisplayManagement.Shapes;
using Orchard.Environment.Extensions.Models;
using Orchard.Themes;
namespace Orchard.Tests.DisplayManagement {
@@ -22,7 +23,7 @@ namespace Orchard.Tests.DisplayManagement {
Bindings = new Dictionary<string, ShapeBinding>(StringComparer.OrdinalIgnoreCase)
};
_workContext = new TestWorkContext {
CurrentTheme = new Theme { ThemeName = "Hello" }
CurrentTheme = new FeatureDescriptor { Name = "Hello" }
};
@@ -45,18 +46,6 @@ namespace Orchard.Tests.DisplayManagement {
void IShapeDisplayEvents.Displayed(ShapeDisplayedContext context) { Displayed(context); }
}
public class Theme : ITheme {
public bool Enabled { get; set; }
public string ThemeName { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public string HomePage { get; set; }
public string Tags { get; set; }
public string Zones { get; set; }
public string BaseTheme { get; set; }
}
public class TestShapeTableManager : IShapeTableManager {

View File

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

View File

@@ -4,6 +4,7 @@ using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using NUnit.Framework;
using Orchard.Environment.Extensions.Models;
using Orchard.Mvc;
using Orchard.Tests.DisplayManagement;
using Orchard.Tests.Stubs;
@@ -28,7 +29,7 @@ namespace Orchard.Tests.Mvc {
var workContext = new DefaultDisplayManagerTests.TestWorkContext
{
CurrentTheme = new DefaultDisplayManagerTests.Theme { ThemeName = "Hello" },
CurrentTheme = new FeatureDescriptor { Name = "Hello" },
ContainerProvider = _containerProvider
};
_workContextAccessor = new DefaultDisplayManagerTests.TestWorkContextAccessor(workContext);

View File

@@ -37,6 +37,7 @@ namespace Orchard.Web {
protected void Application_EndRequest() {
_host.EndRequest();
GC.Collect();
}
static void MvcSingletons(ContainerBuilder builder) {

View File

@@ -1,15 +1,3 @@
using System.Collections.Generic;
using Orchard.Environment.Extensions.Models;
namespace Orchard.Modules.Models {
public class Module : IModule {
public string ModuleName { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public string HomePage { get; set; }
public string Tags { get; set; }
public IEnumerable<FeatureDescriptor> Features { get; set; }
}
namespace Orchard.Modules.Models {
public class Module : IModule {}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Environment.Descriptor;
@@ -48,14 +47,6 @@ namespace Orchard.Modules.Services {
.Select(descriptor => AssembleModuleFromDescriptor(descriptor));
}
public void InstallModule(HttpPostedFileBase file) {
_extensionManager.InstallExtension(ModuleExtensionType, file);
}
public void UninstallModule(string moduleName) {
_extensionManager.UninstallExtension(ModuleExtensionType, moduleName);
}
public IEnumerable<IModuleFeature> GetAvailableFeatures() {
var enabledFeatures = _shellDescriptorManager.GetShellDescriptor().Features;
return _extensionManager.AvailableExtensions()
@@ -114,15 +105,6 @@ namespace Orchard.Modules.Services {
shellDescriptor.Parameters);
}
public IModule GetModuleByFeatureName(string featureName) {
return GetInstalledModules()
.Where(
m =>
m.Features.FirstOrDefault(
f => string.Equals(f.Name, featureName, StringComparison.OrdinalIgnoreCase)) !=
null).FirstOrDefault();
}
private IEnumerable<string> EnableFeature(string featureName, IEnumerable<IModuleFeature> features, bool force) {
var featuresList = features.ToList();
var getDisabledDependencies =
@@ -209,21 +191,21 @@ namespace Orchard.Modules.Services {
var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(extensionDescriptor.Location, "/", extensionDescriptor.Name, "/Module.txt"));
return new Module {
ModuleName = extensionDescriptor.Name,
DisplayName = TryLocalize("Name", extensionDescriptor.DisplayName, localizer),
Description = TryLocalize("Description", extensionDescriptor.Description, localizer),
Version = extensionDescriptor.Version,
Author = TryLocalize("Author", extensionDescriptor.Author, localizer),
HomePage = TryLocalize("Website", extensionDescriptor.WebSite, localizer),
Tags = TryLocalize("Tags", extensionDescriptor.Tags, localizer),
Features = extensionDescriptor.Features.Select(f => new FeatureDescriptor {
Category = TryLocalize(f.Name + " Category", f.Category, localizer),
Dependencies = f.Dependencies,
Description = TryLocalize(f.Name + " Description", f.Description, localizer),
DisplayName = TryLocalize(f.Name + " Name", f.DisplayName, localizer),
Extension = f.Extension,
Name = f.Name,
})
//ModuleName = extensionDescriptor.Name,
//DisplayName = TryLocalize("Name", extensionDescriptor.DisplayName, localizer),
//Description = TryLocalize("Description", extensionDescriptor.Description, localizer),
//Version = extensionDescriptor.Version,
//Author = TryLocalize("Author", extensionDescriptor.Author, localizer),
//HomePage = TryLocalize("Website", extensionDescriptor.WebSite, localizer),
//Tags = TryLocalize("Tags", extensionDescriptor.Tags, localizer),
//Features = extensionDescriptor.Features.Select(f => new FeatureDescriptor {
// Category = TryLocalize(f.Name + " Category", f.Category, localizer),
// Dependencies = f.Dependencies,
// Description = TryLocalize(f.Name + " Description", f.Description, localizer),
// DisplayName = TryLocalize(f.Name + " Name", f.DisplayName, localizer),
// Extension = f.Extension,
// Name = f.Name,
//})
};
}

View File

@@ -103,32 +103,28 @@ namespace Orchard.Setup {
[UsedImplicitly]
class SafeModeThemeService : IThemeService {
class SafeModeTheme : ITheme {
class SafeModeTheme : FeatureDescriptor {
public ContentItem ContentItem { get; set; }
public bool Enabled { get; set; }
public string ThemeName { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public string HomePage { get; set; }
public string Tags { get; set; }
public string Zones { get; set; }
public string BaseTheme { get; set; }
}
private readonly SafeModeTheme _theme = new SafeModeTheme {
Enabled = true,
ThemeName = "SafeMode",
private readonly FeatureDescriptor _theme = new FeatureDescriptor {
Name = "SafeMode",
DisplayName = "SafeMode",
Extension = new ExtensionDescriptor { Name = "SafeMode" },
};
public ITheme GetThemeByName(string themeName) { return _theme; }
public ITheme GetSiteTheme() { return _theme; }
public FeatureDescriptor GetThemeByName(string themeName) { return _theme; }
public FeatureDescriptor GetSiteTheme() { return _theme; }
public void SetSiteTheme(string themeName) { }
public ITheme GetRequestTheme(RequestContext requestContext) { return _theme; }
public IEnumerable<ITheme> GetInstalledThemes() { return new[] { _theme }; }
public IEnumerable<ITheme> GetEnabledThemes() { return new[] { _theme }; }
public FeatureDescriptor GetRequestTheme(RequestContext requestContext) { return _theme; }
public IEnumerable<FeatureDescriptor> GetInstalledThemes() { return new[] { _theme }; }
public IEnumerable<FeatureDescriptor> GetEnabledThemes() { return new[] { _theme }; }
public void InstallTheme(HttpPostedFileBase file) { }
public void UninstallTheme(string themeName) { }

View File

@@ -1,14 +0,0 @@
namespace Orchard.Themes.Models {
public class Theme : ITheme {
public bool Enabled { get; set; }
public string ThemeName { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public string HomePage { get; set; }
public string Tags { get; set; }
public string Zones { get; set; }
public string BaseTheme { get; set; }
}
}

View File

@@ -75,7 +75,6 @@
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="Handlers\ThemeSiteSettingsPartHandler.cs" />
<Compile Include="Models\Theme.cs" />
<Compile Include="Models\ThemeSiteSettingsPart.cs" />
<Compile Include="Models\ThemeSiteSettingsPartRecord.cs" />
<Compile Include="Permissions.cs" />

View File

@@ -31,8 +31,8 @@ namespace Orchard.Themes.Preview {
var themeListItems = installedThemes
.Select(theme => new SelectListItem {
Text = theme.DisplayName,
Value = theme.ThemeName,
Selected = theme.ThemeName == previewThemeName
Value = theme.Name,
Selected = theme.Name == previewThemeName
})
.ToList();

View File

@@ -46,7 +46,7 @@ namespace Orchard.Themes.Services {
public ILogger Logger { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public ITheme GetSiteTheme() {
public FeatureDescriptor GetSiteTheme() {
string currentThemeName = CurrentSite.As<ThemeSiteSettingsPart>().CurrentThemeName;
if (string.IsNullOrEmpty(currentThemeName)) {
@@ -81,7 +81,7 @@ namespace Orchard.Themes.Services {
var baseTheme = GetThemeByName(baseThemeName);
if (baseTheme == null)
return false;
baseThemeName = baseTheme.BaseTheme;
baseThemeName = baseTheme.Extension.BaseTheme;
}
return true;
@@ -97,8 +97,8 @@ namespace Orchard.Themes.Services {
break;
themes.Enqueue(themeName);
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
? theme.BaseTheme
themeName = !string.IsNullOrWhiteSpace(theme.Extension.BaseTheme)
? theme.Extension.BaseTheme
: null;
}
@@ -115,8 +115,8 @@ namespace Orchard.Themes.Services {
themes.Push(themeName);
var theme = GetThemeByName(themeName);
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
? theme.BaseTheme
themeName = !string.IsNullOrWhiteSpace(theme.Extension.BaseTheme)
? theme.Extension.BaseTheme
: null;
}
@@ -135,15 +135,15 @@ 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.BaseTheme))
if (!AllBaseThemesAreInstalled(themeToEnable.Extension.BaseTheme))
return false;
// enable all theme features
EnableThemeFeatures(themeToEnable.ThemeName);
EnableThemeFeatures(themeToEnable.Name);
return true;
}
public ITheme GetRequestTheme(RequestContext requestContext) {
public FeatureDescriptor GetRequestTheme(RequestContext requestContext) {
var requestTheme = _themeSelectors
.Select(x => x.GetTheme(requestContext))
.Where(x => x != null)
@@ -154,17 +154,17 @@ namespace Orchard.Themes.Services {
foreach (var theme in requestTheme) {
var t = GetThemeByName(theme.ThemeName);
if (t != null && t.Enabled)
if (t != null)
return t;
}
return GetThemeByName("SafeMode");
}
public ITheme GetThemeByName(string name) {
foreach (var descriptor in _extensionManager.AvailableExtensions()) {
public FeatureDescriptor GetThemeByName(string name) {
foreach (var descriptor in _extensionManager.AvailableFeatures()) {
if (string.Equals(descriptor.Name, name, StringComparison.OrdinalIgnoreCase)) {
return CreateTheme(descriptor);
return descriptor;
}
}
return null;
@@ -173,28 +173,28 @@ namespace Orchard.Themes.Services {
/// <summary>
/// Loads only installed themes
/// </summary>
public IEnumerable<ITheme> GetInstalledThemes() {
public IEnumerable<FeatureDescriptor> GetInstalledThemes() {
return GetThemes(_extensionManager.AvailableExtensions());
}
/// <summary>
/// Loads only enabled themes
/// </summary>
public IEnumerable<ITheme> GetEnabledThemes() {
public IEnumerable<FeatureDescriptor> GetEnabledThemes() {
return GetThemes(_extensionManager.EnabledExtensions(_shellDescriptor));
}
private IEnumerable<ITheme> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
var themes = new List<ITheme>();
foreach (var descriptor in extensions) {
private IEnumerable<FeatureDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
var themes = new List<FeatureDescriptor>();
foreach (var descriptor in extensions.SelectMany(x=>x.Features)) {
if (!string.Equals(descriptor.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
if (!string.Equals(descriptor.Extension.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
continue;
}
ITheme theme = CreateTheme(descriptor);
FeatureDescriptor theme = descriptor;
if (!theme.Tags.Contains("hidden")) {
if (!theme.Extension.Tags.Contains("hidden")) {
themes.Add(theme);
}
}
@@ -225,22 +225,22 @@ namespace Orchard.Themes.Services {
_shellDescriptorManager.GetShellDescriptor().Features.Any(sf => sf.Name == descriptor.Name);
}
private ITheme CreateTheme(ExtensionDescriptor descriptor) {
//private ITheme CreateTheme(ExtensionDescriptor descriptor) {
var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(descriptor.Location, "/", descriptor.Name, "/Theme.txt"));
// var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(descriptor.Location, "/", descriptor.Name, "/Theme.txt"));
return new Theme {
Author = TryLocalize("Author", descriptor.Author, localizer) ?? "",
Description = TryLocalize("Description", descriptor.Description, localizer) ?? "",
DisplayName = TryLocalize("Name", descriptor.DisplayName, localizer) ?? "",
HomePage = TryLocalize("Website", descriptor.WebSite, localizer) ?? "",
ThemeName = descriptor.Name,
Version = descriptor.Version ?? "",
Tags = TryLocalize("Tags", descriptor.Tags, localizer) ?? "",
Zones = descriptor.Zones ?? "",
BaseTheme = descriptor.BaseTheme ?? "",
Enabled = IsThemeEnabled(descriptor)
};
}
// return new Theme {
// //Author = TryLocalize("Author", descriptor.Author, localizer) ?? "",
// //Description = TryLocalize("Description", descriptor.Description, localizer) ?? "",
// DisplayName = TryLocalize("Name", descriptor.DisplayName, localizer) ?? "",
// //HomePage = TryLocalize("Website", descriptor.WebSite, localizer) ?? "",
// ThemeName = descriptor.Name,
// //Version = descriptor.Version ?? "",
// Tags = TryLocalize("Tags", descriptor.Tags, localizer) ?? "",
// Zones = descriptor.Zones ?? "",
// BaseTheme = descriptor.BaseTheme ?? "",
// Enabled = IsThemeEnabled(descriptor)
// };
//}
}
}

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic;
using Orchard.Environment.Extensions.Models;
namespace Orchard.Themes.ViewModels {
public class ThemesIndexViewModel {
public ITheme CurrentTheme { get; set; }
public IEnumerable<ITheme> Themes { get; set; }
public FeatureDescriptor CurrentTheme { get; set; }
public IEnumerable<FeatureDescriptor> 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.Zones != null && !theme.Zones.Trim().Equals(string.Empty))) {
foreach (string zone in theme.Zones.Split(',').Where(zone => !zones.Contains(zone))) {
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))) {
zones.Add(zone.Trim());
}
}

View File

@@ -118,7 +118,7 @@ namespace Orchard.ContentManagement {
//var workContext = _workContextAccessor.GetContext();
//var theme = workContext.CurrentTheme;
var theme = _themeService.Value.GetRequestTheme(_requestContext);
var shapeTable = _shapeTableManager.GetShapeTable(theme.ThemeName);
var shapeTable = _shapeTableManager.GetShapeTable(theme.Name);
ShapeDescriptor descriptor;
if (shapeTable.Descriptors.TryGetValue(partShapeType, out descriptor)) {
var placementContext = new ShapePlacementContext {

View File

@@ -53,7 +53,7 @@ namespace Orchard.DisplayManagement.Implementation {
return CoerceHtmlString(context.Value);
var workContext = _workContextAccessor.GetContext(context.ViewContext);
var shapeTable = _shapeTableManager.GetShapeTable(workContext.CurrentTheme.ThemeName);
var shapeTable = _shapeTableManager.GetShapeTable(workContext.CurrentTheme.Name);
var displayingContext = new ShapeDisplayingContext {
Shape = shape,

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Orchard.Environment.Extensions.Models {
public class ExtensionDescriptor {
@@ -26,7 +27,7 @@ namespace Orchard.Environment.Extensions.Models {
public string WebSite { get; set; }
public string Tags { get; set; }
public string AntiForgery { get; set; }
public string Zones { get; set; }
public string Zones { get; set; }
public string BaseTheme { get; set; }
public IEnumerable<FeatureDescriptor> Features { get; set; }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Orchard.Environment.Extensions.Models {
@@ -14,5 +15,8 @@ namespace Orchard.Environment.Extensions.Models {
public string Description { get; set; }
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

@@ -1,15 +1,6 @@
using System.Collections.Generic;
using Orchard.Environment.Extensions.Models;
using System;
namespace Orchard.Modules {
public interface IModule {
string ModuleName { get; set; }
string DisplayName { get; set; }
string Description { get; set; }
string Version { get; set; }
string Author { get; set; }
string HomePage { get; set; }
string Tags { get; set; }
IEnumerable<FeatureDescriptor> Features { get; set; }
}
[Obsolete]
public interface IModule { }
}

View File

@@ -1,8 +1,12 @@
using Orchard.Environment.Extensions.Models;
using System;
using Orchard.Environment.Extensions.Models;
namespace Orchard.Modules {
[Obsolete]
public interface IModuleFeature {
[Obsolete]
FeatureDescriptor Descriptor { get; set; }
[Obsolete]
bool IsEnabled { get; set; }
}
}

View File

@@ -1,16 +1,20 @@
using System.Collections.Generic;
using System.Web;
using System;
using System.Collections.Generic;
namespace Orchard.Modules {
[Obsolete]
public interface IModuleService : IDependency {
IModule GetModuleByName(string moduleName);
[Obsolete]
IEnumerable<IModule> GetInstalledModules();
void InstallModule(HttpPostedFileBase file);
void UninstallModule(string moduleName);
[Obsolete]
IEnumerable<IModuleFeature> GetAvailableFeatures();
[Obsolete]
void EnableFeatures(IEnumerable<string> featureNames);
[Obsolete]
void EnableFeatures(IEnumerable<string> featureNames, bool force);
[Obsolete]
void DisableFeatures(IEnumerable<string> featureNames);
[Obsolete]
void DisableFeatures(IEnumerable<string> featureNames, bool force);
}
}

View File

@@ -1,7 +1,9 @@
using System.Web.Mvc;
using System;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.UI;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Themes;
using Orchard.Validation;
@@ -15,12 +17,13 @@ namespace Orchard.Mvc.Html {
helper.RenderPartial(viewName);
}
[Obsolete("How do you know the request theme is the same as the place the theme template is rendering from?")]
public static string ThemePath(this HtmlHelper helper, string path) {
return helper.ThemePath(helper.Resolve<IThemeService>().GetRequestTheme(helper.ViewContext.RequestContext), path);
}
public static string ThemePath(this HtmlHelper helper, ITheme theme, string path) {
return helper.Resolve<IExtensionManager>().GetThemeLocation(theme) + path;
public static string ThemePath(this HtmlHelper helper, FeatureDescriptor theme, string path) {
return theme.Extension.Location + "/" + theme.Extension.Name + path;
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Web.Mvc;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Themes;
namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
@@ -64,15 +65,15 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
return _configuredEnginesCache.BindBareEngines(() => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine())));
}
private IViewEngine ShallowEngines(ITheme theme) {
private IViewEngine ShallowEngines(FeatureDescriptor theme) {
//return _configuredEnginesCache.BindShallowEngines(theme.ThemeName, () => new ViewEngineCollectionWrapper(_viewEngineProviders.Select(vep => vep.CreateBareViewEngine())));
return DeepEngines(theme);
}
private IViewEngine DeepEngines(ITheme theme) {
return _configuredEnginesCache.BindDeepEngines(theme.ThemeName, () => {
private IViewEngine DeepEngines(FeatureDescriptor theme) {
return _configuredEnginesCache.BindDeepEngines(theme.Name, () => {
var engines = Enumerable.Empty<IViewEngine>();
var themeLocation = _extensionManager.GetThemeLocation(theme);
var themeLocation = theme.Extension.Location + "/" + theme.Extension.Name;
var themeParams = new CreateThemeViewEngineParams { VirtualPath = themeLocation };
engines = engines.Concat(_viewEngineProviders.Select(vep => vep.CreateThemeViewEngine(themeParams)));

View File

@@ -711,7 +711,6 @@
<Compile Include="Tasks\Scheduling\IScheduledTaskHandler.cs" />
<Compile Include="Tasks\Scheduling\IScheduledTaskManager.cs" />
<Compile Include="Tasks\Scheduling\ScheduledTaskContext.cs" />
<Compile Include="Themes\ExtensionManagerExtensions.cs" />
<Compile Include="Environment\Extensions\Helpers\PathHelpers.cs" />
<Compile Include="Environment\Extensions\IExtensionManager.cs" />
<Compile Include="Environment\Extensions\Folders\ModuleFolders.cs" />
@@ -780,7 +779,6 @@
<Compile Include="Tasks\BackgroundService.cs" />
<Compile Include="Tasks\IBackgroundTask.cs" />
<Compile Include="Tasks\SweepGenerator.cs" />
<Compile Include="Themes\ITheme.cs" />
<Compile Include="Themes\IThemeSelector.cs" />
<Compile Include="Themes\IThemeService.cs" />
<Compile Include="Themes\ThemesModule.cs" />

View File

@@ -1,20 +0,0 @@
using System.IO;
using System.Linq;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
namespace Orchard.Themes {
public static class ExtensionManagerExtensions {
public static ExtensionDescriptor GetExtensionDescriptor(this IExtensionManager extensionManager, string extensionType, string extensionName) {
return
extensionManager.AvailableExtensions().FirstOrDefault(
ed => ed.ExtensionType == extensionType && ed.Name == extensionName);
}
public static string GetThemeLocation(this IExtensionManager extensionManager, ITheme theme) {
ExtensionDescriptor descriptor = extensionManager.GetExtensionDescriptor("Theme", theme.ThemeName);
return descriptor != null ? Path.Combine(descriptor.Location, descriptor.Name) : "~";
}
}
}

View File

@@ -1,17 +0,0 @@
namespace Orchard.Themes {
/// <summary>
/// Interface provided by the "themes" model.
/// </summary>
public interface ITheme {
bool Enabled { get; set; }
string ThemeName { get; set; }
string DisplayName { get; set; }
string Description { get; set; }
string Version { get; set; }
string Author { get; set; }
string HomePage { get; set; }
string Tags { get; set; }
string Zones { get; set; }
string BaseTheme { get; set; }
}
}

View File

@@ -1,21 +1,35 @@
using System.Collections.Generic;
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 {
ITheme GetThemeByName(string themeName);
ITheme GetSiteTheme();
void SetSiteTheme(string themeName);
ITheme GetRequestTheme(RequestContext requestContext);
[Obsolete]
FeatureDescriptor GetThemeByName(string themeName);
[Obsolete]
FeatureDescriptor GetSiteTheme();
[Obsolete]
void SetSiteTheme(string themeName);
[Obsolete]
FeatureDescriptor GetRequestTheme(RequestContext requestContext);
[Obsolete]
void EnableTheme(string themeName);
[Obsolete]
void DisableTheme(string themeName);
IEnumerable<ITheme> GetInstalledThemes();
IEnumerable<ITheme> GetEnabledThemes();
[Obsolete]
IEnumerable<FeatureDescriptor> GetInstalledThemes();
[Obsolete]
IEnumerable<FeatureDescriptor> GetEnabledThemes();
[Obsolete]
void InstallTheme(HttpPostedFileBase file);
[Obsolete]
void UninstallTheme(string themeName);
}
}

View File

@@ -2,6 +2,7 @@
using System.Reflection;
using Autofac;
using Autofac.Core;
using Orchard.Environment.Extensions.Models;
using Module = Autofac.Module;
namespace Orchard.Themes {
@@ -20,7 +21,7 @@ namespace Orchard.Themes {
}
private static PropertyInfo FindThemeProperty(Type type) {
return type.GetProperty("CurrentTheme", typeof(ITheme));
return type.GetProperty("CurrentTheme", typeof(FeatureDescriptor));
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Web;
using Orchard.Environment.Extensions.Models;
using Orchard.Security;
using Orchard.Settings;
using Orchard.Themes;
@@ -31,10 +32,9 @@ namespace Orchard {
set { SetState("CurrentUser", value); }
}
public ITheme CurrentTheme {
get { return GetState<ITheme>("CurrentTheme"); }
public FeatureDescriptor CurrentTheme {
get { return GetState<FeatureDescriptor>("CurrentTheme"); }
set { SetState("CurrentTheme", value); }
}
}
}
}