From 947fb55d7d33f9378829d224d6c1cfcc52cb154f Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Sun, 5 Dec 2010 14:41:41 -0800 Subject: [PATCH] Fix regression in monitoring file changes We were only monitoring existing directories only (not files). Since asp.net supports monitoring missing files, but not missing directories, we have to catch the HttpException and fallback adequatly. --HG-- branch : dev --- .../VirtualPath/DefaultVirtualPathMonitor.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs index 486cc4153..308e012e7 100644 --- a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs +++ b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathMonitor.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Web; using System.Web.Caching; using System.Web.Hosting; using Orchard.Caching; +using Orchard.Logging; using Orchard.Services; namespace Orchard.FileSystems.VirtualPath { @@ -11,22 +13,28 @@ 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, IVirtualPathProvider virtualPathProvider) { + public DefaultVirtualPathMonitor(IClock clock) { _clock = clock; - _virtualPathProvider = virtualPathProvider; _thunk = new Thunk(this); + Logger = NullLogger.Instance; } + ILogger Logger { get; set; } + public IVolatileToken WhenPathChanges(string virtualPath) { - // Fix this to monitor first existing parent directory. - IVolatileToken token = new Token(virtualPath); - if (_virtualPathProvider.DirectoryExists(virtualPath)) { - token = BindToken(virtualPath); + try { + var token = BindToken(virtualPath); BindSignal(virtualPath); + return token; + } + catch (HttpException e) { + // This exception happens if trying to monitor a directory or file + // inside a directory which doesn't exist + Logger.Warning(e, "Error monitor file changes on virtual path '{0}'", virtualPath); + // Fix this to monitor first existing parent directory. + return new Token(virtualPath); } - return token; } private Token BindToken(string virtualPath) {