mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-18 17:47:54 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Orchard.Indexing.Services {
|
||||
}
|
||||
|
||||
public DateTime GetLastTaskDateTime() {
|
||||
return _repository.Table.Max(t => t.CreatedUtc) ?? DateTime.MinValue;
|
||||
return _repository.Table.Max(t => t.CreatedUtc) ?? new DateTime(1980, 1, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -180,10 +180,24 @@ namespace Orchard.Setup.Services {
|
||||
//hackInstallationGenerator.GenerateInstallEvents();
|
||||
|
||||
var contentDefinitionManager = environment.Resolve<IContentDefinitionManager>();
|
||||
contentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.DisplayedAs("Blog Post").WithPart("HasComments").WithPart("HasTags").WithPart("Localized").Indexed());
|
||||
contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.DisplayedAs("Page").WithPart("CommonAspect").WithPart("IsRoutable").WithPart("BodyAspect").WithPart("HasComments").WithPart("HasTags").WithPart("Localized").Indexed());
|
||||
contentDefinitionManager.AlterTypeDefinition("SandboxPage", cfg => cfg.DisplayedAs("Sandbox Page").WithPart("HasComments").WithPart("HasTags").WithPart("Localized").Indexed());
|
||||
contentDefinitionManager.AlterPartDefinition("BodyAspect", cfg => cfg.WithSetting("BodyPartSettings.FlavorDefault", BodyPartSettings.FlavorDefaultDefault));
|
||||
contentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg
|
||||
.DisplayedAs("Blog Post")
|
||||
.WithPart("HasComments")
|
||||
.WithPart("HasTags")
|
||||
.WithPart("Localized")
|
||||
.Indexed());
|
||||
contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg
|
||||
.DisplayedAs("Page")
|
||||
.WithPart("CommonAspect")
|
||||
.WithPart("PublishLaterPart")
|
||||
.WithPart("IsRoutable")
|
||||
.WithPart("BodyAspect")
|
||||
.WithPart("HasComments")
|
||||
.WithPart("HasTags")
|
||||
.WithPart("Localized")
|
||||
.Indexed());
|
||||
contentDefinitionManager.AlterPartDefinition("BodyAspect", cfg => cfg
|
||||
.WithSetting("BodyPartSettings.FlavorDefault", BodyPartSettings.FlavorDefaultDefault));
|
||||
|
||||
// create home page as a CMS page
|
||||
var page = contentManager.Create("Page", VersionOptions.Draft);
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using NHibernate;
|
||||
using NHibernate.Cfg;
|
||||
using Orchard.Data;
|
||||
using Orchard.Data.Providers;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
@@ -16,11 +18,57 @@ namespace Orchard.Data {
|
||||
SessionFactoryParameters GetSessionFactoryParameters();
|
||||
}
|
||||
|
||||
public interface ISessionConfigurationCache {
|
||||
void StoreConfig(string shellName, Configuration config);
|
||||
void DeleteConfig(string shellName);
|
||||
Configuration GetConfiguration(string shellName);
|
||||
}
|
||||
|
||||
public class SessionConfigurationCache : ISessionConfigurationCache {
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
|
||||
public SessionConfigurationCache(IAppDataFolder appDataFolder) {
|
||||
_appDataFolder = appDataFolder;
|
||||
}
|
||||
|
||||
public void StoreConfig(string shellName, Configuration config) {
|
||||
var filename = GetFileName(shellName);
|
||||
|
||||
using ( var stream = File.OpenWrite(filename) ) {
|
||||
new BinaryFormatter().Serialize(stream, config);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteConfig(string shellName) {
|
||||
var filename = GetFileName(shellName);
|
||||
if(File.Exists(filename)) {
|
||||
File.Delete(filename);
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration GetConfiguration(string shellName) {
|
||||
var filename = GetFileName(shellName);
|
||||
|
||||
if (!_appDataFolder.FileExists(filename)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
using (var stream = File.OpenRead(filename)) {
|
||||
return new BinaryFormatter().Deserialize(stream) as Configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetFileName(string shellName) {
|
||||
return _appDataFolder.MapPath(_appDataFolder.Combine("Sites", shellName, "mappings.bin"));
|
||||
}
|
||||
}
|
||||
|
||||
public class SessionFactoryHolder : ISessionFactoryHolder {
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly ShellBlueprint _shellBlueprint;
|
||||
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
private readonly ISessionConfigurationCache _sessionConfigurationCache;
|
||||
|
||||
private ISessionFactory _sessionFactory;
|
||||
private Configuration _configuration;
|
||||
@@ -29,11 +77,13 @@ namespace Orchard.Data {
|
||||
ShellSettings shellSettings,
|
||||
ShellBlueprint shellBlueprint,
|
||||
IDataServicesProviderFactory dataServicesProviderFactory,
|
||||
IAppDataFolder appDataFolder) {
|
||||
IAppDataFolder appDataFolder,
|
||||
ISessionConfigurationCache sessionConfigurationCache) {
|
||||
_shellSettings = shellSettings;
|
||||
_shellBlueprint = shellBlueprint;
|
||||
_dataServicesProviderFactory = dataServicesProviderFactory;
|
||||
_appDataFolder = appDataFolder;
|
||||
_sessionConfigurationCache = sessionConfigurationCache;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -70,26 +120,16 @@ namespace Orchard.Data {
|
||||
private Configuration BuildConfiguration() {
|
||||
var parameters = GetSessionFactoryParameters();
|
||||
|
||||
Configuration config = null;
|
||||
var bf = new BinaryFormatter();
|
||||
var config = _sessionConfigurationCache.GetConfiguration(_shellSettings.Name);
|
||||
|
||||
var filename = _appDataFolder.MapPath(_appDataFolder.Combine("Sites", "mappings.bin"));
|
||||
if(_appDataFolder.FileExists(filename)) {
|
||||
Logger.Debug("Loading mappings from cached file");
|
||||
using ( var stream = File.OpenRead(filename) ) {
|
||||
config = bf.Deserialize(stream) as Configuration;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger.Debug("Generating mappings and cached file");
|
||||
if ( config == null ) {
|
||||
config = _dataServicesProviderFactory
|
||||
.CreateProvider(parameters)
|
||||
.BuildConfiguration(parameters);
|
||||
|
||||
using ( var stream = File.OpenWrite(filename) ) {
|
||||
bf.Serialize(stream, config);
|
||||
}
|
||||
_sessionConfigurationCache.StoreConfig(_shellSettings.Name, config);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@ using System.Web.Hosting;
|
||||
using Autofac;
|
||||
using Autofac.Configuration;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Data;
|
||||
using Orchard.Environment.AutofacUtil;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
@@ -52,6 +53,7 @@ namespace Orchard.Environment {
|
||||
builder.RegisterType<DefaultOrchardHost>().As<IOrchardHost>().As<IEventHandler>().SingleInstance();
|
||||
{
|
||||
builder.RegisterType<ShellSettingsManager>().As<IShellSettingsManager>().SingleInstance();
|
||||
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>().SingleInstance();
|
||||
|
||||
builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>().SingleInstance();
|
||||
{
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
using Orchard.Data;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
@@ -35,14 +36,17 @@ namespace Orchard.Environment.ShellBuilders {
|
||||
private readonly IShellDescriptorCache _shellDescriptorCache;
|
||||
private readonly ICompositionStrategy _compositionStrategy;
|
||||
private readonly IShellContainerFactory _shellContainerFactory;
|
||||
private readonly ISessionConfigurationCache _sessionConfigurationCache;
|
||||
|
||||
public ShellContextFactory(
|
||||
IShellDescriptorCache shellDescriptorCache,
|
||||
ICompositionStrategy compositionStrategy,
|
||||
IShellContainerFactory shellContainerFactory) {
|
||||
IShellContainerFactory shellContainerFactory,
|
||||
ISessionConfigurationCache sessionConfigurationCache) {
|
||||
_shellDescriptorCache = shellDescriptorCache;
|
||||
_compositionStrategy = compositionStrategy;
|
||||
_shellContainerFactory = shellContainerFactory;
|
||||
_sessionConfigurationCache = sessionConfigurationCache;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
@@ -70,6 +74,7 @@ namespace Orchard.Environment.ShellBuilders {
|
||||
if (currentDescriptor != null && knownDescriptor.SerialNumber != currentDescriptor.SerialNumber) {
|
||||
Logger.Information("Newer descriptor obtained. Rebuilding shell container.");
|
||||
|
||||
_sessionConfigurationCache.DeleteConfig(settings.Name);
|
||||
_shellDescriptorCache.Store(settings.Name, currentDescriptor);
|
||||
blueprint = _compositionStrategy.Compose(settings, currentDescriptor);
|
||||
shellScope = _shellContainerFactory.CreateContainer(settings, blueprint);
|
||||
|
Reference in New Issue
Block a user