From 88679bd7ca113142374df4025b9513da62910cd4 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Tue, 9 Jun 2015 01:33:46 +0300 Subject: [PATCH] Corrected bad merge. --- src/Orchard/Mvc/HttpContextAccessor.cs | 21 ++++++--------------- src/Orchard/Mvc/IHttpContextAccessor.cs | 3 +-- src/Orchard/Tasks/BackgroundService.cs | 13 +++---------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/Orchard/Mvc/HttpContextAccessor.cs b/src/Orchard/Mvc/HttpContextAccessor.cs index fc3d09fe5..34f50c7a9 100644 --- a/src/Orchard/Mvc/HttpContextAccessor.cs +++ b/src/Orchard/Mvc/HttpContextAccessor.cs @@ -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 _threadStaticContexts; @@ -38,7 +29,7 @@ namespace Orchard.Mvc { HttpContextBase context; return ThreadStaticContexts.TryGetValue(_contextKey, out context) ? context : null; } - + static ConcurrentDictionary ThreadStaticContexts { get { return _threadStaticContexts ?? (_threadStaticContexts = new ConcurrentDictionary()); diff --git a/src/Orchard/Mvc/IHttpContextAccessor.cs b/src/Orchard/Mvc/IHttpContextAccessor.cs index ba4f8fe5e..f34462581 100644 --- a/src/Orchard/Mvc/IHttpContextAccessor.cs +++ b/src/Orchard/Mvc/IHttpContextAccessor.cs @@ -1,5 +1,4 @@ -using System; -using System.Web; +using System.Web; using Autofac; namespace Orchard.Mvc { diff --git a/src/Orchard/Tasks/BackgroundService.cs b/src/Orchard/Tasks/BackgroundService.cs index 1775d4c19..6a51ba51f 100644 --- a/src/Orchard/Tasks/BackgroundService.cs +++ b/src/Orchard/Tasks/BackgroundService.cs @@ -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 _tasks; private readonly ITransactionManager _transactionManager; - private readonly IBackgroundHttpContextFactory _backgroundHttpContextFactory; private readonly string _shellName; public BackgroundService( - IEnumerable tasks, - ITransactionManager transactionManager, + IEnumerable 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 {