Adding IsTheme and IsModule static methods.

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues 2010-12-01 17:52:10 -08:00
parent f3f518b0db
commit d3eb21e8de
14 changed files with 32 additions and 23 deletions

View File

@ -51,7 +51,7 @@ namespace Orchard.CodeGeneration.Commands {
public bool CreateDataMigration(string featureName) {
Context.Output.WriteLine(T("Creating Data Migration for {0}", featureName));
ExtensionDescriptor extensionDescriptor = _extensionManager.AvailableExtensions().FirstOrDefault(extension => extension.ExtensionType == DefaultExtensionTypes.Module &&
ExtensionDescriptor extensionDescriptor = _extensionManager.AvailableExtensions().FirstOrDefault(extension => DefaultExtensionTypes.IsModule(extension.ExtensionType) &&
extension.Features.Any(feature => String.Equals(feature.Id, featureName, StringComparison.OrdinalIgnoreCase)));
if (extensionDescriptor == null) {
@ -152,7 +152,7 @@ namespace Orchard.CodeGeneration.Commands {
public void CreateController(string moduleName, string controllerName) {
Context.Output.WriteLine(T("Creating Controller {0} in Module {1}", controllerName, moduleName));
ExtensionDescriptor extensionDescriptor = _extensionManager.AvailableExtensions().FirstOrDefault(extension => extension.ExtensionType == DefaultExtensionTypes.Module &&
ExtensionDescriptor extensionDescriptor = _extensionManager.AvailableExtensions().FirstOrDefault(extension => DefaultExtensionTypes.IsModule(extension.ExtensionType) &&
string.Equals(moduleName, extension.Name, StringComparison.OrdinalIgnoreCase));
if (extensionDescriptor == null) {

View File

@ -47,7 +47,7 @@ namespace Orchard.Modules.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Not allowed to manage modules")))
return new HttpUnauthorizedResult();
var modules = _extensionManager.AvailableExtensions().Where(x => x.ExtensionType == DefaultExtensionTypes.Module);
var modules = _extensionManager.AvailableExtensions().Where(x => DefaultExtensionTypes.IsModule(x.ExtensionType));
return View(new ModulesIndexViewModel {
Modules = modules,
@ -61,7 +61,7 @@ namespace Orchard.Modules.Controllers {
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
var features = _featureManager.GetAvailableFeatures()
.Where(f => !f.Extension.ExtensionType.Equals(DefaultExtensionTypes.Theme, StringComparison.OrdinalIgnoreCase))
.Where(f => !DefaultExtensionTypes.IsTheme(f.Extension.ExtensionType))
.Select(f=>new ModuleFeature{Descriptor=f,
IsEnabled=_shellDescriptor.Features.Any(sf=>sf.Name==f.Id),
NeedsUpdate=featuresThatNeedUpdate.Contains(f.Id)})

View File

@ -46,8 +46,7 @@ namespace Orchard.Packaging.Services {
EmbedVirtualFile(context, projectFile, MediaTypeNames.Text.Xml);
EmbedProjectFiles(context, "Compile", "Content", "None", "EmbeddedResource");
EmbedReferenceFiles(context);
}
else if (extensionDescriptor.ExtensionType == DefaultExtensionTypes.Theme) {
} else if (DefaultExtensionTypes.IsTheme(extensionDescriptor.ExtensionType)) {
// this is a simple theme with no csproj
EmbedThemeFiles(context);
}
@ -141,7 +140,7 @@ namespace Orchard.Packaging.Services {
private static void EstablishPaths(CreateContext context, IWebSiteFolder webSiteFolder, string locationPath, string moduleName, string moduleType) {
context.SourceFolder = webSiteFolder;
if (moduleType == DefaultExtensionTypes.Theme) {
if (DefaultExtensionTypes.IsTheme(moduleType)) {
context.SourcePath = "~/Themes/" + moduleName + "/";
context.TargetPath = "\\Content\\Themes\\" + moduleName + "\\";
}

View File

@ -59,7 +59,7 @@ namespace Orchard.Themes.Controllers {
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
var themes = _extensionManager.AvailableExtensions()
.Where(d => d.ExtensionType == DefaultExtensionTypes.Theme)
.Where(d => DefaultExtensionTypes.IsTheme(d.ExtensionType))
.Select(d => new ThemeEntry {
Descriptor = d,
NeedsUpdate = featuresThatNeedUpdate.Contains(d.Id),

View File

@ -30,7 +30,7 @@ namespace Orchard.Themes.Preview {
var installedThemes = _featureManager.GetEnabledFeatures()
.Select(x => x.Extension)
.Where(x => x.ExtensionType == DefaultExtensionTypes.Theme)
.Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType))
.Distinct();
var themeListItems = installedThemes

View File

@ -110,7 +110,7 @@ namespace Orchard.Themes.Services {
var themes = new List<ExtensionDescriptor>();
foreach (var descriptor in extensions) {
if (!string.Equals(descriptor.ExtensionType, DefaultExtensionTypes.Theme, StringComparison.OrdinalIgnoreCase)) {
if (!DefaultExtensionTypes.IsTheme(descriptor.ExtensionType)) {
continue;
}

View File

@ -43,7 +43,7 @@ namespace Orchard.Widgets.Services {
public IEnumerable<string> GetZones() {
return _featureManager.GetEnabledFeatures()
.Select(x => x.Extension)
.Where(x => x.ExtensionType == DefaultExtensionTypes.Theme)
.Where(x => DefaultExtensionTypes.IsTheme(x.ExtensionType))
.SelectMany(x => x.Zones.Split(','))
.Distinct()
.Select(x => x.Trim())

View File

@ -66,11 +66,11 @@ namespace Orchard.DisplayManagement.Descriptors {
}
var extensionType = alteration.Feature.Descriptor.Extension.ExtensionType;
if (extensionType == DefaultExtensionTypes.Module) {
if (DefaultExtensionTypes.IsModule(extensionType)) {
return true;
}
if (extensionType == DefaultExtensionTypes.Theme) {
if (DefaultExtensionTypes.IsTheme(extensionType)) {
// alterations from themes must be from the given theme or a base theme
var featureName = alteration.Feature.Descriptor.Id;
return featureName == themeName || IsBaseTheme(featureName, themeName);

View File

@ -102,7 +102,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy {
}
private bool FeatureIsTheme(FeatureDescriptor fd) {
return fd.Extension.ExtensionType == DefaultExtensionTypes.Theme;
return DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType);
}
private bool FeatureIsEnabled(FeatureDescriptor fd) {

View File

@ -87,7 +87,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
}
private bool FeatureIsEnabled(FeatureDescriptor fd) {
return (fd.Extension.ExtensionType == DefaultExtensionTypes.Theme && (fd.Id == "TheAdmin" || fd.Id == "SafeMode")) ||
return (DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType) && (fd.Id == "TheAdmin" || fd.Id == "SafeMode")) ||
_shellDescriptor.Features.Any(sf => sf.Name == fd.Id);
}

View File

@ -156,7 +156,7 @@ namespace Orchard.Environment.Extensions {
private ExtensionLoadingContext CreateLoadingContext() {
var availableExtensions = _extensionManager
.AvailableExtensions()
.Where(d => d.ExtensionType == DefaultExtensionTypes.Module || d.ExtensionType == DefaultExtensionTypes.Theme)
.Where(d => DefaultExtensionTypes.IsModule(d.ExtensionType) || DefaultExtensionTypes.IsTheme(d.ExtensionType))
.OrderBy(d => d.Id)
.ToList();
@ -293,7 +293,7 @@ namespace Orchard.Environment.Extensions {
monitor(_virtualPathMonitor.WhenPathChanges("~/Themes"));
// Give loaders a chance to monitor any additional changes
var extensions = _extensionManager.AvailableExtensions().Where(d => d.ExtensionType == DefaultExtensionTypes.Module || d.ExtensionType == DefaultExtensionTypes.Theme).ToList();
var extensions = _extensionManager.AvailableExtensions().Where(d => DefaultExtensionTypes.IsModule(d.ExtensionType) || DefaultExtensionTypes.IsTheme(d.ExtensionType)).ToList();
foreach (var extension in extensions) {
foreach (var loader in _loaders) {
loader.Monitor(extension, monitor);

View File

@ -49,13 +49,13 @@ namespace Orchard.Environment.Extensions {
/// <param name="subject"></param>
/// <returns></returns>
internal static bool HasDependency(FeatureDescriptor item, FeatureDescriptor subject) {
if (item.Extension.ExtensionType == DefaultExtensionTypes.Theme) {
if (subject.Extension.ExtensionType == DefaultExtensionTypes.Module) {
if (DefaultExtensionTypes.IsTheme(item.Extension.ExtensionType)) {
if (DefaultExtensionTypes.IsModule(subject.Extension.ExtensionType)) {
// Themes implicitly depend on modules to ensure build and override ordering
return true;
}
if (subject.Extension.ExtensionType == DefaultExtensionTypes.Theme) {
if (DefaultExtensionTypes.IsTheme(subject.Extension.ExtensionType)) {
// Theme depends on another if it is its base theme
return item.Extension.BaseTheme == subject.Id;
}

View File

@ -1,7 +1,17 @@
namespace Orchard.Environment.Extensions.Models {
using System;
namespace Orchard.Environment.Extensions.Models {
public static class DefaultExtensionTypes {
public const string Module = "Module";
public const string Theme = "Theme";
public const string Core = "Core";
public static bool IsModule(string extensionType) {
return string.Equals(extensionType, Module, StringComparison.OrdinalIgnoreCase);
}
public static bool IsTheme(string extensionType) {
return string.Equals(extensionType, Theme, StringComparison.OrdinalIgnoreCase);
}
}
}

View File

@ -113,7 +113,7 @@ namespace Orchard.Localization.Services {
}
foreach (var module in _extensionManager.AvailableExtensions()) {
if (String.Equals(module.ExtensionType, DefaultExtensionTypes.Module)) {
if (DefaultExtensionTypes.IsModule(module.ExtensionType)) {
string modulePath = string.Format(ModulesLocalizationFilePathFormat, module.Id, culture);
text = _webSiteFolder.ReadFile(modulePath);
if (text != null) {
@ -124,7 +124,7 @@ namespace Orchard.Localization.Services {
}
foreach (var theme in _extensionManager.AvailableExtensions()) {
if (String.Equals(theme.ExtensionType, DefaultExtensionTypes.Theme)) {
if (DefaultExtensionTypes.IsTheme(theme.ExtensionType)) {
string themePath = string.Format(ThemesLocalizationFilePathFormat, theme.Id, culture);
text = _webSiteFolder.ReadFile(themePath);
if (text != null) {