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;
using System.Collections.Concurrent;
using System.Web; using System.Web;
using Autofac;
using Orchard.Mvc.Extensions;
using Orchard.Settings;
namespace Orchard.Mvc { namespace Orchard.Mvc {
public class HttpContextAccessor : IHttpContextAccessor { public class HttpContextAccessor : IHttpContextAccessor {
private HttpContextBase _httpContext; readonly object _contextKey = new object();
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);
}
[ThreadStatic] [ThreadStatic]
static ConcurrentDictionary<object, HttpContextBase> _threadStaticContexts; static ConcurrentDictionary<object, HttpContextBase> _threadStaticContexts;

View File

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

View File

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