Corrected bad merge.

This commit is contained in:
Sipke Schoorstra
2015-06-09 01:33:46 +03:00
parent e03df31e50
commit 88679bd7ca
3 changed files with 10 additions and 27 deletions

View File

@@ -1,22 +1,13 @@
using System;
using System.Collections.Concurrent;
using System.Web;
using Autofac;
using Orchard.Mvc.Extensions;
using Orchard.Settings;
namespace Orchard.Mvc {
public class HttpContextAccessor : IHttpContextAccessor {
private HttpContextBase _httpContext;
public HttpContextBase Current() {
var httpContext = GetStaticProperty();
return !IsBackgroundHttpContext(httpContext) ? new HttpContextWrapper(httpContext) : _httpContext;
}
public void Set(HttpContextBase httpContext) {
_httpContext = httpContext;
}
private static bool IsBackgroundHttpContext(HttpContext httpContext) {
return httpContext == null || httpContext.Items.Contains(BackgroundHttpContextFactory.IsBackgroundHttpContextKey);
}
readonly object _contextKey = new object();
[ThreadStatic]
static ConcurrentDictionary<object, HttpContextBase> _threadStaticContexts;
@@ -38,7 +29,7 @@ namespace Orchard.Mvc {
HttpContextBase context;
return ThreadStaticContexts.TryGetValue(_contextKey, out context) ? context : null;
}
static ConcurrentDictionary<object, HttpContextBase> ThreadStaticContexts {
get {
return _threadStaticContexts ?? (_threadStaticContexts = new ConcurrentDictionary<object, HttpContextBase>());

View File

@@ -1,5 +1,4 @@
using System;
using System.Web;
using System.Web;
using Autofac;
namespace Orchard.Mvc {

View File

@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Orchard.Data;
using Orchard.Environment.Configuration;
using Orchard.Logging;
using Orchard.ContentManagement;
namespace Orchard.Tasks {
@@ -12,21 +10,18 @@ namespace Orchard.Tasks {
void Sweep();
}
[UsedImplicitly]
public class BackgroundService : IBackgroundService {
private readonly IEnumerable<IBackgroundTask> _tasks;
private readonly ITransactionManager _transactionManager;
private readonly IBackgroundHttpContextFactory _backgroundHttpContextFactory;
private readonly string _shellName;
public BackgroundService(
IEnumerable<IBackgroundTask> tasks,
ITransactionManager transactionManager,
IEnumerable<IBackgroundTask> tasks,
ITransactionManager transactionManager,
ShellSettings shellSettings) {
_tasks = tasks;
_transactionManager = transactionManager;
_backgroundHttpContextFactory = backgroundHttpContextFactory;
_shellName = shellSettings.Name;
Logger = NullLogger.Instance;
}
@@ -34,9 +29,7 @@ namespace Orchard.Tasks {
public ILogger Logger { get; set; }
public void Sweep() {
_backgroundHttpContextFactory.InitializeHttpContext();
foreach(var task in _tasks) {
foreach (var task in _tasks) {
var taskName = task.GetType().FullName;
try {