From aa7077af22a564e52b8cf4b66b044551a224dd29 Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Wed, 28 Jul 2010 18:14:22 -0700 Subject: [PATCH] Fix enable feature from command line If we enable a feature from the command line, we need the host to recompute it's list of shell topologies on the next request of the web application. We enable this by making the OrchardHost watch for file changes on the "cache.dat" file (topology cache) --HG-- branch : dev --- src/Orchard/Environment/DefaultOrchardHost.cs | 4 ++++ .../Descriptor/ShellDescriptorCache.cs | 20 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Orchard/Environment/DefaultOrchardHost.cs b/src/Orchard/Environment/DefaultOrchardHost.cs index 5939021fb..6c8e352d7 100644 --- a/src/Orchard/Environment/DefaultOrchardHost.cs +++ b/src/Orchard/Environment/DefaultOrchardHost.cs @@ -21,6 +21,7 @@ namespace Orchard.Environment { private readonly ControllerBuilder _controllerBuilder; private readonly IShellSettingsManager _shellSettingsManager; private readonly IShellContextFactory _shellContextFactory; + private readonly IShellDescriptorCache _shellDescriptorCache; private readonly IRunningShellTable _runningShellTable; private readonly IProcessingEngine _processingEngine; private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator; @@ -32,6 +33,7 @@ namespace Orchard.Environment { public DefaultOrchardHost( IShellSettingsManager shellSettingsManager, IShellContextFactory shellContextFactory, + IShellDescriptorCache shellDescriptorCache, IRunningShellTable runningShellTable, IProcessingEngine processingEngine, IExtensionLoaderCoordinator extensionLoaderCoordinator, @@ -40,6 +42,7 @@ namespace Orchard.Environment { _shellSettingsManager = shellSettingsManager; _shellContextFactory = shellContextFactory; + _shellDescriptorCache = shellDescriptorCache; _runningShellTable = runningShellTable; _processingEngine = processingEngine; _extensionLoaderCoordinator = extensionLoaderCoordinator; @@ -149,6 +152,7 @@ namespace Orchard.Environment { _cacheManager.Get("OrchardHost_Extensions", ctx => { _extensionLoaderCoordinator.MonitorExtensions(ctx.Monitor); + _shellDescriptorCache.Monitor(ctx.Monitor); _current = null; return ""; }); diff --git a/src/Orchard/Environment/Descriptor/ShellDescriptorCache.cs b/src/Orchard/Environment/Descriptor/ShellDescriptorCache.cs index 8f718b746..1c5654eaa 100644 --- a/src/Orchard/Environment/Descriptor/ShellDescriptorCache.cs +++ b/src/Orchard/Environment/Descriptor/ShellDescriptorCache.cs @@ -2,13 +2,14 @@ using System.IO; using System.Runtime.Serialization; using System.Xml; +using Orchard.Caching; using Orchard.Environment.Descriptor.Models; using Orchard.FileSystems.AppData; using Orchard.Localization; using Orchard.Logging; namespace Orchard.Environment.Descriptor { - /// + /// /// Single service instance registered at the host level. Provides storage /// and recall of shell descriptor information. Default implementation uses /// app_data, but configured replacements could use other per-host writable location. @@ -26,6 +27,11 @@ namespace Orchard.Environment.Descriptor { /// Loss of storage is expected. /// void Store(string shellName, ShellDescriptor descriptor); + + /// + /// Monitor changes on the persistent storage. + /// + void Monitor(Action monitor); } public class ShellDescriptorCache : IShellDescriptorCache { @@ -55,7 +61,7 @@ namespace Orchard.Environment.Descriptor { var serializer = new DataContractSerializer(typeof(ShellDescriptor)); var reader = new StringReader(tenantNode.InnerText); using (var xmlReader = XmlReader.Create(reader)) { - return (ShellDescriptor) serializer.ReadObject(xmlReader, true); + return (ShellDescriptor)serializer.ReadObject(xmlReader, true); } } } @@ -73,7 +79,7 @@ namespace Orchard.Environment.Descriptor { XmlNode rootNode = xmlDocument.DocumentElement; foreach (XmlNode tenantNode in rootNode.ChildNodes) { if (String.Equals(tenantNode.Name, name, StringComparison.OrdinalIgnoreCase)) { - var serializer = new DataContractSerializer(typeof (ShellDescriptor)); + var serializer = new DataContractSerializer(typeof(ShellDescriptor)); var writer = new StringWriter(); using (var xmlWriter = XmlWriter.Create(writer)) { serializer.WriteObject(xmlWriter, descriptor); @@ -98,6 +104,10 @@ namespace Orchard.Environment.Descriptor { _appDataFolder.CreateFile(DescriptorCacheFileName, saveWriter.ToString()); } + public void Monitor(Action monitor) { + monitor(_appDataFolder.WhenPathChanges(DescriptorCacheFileName)); + } + #endregion private void VerifyCacheFile() { @@ -106,8 +116,8 @@ namespace Orchard.Environment.Descriptor { using (XmlWriter xmlWriter = XmlWriter.Create(writer)) { if (xmlWriter != null) { xmlWriter.WriteStartDocument(); - xmlWriter.WriteStartElement("Tenants"); - xmlWriter.WriteEndElement(); + xmlWriter.WriteStartElement("Tenants"); + xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); } }