mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Merge with 1.x
--HG-- branch : autoroute
This commit is contained in:
@@ -38,7 +38,7 @@ namespace Orchard.Specs.Hosting {
|
||||
// Trying the two known relative paths to the Orchard.Web directory.
|
||||
// The second one is for the target "spec" in orchard.proj.
|
||||
if (ConfigurationManager.AppSettings["orchardHosting"] != null) {
|
||||
_orchardWebPath = baseDir.Combine(ConfigurationManager.AppSettings["orchardHosting"]).Combine("Orchard.Web");
|
||||
_orchardWebPath = baseDir.Combine(ConfigurationManager.AppSettings["orchardHosting"]);
|
||||
}
|
||||
else {
|
||||
_orchardWebPath = baseDir.Up(3).Combine("Orchard.Web");
|
||||
|
||||
@@ -33,9 +33,9 @@ namespace Orchard.Tests.Tasks {
|
||||
_container.Resolve<Mock<IBackgroundService>>()
|
||||
.Verify(x => x.Sweep(), Times.Never());
|
||||
|
||||
heartbeatSource.Activated();
|
||||
heartbeatSource.Activate();
|
||||
System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(80));
|
||||
heartbeatSource.Terminating();
|
||||
heartbeatSource.Terminate();
|
||||
|
||||
_container.Resolve<Mock<IBackgroundService>>()
|
||||
.Verify(x => x.Sweep(), Times.AtLeastOnce());
|
||||
|
||||
@@ -5,6 +5,7 @@ using Autofac.Features.OwnedInstances;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc.ModelBinders;
|
||||
using Orchard.Mvc.Routes;
|
||||
using Orchard.Tasks;
|
||||
using IModelBinderProvider = Orchard.Mvc.ModelBinders.IModelBinderProvider;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
@@ -14,18 +15,21 @@ namespace Orchard.Environment {
|
||||
private readonly IRoutePublisher _routePublisher;
|
||||
private readonly IEnumerable<IModelBinderProvider> _modelBinderProviders;
|
||||
private readonly IModelBinderPublisher _modelBinderPublisher;
|
||||
private readonly ISweepGenerator _sweepGenerator;
|
||||
|
||||
public DefaultOrchardShell(
|
||||
Func<Owned<IOrchardShellEvents>> eventsFactory,
|
||||
IEnumerable<IRouteProvider> routeProviders,
|
||||
IRoutePublisher routePublisher,
|
||||
IEnumerable<IModelBinderProvider> modelBinderProviders,
|
||||
IModelBinderPublisher modelBinderPublisher) {
|
||||
IModelBinderPublisher modelBinderPublisher,
|
||||
ISweepGenerator sweepGenerator) {
|
||||
_eventsFactory = eventsFactory;
|
||||
_routeProviders = routeProviders;
|
||||
_routePublisher = routePublisher;
|
||||
_modelBinderProviders = modelBinderProviders;
|
||||
_modelBinderPublisher = modelBinderPublisher;
|
||||
_sweepGenerator = sweepGenerator;
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
@@ -36,19 +40,23 @@ namespace Orchard.Environment {
|
||||
_routePublisher.Publish(_routeProviders.SelectMany(provider => provider.GetRoutes()));
|
||||
_modelBinderPublisher.Publish(_modelBinderProviders.SelectMany(provider => provider.GetModelBinders()));
|
||||
|
||||
_sweepGenerator.Activate();
|
||||
|
||||
using (var events = _eventsFactory()) {
|
||||
events.Value.Activated();
|
||||
}
|
||||
}
|
||||
|
||||
public void Terminate() {
|
||||
try {
|
||||
using (var events = _eventsFactory()) {
|
||||
using (var events = _eventsFactory()) {
|
||||
try {
|
||||
events.Value.Terminating();
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// ignore exceptions while terminating the application
|
||||
catch {
|
||||
// ignore exceptions while terminating the application
|
||||
}
|
||||
|
||||
_sweepGenerator.Terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Timers;
|
||||
using Orchard.Data;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Logging;
|
||||
|
||||
namespace Orchard.Tasks {
|
||||
public class SweepGenerator : IOrchardShellEvents {
|
||||
|
||||
public interface ISweepGenerator : ISingletonDependency {
|
||||
void Activate();
|
||||
void Terminate();
|
||||
}
|
||||
|
||||
public class SweepGenerator : ISweepGenerator, IDisposable {
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
private readonly Timer _timer;
|
||||
|
||||
@@ -24,13 +29,13 @@ namespace Orchard.Tasks {
|
||||
set { _timer.Interval = value.TotalMilliseconds; }
|
||||
}
|
||||
|
||||
public void Activated() {
|
||||
public void Activate() {
|
||||
lock (_timer) {
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void Terminating() {
|
||||
public void Terminate() {
|
||||
lock (_timer) {
|
||||
_timer.Stop();
|
||||
}
|
||||
@@ -56,10 +61,17 @@ namespace Orchard.Tasks {
|
||||
|
||||
public void DoWork() {
|
||||
using (var scope = _workContextAccessor.CreateWorkContextScope()) {
|
||||
var transactionManager = scope.Resolve<ITransactionManager>();
|
||||
transactionManager.Demand();
|
||||
|
||||
// resolve the manager and invoke it
|
||||
var manager = scope.Resolve<IBackgroundService>();
|
||||
manager.Sweep();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_timer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user