diff --git a/src/Orchard/Commands/CommandHostAgent.cs b/src/Orchard/Commands/CommandHostAgent.cs index 7a720155a..0177b9a24 100644 --- a/src/Orchard/Commands/CommandHostAgent.cs +++ b/src/Orchard/Commands/CommandHostAgent.cs @@ -8,6 +8,7 @@ using Autofac; using Orchard.Environment; using Orchard.Environment.Configuration; using Orchard.Environment.State; +using Orchard.FileSystems.VirtualPath; using Orchard.Localization; using Orchard.Logging; using Orchard.Tasks; @@ -153,6 +154,7 @@ namespace Orchard.Commands { MvcSingletons(builder); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); } protected void MvcSingletons(ContainerBuilder builder) { diff --git a/src/Orchard/Commands/CommandHostEnvironment.cs b/src/Orchard/Commands/CommandHostEnvironment.cs index ac085b3cd..23153b06c 100644 --- a/src/Orchard/Commands/CommandHostEnvironment.cs +++ b/src/Orchard/Commands/CommandHostEnvironment.cs @@ -1,25 +1,10 @@ using System; using System.Linq; -using System.Runtime.Serialization; using System.Web.Hosting; using Orchard.Environment; using Orchard.Localization; namespace Orchard.Commands { - public class OrchardCommandHostRetryException : OrchardCoreException { - public OrchardCommandHostRetryException(LocalizedString message) - : base(message) { - } - - public OrchardCommandHostRetryException(LocalizedString message, Exception innerException) - : base(message, innerException) { - } - - protected OrchardCommandHostRetryException(SerializationInfo info, StreamingContext context) - : base(info, context) { - } - } - public class CommandHostEnvironment : IHostEnvironment { public CommandHostEnvironment() { T = NullLocalizer.Instance; diff --git a/src/Orchard/Commands/CommandHostVirtualPathMonitor.cs b/src/Orchard/Commands/CommandHostVirtualPathMonitor.cs new file mode 100644 index 000000000..7b83fac7c --- /dev/null +++ b/src/Orchard/Commands/CommandHostVirtualPathMonitor.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Orchard.Caching; +using Orchard.FileSystems.VirtualPath; + +namespace Orchard.Commands { + public class CommandHostVirtualPathMonitor : IVirtualPathMonitor { + private readonly IVirtualPathProvider _virtualPathProvider; + + public CommandHostVirtualPathMonitor(IVirtualPathProvider virtualPathProvider) { + _virtualPathProvider = virtualPathProvider; + } + + public IVolatileToken WhenPathChanges(string virtualPath) { + var filename = _virtualPathProvider.MapPath(virtualPath); + if (File.Exists(filename)) { + return new FileToken(filename); + } + if (Directory.Exists(filename)) { + return new DirectoryToken(filename); + } + return new EmptyVolativeToken(filename); + } + + public class EmptyVolativeToken : IVolatileToken { + private readonly string _filename; + + public EmptyVolativeToken(string filename) { + _filename = filename; + } + + public bool IsCurrent { + get { + if (Directory.Exists(_filename)) { + return false; + } + if (File.Exists(_filename)) { + return false; + } + return true; + } + } + } + + public class FileToken : IVolatileToken { + private readonly string _filename; + private readonly DateTime _lastWriteTimeUtc; + + public FileToken(string filename) { + _filename = filename; + _lastWriteTimeUtc = File.GetLastWriteTimeUtc(filename); + } + + public bool IsCurrent { + get { + try { + if (_lastWriteTimeUtc != File.GetLastWriteTimeUtc(_filename)) + return false; + } + catch { + return false; + } + return true; + } + } + } + + public class DirectoryToken : IVolatileToken { + private readonly string _filename; + private readonly DateTime _lastWriteTimeUtc; + + public DirectoryToken(string filename) { + _filename = filename; + _lastWriteTimeUtc = Directory.GetLastWriteTimeUtc(filename); + } + + public bool IsCurrent { + get { + try { + if (_lastWriteTimeUtc != Directory.GetLastWriteTimeUtc(_filename)) + return false; + } + catch { + return false; + } + return true; + } + } + } + } +} \ No newline at end of file diff --git a/src/Orchard/Commands/OrchardCommandHostRetryException.cs b/src/Orchard/Commands/OrchardCommandHostRetryException.cs new file mode 100644 index 000000000..53d697771 --- /dev/null +++ b/src/Orchard/Commands/OrchardCommandHostRetryException.cs @@ -0,0 +1,19 @@ +using System; +using System.Runtime.Serialization; +using Orchard.Localization; + +namespace Orchard.Commands { + public class OrchardCommandHostRetryException : OrchardCoreException { + public OrchardCommandHostRetryException(LocalizedString message) + : base(message) { + } + + public OrchardCommandHostRetryException(LocalizedString message, Exception innerException) + : base(message, innerException) { + } + + protected OrchardCommandHostRetryException(SerializationInfo info, StreamingContext context) + : base(info, context) { + } + } +} \ No newline at end of file diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index cde886590..2b5a64c78 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -135,6 +135,8 @@ + + Code