mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Specialize IVirtualPathMonitor for command line host
More deterministic behavior and no file locking at the expense of performance. --HG-- branch : dev
This commit is contained in:
@@ -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<CommandHostEnvironment>().As<IHostEnvironment>();
|
||||
builder.RegisterType<CommandBackgroundService>().As<IBackgroundService>();
|
||||
builder.RegisterType<CommandHostVirtualPathMonitor>().As<IVirtualPathMonitor>();
|
||||
}
|
||||
|
||||
protected void MvcSingletons(ContainerBuilder builder) {
|
||||
|
@@ -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;
|
||||
|
93
src/Orchard/Commands/CommandHostVirtualPathMonitor.cs
Normal file
93
src/Orchard/Commands/CommandHostVirtualPathMonitor.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
src/Orchard/Commands/OrchardCommandHostRetryException.cs
Normal file
19
src/Orchard/Commands/OrchardCommandHostRetryException.cs
Normal file
@@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
@@ -135,6 +135,8 @@
|
||||
<Compile Include="Collections\PageOfItems.cs" />
|
||||
<Compile Include="Commands\CommandBackgroundService.cs" />
|
||||
<Compile Include="Commands\CommandHostEnvironment.cs" />
|
||||
<Compile Include="Commands\CommandHostVirtualPathMonitor.cs" />
|
||||
<Compile Include="Commands\OrchardCommandHostRetryException.cs" />
|
||||
<Compile Include="ContentManagement\Aspects\ICommonPart.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
Reference in New Issue
Block a user