mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
Merge with 1.x
--HG-- branch : autoroute
This commit is contained in:
@@ -4,5 +4,5 @@ c54cb640d6bc14c51b9fb9bd78231bb0facec067 src/Orchard.Web/Modules/Orchard.Forms
|
||||
ce578373f907c0a55fd91229a344f0755f290174 src/Orchard.Web/Modules/Orchard.TaskLease
|
||||
5207d27b3acb559fc5dc65a2dbaf307cac8474de src/Orchard.Web/Modules/Orchard.Tokens
|
||||
8375c8c10297aa9b66f792354bed25268184cd08 src/orchard.web/modules/Orchard.Alias
|
||||
386c2863a5e27872a0d6244eac04de6b81b10266 src/orchard.web/modules/Orchard.Fields
|
||||
114e75928872042f092b0cc7cafa1a58c208d8ae src/orchard.web/modules/Orchard.Fields
|
||||
913ced6d47a208394f8149d1573c2f2d61240d24 src/orchard.web/modules/orchard.Projections
|
||||
|
||||
@@ -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