diff --git a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs index a71c449bb8..cf2667c121 100644 --- a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs +++ b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs @@ -23,5 +23,8 @@ namespace Umbraco.Core.Hosting /// Terminates the current application. The application restarts the next time a request is received for it. /// void LazyRestartApplication(); + + void RegisterObject(IRegisteredObject registeredObject); + void UnregisterObject(IRegisteredObject registeredObject); } } diff --git a/src/Umbraco.Abstractions/IRegisteredObject.cs b/src/Umbraco.Abstractions/IRegisteredObject.cs new file mode 100644 index 0000000000..abe52e2350 --- /dev/null +++ b/src/Umbraco.Abstractions/IRegisteredObject.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Core +{ + public interface IRegisteredObject + { + void Stop(bool immediate); + } +} diff --git a/src/Umbraco.Core/Properties/AssemblyInfo.cs b/src/Umbraco.Core/Properties/AssemblyInfo.cs deleted file mode 100644 index 87e0732d47..0000000000 --- a/src/Umbraco.Core/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Umbraco.Core")] -[assembly: AssemblyDescription("Umbraco Core")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyProduct("Umbraco CMS")] - -[assembly: ComVisible(false)] -[assembly: Guid("130a6b5c-50e7-4df3-a0dd-e9e7eb0b7c5c")] - -// Umbraco Cms -[assembly: InternalsVisibleTo("Umbraco.Web")] -[assembly: InternalsVisibleTo("Umbraco.Web.UI")] -[assembly: InternalsVisibleTo("Umbraco.Examine")] -[assembly: InternalsVisibleTo("Umbraco.ModelsBuilder.Embedded")] - -[assembly: InternalsVisibleTo("Umbraco.Tests")] -[assembly: InternalsVisibleTo("Umbraco.Tests.Benchmarks")] - -// Allow this to be mocked in our unit tests -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] - -// Umbraco Deploy -[assembly: InternalsVisibleTo("Umbraco.Deploy")] -[assembly: InternalsVisibleTo("Umbraco.Deploy.UI")] -[assembly: InternalsVisibleTo("Umbraco.Deploy.Cloud")] - -// Umbraco Forms -[assembly: InternalsVisibleTo("Umbraco.Forms.Core")] -[assembly: InternalsVisibleTo("Umbraco.Forms.Core.Providers")] -[assembly: InternalsVisibleTo("Umbraco.Forms.Web")] - -// Umbraco Headless -[assembly: InternalsVisibleTo("Umbraco.Cloud.Headless")] - -// code analysis -// IDE1006 is broken, wants _value syntax for consts, etc - and it's even confusing ppl at MS, kill it -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "~_~")] diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj deleted file mode 100755 index e1df95ff6f..0000000000 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ /dev/null @@ -1,145 +0,0 @@ - - - - - v4.7.2 - false - {31785BC3-256C-4613-B2F5-A1B0BDDED8C1} - Library - Umbraco.Core - Umbraco.Core - ..\ - - $(AdditionalFileItemNames);Content - - - true - portable - false - bin\Debug\ - TRACE;DEBUG - prompt - 4 - false - latest - - - portable - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\Umbraco.Core.xml - false - latest - - - - - - - - - - - - - - - - - - - - - - 1.0.0-beta2-19324-01 - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - 3.3.0 - runtime; build; native; contentfiles; analyzers - all - - - 1.4.0 - - - 1.0.0 - - - 4.6.0 - - - 1.0.5 - runtime; build; native; contentfiles; analyzers - all - - - - - - 2.2.2 - - - 5.2.7 - - - 4.0.1 - - - - - - 2.9.0 - - - 2.0.1 - - - 3.1.0 - - - 2.0.0 - - - 1.1.0 - - - 1.0.3 - - - 2.2.2 - - - 4.1.0 - - - - - - - - Properties\SolutionInfo.cs - - - - - {29aa69d9-b597-4395-8d42-43b1263c240a} - Umbraco.Abstractions - - - {3ae7bf57-966b-45a5-910a-954d7c554441} - Umbraco.Infrastructure - - - - \ No newline at end of file diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index 91c200bdfe..ea3ce83f5a 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -110,10 +110,6 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions - - {31785bc3-256c-4613-b2f5-a1b0bdded8c1} - Umbraco.Core - {3ae7bf57-966b-45a5-910a-954d7c554441} Umbraco.Infrastructure diff --git a/src/Umbraco.Core/MainDom.cs b/src/Umbraco.Infrastructure/MainDom.cs similarity index 96% rename from src/Umbraco.Core/MainDom.cs rename to src/Umbraco.Infrastructure/MainDom.cs index eba7492563..be962beffc 100644 --- a/src/Umbraco.Core/MainDom.cs +++ b/src/Umbraco.Infrastructure/MainDom.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Threading; -using System.Web.Hosting; using Umbraco.Core.Hosting; using Umbraco.Core.Logging; @@ -16,11 +15,12 @@ namespace Umbraco.Core /// When an AppDomain starts, it tries to acquire the main domain status. /// When an AppDomain stops (eg the application is restarting) it should release the main domain status. /// - internal class MainDom : IMainDom, IRegisteredObject, IDisposable + public class MainDom : IMainDom, IRegisteredObject, IDisposable { #region Vars private readonly ILogger _logger; + private readonly IHostingEnvironment _hostingEnvironment; // our own lock for local consistency private object _locko = new object(); @@ -50,9 +50,11 @@ namespace Umbraco.Core // initializes a new instance of MainDom public MainDom(ILogger logger, IHostingEnvironment hostingEnvironment) { - HostingEnvironment.RegisterObject(this); + + hostingEnvironment.RegisterObject(this); _logger = logger; + _hostingEnvironment = hostingEnvironment; // HostingEnvironment.ApplicationID is null in unit tests, making ReplaceNonAlphanumericChars fail var appId = hostingEnvironment.ApplicationId?.ReplaceNonAlphanumericChars(string.Empty); @@ -216,7 +218,7 @@ namespace Umbraco.Core // The web app is stopping, need to wind down Dispose(true); - HostingEnvironment.UnregisterObject(this); + _hostingEnvironment.UnregisterObject(this); } #region IDisposable Support diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index 8e8a19c729..fe28817cba 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -10,9 +10,9 @@ using System.Text.RegularExpressions; using System.Threading; using System.Web; using System.Web.Compilation; -using System.Web.Hosting; using System.Web.WebPages.Razor; using Umbraco.Core; +using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded.Building; @@ -41,20 +41,22 @@ namespace Umbraco.ModelsBuilder.Embedded private static readonly string[] OurFiles = { "models.hash", "models.generated.cs", "all.generated.cs", "all.dll.path", "models.err" }; private readonly IModelsBuilderConfig _config; + private readonly IHostingEnvironment _hostingEnvironment; private readonly ModelsGenerationError _errors; - public PureLiveModelFactory(Lazy umbracoServices, IProfilingLogger logger, IModelsBuilderConfig config) + public PureLiveModelFactory(Lazy umbracoServices, IProfilingLogger logger, IModelsBuilderConfig config, IHostingEnvironment hostingEnvironment) { _umbracoServices = umbracoServices; _logger = logger; _config = config; + _hostingEnvironment = hostingEnvironment; _errors = new ModelsGenerationError(config); _ver = 1; // zero is for when we had no version _skipver = -1; // nothing to skip RazorBuildProvider.CodeGenerationStarted += RazorBuildProvider_CodeGenerationStarted; - if (!HostingEnvironment.IsHosted) return; + if (!_hostingEnvironment.IsHosted) return; var modelsDirectory = _config.ModelsDirectory; if (!Directory.Exists(modelsDirectory)) @@ -63,7 +65,7 @@ namespace Umbraco.ModelsBuilder.Embedded // BEWARE! if the watcher is not properly released then for some reason the // BuildManager will start confusing types - using a 'registered object' here // though we should probably plug into Umbraco's MainDom - which is internal - HostingEnvironment.RegisterObject(this); + _hostingEnvironment.RegisterObject(this); _watcher = new FileSystemWatcher(modelsDirectory); _watcher.Changed += WatcherOnChanged; _watcher.EnableRaisingEvents = true; @@ -667,7 +669,7 @@ namespace Umbraco.ModelsBuilder.Embedded { _watcher.EnableRaisingEvents = false; _watcher.Dispose(); - HostingEnvironment.UnregisterObject(this); + _hostingEnvironment.UnregisterObject(this); } #endregion diff --git a/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj b/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj index f4a1780ad2..d1eab15350 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj +++ b/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj @@ -105,10 +105,6 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions - - {31785BC3-256C-4613-B2F5-A1B0BDDED8C1} - Umbraco.Core - {3ae7bf57-966b-45a5-910a-954d7c554441} Umbraco.Infrastructure diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs index a744a8d488..f989fd3832 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs @@ -148,7 +148,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache LongRunning = true, KeepAlive = true, Hosted = false // main domain will take care of stopping the runner (see below) - }, logger); + }, logger, _hostingEnvironment); // create (and add to runner) _persisterTask = new XmlStoreFilePersister(runner, this, logger); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index c7a9d4b04f..f05acf8831 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Data; -using System.Web.Hosting; using Examine; using Moq; using NUnit.Framework; diff --git a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs index 5658434017..f10b141916 100644 --- a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs +++ b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Scheduling; @@ -18,17 +19,19 @@ namespace Umbraco.Tests.Scheduling public class BackgroundTaskRunnerTests { private ILogger _logger; + private IHostingEnvironment _hostingEnvironment; [OneTimeSetUp] public void InitializeFixture() { _logger = new ConsoleLogger(new MessageTemplates()); + _hostingEnvironment = TestHelper.GetHostingEnvironment(); } [Test] public async Task ShutdownWhenRunningWithWait() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var stopped = false; runner.Stopped += (sender, args) => { stopped = true; }; @@ -51,7 +54,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task ShutdownWhenRunningWithoutWait() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var stopped = false; runner.Stopped += (sender, args) => { stopped = true; }; @@ -78,7 +81,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task ShutdownCompletesTheRunner() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { Assert.IsFalse(runner.IsRunning); // because AutoStart is false @@ -101,7 +104,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task ShutdownFlushesTheQueue() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { MyTask t1, t2, t3; @@ -123,7 +126,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task ShutdownForceTruncatesTheQueue() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { MyTask t1, t2, t3; @@ -150,7 +153,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task ShutdownThenForce() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { Assert.IsFalse(runner.IsRunning); // because AutoStart is false @@ -185,7 +188,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task HostingStopNonImmediate() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { MyTask t; @@ -219,7 +222,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task HostingStopImmediate() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { MyTask t; @@ -254,7 +257,7 @@ namespace Umbraco.Tests.Scheduling [Test] public void Create_IsNotRunning() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { Assert.IsFalse(runner.IsRunning); } @@ -268,7 +271,7 @@ namespace Umbraco.Tests.Scheduling { AutoStart = true, KeepAlive = true // else stops! - }, _logger)) + }, _logger, _hostingEnvironment)) { Assert.IsTrue(runner.IsRunning); // because AutoStart is true await runner.StopInternal(false); // keepalive = must be stopped @@ -278,7 +281,7 @@ namespace Umbraco.Tests.Scheduling [Test] public void Create_AutoStartAndKeepAlive_IsRunning() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { AutoStart = true, KeepAlive = true }, _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { AutoStart = true, KeepAlive = true }, _logger, _hostingEnvironment)) { Assert.IsTrue(runner.IsRunning); // because AutoStart is true Thread.Sleep(800); // for long @@ -291,7 +294,7 @@ namespace Umbraco.Tests.Scheduling public async Task Dispose_IsRunning() { BackgroundTaskRunner runner; - using (runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { AutoStart = true, KeepAlive = true }, _logger)) + using (runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { AutoStart = true, KeepAlive = true }, _logger, _hostingEnvironment)) { Assert.IsTrue(runner.IsRunning); // dispose will stop it @@ -315,7 +318,7 @@ namespace Umbraco.Tests.Scheduling [Test] public void Startup_KeepAlive_IsRunning() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true }, _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true }, _logger, _hostingEnvironment)) { Assert.IsFalse(runner.IsRunning); runner.StartUp(); @@ -327,7 +330,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task Create_AddTask_IsRunning() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var waitHandle = new ManualResetEvent(false); runner.TaskCompleted += (sender, args) => @@ -345,7 +348,7 @@ namespace Umbraco.Tests.Scheduling [Test] public void Create_KeepAliveAndAddTask_IsRunning() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true }, _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true }, _logger, _hostingEnvironment)) { var waitHandle = new ManualResetEvent(false); runner.TaskCompleted += (sender, args) => @@ -363,7 +366,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task WaitOnRunner_OneTask() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var task = new MyTask(); Assert.IsTrue(task.Ended == default(DateTime)); @@ -382,7 +385,7 @@ namespace Umbraco.Tests.Scheduling for (var i = 0; i < 10; i++) tasks.Add(new MyTask()); - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = false, LongRunning = true, PreserveRunningTask = true }, _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = false, LongRunning = true, PreserveRunningTask = true }, _logger, _hostingEnvironment)) { tasks.ForEach(runner.Add); @@ -400,7 +403,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task WaitOnTask() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var task = new MyTask(); var waitHandle = new ManualResetEvent(false); @@ -420,7 +423,7 @@ namespace Umbraco.Tests.Scheduling for (var i = 0; i < 10; i++) tasks.Add(new MyTask(), new ManualResetEvent(false)); - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { runner.TaskCompleted += (sender, task) => tasks[task.Task].Set(); foreach (var t in tasks) runner.Add(t.Key); @@ -449,7 +452,7 @@ namespace Umbraco.Tests.Scheduling IDictionary tasks = getTasks(); BackgroundTaskRunner tManager; - using (tManager = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { LongRunning = true, KeepAlive = true }, _logger)) + using (tManager = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { LongRunning = true, KeepAlive = true }, _logger, _hostingEnvironment)) { tManager.TaskCompleted += (sender, task) => tasks[task.Task].Set(); @@ -495,7 +498,7 @@ namespace Umbraco.Tests.Scheduling List tasks = getTasks(); - using (var tManager = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { LongRunning = true, PreserveRunningTask = true }, _logger)) + using (var tManager = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { LongRunning = true, PreserveRunningTask = true }, _logger, _hostingEnvironment)) { tasks.ForEach(tManager.Add); @@ -537,7 +540,7 @@ namespace Umbraco.Tests.Scheduling { var runCount = 0; var waitHandle = new ManualResetEvent(false); - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { runner.TaskCompleted += (sender, args) => { @@ -568,7 +571,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task LatchedTaskRuns() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var task = new MyLatchedTask(200, false); runner.Add(task); @@ -588,7 +591,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task LatchedTaskStops_Runs_On_Shutdown() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var task = new MyLatchedTask(200, true); runner.Add(task); @@ -608,7 +611,7 @@ namespace Umbraco.Tests.Scheduling { var runCount = 0; var waitHandle = new ManualResetEvent(false); - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { runner.TaskCompleted += (sender, args) => { @@ -635,7 +638,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task FailingTaskSync() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var exceptions = new ConcurrentQueue(); runner.TaskError += (sender, args) => exceptions.Enqueue(args.Exception); @@ -652,7 +655,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task FailingTaskDisposing() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var exceptions = new ConcurrentQueue(); runner.TaskError += (sender, args) => exceptions.Enqueue(args.Exception); @@ -669,7 +672,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task FailingTaskAsync() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var exceptions = new ConcurrentQueue(); runner.TaskError += (sender, args) => exceptions.Enqueue(args.Exception); @@ -685,7 +688,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task FailingTaskDisposingAsync() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var exceptions = new ConcurrentQueue(); runner.TaskError += (sender, args) => exceptions.Enqueue(args.Exception); @@ -702,7 +705,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task CancelAsyncTask() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var task = new MyAsyncTask(4000); runner.Add(task); @@ -718,7 +721,7 @@ namespace Umbraco.Tests.Scheduling [Test] public async Task CancelLatchedTask() { - using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger)) + using (var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions(), _logger, _hostingEnvironment)) { var task = new MyLatchedTask(4000, false); runner.Add(task); @@ -931,7 +934,7 @@ namespace Umbraco.Tests.Scheduling [Test] public void SourceTaskTest() { - var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, _logger); + var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, _logger, TestHelper.GetHostingEnvironment()); var task = new SourceTask(); runner.Add(task); diff --git a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs index 6a65f3afbc..c65c7e3efb 100644 --- a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs +++ b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Scheduling public async Task ThreadResumeIssue() { var logger = new DebugDiagnosticsLogger(new MessageTemplates()); - var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger); + var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger, TestHelper.GetHostingEnvironment()); var work = new ThreadResumeIssueWorkItem(); runner.Add(work); @@ -77,7 +77,7 @@ namespace Umbraco.Tests.Scheduling public async Task DebuggerInterferenceIssue() { var logger = new DebugDiagnosticsLogger(new MessageTemplates()); - var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger); + var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger, TestHelper.GetHostingEnvironment()); var taskCompleted = false; runner.TaskCompleted += (sender, args) => { diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 1556d0999f..18fe0b2882 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -354,7 +354,7 @@ namespace Umbraco.Tests.Testing { return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(hostingEnvironment.LocalTempPath), logger, false, new[] { - Assembly.Load("Umbraco.Core"), + Assembly.Load("Umbraco.Abstractions"), Assembly.Load("Umbraco.Web"), Assembly.Load("Umbraco.Tests"), Assembly.Load("Umbraco.Infrastructure") diff --git a/src/Umbraco.Web.UI/config/serilog.Release.config b/src/Umbraco.Web.UI/config/serilog.Release.config index 4d9151b2fd..e3cf52b3c5 100644 --- a/src/Umbraco.Web.UI/config/serilog.Release.config +++ b/src/Umbraco.Web.UI/config/serilog.Release.config @@ -17,7 +17,7 @@ - + diff --git a/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs b/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs index 6dfad8c45b..66e52dcece 100644 --- a/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs +++ b/src/Umbraco.Web/Compose/DatabaseServerRegistrarAndMessengerComponent.cs @@ -2,6 +2,7 @@ using System.Threading; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; @@ -89,7 +90,7 @@ namespace Umbraco.Web.Compose private IBackgroundTask[] _tasks; private IndexRebuilder _indexRebuilder; - public DatabaseServerRegistrarAndMessengerComponent(IRuntimeState runtime, IServerRegistrar serverRegistrar, IServerMessenger serverMessenger, IServerRegistrationService registrationService, ILogger logger, IndexRebuilder indexRebuilder) + public DatabaseServerRegistrarAndMessengerComponent(IRuntimeState runtime, IServerRegistrar serverRegistrar, IServerMessenger serverMessenger, IServerRegistrationService registrationService, ILogger logger, IHostingEnvironment hostingEnvironment, IndexRebuilder indexRebuilder) { _runtime = runtime; _logger = logger; @@ -101,7 +102,7 @@ namespace Umbraco.Web.Compose if (_registrar != null) { _touchTaskRunner = new BackgroundTaskRunner("ServerRegistration", - new BackgroundTaskRunnerOptions { AutoStart = true }, logger); + new BackgroundTaskRunnerOptions { AutoStart = true }, logger, hostingEnvironment); } // create task runner for BatchedDatabaseServerMessenger @@ -109,7 +110,7 @@ namespace Umbraco.Web.Compose if (_messenger != null) { _processTaskRunner = new BackgroundTaskRunner("ServerInstProcess", - new BackgroundTaskRunnerOptions { AutoStart = true }, logger); + new BackgroundTaskRunnerOptions { AutoStart = true }, logger, hostingEnvironment); } } diff --git a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs index 2da1c19948..7d10598e2a 100644 --- a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs @@ -1,10 +1,13 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.Web; using System.Web.Hosting; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.IO; +using IRegisteredObject = Umbraco.Core.IRegisteredObject; namespace Umbraco.Web.Hosting { @@ -44,6 +47,23 @@ namespace Umbraco.Web.Hosting HttpRuntime.UnloadAppDomain(); } + private IDictionary RegisteredObjects { get; } = new Dictionary(); + + public void RegisterObject(IRegisteredObject registeredObject) + { + var wrapped = new RegisteredObjectWrapper(registeredObject); + RegisteredObjects.Add(registeredObject, wrapped); + + HostingEnvironment.RegisterObject(wrapped); + } + + public void UnregisterObject(IRegisteredObject registeredObject) + { + if (RegisteredObjects.TryGetValue(registeredObject, out var wrapped)) + { + HostingEnvironment.UnregisterObject(wrapped); + } + } public string LocalTempPath { @@ -82,6 +102,21 @@ namespace Umbraco.Web.Hosting } } } + private class RegisteredObjectWrapper : System.Web.Hosting.IRegisteredObject + { + private readonly IRegisteredObject _inner; + public RegisteredObjectWrapper(IRegisteredObject inner) + { + _inner = inner; + } + + public void Stop(bool immediate) + { + _inner.Stop(immediate); + } + } } + + } diff --git a/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs b/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs index c0475b1f79..e51edccb8b 100644 --- a/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs +++ b/src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks.Dataflow; using System.Web.Hosting; using Umbraco.Core; using Umbraco.Core.Events; +using Umbraco.Core.Hosting; using Umbraco.Core.Logging; namespace Umbraco.Web.Scheduling @@ -81,6 +82,7 @@ namespace Umbraco.Web.Scheduling private readonly string _logPrefix; private readonly BackgroundTaskRunnerOptions _options; private readonly ILogger _logger; + private readonly IHostingEnvironment _hostingEnvironment; private readonly object _locker = new object(); private readonly BufferBlock _tasks = new BufferBlock(new DataflowBlockOptions()); @@ -102,9 +104,10 @@ namespace Umbraco.Web.Scheduling /// Initializes a new instance of the class. /// /// A logger. + /// The hosting environment /// An optional main domain hook. - public BackgroundTaskRunner(ILogger logger, MainDomHook hook = null) - : this(typeof(T).FullName, new BackgroundTaskRunnerOptions(), logger, hook) + public BackgroundTaskRunner(ILogger logger, IHostingEnvironment hostingEnvironment, MainDomHook hook = null) + : this(typeof(T).FullName, new BackgroundTaskRunnerOptions(), logger, hostingEnvironment, hook) { } /// @@ -112,9 +115,10 @@ namespace Umbraco.Web.Scheduling /// /// The name of the runner. /// A logger. + /// The hosting environment /// An optional main domain hook. - public BackgroundTaskRunner(string name, ILogger logger, MainDomHook hook = null) - : this(name, new BackgroundTaskRunnerOptions(), logger, hook) + public BackgroundTaskRunner(string name, ILogger logger, IHostingEnvironment hostingEnvironment, MainDomHook hook = null) + : this(name, new BackgroundTaskRunnerOptions(), logger, hostingEnvironment, hook) { } /// @@ -122,9 +126,10 @@ namespace Umbraco.Web.Scheduling /// /// The set of options. /// A logger. + /// The hosting environment /// An optional main domain hook. - public BackgroundTaskRunner(BackgroundTaskRunnerOptions options, ILogger logger, MainDomHook hook = null) - : this(typeof(T).FullName, options, logger, hook) + public BackgroundTaskRunner(BackgroundTaskRunnerOptions options, ILogger logger, IHostingEnvironment hostingEnvironment, MainDomHook hook = null) + : this(typeof(T).FullName, options, logger, hostingEnvironment, hook) { } /// @@ -133,15 +138,17 @@ namespace Umbraco.Web.Scheduling /// The name of the runner. /// The set of options. /// A logger. + /// The hosting environment /// An optional main domain hook. - public BackgroundTaskRunner(string name, BackgroundTaskRunnerOptions options, ILogger logger, MainDomHook hook = null) + public BackgroundTaskRunner(string name, BackgroundTaskRunnerOptions options, ILogger logger, IHostingEnvironment hostingEnvironment, MainDomHook hook = null) { _options = options ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _hostingEnvironment = hostingEnvironment; _logPrefix = "[" + name + "] "; if (options.Hosted) - HostingEnvironment.RegisterObject(this); + _hostingEnvironment.RegisterObject(this); if (hook != null) _completed = _terminated = hook.Register() == false; @@ -212,7 +219,7 @@ namespace Umbraco.Web.Scheduling /// /// Used to wait until the runner has terminated. /// - /// The only time the runner will be terminated is by the Hosting Environment when the application is being shutdown. + /// The only time the runner will be terminated is by the Hosting Environment when the application is being shutdown. /// /// internal ThreadingTaskImmutable TerminatedAwaitable @@ -350,14 +357,14 @@ namespace Umbraco.Web.Scheduling if (force) { - // we must bring everything down, now + // we must bring everything down, now lock (_locker) { // was Complete() enough? // if _tasks.Complete() ended up triggering code to stop the runner and reset // the _isRunning flag, then there's no need to initiate a cancel on the cancelation token. if (_isRunning == false) - return; + return; } // try to cancel running async tasks (cannot do much about sync tasks) @@ -805,7 +812,7 @@ namespace Umbraco.Web.Scheduling if (immediate) { //only unregister when it's the final call, else we won't be notified of the final call - HostingEnvironment.UnregisterObject(this); + _hostingEnvironment.UnregisterObject(this); } if (_terminated) return; // already taken care of diff --git a/src/Umbraco.Web/Scheduling/IBackgroundTaskRunner.cs b/src/Umbraco.Web/Scheduling/IBackgroundTaskRunner.cs index 9dd5722592..8cbf5fc8d6 100644 --- a/src/Umbraco.Web/Scheduling/IBackgroundTaskRunner.cs +++ b/src/Umbraco.Web/Scheduling/IBackgroundTaskRunner.cs @@ -1,5 +1,5 @@ using System; -using System.Web.Hosting; +using Umbraco.Core; namespace Umbraco.Web.Scheduling { diff --git a/src/Umbraco.Web/Scheduling/SchedulerComponent.cs b/src/Umbraco.Web/Scheduling/SchedulerComponent.cs index f719a82e4e..fc47eccae3 100644 --- a/src/Umbraco.Web/Scheduling/SchedulerComponent.cs +++ b/src/Umbraco.Web/Scheduling/SchedulerComponent.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Hosting; using Umbraco.Core.Logging; using Umbraco.Core.Scoping; using Umbraco.Core.Services; @@ -26,6 +27,7 @@ namespace Umbraco.Web.Scheduling private readonly IContentService _contentService; private readonly IAuditService _auditService; private readonly IProfilingLogger _logger; + private readonly IHostingEnvironment _hostingEnvironment; private readonly IScopeProvider _scopeProvider; private readonly HealthCheckCollection _healthChecks; private readonly HealthCheckNotificationMethodCollection _notifications; @@ -45,13 +47,14 @@ namespace Umbraco.Web.Scheduling public SchedulerComponent(IRuntimeState runtime, IContentService contentService, IAuditService auditService, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, - IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger) + IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger, IHostingEnvironment hostingEnvironment) { _runtime = runtime; _contentService = contentService; _auditService = auditService; _scopeProvider = scopeProvider; _logger = logger; + _hostingEnvironment = hostingEnvironment; _umbracoContextFactory = umbracoContextFactory; _healthChecks = healthChecks; @@ -61,12 +64,12 @@ namespace Umbraco.Web.Scheduling public void Initialize() { // backgrounds runners are web aware, if the app domain dies, these tasks will wind down correctly - _keepAliveRunner = new BackgroundTaskRunner("KeepAlive", _logger); - _publishingRunner = new BackgroundTaskRunner("ScheduledPublishing", _logger); - _tasksRunner = new BackgroundTaskRunner("ScheduledTasks", _logger); - _scrubberRunner = new BackgroundTaskRunner("LogScrubber", _logger); - _fileCleanupRunner = new BackgroundTaskRunner("TempFileCleanup", _logger); - _healthCheckRunner = new BackgroundTaskRunner("HealthCheckNotifier", _logger); + _keepAliveRunner = new BackgroundTaskRunner("KeepAlive", _logger, _hostingEnvironment); + _publishingRunner = new BackgroundTaskRunner("ScheduledPublishing", _logger, _hostingEnvironment); + _tasksRunner = new BackgroundTaskRunner("ScheduledTasks", _logger, _hostingEnvironment); + _scrubberRunner = new BackgroundTaskRunner("LogScrubber", _logger, _hostingEnvironment); + _fileCleanupRunner = new BackgroundTaskRunner("TempFileCleanup", _logger, _hostingEnvironment); + _healthCheckRunner = new BackgroundTaskRunner("HealthCheckNotifier", _logger, _hostingEnvironment); // we will start the whole process when a successful request is made UmbracoModule.RouteAttempt += RegisterBackgroundTasksOnce; diff --git a/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs b/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs index 0ae5ceade9..9f83b97393 100644 --- a/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs +++ b/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs @@ -4,6 +4,7 @@ using Umbraco.Core.Logging; using Umbraco.Examine; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Hosting; using Umbraco.Web.Scheduling; namespace Umbraco.Web.Search @@ -17,12 +18,14 @@ namespace Umbraco.Web.Search private readonly IndexRebuilder _indexRebuilder; private readonly IMainDom _mainDom; private readonly IProfilingLogger _logger; + private readonly IHostingEnvironment _hostingEnvironment; private static BackgroundTaskRunner _rebuildOnStartupRunner; - public BackgroundIndexRebuilder(IMainDom mainDom, IProfilingLogger logger, IndexRebuilder indexRebuilder) + public BackgroundIndexRebuilder(IMainDom mainDom, IProfilingLogger logger, IHostingEnvironment hostingEnvironment, IndexRebuilder indexRebuilder) { _mainDom = mainDom; _logger = logger; + _hostingEnvironment = hostingEnvironment; _indexRebuilder = indexRebuilder; } @@ -51,7 +54,7 @@ namespace Umbraco.Web.Search _rebuildOnStartupRunner = new BackgroundTaskRunner( "RebuildIndexesOnStartup", - _logger); + _logger, _hostingEnvironment); _rebuildOnStartupRunner.TryAdd(task); } diff --git a/src/umbraco.sln b/src/umbraco.sln index 1a83587ab8..96897e0d27 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -60,8 +60,6 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Umbraco.Web.UI.Client", "ht EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Web", "Umbraco.Web\Umbraco.Web.csproj", "{651E1350-91B6-44B7-BD60-7207006D7003}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Core", "Umbraco.Core\Umbraco.Core.csproj", "{31785BC3-256C-4613-B2F5-A1B0BDDED8C1}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Tests", "Umbraco.Tests\Umbraco.Tests.csproj", "{5D3B8245-ADA6-453F-A008-50ED04BFE770}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Examine", "Umbraco.Examine\Umbraco.Examine.csproj", "{07FBC26B-2927-4A22-8D96-D644C667FECC}" @@ -128,10 +126,6 @@ Global {651E1350-91B6-44B7-BD60-7207006D7003}.Debug|Any CPU.Build.0 = Debug|Any CPU {651E1350-91B6-44B7-BD60-7207006D7003}.Release|Any CPU.ActiveCfg = Release|Any CPU {651E1350-91B6-44B7-BD60-7207006D7003}.Release|Any CPU.Build.0 = Release|Any CPU - {31785BC3-256C-4613-B2F5-A1B0BDDED8C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {31785BC3-256C-4613-B2F5-A1B0BDDED8C1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {31785BC3-256C-4613-B2F5-A1B0BDDED8C1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {31785BC3-256C-4613-B2F5-A1B0BDDED8C1}.Release|Any CPU.Build.0 = Release|Any CPU {5D3B8245-ADA6-453F-A008-50ED04BFE770}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5D3B8245-ADA6-453F-A008-50ED04BFE770}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D3B8245-ADA6-453F-A008-50ED04BFE770}.Release|Any CPU.ActiveCfg = Release|Any CPU