mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Initial work to support loading MVC Areas as Orchard modules
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045728
This commit is contained in:
@@ -30,6 +30,7 @@ namespace Orchard.Environment {
|
|||||||
builder.Register<ContainerProvider>().As<IContainerProvider>().ContainerScoped();
|
builder.Register<ContainerProvider>().As<IContainerProvider>().ContainerScoped();
|
||||||
|
|
||||||
builder.Register<ExtensionManager>().As<IExtensionManager>().SingletonScoped();
|
builder.Register<ExtensionManager>().As<IExtensionManager>().SingletonScoped();
|
||||||
|
builder.Register<AreaExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
|
||||||
builder.Register<CoreExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
|
builder.Register<CoreExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
|
||||||
builder.Register<ReferencedExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
|
builder.Register<ReferencedExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
|
||||||
builder.Register<PrecompiledExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
|
builder.Register<PrecompiledExtensionLoader>().As<IExtensionLoader>().SingletonScoped();
|
||||||
@@ -38,6 +39,9 @@ namespace Orchard.Environment {
|
|||||||
builder.Register<PackageFolders>().As<IExtensionFolders>()
|
builder.Register<PackageFolders>().As<IExtensionFolders>()
|
||||||
.WithArguments(new NamedParameter("paths", new[] { "~/Core", "~/Packages" }))
|
.WithArguments(new NamedParameter("paths", new[] { "~/Core", "~/Packages" }))
|
||||||
.SingletonScoped();
|
.SingletonScoped();
|
||||||
|
builder.Register<AreaFolders>().As<IExtensionFolders>()
|
||||||
|
.WithArguments(new NamedParameter("paths", new[] { "~/Areas" }))
|
||||||
|
.SingletonScoped();
|
||||||
builder.Register<ThemeFolders>().As<IExtensionFolders>()
|
builder.Register<ThemeFolders>().As<IExtensionFolders>()
|
||||||
.WithArguments(new NamedParameter("paths", new[] { "~/Core", "~/Themes" }))
|
.WithArguments(new NamedParameter("paths", new[] { "~/Core", "~/Themes" }))
|
||||||
.SingletonScoped();
|
.SingletonScoped();
|
||||||
|
9
src/Orchard/Extensions/AreaFolders.cs
Normal file
9
src/Orchard/Extensions/AreaFolders.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Orchard.Extensions {
|
||||||
|
public class AreaFolders : ExtensionFolders {
|
||||||
|
public AreaFolders(IEnumerable<string> paths) :
|
||||||
|
base(paths, "Package.txt", true/*isManifestOptional*/) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
67
src/Orchard/Extensions/ExtensionFolders.cs
Normal file
67
src/Orchard/Extensions/ExtensionFolders.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.Extensions.Helpers;
|
||||||
|
using Yaml.Grammar;
|
||||||
|
|
||||||
|
namespace Orchard.Extensions {
|
||||||
|
public class ExtensionFolders : IExtensionFolders {
|
||||||
|
private readonly IEnumerable<string> _paths;
|
||||||
|
private readonly string _manifestName;
|
||||||
|
private readonly bool _manifestIsOptional;
|
||||||
|
|
||||||
|
public ExtensionFolders(IEnumerable<string> paths, string manifestName, bool manifestIsOptional) {
|
||||||
|
_paths = paths;
|
||||||
|
_manifestName = manifestName;
|
||||||
|
_manifestIsOptional = manifestIsOptional;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> ListNames() {
|
||||||
|
foreach (var path in _paths) {
|
||||||
|
if (!Directory.Exists(PathHelpers.GetPhysicalPath(path)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var directoryName in Directory.GetDirectories(PathHelpers.GetPhysicalPath(path))) {
|
||||||
|
if (_manifestIsOptional || File.Exists(Path.Combine(directoryName, _manifestName))) {
|
||||||
|
yield return Path.GetFileName(directoryName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParseResult ParseManifest(string name) {
|
||||||
|
foreach (var path in _paths) {
|
||||||
|
if (!Directory.Exists(PathHelpers.GetPhysicalPath(path)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var extensionDirectoryPath = Path.Combine(PathHelpers.GetPhysicalPath(path), name);
|
||||||
|
if (!Directory.Exists(PathHelpers.GetPhysicalPath(extensionDirectoryPath)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var extensionManifestPath = Path.Combine(extensionDirectoryPath, _manifestName);
|
||||||
|
|
||||||
|
if (File.Exists(extensionManifestPath)) {
|
||||||
|
var yamlStream = YamlParser.Load(extensionManifestPath);
|
||||||
|
return new ParseResult {
|
||||||
|
Location = path,
|
||||||
|
Name = name,
|
||||||
|
YamlDocument = yamlStream.Documents.Single()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_manifestIsOptional) {
|
||||||
|
var yamlInput = new TextInput(string.Format("name: {0}", name));
|
||||||
|
var parser = new YamlParser();
|
||||||
|
bool success;
|
||||||
|
var yamlStream = parser.ParseYamlStream(yamlInput, out success);
|
||||||
|
return new ParseResult {
|
||||||
|
Location = path,
|
||||||
|
Name = name,
|
||||||
|
YamlDocument = yamlStream.Documents.Single()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
src/Orchard/Extensions/Loaders/AreaExtensionLoader.cs
Normal file
26
src/Orchard/Extensions/Loaders/AreaExtensionLoader.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Orchard.Extensions.Loaders {
|
||||||
|
public class AreaExtensionLoader : IExtensionLoader {
|
||||||
|
public int Order { get { return 5; } }
|
||||||
|
|
||||||
|
public ExtensionEntry Load(ExtensionDescriptor descriptor) {
|
||||||
|
if (descriptor.Location == "~/Areas") {
|
||||||
|
|
||||||
|
var assembly = Assembly.Load("Orchard.Web");
|
||||||
|
return new ExtensionEntry {
|
||||||
|
Descriptor = descriptor,
|
||||||
|
Assembly = assembly,
|
||||||
|
ExportedTypes = assembly.GetExportedTypes().Where(x => IsTypeFromPackage(x, descriptor))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsTypeFromPackage(Type type, ExtensionDescriptor descriptor) {
|
||||||
|
return (type.Namespace + ".").StartsWith("Orchard.Web.Areas." + descriptor.Name + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -8,7 +8,7 @@ using System.Web.Hosting;
|
|||||||
|
|
||||||
namespace Orchard.Extensions.Loaders {
|
namespace Orchard.Extensions.Loaders {
|
||||||
public class DynamicExtensionLoader : IExtensionLoader {
|
public class DynamicExtensionLoader : IExtensionLoader {
|
||||||
public int Order { get { return 4; } }
|
public int Order { get { return 10; } }
|
||||||
|
|
||||||
public ExtensionEntry Load(ExtensionDescriptor descriptor) {
|
public ExtensionEntry Load(ExtensionDescriptor descriptor) {
|
||||||
if (HostingEnvironment.IsHosted == false)
|
if (HostingEnvironment.IsHosted == false)
|
||||||
|
@@ -1,43 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using Orchard.Extensions.Helpers;
|
|
||||||
using Yaml.Grammar;
|
|
||||||
|
|
||||||
namespace Orchard.Extensions {
|
namespace Orchard.Extensions {
|
||||||
public class PackageFolders : IExtensionFolders {
|
public class PackageFolders : ExtensionFolders {
|
||||||
private readonly IEnumerable<string> _paths;
|
public PackageFolders(IEnumerable<string> paths) :
|
||||||
|
base(paths, "Package.txt", false/*isManifestOptional*/) {
|
||||||
public PackageFolders(IEnumerable<string> paths) {
|
|
||||||
_paths = paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<string> ListNames() {
|
|
||||||
foreach (var path in _paths) {
|
|
||||||
if (!Directory.Exists(PathHelpers.GetPhysicalPath(path)))
|
|
||||||
continue;
|
|
||||||
foreach (var directoryName in Directory.GetDirectories(PathHelpers.GetPhysicalPath(path))) {
|
|
||||||
if (File.Exists(Path.Combine(directoryName, "Package.txt")))
|
|
||||||
yield return Path.GetFileName(directoryName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParseResult ParseManifest(string name) {
|
|
||||||
foreach (var path in _paths) {
|
|
||||||
var extensionDirectoryPath = Path.Combine(PathHelpers.GetPhysicalPath(path), name);
|
|
||||||
var extensionManifestPath = Path.Combine(extensionDirectoryPath, "Package.txt");
|
|
||||||
if (!File.Exists(extensionManifestPath)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var yamlStream = YamlParser.Load(extensionManifestPath);
|
|
||||||
return new ParseResult {
|
|
||||||
Location = path,
|
|
||||||
Name = name,
|
|
||||||
YamlDocument = yamlStream.Documents.Single()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,41 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using Orchard.Extensions.Helpers;
|
|
||||||
using Yaml.Grammar;
|
|
||||||
|
|
||||||
namespace Orchard.Extensions {
|
namespace Orchard.Extensions {
|
||||||
public class ThemeFolders : IExtensionFolders {
|
public class ThemeFolders : ExtensionFolders {
|
||||||
private readonly IEnumerable<string> _paths;
|
public ThemeFolders(IEnumerable<string> paths) :
|
||||||
|
base(paths, "Theme.txt", false/*manifestIsOptional*/) {
|
||||||
public ThemeFolders(IEnumerable<string> paths) {
|
|
||||||
_paths = paths;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<string> ListNames() {
|
|
||||||
foreach (var path in _paths) {
|
|
||||||
foreach (var directoryName in Directory.GetDirectories(PathHelpers.GetPhysicalPath(path))) {
|
|
||||||
if (File.Exists(Path.Combine(directoryName, "Theme.txt")))
|
|
||||||
yield return Path.GetFileName(directoryName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParseResult ParseManifest(string name) {
|
|
||||||
foreach (var path in _paths) {
|
|
||||||
var extensionDirectoryPath = Path.Combine(PathHelpers.GetPhysicalPath(path), name);
|
|
||||||
var extensionManifestPath = Path.Combine(extensionDirectoryPath, "Theme.txt");
|
|
||||||
if (!File.Exists(extensionManifestPath)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var yamlStream = YamlParser.Load(extensionManifestPath);
|
|
||||||
return new ParseResult {
|
|
||||||
Location = path,
|
|
||||||
Name = name,
|
|
||||||
YamlDocument = yamlStream.Documents.Single()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -131,6 +131,9 @@
|
|||||||
<Compile Include="ContentManagement\Handlers\PublishContentContext.cs" />
|
<Compile Include="ContentManagement\Handlers\PublishContentContext.cs" />
|
||||||
<Compile Include="ContentManagement\Handlers\RemoveContentContext.cs" />
|
<Compile Include="ContentManagement\Handlers\RemoveContentContext.cs" />
|
||||||
<Compile Include="ContentManagement\Handlers\VersionContentContext.cs" />
|
<Compile Include="ContentManagement\Handlers\VersionContentContext.cs" />
|
||||||
|
<Compile Include="Extensions\AreaFolders.cs" />
|
||||||
|
<Compile Include="Extensions\ExtensionFolders.cs" />
|
||||||
|
<Compile Include="Extensions\Loaders\AreaExtensionLoader.cs" />
|
||||||
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
|
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
|
||||||
<Compile Include="ContentManagement\ContentExtensions.cs" />
|
<Compile Include="ContentManagement\ContentExtensions.cs" />
|
||||||
<Compile Include="ContentManagement\ContentItem.cs" />
|
<Compile Include="ContentManagement\ContentItem.cs" />
|
||||||
|
Reference in New Issue
Block a user