mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 17:32:44 +08:00
Creating and using shell settings loader
All *.txt files in ~/app_data/sites are discovered Only one file should be present at the moment If no files are present the setup shell container will be used --HG-- branch : dev
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
@@ -11,6 +10,7 @@ using Autofac.Modules;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
using Orchard.Mvc.ModelBinders;
|
using Orchard.Mvc.ModelBinders;
|
||||||
using Orchard.Mvc.Routes;
|
using Orchard.Mvc.Routes;
|
||||||
@@ -46,9 +46,16 @@ namespace Orchard.Tests.Environment {
|
|||||||
builder.Register(new ViewEngineCollection { new WebFormViewEngine() });
|
builder.Register(new ViewEngineCollection { new WebFormViewEngine() });
|
||||||
builder.Register(new StuExtensionManager()).As<IExtensionManager>();
|
builder.Register(new StuExtensionManager()).As<IExtensionManager>();
|
||||||
builder.Register(new Mock<IHackInstallationGenerator>().Object);
|
builder.Register(new Mock<IHackInstallationGenerator>().Object);
|
||||||
|
builder.Register(new StubShellSettingsLoader()).As<IShellSettingsLoader>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class StubShellSettingsLoader : IShellSettingsLoader {
|
||||||
|
public IEnumerable<IShellSettings> LoadSettings() {
|
||||||
|
return new[] { new ShellSettings { Name = "testing" } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class StuExtensionManager : IExtensionManager {
|
public class StuExtensionManager : IExtensionManager {
|
||||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||||
return Enumerable.Empty<ExtensionDescriptor>();
|
return Enumerable.Empty<ExtensionDescriptor>();
|
||||||
|
|||||||
9
src/Orchard/Environment/Configuration/ShellSettings.cs
Normal file
9
src/Orchard/Environment/Configuration/ShellSettings.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Orchard.Environment.Configuration {
|
||||||
|
public interface IShellSettings {
|
||||||
|
string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ShellSettings : IShellSettings {
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
52
src/Orchard/Environment/Configuration/ShellSettingsLoader.cs
Normal file
52
src/Orchard/Environment/Configuration/ShellSettingsLoader.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web.Hosting;
|
||||||
|
using Yaml.Grammar;
|
||||||
|
|
||||||
|
namespace Orchard.Environment.Configuration {
|
||||||
|
public interface IShellSettingsLoader {
|
||||||
|
IEnumerable<IShellSettings> LoadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ShellSettingsLoader : IShellSettingsLoader {
|
||||||
|
|
||||||
|
IEnumerable<IShellSettings> IShellSettingsLoader.LoadSettings() {
|
||||||
|
return LoadSettings().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable<IShellSettings> LoadSettings() {
|
||||||
|
foreach (var yamlDocument in LoadFiles()) {
|
||||||
|
yield return ParseSettings(yamlDocument);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable<YamlDocument> LoadFiles() {
|
||||||
|
var sitesPath = HostingEnvironment.MapPath("~/App_Data/Sites");
|
||||||
|
if (sitesPath != null && Directory.Exists(sitesPath)) {
|
||||||
|
foreach (var settingsFilePath in Directory.GetFiles(sitesPath, "*.txt")) {
|
||||||
|
var yamlStream = YamlParser.Load(settingsFilePath);
|
||||||
|
yield return yamlStream.Documents.Single();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static IShellSettings ParseSettings(YamlDocument document) {
|
||||||
|
var mapping = (Mapping)document.Root;
|
||||||
|
var fields = mapping.Entities
|
||||||
|
.Where(x => x.Key is Scalar)
|
||||||
|
.ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value);
|
||||||
|
|
||||||
|
return new ShellSettings { Name = GetValue(fields, "Name") };
|
||||||
|
}
|
||||||
|
|
||||||
|
static string GetValue(
|
||||||
|
IDictionary<string, DataItem> fields,
|
||||||
|
string key) {
|
||||||
|
|
||||||
|
DataItem value;
|
||||||
|
return fields.TryGetValue(key, out value) ? value.ToString() : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Builder;
|
|
||||||
using Autofac.Integration.Web;
|
using Autofac.Integration.Web;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using AutofacContrib.DynamicProxy2;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Environment.ShellBuilders;
|
using Orchard.Environment.ShellBuilders;
|
||||||
using Orchard.Extensions;
|
using Orchard.Extensions;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
@@ -19,14 +16,17 @@ namespace Orchard.Environment {
|
|||||||
private readonly ControllerBuilder _controllerBuilder;
|
private readonly ControllerBuilder _controllerBuilder;
|
||||||
private readonly IEnumerable<IShellContainerFactory> _shellContainerFactories;
|
private readonly IEnumerable<IShellContainerFactory> _shellContainerFactories;
|
||||||
|
|
||||||
|
private readonly IShellSettingsLoader _shellSettingsLoader;
|
||||||
private IOrchardShell _current;
|
private IOrchardShell _current;
|
||||||
|
|
||||||
|
|
||||||
public DefaultOrchardHost(
|
public DefaultOrchardHost(
|
||||||
IContainerProvider containerProvider,
|
IContainerProvider containerProvider,
|
||||||
|
IShellSettingsLoader shellSettingsLoader,
|
||||||
ControllerBuilder controllerBuilder,
|
ControllerBuilder controllerBuilder,
|
||||||
IEnumerable<IShellContainerFactory> shellContainerFactories) {
|
IEnumerable<IShellContainerFactory> shellContainerFactories) {
|
||||||
_containerProvider = containerProvider;
|
_containerProvider = containerProvider;
|
||||||
|
_shellSettingsLoader = shellSettingsLoader;
|
||||||
_controllerBuilder = controllerBuilder;
|
_controllerBuilder = controllerBuilder;
|
||||||
_shellContainerFactories = shellContainerFactories;
|
_shellContainerFactories = shellContainerFactories;
|
||||||
}
|
}
|
||||||
@@ -71,10 +71,21 @@ namespace Orchard.Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual IContainer CreateShellContainer() {
|
public virtual IContainer CreateShellContainer() {
|
||||||
foreach(var factory in _shellContainerFactories) {
|
var settings = _shellSettingsLoader.LoadSettings();
|
||||||
var container = factory.CreateContainer(null);
|
if (settings.Any()) {
|
||||||
if (container != null)
|
//TEMP: multi-tenancy not implemented yet
|
||||||
return container;
|
foreach (var factory in _shellContainerFactories) {
|
||||||
|
var container = factory.CreateContainer(settings.Single());
|
||||||
|
if (container != null)
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach (var factory in _shellContainerFactories) {
|
||||||
|
var container = factory.CreateContainer(null);
|
||||||
|
if (container != null)
|
||||||
|
return container;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Autofac.Builder;
|
|||||||
using Autofac.Integration.Web;
|
using Autofac.Integration.Web;
|
||||||
using Autofac.Modules;
|
using Autofac.Modules;
|
||||||
using AutofacContrib.DynamicProxy2;
|
using AutofacContrib.DynamicProxy2;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Environment.ShellBuilders;
|
using Orchard.Environment.ShellBuilders;
|
||||||
using Orchard.Extensions;
|
using Orchard.Extensions;
|
||||||
using Orchard.Extensions.Loaders;
|
using Orchard.Extensions.Loaders;
|
||||||
@@ -21,6 +22,7 @@ namespace Orchard.Environment {
|
|||||||
builder.Register<DefaultOrchardHost>().As<IOrchardHost>().SingletonScoped();
|
builder.Register<DefaultOrchardHost>().As<IOrchardHost>().SingletonScoped();
|
||||||
builder.Register<DefaultCompositionStrategy>().As<ICompositionStrategy>().SingletonScoped();
|
builder.Register<DefaultCompositionStrategy>().As<ICompositionStrategy>().SingletonScoped();
|
||||||
builder.Register<DefaultShellContainerFactory>().As<IShellContainerFactory>().SingletonScoped();
|
builder.Register<DefaultShellContainerFactory>().As<IShellContainerFactory>().SingletonScoped();
|
||||||
|
builder.Register<ShellSettingsLoader>().As<IShellSettingsLoader>().SingletonScoped();
|
||||||
builder.Register<SetupShellContainerFactory>().As<IShellContainerFactory>().SingletonScoped();
|
builder.Register<SetupShellContainerFactory>().As<IShellContainerFactory>().SingletonScoped();
|
||||||
|
|
||||||
// The container provider gives you access to the lowest container at the time,
|
// The container provider gives you access to the lowest container at the time,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Builder;
|
using Autofac.Builder;
|
||||||
using AutofacContrib.DynamicProxy2;
|
using AutofacContrib.DynamicProxy2;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
|
|
||||||
namespace Orchard.Environment.ShellBuilders {
|
namespace Orchard.Environment.ShellBuilders {
|
||||||
public class DefaultShellContainerFactory : IShellContainerFactory {
|
public class DefaultShellContainerFactory : IShellContainerFactory {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Autofac;
|
using Autofac;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
|
|
||||||
namespace Orchard.Environment.ShellBuilders {
|
namespace Orchard.Environment.ShellBuilders {
|
||||||
public interface IShellContainerFactory {
|
public interface IShellContainerFactory {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Web.Routing;
|
|||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Extensions;
|
using Orchard.Extensions;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Orchard.Environment.ShellBuilders {
|
|
||||||
public interface IShellSettings {
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ShellSettings : IShellSettings {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -43,10 +43,10 @@ namespace Orchard.Extensions {
|
|||||||
if (File.Exists(extensionManifestPath)) {
|
if (File.Exists(extensionManifestPath)) {
|
||||||
var yamlStream = YamlParser.Load(extensionManifestPath);
|
var yamlStream = YamlParser.Load(extensionManifestPath);
|
||||||
return new ParseResult {
|
return new ParseResult {
|
||||||
Location = path,
|
Location = path,
|
||||||
Name = name,
|
Name = name,
|
||||||
YamlDocument = yamlStream.Documents.Single()
|
YamlDocument = yamlStream.Documents.Single()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_manifestIsOptional) {
|
if (_manifestIsOptional) {
|
||||||
@@ -55,10 +55,10 @@ namespace Orchard.Extensions {
|
|||||||
bool success;
|
bool success;
|
||||||
var yamlStream = parser.ParseYamlStream(yamlInput, out success);
|
var yamlStream = parser.ParseYamlStream(yamlInput, out success);
|
||||||
return new ParseResult {
|
return new ParseResult {
|
||||||
Location = path,
|
Location = path,
|
||||||
Name = name,
|
Name = name,
|
||||||
YamlDocument = yamlStream.Documents.Single()
|
YamlDocument = yamlStream.Documents.Single()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -139,10 +139,6 @@ namespace Orchard.Extensions {
|
|||||||
foreach (var descriptor in AvailableExtensions()) {
|
foreach (var descriptor in AvailableExtensions()) {
|
||||||
// Extensions that are Themes don't have buildable components.
|
// Extensions that are Themes don't have buildable components.
|
||||||
if (String.Equals(descriptor.ExtensionType, "Package", StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(descriptor.ExtensionType, "Package", StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
|
||||||
//TEMP!!!!
|
|
||||||
if (descriptor.DisplayName!="Setup") continue;
|
|
||||||
|
|
||||||
yield return BuildEntry(descriptor);
|
yield return BuildEntry(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,11 +133,12 @@
|
|||||||
<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="Data\Conventions\RecordTableNameConvention.cs" />
|
<Compile Include="Data\Conventions\RecordTableNameConvention.cs" />
|
||||||
|
<Compile Include="Environment\Configuration\ShellSettingsLoader.cs" />
|
||||||
<Compile Include="Environment\ExtensibleInterceptionModule.cs" />
|
<Compile Include="Environment\ExtensibleInterceptionModule.cs" />
|
||||||
<Compile Include="Environment\ShellBuilders\DefaultShellContainerFactory.cs" />
|
<Compile Include="Environment\ShellBuilders\DefaultShellContainerFactory.cs" />
|
||||||
<Compile Include="Environment\ShellBuilders\IShellContainerFactory.cs" />
|
<Compile Include="Environment\ShellBuilders\IShellContainerFactory.cs" />
|
||||||
<Compile Include="Environment\ShellBuilders\SetupShellContainerFactory.cs" />
|
<Compile Include="Environment\ShellBuilders\SetupShellContainerFactory.cs" />
|
||||||
<Compile Include="Environment\ShellBuilders\ShellSettings.cs" />
|
<Compile Include="Environment\Configuration\ShellSettings.cs" />
|
||||||
<Compile Include="Extensions\AreaFolders.cs" />
|
<Compile Include="Extensions\AreaFolders.cs" />
|
||||||
<Compile Include="Extensions\ExtensionFolders.cs" />
|
<Compile Include="Extensions\ExtensionFolders.cs" />
|
||||||
<Compile Include="Extensions\Loaders\AreaExtensionLoader.cs" />
|
<Compile Include="Extensions\Loaders\AreaExtensionLoader.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user