diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskManager.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskManager.cs index 9c2cb0de6..75c30f699 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskManager.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskManager.cs @@ -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); } /// diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index a253e1ea2..3e21961c1 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -180,10 +180,24 @@ namespace Orchard.Setup.Services { //hackInstallationGenerator.GenerateInstallEvents(); var contentDefinitionManager = environment.Resolve(); - 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); diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index de656db58..76eac4cae 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -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; } diff --git a/src/Orchard/Environment/OrchardStarter.cs b/src/Orchard/Environment/OrchardStarter.cs index a1a71201d..f3541f15d 100644 --- a/src/Orchard/Environment/OrchardStarter.cs +++ b/src/Orchard/Environment/OrchardStarter.cs @@ -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().As().As().SingleInstance(); { builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); { diff --git a/src/Orchard/Environment/ShellBuilders/ShellContextFactory.cs b/src/Orchard/Environment/ShellBuilders/ShellContextFactory.cs index 27e09bac4..d79598aed 100644 --- a/src/Orchard/Environment/ShellBuilders/ShellContextFactory.cs +++ b/src/Orchard/Environment/ShellBuilders/ShellContextFactory.cs @@ -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);