diff --git a/src/Orchard.Tests/DisplayManagement/Descriptors/ShapeTemplateBindingStrategyTests.cs b/src/Orchard.Tests/DisplayManagement/Descriptors/ShapeTemplateBindingStrategyTests.cs index ec16aa7cb..eb35adff9 100644 --- a/src/Orchard.Tests/DisplayManagement/Descriptors/ShapeTemplateBindingStrategyTests.cs +++ b/src/Orchard.Tests/DisplayManagement/Descriptors/ShapeTemplateBindingStrategyTests.cs @@ -5,12 +5,14 @@ using System.Linq; using Autofac; using Moq; using NUnit.Framework; +using Orchard.Caching; using Orchard.DisplayManagement.Descriptors; using Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy; using Orchard.Environment.Descriptor.Models; using Orchard.Environment.Extensions; using Orchard.Environment.Extensions.Models; using Orchard.FileSystems.VirtualPath; +using Orchard.Tests.Stubs; namespace Orchard.Tests.DisplayManagement.Descriptors { [TestFixture] @@ -21,12 +23,14 @@ namespace Orchard.Tests.DisplayManagement.Descriptors { private TestVirtualPathProvider _testVirtualPathProvider; - protected override void Register(Autofac.ContainerBuilder builder) { - _descriptor = new ShellDescriptor { }; + protected override void Register(ContainerBuilder builder) { + _descriptor = new ShellDescriptor(); _testViewEngine = new TestViewEngine(); _testVirtualPathProvider = new TestVirtualPathProvider(); builder.Register(ctx => _descriptor); + builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterInstance(_testViewEngine).As(); diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index f7ba7389a..bc39d6e2f 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -1,9 +1,5 @@ -using System; -using System.IO; -using System.Xml.Serialization; -using NHibernate; +using NHibernate; using NHibernate.Cfg; -using Orchard.Data; using Orchard.Data.Providers; using Orchard.Environment; using Orchard.Environment.Configuration; diff --git a/src/Orchard/DisplayManagement/Descriptors/ShapeTemplateStrategy/ShapeTemplateBindingStrategy.cs b/src/Orchard/DisplayManagement/Descriptors/ShapeTemplateStrategy/ShapeTemplateBindingStrategy.cs index 921ffc803..f038ed61e 100644 --- a/src/Orchard/DisplayManagement/Descriptors/ShapeTemplateStrategy/ShapeTemplateBindingStrategy.cs +++ b/src/Orchard/DisplayManagement/Descriptors/ShapeTemplateStrategy/ShapeTemplateBindingStrategy.cs @@ -1,10 +1,12 @@ -using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Html; +using Orchard.Caching; using Orchard.DisplayManagement.Implementation; using Orchard.Environment.Descriptor.Models; using Orchard.Environment.Extensions; @@ -15,6 +17,8 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy { public class ShapeTemplateBindingStrategy : IShapeTableProvider { private readonly ShellDescriptor _shellDescriptor; private readonly IExtensionManager _extensionManager; + private readonly ICacheManager _cacheManager; + private readonly IVirtualPathMonitor _virtualPathMonitor; private readonly IVirtualPathProvider _virtualPathProvider; private readonly IEnumerable _harvesters; private readonly IEnumerable _shapeTemplateViewEngines; @@ -24,11 +28,15 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy { IEnumerable harvesters, ShellDescriptor shellDescriptor, IExtensionManager extensionManager, + ICacheManager cacheManager, + IVirtualPathMonitor virtualPathMonitor, IVirtualPathProvider virtualPathProvider, IEnumerable shapeTemplateViewEngines) { _harvesters = harvesters; _shellDescriptor = shellDescriptor; _extensionManager = extensionManager; + _cacheManager = cacheManager; + _virtualPathMonitor = virtualPathMonitor; _virtualPathProvider = virtualPathProvider; _shapeTemplateViewEngines = shapeTemplateViewEngines; } @@ -49,13 +57,21 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy { var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath => { var basePath = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/'); var virtualPath = Path.Combine(basePath, subPath).Replace(Path.DirectorySeparatorChar, '/'); - var fileNames = _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName); + var fileNames = _cacheManager.Get(virtualPath, ctx => { + ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath)); + return _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName); + }); return new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames }; })); var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => { var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames); - return fileNames.Select(fileName => new { fileName = Path.GetFileNameWithoutExtension(fileName), fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'), pathContext }); + return fileNames.Select( + fileName => new { + fileName = Path.GetFileNameWithoutExtension(fileName), + fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'), + pathContext + }); })); var shapeContexts = fileContexts.SelectMany(fileContext => { diff --git a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs index 12fa9ec42..486cc4153 100644 --- a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs +++ b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs @@ -11,16 +11,21 @@ namespace Orchard.FileSystems.VirtualPath { private readonly string _prefix = Guid.NewGuid().ToString("n"); private readonly IDictionary> _tokens = new Dictionary>(); private readonly IClock _clock; + private readonly IVirtualPathProvider _virtualPathProvider; - public DefaultVirtualPathMonitor(IClock clock) { + public DefaultVirtualPathMonitor(IClock clock, IVirtualPathProvider virtualPathProvider) { _clock = clock; + _virtualPathProvider = virtualPathProvider; _thunk = new Thunk(this); } public IVolatileToken WhenPathChanges(string virtualPath) { // Fix this to monitor first existing parent directory. - var token = BindToken(virtualPath); - BindSignal(virtualPath); + IVolatileToken token = new Token(virtualPath); + if (_virtualPathProvider.DirectoryExists(virtualPath)) { + token = BindToken(virtualPath); + BindSignal(virtualPath); + } return token; } @@ -108,6 +113,5 @@ namespace Orchard.FileSystems.VirtualPath { provider.Signal(key, value, reason); } } - } } \ No newline at end of file