From 28ecb355dd07d87cd660636e2a405b4fb9f7ef34 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 4 Dec 2019 14:03:39 +0100 Subject: [PATCH] Let IOHelper use IHostingEnvironment --- .../Composing/Composition.cs | 11 +++- .../Hosting/IHostingEnvironment.cs | 4 ++ src/Umbraco.Abstractions/IO/IIOHelper.cs | 5 -- src/Umbraco.Core/Composing/Current.cs | 2 +- src/Umbraco.Core/IO/IOHelper.cs | 39 +++++++----- src/Umbraco.Core/Logging/LogHttpRequest.cs | 6 +- .../Enrichers/HttpRequestIdEnricher.cs | 18 +++++- .../Enrichers/HttpRequestNumberEnricher.cs | 15 +++-- .../Enrichers/HttpSessionIdEnricher.cs | 6 +- .../Logging/Serilog/LoggerConfigExtensions.cs | 8 +-- .../Logging/Serilog/SerilogLogger.cs | 6 +- .../DropDownPropertyEditorsMigration.cs | 11 +++- .../MergeDateAndDateTimePropertyEditor.cs | 11 +++- .../V_8_0_0/PropertyEditorsMigrationBase.cs | 7 ++- ...adioAndCheckboxPropertyEditorsMigration.cs | 11 +++- .../Persistence/Factories/DataTypeFactory.cs | 5 +- .../Implement/DataTypeRepository.cs | 9 ++- .../ConfigurationEditorOfTConfiguration.cs | 9 +-- .../LabelConfigurationEditor.cs | 7 +++ .../PropertyEditors/LabelPropertyEditor.cs | 11 +++- src/Umbraco.Core/Runtime/CoreRuntime.cs | 2 +- src/Umbraco.Core/UriExtensions.cs | 12 ++-- .../Compose/ModelsBuilderComposer.cs | 4 +- .../Configuration/ModelsBuilderConfig.cs | 12 ++-- .../DistributedCache/DistributedCacheTests.cs | 2 +- .../Cache/DistributedCacheBinderTests.cs | 3 +- .../PublishedContentCacheTests.cs | 4 +- .../Components/ComponentTests.cs | 29 ++++----- .../Composing/CollectionBuildersTests.cs | 3 +- .../Composing/CompositionTests.cs | 2 +- .../Composing/LazyCollectionBuilderTests.cs | 10 ++-- .../Composing/PackageActionCollectionTests.cs | 3 +- .../CoreThings/UriExtensionsTests.cs | 7 ++- src/Umbraco.Tests/IO/FileSystemsTests.cs | 3 +- .../Models/ContentExtensionsTests.cs | 3 +- src/Umbraco.Tests/Models/ContentTests.cs | 3 +- .../Mapping/ContentTypeModelMappingTests.cs | 3 +- .../Mapping/ContentWebModelMappingTests.cs | 2 +- .../ModelsBuilder/ConfigTests.cs | 7 ++- .../Packaging/PackageExtractionTests.cs | 3 +- .../DataTypeDefinitionRepositoryTest.cs | 20 +++---- .../Repositories/DocumentRepositoryTest.cs | 2 +- .../PropertyEditors/ColorListValidatorTest.cs | 7 ++- .../EnsureUniqueValuesValidatorTest.cs | 11 ++-- .../PropertyEditors/ImageCropperTest.cs | 4 +- .../MultiValuePropertyEditorTests.cs | 6 +- .../PropertyEditorValueEditorTests.cs | 3 +- .../Published/ConvertersTests.cs | 3 +- .../Published/NestedContentTests.cs | 4 +- .../PublishedContentSnapshotTestBase.cs | 3 +- .../PublishedContentTestBase.cs | 2 +- .../PublishedContent/PublishedContentTests.cs | 8 +-- .../Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 4 +- .../Runtimes/WebRuntimeComponentTests.cs | 6 +- .../Scoping/ScopeEventDispatcherTests.cs | 3 +- .../Scoping/ScopedNuCacheTests.cs | 3 +- .../Security/BackOfficeCookieManagerTests.cs | 9 +-- .../Services/CachedDataTypeServiceTests.cs | 4 +- .../Services/DataTypeServiceTests.cs | 8 +-- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- .../TestControllerActivatorBase.cs | 3 +- .../TestHelpers/SettingsForTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 4 +- .../TestHelpers/TestObjects-Mocks.cs | 3 +- .../TestHelpers/TestWithDatabaseBase.cs | 3 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 4 +- ...RenderIndexActionSelectorAttributeTests.cs | 12 ++-- .../Web/Mvc/SurfaceControllerTests.cs | 12 ++-- .../Web/Mvc/UmbracoViewPageTests.cs | 3 +- .../Web/TemplateUtilitiesTests.cs | 5 +- .../Web/WebExtensionMethodTests.cs | 9 ++- .../Composing/BuildManagerTypeFinder.cs | 8 ++- .../Hosting/AspNetHostingEnvironment.cs | 26 ++++---- src/Umbraco.Web/Mvc/RenderViewEngine.cs | 10 +++- src/Umbraco.Web/Mvc/UmbracoViewPage.cs | 7 ++- .../Mvc/UmbracoViewPageOfTModel.cs | 13 ++++ .../CheckBoxListPropertyEditor.cs | 7 ++- .../ColorPickerConfigurationEditor.cs | 5 +- .../ColorPickerPropertyEditor.cs | 11 +++- .../ContentPickerConfigurationEditor.cs | 5 +- .../ContentPickerPropertyEditor.cs | 11 +++- .../DateTimeConfigurationEditor.cs | 5 ++ .../PropertyEditors/DateTimePropertyEditor.cs | 11 +++- .../DropDownFlexibleConfigurationEditor.cs | 7 ++- .../DropDownFlexiblePropertyEditor.cs | 7 ++- .../EmailAddressConfigurationEditor.cs | 11 +++- .../EmailAddressPropertyEditor.cs | 8 ++- .../GridConfigurationEditor.cs | 3 +- .../PropertyEditors/GridPropertyEditor.cs | 7 ++- .../ImageCropperConfigurationEditor.cs | 7 ++- .../ImageCropperPropertyEditor.cs | 6 +- .../ListViewConfigurationEditor.cs | 9 ++- .../PropertyEditors/ListViewPropertyEditor.cs | 11 +++- .../MarkdownConfigurationEditor.cs | 11 +++- .../PropertyEditors/MarkdownPropertyEditor.cs | 11 +++- .../MediaPickerConfigurationEditor.cs | 3 +- .../MediaPickerPropertyEditor.cs | 11 +++- .../MultiNodePickerConfigurationEditor.cs | 3 +- .../MultiNodeTreePickerPropertyEditor.cs | 13 ++-- .../MultiUrlPickerConfigurationEditor.cs | 4 ++ .../MultiUrlPickerPropertyEditor.cs | 7 ++- .../MultipleTextStringConfigurationEditor.cs | 3 +- .../MultipleTextStringPropertyEditor.cs | 11 +++- .../NestedContentConfigurationEditor.cs | 9 ++- .../NestedContentPropertyEditor.cs | 7 ++- .../RadioButtonsPropertyEditor.cs | 7 ++- .../RichTextConfigurationEditor.cs | 9 ++- .../PropertyEditors/RichTextPropertyEditor.cs | 8 ++- .../SliderConfigurationEditor.cs | 11 +++- .../PropertyEditors/SliderPropertyEditor.cs | 11 +++- .../PropertyEditors/TagConfigurationEditor.cs | 3 +- .../PropertyEditors/TagsPropertyEditor.cs | 7 ++- .../TextAreaConfigurationEditor.cs | 9 ++- .../PropertyEditors/TextAreaPropertyEditor.cs | 7 ++- .../TextboxConfigurationEditor.cs | 11 +++- .../PropertyEditors/TextboxPropertyEditor.cs | 7 ++- .../TrueFalseConfigurationEditor.cs | 11 +++- .../TrueFalsePropertyEditor.cs | 11 +++- .../RteMacroRenderingValueConverter.cs | 3 +- .../ValueListConfigurationEditor.cs | 3 +- .../Runtime/WebInitialComponent.cs | 10 ++-- src/Umbraco.Web/Runtime/WebRuntime.cs | 2 +- .../Security/AppBuilderExtensions.cs | 59 +++++++++++++------ .../BackOfficeCookieAuthenticationProvider.cs | 7 ++- .../Security/BackOfficeCookieManager.cs | 13 ++-- .../PreviewAuthenticationMiddleware.cs | 7 ++- .../Security/SessionIdValidator.cs | 5 +- .../UmbracoBackOfficeCookieAuthOptions.cs | 6 +- src/Umbraco.Web/UmbracoApplicationBase.cs | 15 +++-- src/Umbraco.Web/UmbracoContext.cs | 8 ++- src/Umbraco.Web/UmbracoContextFactory.cs | 7 ++- src/Umbraco.Web/UmbracoDefaultOwinStartup.cs | 8 ++- src/Umbraco.Web/UmbracoInjectedModule.cs | 4 +- 134 files changed, 697 insertions(+), 352 deletions(-) diff --git a/src/Umbraco.Abstractions/Composing/Composition.cs b/src/Umbraco.Abstractions/Composing/Composition.cs index 8cf02151e8..a186a1f00a 100644 --- a/src/Umbraco.Abstractions/Composing/Composition.cs +++ b/src/Umbraco.Abstractions/Composing/Composition.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Core.Logging; namespace Umbraco.Core.Composing @@ -19,6 +21,7 @@ namespace Umbraco.Core.Composing private readonly Dictionary> _uniques = new Dictionary>(); private readonly IRegister _register; + /// /// Initializes a new instance of the class. /// @@ -27,13 +30,16 @@ namespace Umbraco.Core.Composing /// A logger. /// The runtime state. /// Optional configs. - public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs) + /// An IOHelper + public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs, IIOHelper ioHelper, AppCaches appCaches) { _register = register; TypeLoader = typeLoader; Logger = logger; RuntimeState = runtimeState; Configs = configs; + IOHelper = ioHelper; + AppCaches = appCaches; } #region Services @@ -43,6 +49,9 @@ namespace Umbraco.Core.Composing /// public IProfilingLogger Logger { get; } + public IIOHelper IOHelper { get; } + public AppCaches AppCaches { get; } + /// /// Gets the type loader. /// diff --git a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs index 19ad5614b4..4fe8efc86d 100644 --- a/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs +++ b/src/Umbraco.Abstractions/Hosting/IHostingEnvironment.cs @@ -10,7 +10,11 @@ namespace Umbraco.Core.Hosting string ApplicationVirtualPath { get; } bool IsDebugMode { get; } + /// + /// Gets a value indicating whether Umbraco is hosted. + /// bool IsHosted { get; } string MapPath(string path); + string ToAbsolute(string virtualPath, string root); } } diff --git a/src/Umbraco.Abstractions/IO/IIOHelper.cs b/src/Umbraco.Abstractions/IO/IIOHelper.cs index b4a1007c2d..8b090f7f50 100644 --- a/src/Umbraco.Abstractions/IO/IIOHelper.cs +++ b/src/Umbraco.Abstractions/IO/IIOHelper.cs @@ -6,11 +6,6 @@ namespace Umbraco.Core.IO { bool ForceNotHosted { get; set; } - /// - /// Gets a value indicating whether Umbraco is hosted. - /// - bool IsHosted { get; } - char DirSepChar { get; } string FindFile(string virtualPath); string ResolveVirtualUrl(string path); diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index 4eba166020..4b200307e9 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -208,7 +208,7 @@ namespace Umbraco.Core.Composing public static IVariationContextAccessor VariationContextAccessor => Factory.GetInstance(); - public static IIOHelper IOHelper = new IOHelper(); + public static IIOHelper IOHelper => Factory.GetInstance(); public static IHostingEnvironment HostingEnvironment => Factory.GetInstance(); diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 450e3862f2..1b0fed9c0f 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -4,13 +4,19 @@ using System.Globalization; using System.Reflection; using System.IO; using System.Linq; -using System.Web; -using System.Web.Hosting; +using Umbraco.Core.Hosting; namespace Umbraco.Core.IO { public class IOHelper : IIOHelper { + private readonly IHostingEnvironment _hostingEnvironment; + + public IOHelper(IHostingEnvironment hostingEnvironment) + { + _hostingEnvironment = hostingEnvironment; + } + /// /// Gets or sets a value forcing Umbraco to consider it is non-hosted. /// @@ -22,10 +28,6 @@ namespace Umbraco.Core.IO // static compiled regex for faster performance //private static readonly Regex ResolveUrlPattern = new Regex("(=[\"\']?)(\\W?\\~(?:.(?![\"\']?\\s+(?:\\S+)=|[>\"\']))+.)[\"\']?", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); - /// - /// Gets a value indicating whether Umbraco is hosted. - /// - public bool IsHosted => !ForceNotHosted && (HttpContext.Current != null || HostingEnvironment.IsHosted); public char DirSepChar => Path.DirectorySeparatorChar; @@ -57,7 +59,7 @@ namespace Umbraco.Core.IO else if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) return virtualPath; else - return VirtualPathUtility.ToAbsolute(virtualPath, Root); + return _hostingEnvironment.ToAbsolute(virtualPath, Root); } public Attempt TryResolveUrl(string virtualPath) @@ -68,7 +70,7 @@ namespace Umbraco.Core.IO return Attempt.Succeed(virtualPath.Replace("~", Root).Replace("//", "/")); if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) return Attempt.Succeed(virtualPath); - return Attempt.Succeed(VirtualPathUtility.ToAbsolute(virtualPath, Root)); + return Attempt.Succeed(_hostingEnvironment.ToAbsolute(virtualPath, Root)); } catch (Exception ex) { @@ -79,7 +81,7 @@ namespace Umbraco.Core.IO public string MapPath(string path, bool useHttpContext) { if (path == null) throw new ArgumentNullException("path"); - useHttpContext = useHttpContext && IsHosted; + useHttpContext = useHttpContext && _hostingEnvironment.IsHosted; // Check if the path is already mapped if ((path.Length >= 2 && path[1] == Path.VolumeSeparatorChar) @@ -90,15 +92,20 @@ namespace Umbraco.Core.IO // Check that we even have an HttpContext! otherwise things will fail anyways // http://umbraco.codeplex.com/workitem/30946 - if (useHttpContext && HttpContext.Current != null) + + if (useHttpContext && _hostingEnvironment.IsHosted) { - //string retval; - if (String.IsNullOrEmpty(path) == false && (path.StartsWith("~") || path.StartsWith(Root))) - return HostingEnvironment.MapPath(path); - else - return HostingEnvironment.MapPath("~/" + path.TrimStart('/')); + var result = (String.IsNullOrEmpty(path) == false && (path.StartsWith("~") || path.StartsWith(Root))) + ? _hostingEnvironment.MapPath(path) + : _hostingEnvironment.MapPath("~/" + path.TrimStart('/')); + + if (result != null) return result; + + } + + var root = GetRootDirectorySafe(); var newPath = path.TrimStart('~', '/').Replace('/', DirSepChar); var retval = root + DirSepChar.ToString(CultureInfo.InvariantCulture) + newPath; @@ -294,7 +301,7 @@ namespace Umbraco.Core.IO { if (_root != null) return _root; - var appPath = HostingEnvironment.ApplicationVirtualPath; + var appPath = _hostingEnvironment.ApplicationVirtualPath; // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (appPath == null || appPath == "/") appPath = string.Empty; diff --git a/src/Umbraco.Core/Logging/LogHttpRequest.cs b/src/Umbraco.Core/Logging/LogHttpRequest.cs index 01a2e922af..7e1ec38491 100644 --- a/src/Umbraco.Core/Logging/LogHttpRequest.cs +++ b/src/Umbraco.Core/Logging/LogHttpRequest.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.Cache; using Umbraco.Core.Composing; namespace Umbraco.Core.Logging @@ -11,10 +12,11 @@ namespace Umbraco.Core.Logging /// Retrieve the id assigned to the currently-executing HTTP request, if any. /// /// The request id. + /// /// true if there is a request in progress; false otherwise. - public static bool TryGetCurrentHttpRequestId(out Guid requestId) + public static bool TryGetCurrentHttpRequestId(out Guid requestId, IRequestCache requestCache) { - var requestIdItem = Current.AppCaches.RequestCache.Get(RequestIdItemName, () => Guid.NewGuid()); + var requestIdItem = requestCache.Get(RequestIdItemName, () => Guid.NewGuid()); requestId = (Guid)requestIdItem; return true; diff --git a/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestIdEnricher.cs b/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestIdEnricher.cs index 2099698b6f..f1dd04bf76 100644 --- a/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestIdEnricher.cs +++ b/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestIdEnricher.cs @@ -1,6 +1,8 @@ using System; using Serilog.Core; using Serilog.Events; +using Umbraco.Core.Cache; +using Umbraco.Core.Composing; namespace Umbraco.Core.Logging.Serilog.Enrichers { @@ -11,6 +13,13 @@ namespace Umbraco.Core.Logging.Serilog.Enrichers /// internal class HttpRequestIdEnricher : ILogEventEnricher { + private readonly Func _factoryGetter; + + public HttpRequestIdEnricher(Func factoryGetter) + { + _factoryGetter = factoryGetter; + } + /// /// The property name added to enriched log events. /// @@ -25,12 +34,17 @@ namespace Umbraco.Core.Logging.Serilog.Enrichers { if (logEvent == null) throw new ArgumentNullException("logEvent"); + var factory = _factoryGetter(); + if(factory is null) return; + + var requestCache = factory.GetInstance(); + Guid requestId; - if (!LogHttpRequest.TryGetCurrentHttpRequestId(out requestId)) + if (!LogHttpRequest.TryGetCurrentHttpRequestId(out requestId, requestCache)) return; var requestIdProperty = new LogEventProperty(HttpRequestIdPropertyName, new ScalarValue(requestId)); logEvent.AddPropertyIfAbsent(requestIdProperty); - } + } } } diff --git a/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestNumberEnricher.cs b/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestNumberEnricher.cs index 67bb3ed8d3..5142f3d30f 100644 --- a/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestNumberEnricher.cs +++ b/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpRequestNumberEnricher.cs @@ -3,6 +3,7 @@ using System.Threading; using Serilog.Core; using Serilog.Events; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; namespace Umbraco.Core.Logging.Serilog.Enrichers { @@ -14,6 +15,7 @@ namespace Umbraco.Core.Logging.Serilog.Enrichers /// internal class HttpRequestNumberEnricher : ILogEventEnricher { + private readonly Func _factoryFunc; private static int _lastRequestNumber; private static readonly string _requestNumberItemName = typeof(HttpRequestNumberEnricher).Name + "+RequestNumber"; @@ -22,11 +24,10 @@ namespace Umbraco.Core.Logging.Serilog.Enrichers /// private const string _httpRequestNumberPropertyName = "HttpRequestNumber"; - private readonly Lazy _requestCache; - public HttpRequestNumberEnricher(Lazy requestCache) + public HttpRequestNumberEnricher(Func factoryFunc) { - _requestCache = requestCache; + _factoryFunc = factoryFunc; } /// @@ -36,9 +37,13 @@ namespace Umbraco.Core.Logging.Serilog.Enrichers /// Factory for creating new properties to add to the event. public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { - if (logEvent == null) throw new ArgumentNullException("logEvent"); + if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); - var requestNumber = _requestCache.Value.Get(_requestNumberItemName, + var factory = _factoryFunc(); + if (factory is null) return; + + var requestCache = factory.GetInstance(); + var requestNumber = requestCache.Get(_requestNumberItemName, () => Interlocked.Increment(ref _lastRequestNumber)); var requestNumberProperty = new LogEventProperty(_httpRequestNumberPropertyName, new ScalarValue(requestNumber)); diff --git a/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpSessionIdEnricher.cs b/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpSessionIdEnricher.cs index 0708cb7eb5..1558cdcf21 100644 --- a/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpSessionIdEnricher.cs +++ b/src/Umbraco.Core/Logging/Serilog/Enrichers/HttpSessionIdEnricher.cs @@ -12,9 +12,9 @@ namespace Umbraco.Core.Logging.Serilog.Enrichers /// internal class HttpSessionIdEnricher : ILogEventEnricher { - private readonly Lazy _sessionIdResolver; + private readonly ISessionIdResolver _sessionIdResolver; - public HttpSessionIdEnricher(Lazy sessionIdResolver) + public HttpSessionIdEnricher(ISessionIdResolver sessionIdResolver) { _sessionIdResolver = sessionIdResolver; } @@ -32,7 +32,7 @@ namespace Umbraco.Core.Logging.Serilog.Enrichers { if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); - var sessionId = _sessionIdResolver.Value.SessionId; + var sessionId = _sessionIdResolver.SessionId; if (sessionId is null) return; diff --git a/src/Umbraco.Core/Logging/Serilog/LoggerConfigExtensions.cs b/src/Umbraco.Core/Logging/Serilog/LoggerConfigExtensions.cs index fc6b9982ad..39b02d4684 100644 --- a/src/Umbraco.Core/Logging/Serilog/LoggerConfigExtensions.cs +++ b/src/Umbraco.Core/Logging/Serilog/LoggerConfigExtensions.cs @@ -25,7 +25,7 @@ namespace Umbraco.Core.Logging.Serilog /// /// A Serilog LoggerConfiguration /// - public static LoggerConfiguration MinimalConfiguration(this LoggerConfiguration logConfig, IHostingEnvironment hostingEnvironment) + public static LoggerConfiguration MinimalConfiguration(this LoggerConfiguration logConfig, IHostingEnvironment hostingEnvironment, ISessionIdResolver sessionIdResolver, Func factoryFunc) { global::Serilog.Debugging.SelfLog.Enable(msg => System.Diagnostics.Debug.WriteLine(msg)); @@ -42,9 +42,9 @@ namespace Umbraco.Core.Logging.Serilog .Enrich.WithProperty("AppDomainAppId", hostingEnvironment.ApplicationId.ReplaceNonAlphanumericChars(string.Empty)) .Enrich.WithProperty("MachineName", Environment.MachineName) .Enrich.With() - .Enrich.With(new HttpSessionIdEnricher(new Lazy(() => Current.SessionIdResolver))) - .Enrich.With(new HttpRequestNumberEnricher(new Lazy(() => Current.AppCaches.RequestCache))) - .Enrich.With(); + .Enrich.With(new HttpSessionIdEnricher(sessionIdResolver)) + .Enrich.With(new HttpRequestNumberEnricher(factoryFunc)) + .Enrich.With(new HttpRequestIdEnricher(factoryFunc)); return logConfig; } diff --git a/src/Umbraco.Core/Logging/Serilog/SerilogLogger.cs b/src/Umbraco.Core/Logging/Serilog/SerilogLogger.cs index 40be4e0079..47623145ef 100644 --- a/src/Umbraco.Core/Logging/Serilog/SerilogLogger.cs +++ b/src/Umbraco.Core/Logging/Serilog/SerilogLogger.cs @@ -4,9 +4,11 @@ using System.Reflection; using System.Threading; using Serilog; using Serilog.Events; +using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Diagnostics; using Umbraco.Core.Hosting; +using Umbraco.Net; namespace Umbraco.Core.Logging.Serilog { @@ -36,11 +38,11 @@ namespace Umbraco.Core.Logging.Serilog /// Creates a logger with some pre-defined configuration and remainder from config file /// /// Used by UmbracoApplicationBase to get its logger. - public static SerilogLogger CreateWithDefaultConfiguration(IHostingEnvironment hostingEnvironment) + public static SerilogLogger CreateWithDefaultConfiguration(IHostingEnvironment hostingEnvironment, ISessionIdResolver sessionIdResolver, Func factoryFunc) { var loggerConfig = new LoggerConfiguration(); loggerConfig - .MinimalConfiguration(hostingEnvironment) + .MinimalConfiguration(hostingEnvironment, sessionIdResolver, factoryFunc) .ReadFromConfigFile() .ReadFromUserConfigFile(); diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs index d30719231a..243446c5df 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/DropDownPropertyEditorsMigration.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Umbraco.Core.IO; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.PropertyEditors; @@ -12,9 +13,13 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 { public class DropDownPropertyEditorsMigration : PropertyEditorsMigrationBase { - public DropDownPropertyEditorsMigration(IMigrationContext context) + private readonly IIOHelper _ioHelper; + + public DropDownPropertyEditorsMigration(IMigrationContext context, IIOHelper ioHelper) : base(context) - { } + { + _ioHelper = ioHelper; + } public override void Migrate() { @@ -39,7 +44,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 { // parse configuration, and update everything accordingly if (configurationEditor == null) - configurationEditor = new ValueListConfigurationEditor(); + configurationEditor = new ValueListConfigurationEditor(_ioHelper); try { config = (ValueListConfiguration) configurationEditor.FromDatabase(dataType.Configuration); diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs index 0d451e8460..06a7f9aeb6 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/MergeDateAndDateTimePropertyEditor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; @@ -9,9 +10,12 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 { public class MergeDateAndDateTimePropertyEditor : MigrationBase { - public MergeDateAndDateTimePropertyEditor(IMigrationContext context) + private readonly IIOHelper _ioHelper; + + public MergeDateAndDateTimePropertyEditor(IMigrationContext context, IIOHelper ioHelper) : base(context) { + _ioHelper = ioHelper; } public override void Migrate() @@ -23,7 +27,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 DateTimeConfiguration config; try { - config = (DateTimeConfiguration) new CustomDateTimeConfigurationEditor().FromDatabase( + config = (DateTimeConfiguration) new CustomDateTimeConfigurationEditor(_ioHelper).FromDatabase( dataType.Configuration); // If the Umbraco.Date type is the default from V7 and it has never been updated, then the @@ -69,6 +73,9 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 private class CustomDateTimeConfigurationEditor : ConfigurationEditor { + public CustomDateTimeConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } } } } diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs index 605f8a9eed..5ac92b7966 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/PropertyEditorsMigrationBase.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; @@ -92,6 +93,10 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 // dummy editor for deserialization protected class ValueListConfigurationEditor : ConfigurationEditor - { } + { + public ValueListConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } } } diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs index e96fa1f7e9..cdd330f190 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioAndCheckboxPropertyEditorsMigration.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.PostMigrations; using Umbraco.Core.Models; @@ -12,9 +13,13 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 { public class RadioAndCheckboxPropertyEditorsMigration : PropertyEditorsMigrationBase { - public RadioAndCheckboxPropertyEditorsMigration(IMigrationContext context) + private readonly IIOHelper _ioHelper; + + public RadioAndCheckboxPropertyEditorsMigration(IMigrationContext context, IIOHelper ioHelper) : base(context) - { } + { + _ioHelper = ioHelper; + } public override void Migrate() { @@ -43,7 +48,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 // parse configuration, and update everything accordingly if (configurationEditor == null) - configurationEditor = new ValueListConfigurationEditor(); + configurationEditor = new ValueListConfigurationEditor(_ioHelper); try { config = (ValueListConfiguration) configurationEditor.FromDatabase(dataType.Configuration); diff --git a/src/Umbraco.Core/Persistence/Factories/DataTypeFactory.cs b/src/Umbraco.Core/Persistence/Factories/DataTypeFactory.cs index f189d38d05..43ecdbd03f 100644 --- a/src/Umbraco.Core/Persistence/Factories/DataTypeFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/DataTypeFactory.cs @@ -2,6 +2,7 @@ using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Dtos; @@ -11,14 +12,14 @@ namespace Umbraco.Core.Persistence.Factories { internal static class DataTypeFactory { - public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger) + public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger, IIOHelper ioHelper) { if (!editors.TryGet(dto.EditorAlias, out var editor)) { logger.Warn(typeof(DataType), "Could not find an editor with alias {EditorAlias}, treating as Label." +" The site may fail to boot and / or load data types and run.", dto.EditorAlias); //convert to label - editor = new LabelPropertyEditor(logger); + editor = new LabelPropertyEditor(logger, ioHelper); } var dataType = new DataType(editor); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeRepository.cs index d41fbc3c2b..8e40251d6a 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeRepository.cs @@ -7,6 +7,7 @@ using NPoco; using Umbraco.Core.Cache; using Umbraco.Core.Events; using Umbraco.Core.Exceptions; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -26,12 +27,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement internal class DataTypeRepository : NPocoRepositoryBase, IDataTypeRepository { private readonly Lazy _editors; + private readonly IIOHelper _ioHelper; // TODO: https://github.com/umbraco/Umbraco-CMS/issues/4237 - get rid of Lazy injection and fix circular dependencies - public DataTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, Lazy editors, ILogger logger) + public DataTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, Lazy editors, ILogger logger, IIOHelper ioHelper) : base(scopeAccessor, cache, logger) { _editors = editors; + _ioHelper = ioHelper; } #region Overrides of RepositoryBase @@ -55,7 +58,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } var dtos = Database.Fetch(dataTypeSql); - return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger)).ToArray(); + return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger,_ioHelper)).ToArray(); } protected override IEnumerable PerformGetByQuery(IQuery query) @@ -66,7 +69,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var dtos = Database.Fetch(sql); - return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger)).ToArray(); + return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger, _ioHelper)).ToArray(); } #endregion diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs index bee923b50e..0e56e0030e 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs @@ -4,6 +4,7 @@ using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core.Composing; +using Umbraco.Core.IO; namespace Umbraco.Core.PropertyEditors { @@ -16,14 +17,14 @@ namespace Umbraco.Core.PropertyEditors /// /// Initializes a new instance of the class. /// - protected ConfigurationEditor() - : base(DiscoverFields()) + protected ConfigurationEditor(IIOHelper ioHelper) + : base(DiscoverFields(ioHelper)) { } /// /// Discovers fields from configuration properties marked with the field attribute. /// - private static List DiscoverFields() + private static List DiscoverFields(IIOHelper ioHelper) { var fields = new List(); var properties = TypeHelper.CachedDiscoverableProperties(typeof(TConfiguration)); @@ -35,7 +36,7 @@ namespace Umbraco.Core.PropertyEditors ConfigurationField field; - var attributeView = Current.IOHelper.ResolveVirtualUrl(attribute.View); + var attributeView = ioHelper.ResolveVirtualUrl(attribute.View); // if the field does not have its own type, use the base type if (attribute.Type == null) { diff --git a/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs index fc87929385..8ec2e32965 100644 --- a/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Umbraco.Core.IO; namespace Umbraco.Core.PropertyEditors { @@ -7,6 +8,10 @@ namespace Umbraco.Core.PropertyEditors /// public class LabelConfigurationEditor : ConfigurationEditor { + public LabelConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + /// public override LabelConfiguration FromConfigurationEditor(IDictionary editorValues, LabelConfiguration configuration) { @@ -24,5 +29,7 @@ namespace Umbraco.Core.PropertyEditors return newConfiguration; } + + } } diff --git a/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs index e47d35107a..f7ada3212f 100644 --- a/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Composing; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Services; @@ -14,18 +15,22 @@ namespace Umbraco.Core.PropertyEditors Icon = "icon-readonly")] public class LabelPropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// Initializes a new instance of the class. /// - public LabelPropertyEditor(ILogger logger) + public LabelPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// protected override IDataValueEditor CreateValueEditor() => new LabelPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService, Attribute); /// - protected override IConfigurationEditor CreateConfigurationEditor() => new LabelConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new LabelConfigurationEditor(_ioHelper); // provides the property value editor internal class LabelPropertyValueEditor : DataValueEditor diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index b21d3355a8..7e07748839 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -154,7 +154,7 @@ namespace Umbraco.Core.Runtime var mainDom = new MainDom(Logger, HostingEnvironment); // create the composition - composition = new Composition(register, typeLoader, ProfilingLogger, _state, Configs); + composition = new Composition(register, typeLoader, ProfilingLogger, _state, Configs, IOHelper, appCaches); composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, UmbracoVersion); // run handlers diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 8aedd8f263..0813c321bc 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -20,7 +20,8 @@ namespace Umbraco.Core /// The current application path or VirtualPath /// /// - /// + /// + /// /// /// There are some special routes we need to check to properly determine this: /// @@ -39,7 +40,7 @@ namespace Umbraco.Core /// But if we've got this far we'll just have to assume it's front-end anyways. /// /// - internal static bool IsBackOfficeRequest(this Uri url, string applicationPath, IGlobalSettings globalSettings) + internal static bool IsBackOfficeRequest(this Uri url, string applicationPath, IGlobalSettings globalSettings, IIOHelper ioHelper) { applicationPath = applicationPath ?? string.Empty; @@ -52,7 +53,7 @@ namespace Umbraco.Core //if not, then def not back office if (isUmbracoPath == false) return false; - var mvcArea = globalSettings.GetUmbracoMvcArea(Current.IOHelper); + var mvcArea = globalSettings.GetUmbracoMvcArea(ioHelper); //if its the normal /umbraco path if (urlPath.InvariantEquals("/" + mvcArea) || urlPath.InvariantEquals("/" + mvcArea + "/")) @@ -107,8 +108,9 @@ namespace Umbraco.Core /// Checks if the current uri is an install request /// /// + /// /// - internal static bool IsInstallerRequest(this Uri url) + internal static bool IsInstallerRequest(this Uri url, IIOHelper ioHelper) { var authority = url.GetLeftPart(UriPartial.Authority); var afterAuthority = url.GetLeftPart(UriPartial.Query) @@ -116,7 +118,7 @@ namespace Umbraco.Core .TrimStart("/"); //check if this is in the umbraco back office - return afterAuthority.InvariantStartsWith(Current.IOHelper.ResolveUrl("~/install").TrimStart("/")); + return afterAuthority.InvariantStartsWith(ioHelper.ResolveUrl("~/install").TrimStart("/")); } /// diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs index c6924e3abe..126a6dbc40 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs @@ -3,6 +3,7 @@ using System.Reflection; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Composing; +using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.ModelsBuilder.Embedded.Configuration; @@ -28,9 +29,10 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose return; } + composition.Components().Append(); composition.Register(Lifetime.Singleton); - composition.Configs.Add(() => new ModelsBuilderConfig()); + composition.Configs.Add(() => new ModelsBuilderConfig(composition.IOHelper)); composition.RegisterUnique(); composition.RegisterUnique(); composition.RegisterUnique(); diff --git a/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs b/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs index d3335ac41b..4fb46facaf 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs @@ -13,14 +13,17 @@ namespace Umbraco.ModelsBuilder.Embedded.Configuration /// public class ModelsBuilderConfig : IModelsBuilderConfig { + private readonly IIOHelper _ioHelper; public const string DefaultModelsNamespace = "Umbraco.Web.PublishedModels"; - public const string DefaultModelsDirectory = "~/App_Data/Models"; + + public string DefaultModelsDirectory => _ioHelper.MapPath("~/App_Data/Models"); /// /// Initializes a new instance of the class. /// - public ModelsBuilderConfig() + public ModelsBuilderConfig(IIOHelper ioHelper) { + _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); const string prefix = "Umbraco.ModelsBuilder."; // giant kill switch, default: false @@ -29,7 +32,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Configuration // ensure defaults are initialized for tests ModelsNamespace = DefaultModelsNamespace; - ModelsDirectory = Current.IOHelper.MapPath(DefaultModelsDirectory); + ModelsDirectory = DefaultModelsDirectory; DebugLevel = 0; // stop here, everything is false @@ -101,7 +104,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Configuration /// /// Initializes a new instance of the class. /// - public ModelsBuilderConfig( + public ModelsBuilderConfig(IIOHelper ioHelper, bool enable = false, ModelsMode modelsMode = ModelsMode.Nothing, string modelsNamespace = null, @@ -111,6 +114,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Configuration bool acceptUnsafeModelsDirectory = false, int debugLevel = 0) { + _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); Enable = enable; ModelsMode = modelsMode; diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index 851c03ad13..ea7819b14d 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.Cache.DistributedCache { var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.RegisterUnique(_ => new TestServerRegistrar()); composition.RegisterUnique(_ => new TestServerMessenger()); diff --git a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs index 17d1d1b4cb..862f6da038 100644 --- a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs @@ -160,7 +160,8 @@ namespace Umbraco.Tests.Cache TestObjects.GetGlobalSettings(), new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + IOHelper); // just assert it does not throw var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null); diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index 1bd6391f0e..579923744c 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -7,7 +7,6 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Hosting; using Umbraco.Core.Services; using Umbraco.Tests.LegacyXmlPublishedCache; using Umbraco.Tests.TestHelpers; @@ -84,7 +83,8 @@ namespace Umbraco.Tests.Cache.PublishedCache Enumerable.Empty(), Enumerable.Empty(), globalSettings, - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); _cache = _umbracoContext.Content; } diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index dc20a44696..4733b2c338 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -71,7 +71,7 @@ namespace Umbraco.Tests.Components public void Boot1A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -110,7 +110,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -126,7 +126,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -141,7 +141,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -158,7 +158,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -181,7 +181,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -216,7 +216,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Mock.Of()); @@ -242,7 +242,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Mock.Of()); @@ -257,7 +257,7 @@ namespace Umbraco.Tests.Components public void Requires2A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Mock.Of()); @@ -274,7 +274,7 @@ namespace Umbraco.Tests.Components { var register = MockRegister(); var factory = MockFactory(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs, TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Mock.Of()); @@ -293,7 +293,7 @@ namespace Umbraco.Tests.Components public void WeakDependencies() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer10) }; var composers = new Composers(composition, types, Mock.Of()); @@ -332,7 +332,7 @@ namespace Umbraco.Tests.Components public void DisableMissing() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list var composers = new Composers(composition, types, Mock.Of()); @@ -347,7 +347,7 @@ namespace Umbraco.Tests.Components public void AttributesPriorities() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs, TestHelper.IOHelper, AppCaches.NoCache); var types = new[] { typeof(Composer26) }; // 26 disabled by assembly attribute var composers = new Composers(composition, types, Mock.Of()); @@ -372,7 +372,8 @@ namespace Umbraco.Tests.Components var typeLoader = new TypeLoader(ioHelper, typeFinder, AppCaches.Disabled.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), Mock.Of()); var register = MockRegister(); - var composition = new Composition(register, typeLoader, Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs); + var composition = new Composition(register, typeLoader, Mock.Of(), + MockRuntimeState(RuntimeLevel.Run), Configs, TestHelper.IOHelper, AppCaches.NoCache); var types = typeLoader.GetTypes().Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")); var composers = new Composers(composition, types, Mock.Of()); diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index 53b4a9c380..9f18d7a061 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Tests.Components; @@ -23,7 +24,7 @@ namespace Umbraco.Tests.Composing Current.Reset(); var register = TestHelper.GetRegister(); - _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); } [TearDown] diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index fd1db16ac4..4dfaf6871d 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing var typeFinder = new TypeFinder(Mock.Of()); var ioHelper = TestHelper.IOHelper; var typeLoader = new TypeLoader(ioHelper, typeFinder, Mock.Of(), new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), logger); - var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.GetConfigs()); + var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); // create the factory, ensure it is the mocked factory var factory = composition.CreateFactory(); diff --git a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs index 6ba6a4c9b0..86d1104b84 100644 --- a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -67,7 +67,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) }) @@ -92,7 +92,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypesAndProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -118,7 +118,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderThrowsOnIllegalTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() @@ -140,7 +140,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderCanExcludeTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add() diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index d4709ae03a..987fe7410c 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -5,6 +5,7 @@ using System.Xml.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Core.PackageActions; @@ -21,7 +22,7 @@ namespace Umbraco.Tests.Composing { var container = TestHelper.GetRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Add(() => TypeLoader.GetPackageActions()); diff --git a/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs b/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs index 8aae71d607..5c0ca7a582 100644 --- a/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs +++ b/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs @@ -45,10 +45,11 @@ namespace Umbraco.Tests.CoreThings [TestCase("http://www.domain.com/umbraco/test/legacyAjaxCalls.ashx?some=query&blah=js", "", true)] public void Is_Back_Office_Request(string input, string virtualPath, bool expected) { - Current.IOHelper.Root = virtualPath; + var ioHelper = TestHelper.IOHelper; + ioHelper.Root = virtualPath; var globalConfig = SettingsForTests.GenerateMockGlobalSettings(); var source = new Uri(input); - Assert.AreEqual(expected, source.IsBackOfficeRequest(virtualPath, globalConfig)); + Assert.AreEqual(expected, source.IsBackOfficeRequest(virtualPath, globalConfig, ioHelper)); } [TestCase("http://www.domain.com/install", true)] @@ -63,7 +64,7 @@ namespace Umbraco.Tests.CoreThings public void Is_Installer_Request(string input, bool expected) { var source = new Uri(input); - Assert.AreEqual(expected, source.IsInstallerRequest()); + Assert.AreEqual(expected, source.IsInstallerRequest(TestHelper.IOHelper)); } [TestCase("http://www.domain.com/foo/bar", "/", "http://www.domain.com/")] diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 423507bcfe..76d1ce85fc 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -4,6 +4,7 @@ using System.Text; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Composing; using Umbraco.Core.IO; @@ -28,7 +29,7 @@ namespace Umbraco.Tests.IO { _register = TestHelper.GetRegister(); - var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs index 52cf5ddef5..0792bf4126 100644 --- a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs +++ b/src/Umbraco.Tests/Models/ContentExtensionsTests.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; using Umbraco.Web.PropertyEditors; @@ -32,7 +33,7 @@ namespace Umbraco.Tests.Models Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... - var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of()) { Alias = "test" }; + var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), IOHelper) { Alias = "test" }; Composition.Register(_ => new DataEditorCollection(new[] { editor })); Composition.Register(); var dataType = Mock.Of(); diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index bdb1a193bc..0b705004f9 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -19,6 +19,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Tests.Testing; @@ -43,7 +44,7 @@ namespace Umbraco.Tests.Models Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... - var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of()) { Alias = "test" }; + var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), TestHelper.IOHelper) { Alias = "test" }; Composition.Register(_ => new DataEditorCollection(new [] { editor })); Composition.Register(); var dataType = Mock.Of(); diff --git a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs index be562241b2..ff30c123a2 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; +using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; using Umbraco.Web.Models.ContentEditing; @@ -32,7 +33,7 @@ namespace Umbraco.Tests.Models.Mapping base.Compose(); // create and register a fake property editor collection to return fake property editors - var editors = new DataEditor[] { new TextboxPropertyEditor(Mock.Of(), _dataTypeService.Object, _localizationService.Object), }; + var editors = new DataEditor[] { new TextboxPropertyEditor(Mock.Of(), _dataTypeService.Object, _localizationService.Object, IOHelper), }; var dataEditors = new DataEditorCollection(editors); _editorsMock = new Mock(dataEditors); _editorsMock.Setup(x => x[It.IsAny()]).Returns(editors[0]); diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index 66d3b570b0..d88b3f1be4 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -37,7 +37,7 @@ namespace Umbraco.Tests.Models.Mapping Composition.Register(_ => Mock.Of()); // all this is required so we can validate properties... - var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of()) { Alias = "test" }; + var editor = new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), IOHelper) { Alias = "test" }; Composition.Register(_ => new DataEditorCollection(new[] { editor })); Composition.Register(); var dataType = Mock.Of(); diff --git a/src/Umbraco.Tests/ModelsBuilder/ConfigTests.cs b/src/Umbraco.Tests/ModelsBuilder/ConfigTests.cs index 5e122ad0fa..ff49bb3f97 100644 --- a/src/Umbraco.Tests/ModelsBuilder/ConfigTests.cs +++ b/src/Umbraco.Tests/ModelsBuilder/ConfigTests.cs @@ -1,6 +1,7 @@ using System.Configuration; using NUnit.Framework; using Umbraco.ModelsBuilder.Embedded.Configuration; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.ModelsBuilder { @@ -10,21 +11,21 @@ namespace Umbraco.Tests.ModelsBuilder [Test] public void Test1() { - var config = new ModelsBuilderConfig(modelsNamespace: "test1"); + var config = new ModelsBuilderConfig(TestHelper.IOHelper, modelsNamespace: "test1"); Assert.AreEqual("test1", config.ModelsNamespace); } [Test] public void Test2() { - var config = new ModelsBuilderConfig(modelsNamespace: "test2"); + var config = new ModelsBuilderConfig(TestHelper.IOHelper, modelsNamespace: "test2"); Assert.AreEqual("test2", config.ModelsNamespace); } [Test] public void DefaultModelsNamespace() { - var config = new ModelsBuilderConfig(); + var config = new ModelsBuilderConfig(TestHelper.IOHelper); Assert.AreEqual(ModelsBuilderConfig.DefaultModelsNamespace, config.ModelsNamespace); } diff --git a/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs b/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs index 909b910feb..9bbda6dbbc 100644 --- a/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs +++ b/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Packaging; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Packaging { @@ -16,7 +17,7 @@ namespace Umbraco.Tests.Packaging private static FileInfo GetTestPackagePath(string packageName) { const string testPackagesDirName = "Packaging\\Packages"; - string path = Path.Combine(Current.IOHelper.GetRootDirectorySafe(), testPackagesDirName, packageName); + string path = Path.Combine(TestHelper.IOHelper.GetRootDirectorySafe(), testPackagesDirName, packageName); return new FileInfo(path); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs index ca8ee29ee3..1ddb9f8c8c 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs @@ -36,9 +36,9 @@ namespace Umbraco.Tests.Persistence.Repositories using (provider.CreateScope()) { var dtRepo = CreateRepository(); - IDataType dataType1 = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService)) { Name = "dt1" }; + IDataType dataType1 = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService, IOHelper)) { Name = "dt1" }; dtRepo.Save(dataType1); - IDataType dataType2 = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService)) { Name = "dt2" }; + IDataType dataType2 = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService, IOHelper)) { Name = "dt2" }; dtRepo.Save(dataType2); var ctRepo = Factory.GetInstance(); @@ -106,14 +106,14 @@ namespace Umbraco.Tests.Persistence.Repositories var container2 = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "blah2", ParentId = container1.Id }; containerRepository.Save(container2); - var dataType = (IDataType) new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService), container2.Id) + var dataType = (IDataType) new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService, IOHelper), container2.Id) { Name = "dt1" }; repository.Save(dataType); //create a - var dataType2 = (IDataType)new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService), dataType.Id) + var dataType2 = (IDataType)new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService, IOHelper), dataType.Id) { Name = "dt2" }; @@ -185,7 +185,7 @@ namespace Umbraco.Tests.Persistence.Repositories var container = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "blah" }; containerRepository.Save(container); - var dataTypeDefinition = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService), container.Id) { Name = "test" }; + var dataTypeDefinition = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService, IOHelper), container.Id) { Name = "test" }; repository.Save(dataTypeDefinition); Assert.AreEqual(container.Id, dataTypeDefinition.ParentId); @@ -205,7 +205,7 @@ namespace Umbraco.Tests.Persistence.Repositories var container = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "blah" }; containerRepository.Save(container); - IDataType dataType = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService), container.Id) { Name = "test" }; + IDataType dataType = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService, IOHelper), container.Id) { Name = "test" }; repository.Save(dataType); // Act @@ -228,7 +228,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (provider.CreateScope()) { var repository = CreateRepository(); - IDataType dataType = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService)) {Name = "test"}; + IDataType dataType = new DataType(new RadioButtonsPropertyEditor(Logger, ServiceContext.TextService, IOHelper)) {Name = "test"}; repository.Save(dataType); @@ -349,7 +349,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (provider.CreateScope()) { var repository = CreateRepository(); - var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger)) + var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger, IOHelper)) { DatabaseType = ValueStorageType.Integer, Name = "AgeDataType", @@ -398,7 +398,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Act var definition = repository.Get(dataTypeDefinition.Id); definition.Name = "AgeDataType Updated"; - definition.Editor = new LabelPropertyEditor(Logger); //change + definition.Editor = new LabelPropertyEditor(Logger, IOHelper); //change repository.Save(definition); var definitionUpdated = repository.Get(dataTypeDefinition.Id); @@ -418,7 +418,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (provider.CreateScope()) { var repository = CreateRepository(); - var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger)) + var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger, IOHelper)) { DatabaseType = ValueStorageType.Integer, Name = "AgeDataType", diff --git a/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs index 85588cbbdb..0b02fd522d 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs @@ -50,7 +50,7 @@ namespace Umbraco.Tests.Persistence.Repositories TemplateRepository tr; var ctRepository = CreateRepository(scopeAccessor, out contentTypeRepository, out tr); var editors = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty())); - dtdRepository = new DataTypeRepository(scopeAccessor, appCaches, new Lazy(() => editors), Logger); + dtdRepository = new DataTypeRepository(scopeAccessor, appCaches, new Lazy(() => editors), Logger, TestHelper.IOHelper); return ctRepository; } diff --git a/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs b/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs index 5e05f729b6..1a5e657bb7 100644 --- a/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using Newtonsoft.Json.Linq; using Umbraco.Core.Logging; using Umbraco.Core.Services; +using Umbraco.Tests.TestHelpers; using Umbraco.Web.PropertyEditors; namespace Umbraco.Tests.PropertyEditors @@ -15,7 +16,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray() { var validator = new ColorPickerConfigurationEditor.ColorListValidator(); - var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of())); + var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(0, result.Count()); } @@ -23,7 +24,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray_Of_Item_JObject() { var validator = new ColorPickerConfigurationEditor.ColorListValidator(); - var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of())); + var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(0, result.Count()); } @@ -36,7 +37,7 @@ namespace Umbraco.Tests.PropertyEditors JObject.FromObject(new { value = "zxcvzxcvxzcv" }), JObject.FromObject(new { value = "ABC" }), JObject.FromObject(new { value = "1234567" })), - null, new ColorPickerPropertyEditor(Mock.Of())); + null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(2, result.Count()); } } diff --git a/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs b/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs index b86a6099b1..cf8c734f40 100644 --- a/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using Newtonsoft.Json.Linq; using Umbraco.Core.Logging; using Umbraco.Core.Services; +using Umbraco.Tests.TestHelpers; using Umbraco.Web.PropertyEditors; namespace Umbraco.Tests.PropertyEditors @@ -15,7 +16,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray() { var validator = new ValueListUniqueValueValidator(); - var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of())); + var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(0, result.Count()); } @@ -23,7 +24,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray_Of_Item_JObject() { var validator = new ValueListUniqueValueValidator(); - var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of())); + var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(0, result.Count()); } @@ -31,7 +32,7 @@ namespace Umbraco.Tests.PropertyEditors public void Allows_Unique_Values() { var validator = new ValueListUniqueValueValidator(); - var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" })), null, new ColorPickerPropertyEditor(Mock.Of())); + var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" })), null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(0, result.Count()); } @@ -40,7 +41,7 @@ namespace Umbraco.Tests.PropertyEditors { var validator = new ValueListUniqueValueValidator(); var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "hello" })), - null, new ColorPickerPropertyEditor(Mock.Of())); + null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(1, result.Count()); } @@ -53,7 +54,7 @@ namespace Umbraco.Tests.PropertyEditors JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" }), JObject.FromObject(new { value = "world" })), - null, new ColorPickerPropertyEditor(Mock.Of())); + null, new ColorPickerPropertyEditor(Mock.Of(), TestHelper.IOHelper)); Assert.AreEqual(2, result.Count()); } } diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index ad9756fa6b..58345e2064 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.PropertyEditors try { var container = TestHelper.GetRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder(); @@ -84,7 +84,7 @@ namespace Umbraco.Tests.PropertyEditors var mediaFileSystem = new MediaFileSystem(Mock.Of(), config, scheme, logger, ioHelper); var dataTypeService = new TestObjects.TestDataTypeService( - new DataType(new ImageCropperPropertyEditor(Mock.Of(), mediaFileSystem, Mock.Of(), Mock.Of(), Mock.Of())) { Id = 1 }); + new DataType(new ImageCropperPropertyEditor(Mock.Of(), mediaFileSystem, Mock.Of(), Mock.Of(), Mock.Of(), TestHelper.IOHelper)) { Id = 1 }); var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeService); diff --git a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs index 5579395b7e..64cca36f04 100644 --- a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void DropDownMultipleValueEditor_Format_Data_For_Cache() { - var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())) + var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), TestHelper.IOHelper)) { Configuration = new ValueListConfiguration { @@ -59,7 +59,7 @@ namespace Umbraco.Tests.PropertyEditors [Test] public void DropDownValueEditor_Format_Data_For_Cache() { - var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())) + var dataType = new DataType(new CheckBoxListPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), TestHelper.IOHelper)) { Configuration = new ValueListConfiguration { @@ -113,7 +113,7 @@ namespace Umbraco.Tests.PropertyEditors } }; - var editor = new ValueListConfigurationEditor(Mock.Of()); + var editor = new ValueListConfigurationEditor(Mock.Of(), TestHelper.IOHelper); var result = editor.ToConfigurationEditor(configuration); diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index b3ec8dd08b..56fc6f95ee 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -3,6 +3,7 @@ using System.Threading; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -24,7 +25,7 @@ namespace Umbraco.Tests.PropertyEditors Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); register.Register(_ => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings()))); diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index f1042519f5..eb4066e2af 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -4,6 +4,7 @@ using System.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -178,7 +179,7 @@ namespace Umbraco.Tests.Published Current.Reset(); var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.WithCollectionBuilder() .Append() diff --git a/src/Umbraco.Tests/Published/NestedContentTests.cs b/src/Umbraco.Tests/Published/NestedContentTests.cs index cc1035f61f..6b04d87e9d 100644 --- a/src/Umbraco.Tests/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests/Published/NestedContentTests.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.Published var localizationService = Mock.Of(); PropertyEditorCollection editors = null; - var editor = new NestedContentPropertyEditor(logger, new Lazy(() => editors), Mock.Of(), localizationService); + var editor = new NestedContentPropertyEditor(logger, new Lazy(() => editors), Mock.Of(), localizationService, TestHelper.IOHelper); editors = new PropertyEditorCollection(new DataEditorCollection(new DataEditor[] { editor })); var dataType1 = new DataType(editor) @@ -66,7 +66,7 @@ namespace Umbraco.Tests.Published } }; - var dataType3 = new DataType(new TextboxPropertyEditor(logger, Mock.Of(), localizationService)) + var dataType3 = new DataType(new TextboxPropertyEditor(logger, Mock.Of(), localizationService, TestHelper.IOHelper)) { Id = 3 }; diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs index da89e76033..2f58cfcd74 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs @@ -76,7 +76,8 @@ namespace Umbraco.Tests.PublishedContent Enumerable.Empty(), Enumerable.Empty(), globalSettings, - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); return umbracoContext; } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index bf55f1783f..7bbc7f0303 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.PublishedContent Mock.Of(), Mock.Of(), Mock.Of(), - Mock.Of())) { Id = 1 }); + Mock.Of(), IOHelper)) { Id = 1 }); var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of(), converters, dataTypeService); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index 0888a4f27c..968f80e1a2 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -53,11 +53,11 @@ namespace Umbraco.Tests.PublishedContent var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(logger)) { Id = 1 }, - new DataType(new TrueFalsePropertyEditor(logger)) { Id = 1001 }, - new DataType(new RichTextPropertyEditor(logger, mediaService, contentTypeBaseServiceProvider, umbracoContextAccessor, Mock.Of(), localizationService)) { Id = 1002 }, + new DataType(new TrueFalsePropertyEditor(logger, IOHelper)) { Id = 1001 }, + new DataType(new RichTextPropertyEditor(logger, mediaService, contentTypeBaseServiceProvider, umbracoContextAccessor, Mock.Of(), localizationService, IOHelper)) { Id = 1002 }, new DataType(new IntegerPropertyEditor(logger)) { Id = 1003 }, - new DataType(new TextboxPropertyEditor(logger, Mock.Of(), localizationService)) { Id = 1004 }, - new DataType(new MediaPickerPropertyEditor(logger)) { Id = 1005 }); + new DataType(new TextboxPropertyEditor(logger, Mock.Of(), localizationService, TestHelper.IOHelper)) { Id = 1004 }, + new DataType(new MediaPickerPropertyEditor(logger, IOHelper)) { Id = 1005 }); Composition.RegisterUnique(f => dataTypeService); } diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index a88d3146ed..a215b5e08c 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -84,7 +84,7 @@ namespace Umbraco.Tests.Runtimes // test application public class TestUmbracoApplication : UmbracoApplicationBase { - public TestUmbracoApplication() : base(_logger, _configs, _ioHelper, _profiler, new AspNetHostingEnvironment(_globalSettings, _ioHelper), new AspNetBackOfficeInfo(_globalSettings, _ioHelper, _settings, _logger)) + public TestUmbracoApplication() : base(_logger, _configs, _ioHelper, _profiler, new AspNetHostingEnvironment(new Lazy(() => _globalSettings)), new AspNetBackOfficeInfo(_globalSettings, _ioHelper, _settings, _logger)) { } diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index ce8c1a2dd3..325f138915 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -74,7 +74,7 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion); // create the core runtime and have it compose itself @@ -268,7 +268,7 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = TestHelper.GetRegister(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs, ioHelper, appCaches); var umbracoVersion = TestHelper.GetUmbracoVersion(); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion); diff --git a/src/Umbraco.Tests/Runtimes/WebRuntimeComponentTests.cs b/src/Umbraco.Tests/Runtimes/WebRuntimeComponentTests.cs index b0d2788b58..c03fe04a2d 100644 --- a/src/Umbraco.Tests/Runtimes/WebRuntimeComponentTests.cs +++ b/src/Umbraco.Tests/Runtimes/WebRuntimeComponentTests.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Web.Mvc; using NUnit.Framework; +using NUnit.Framework.Internal; +using Umbraco.Tests.TestHelpers; using Umbraco.Web.Mvc; using Umbraco.Web.Runtime; @@ -14,7 +16,7 @@ namespace Umbraco.Tests.Runtimes { IList engines = new List { - new RenderViewEngine(), + new RenderViewEngine(TestHelper.IOHelper), new PluginViewEngine() }; @@ -30,7 +32,7 @@ namespace Umbraco.Tests.Runtimes { IList engines = new List { - new RenderViewEngine(), + new RenderViewEngine(TestHelper.IOHelper), new PluginViewEngine() }; diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index d48a54c625..0824501059 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -3,6 +3,7 @@ using System.Linq; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.IO; @@ -32,7 +33,7 @@ namespace Umbraco.Tests.Scoping var register = TestHelper.GetRegister(); - var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); _testObjects = new TestObjects(register); diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 07cbcb2686..950d8c84c1 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -123,7 +123,8 @@ namespace Umbraco.Tests.Scoping urlProviders ?? Enumerable.Empty(), Enumerable.Empty(), globalSettings, - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); if (setSingleton) Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext; diff --git a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs index 2b04a02f46..90c2f6c4bf 100644 --- a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs @@ -9,6 +9,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Services; +using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; using Umbraco.Tests.Testing.Objects.Accessors; using Umbraco.Web; @@ -35,11 +36,11 @@ namespace Umbraco.Tests.Security Mock.Of(), new WebSecurity(Mock.Of(), Current.Services.UserService, globalSettings), TestObjects.GetUmbracoSettings(), new List(), Enumerable.Empty(), globalSettings, - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), IOHelper); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Install); var mgr = new BackOfficeCookieManager( - Mock.Of(accessor => accessor.UmbracoContext == umbracoContext), runtime, TestObjects.GetGlobalSettings()); + Mock.Of(accessor => accessor.UmbracoContext == umbracoContext), runtime, TestObjects.GetGlobalSettings(), TestHelper.IOHelper); var result = mgr.ShouldAuthenticateRequest(Mock.Of(), new Uri("http://localhost/umbraco")); @@ -55,10 +56,10 @@ namespace Umbraco.Tests.Security Mock.Of(), new WebSecurity(Mock.Of(), Current.Services.UserService, globalSettings), TestObjects.GetUmbracoSettings(), new List(), Enumerable.Empty(), globalSettings, - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), IOHelper); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); - var mgr = new BackOfficeCookieManager(Mock.Of(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings()); + var mgr = new BackOfficeCookieManager(Mock.Of(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings(), TestHelper.IOHelper); var request = new Mock(); request.Setup(owinRequest => owinRequest.Uri).Returns(new Uri("http://localhost/umbraco")); diff --git a/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs b/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs index 8ef7e24cae..e7c310ffef 100644 --- a/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs +++ b/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs @@ -1,10 +1,8 @@ using System.Threading; using NUnit.Framework; -using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Tests.Testing; -using Umbraco.Web.PropertyEditors; namespace Umbraco.Tests.Services { @@ -25,7 +23,7 @@ namespace Umbraco.Tests.Services { var dataTypeService = ServiceContext.DataTypeService; - IDataType dataType = new DataType(new LabelPropertyEditor(Logger)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; + IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; dataTypeService.Save(dataType); //Get all the first time (no cache) diff --git a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs index da9cb73ba9..561ade1b54 100644 --- a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs +++ b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs @@ -1,15 +1,11 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using NUnit.Framework; -using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.PropertyEditors; -using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; -using Umbraco.Web.PropertyEditors; namespace Umbraco.Tests.Services { @@ -28,7 +24,7 @@ namespace Umbraco.Tests.Services var dataTypeService = ServiceContext.DataTypeService; // Act - IDataType dataType = new DataType(new LabelPropertyEditor(Logger)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; + IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; dataTypeService.Save(dataType); // Assert @@ -70,7 +66,7 @@ namespace Umbraco.Tests.Services var dataTypeService = ServiceContext.DataTypeService; // Act - var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger)) { Name = string.Empty, DatabaseType = ValueStorageType.Ntext }; + var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger, IOHelper)) { Name = string.Empty, DatabaseType = ValueStorageType.Ntext }; // Act & Assert Assert.Throws(() => dataTypeService.Save(dataTypeDefinition)); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index e66a8d2450..f5f9fbc96f 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -45,7 +45,7 @@ namespace Umbraco.Tests.TestHelpers logger, false); - var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index 1b48e83ab9..fdc2e6a5bd 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -142,7 +142,8 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting Enumerable.Empty(), Enumerable.Empty(), globalSettings, - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + TestHelper.IOHelper); //replace it umbracoContextAccessor.UmbracoContext = umbCtx; diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index 231e6aef66..b1db54764b 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.TestHelpers settings.Path == TestHelper.IOHelper.ResolveUrl("~/umbraco") && settings.TimeOutInMinutes == 20 && settings.DefaultUILanguage == "en" && - settings.LocalTempStorageLocation == LocalTempStorage.Default && + settings.LocalTempStorageLocation == LocalTempStorage.EnvironmentTemp && settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") && settings.ReservedUrls == GlobalSettings.StaticReservedUrls && settings.UmbracoPath == "~/umbraco" && diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 797fdcb51b..e63f12b937 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -82,7 +82,7 @@ namespace Umbraco.Tests.TestHelpers } } - public static IIOHelper IOHelper = new IOHelper(); + public static IIOHelper IOHelper = new IOHelper(GetHostingEnvironment()); /// /// Maps the given making it rooted on . must start with ~/ @@ -313,7 +313,7 @@ namespace Umbraco.Tests.TestHelpers public static IHostingEnvironment GetHostingEnvironment() { - return new AspNetHostingEnvironment(SettingsForTests.GetDefaultGlobalSettings(), TestHelper.IOHelper); + return new AspNetHostingEnvironment(new Lazy(() => SettingsForTests.GetDefaultGlobalSettings())); } public static IIpResolver GetIpResolver() diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index dad3ec4fc0..e78b074b89 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -136,7 +136,8 @@ namespace Umbraco.Tests.TestHelpers globalSettings, urlProviders, mediaUrlProviders, - Mock.Of()); + Mock.Of(), + TestHelper.IOHelper); return umbracoContextFactory.EnsureUmbracoContext(httpContext).UmbracoContext; } diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index ac9ec48c6a..e6ccb67677 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -385,7 +385,8 @@ namespace Umbraco.Tests.TestHelpers urlProviders ?? Enumerable.Empty(), mediaUrlProviders ?? Enumerable.Empty(), globalSettings ?? Factory.GetInstance(), - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); if (setSingleton) Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext; diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 5afac8d3ab..45395d0e4c 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -148,7 +148,7 @@ namespace Umbraco.Tests.Testing var appCaches = GetAppCaches(); var globalSettings = SettingsForTests.GetDefaultGlobalSettings(); var settings = SettingsForTests.GetDefaultUmbracoSettings(); - IHostingEnvironment hostingEnvironment = new AspNetHostingEnvironment(globalSettings, IOHelper); + IHostingEnvironment hostingEnvironment = new AspNetHostingEnvironment(new Lazy(() => globalSettings)); IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, IOHelper, settings, logger); IIpResolver ipResolver = new AspNetIpResolver(); UmbracoVersion = new UmbracoVersion(globalSettings); @@ -156,7 +156,7 @@ namespace Umbraco.Tests.Testing var register = TestHelper.GetRegister(); - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs(), TestHelper.IOHelper, AppCaches.NoCache); Composition.RegisterUnique(IOHelper); diff --git a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs index eeb1eb4b37..89a2e789d3 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs @@ -73,7 +73,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + TestHelper.IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbCtx = umbracoContextReference.UmbracoContext; @@ -103,7 +104,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + TestHelper.IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbCtx = umbracoContextReference.UmbracoContext; @@ -133,7 +135,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + TestHelper.IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbCtx = umbracoContextReference.UmbracoContext; @@ -163,7 +166,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + TestHelper.IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbCtx = umbracoContextReference.UmbracoContext; diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index 0d8e9693d9..4299b57e07 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -49,7 +49,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbracoContext = umbracoContextReference.UmbracoContext; @@ -77,7 +78,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbCtx = umbracoContextReference.UmbracoContext; @@ -108,7 +110,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbracoContext = umbracoContextReference.UmbracoContext; @@ -146,7 +149,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new UrlProviderCollection(Enumerable.Empty()), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + IOHelper); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of()); var umbracoContext = umbracoContextReference.UmbracoContext; diff --git a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs index 6ce1eae7fe..52bd0253a0 100644 --- a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs @@ -444,7 +444,8 @@ namespace Umbraco.Tests.Web.Mvc Enumerable.Empty(), Enumerable.Empty(), globalSettings, - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); //if (setSingleton) //{ diff --git a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs index b13532b824..cbb8253a09 100644 --- a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs +++ b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Web [TestCase("hello href=\"{localLink:umb^://document/9931BDE0-AAC3-4BAB-B838-909A7B47570E}\" world ", "hello href=\"{localLink:umb^://document/9931BDE0-AAC3-4BAB-B838-909A7B47570E}\" world ")] [TestCase("hello href=\"{localLink:umb://document-type/9931BDE0-AAC3-4BAB-B838-909A7B47570E}\" world ", "hello href=\"#\" world ")] public void ParseLocalLinks(string input, string result) - { + { //setup a mock url provider which we'll use for testing var testUrlProvider = new Mock(); testUrlProvider @@ -71,7 +71,8 @@ namespace Umbraco.Tests.Web globalSettings, new UrlProviderCollection(new[] { testUrlProvider.Object }), new MediaUrlProviderCollection(Enumerable.Empty()), - Mock.Of()); + Mock.Of(), + TestHelper.IOHelper); using (var reference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of())) { diff --git a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs index 9ba010642e..bb3db7273c 100644 --- a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs +++ b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs @@ -34,7 +34,8 @@ namespace Umbraco.Tests.Web new List(), Enumerable.Empty(), TestObjects.GetGlobalSettings(), - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); var r1 = new RouteData(); r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx); @@ -53,7 +54,8 @@ namespace Umbraco.Tests.Web new List(), Enumerable.Empty(), TestObjects.GetGlobalSettings(), - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); var r1 = new RouteData(); r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx); @@ -82,7 +84,8 @@ namespace Umbraco.Tests.Web new List(), Enumerable.Empty(), TestObjects.GetGlobalSettings(), - new TestVariationContextAccessor()); + new TestVariationContextAccessor(), + IOHelper); var httpContext = Mock.Of(); diff --git a/src/Umbraco.Web/Composing/BuildManagerTypeFinder.cs b/src/Umbraco.Web/Composing/BuildManagerTypeFinder.cs index 15c8d6d8d6..7063032c76 100644 --- a/src/Umbraco.Web/Composing/BuildManagerTypeFinder.cs +++ b/src/Umbraco.Web/Composing/BuildManagerTypeFinder.cs @@ -11,6 +11,7 @@ using System.Web.Compilation; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -24,15 +25,16 @@ namespace Umbraco.Web.Composing /// internal class BuildManagerTypeFinder : TypeFinder, ITypeFinder { - - public BuildManagerTypeFinder(IIOHelper ioHelper, ILogger logger, ITypeFinderConfig typeFinderConfig = null) : base(logger, typeFinderConfig) + + public BuildManagerTypeFinder(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger logger, ITypeFinderConfig typeFinderConfig = null) : base(logger, typeFinderConfig) { if (ioHelper == null) throw new ArgumentNullException(nameof(ioHelper)); + if (hostingEnvironment == null) throw new ArgumentNullException(nameof(hostingEnvironment)); if (logger == null) throw new ArgumentNullException(nameof(logger)); _allAssemblies = new Lazy>(() => { - var isHosted = ioHelper.IsHosted; + var isHosted = hostingEnvironment.IsHosted; try { if (isHosted) diff --git a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs index 07e77aa7d0..730bd171c4 100644 --- a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs +++ b/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs @@ -10,21 +10,16 @@ namespace Umbraco.Web.Hosting { public class AspNetHostingEnvironment : IHostingEnvironment { - private readonly IGlobalSettings _globalSettings; - private readonly IIOHelper _ioHelper; + private readonly Lazy _globalSettings; private string _localTempPath; - public AspNetHostingEnvironment(IGlobalSettings globalSettings, IIOHelper ioHelper) + public AspNetHostingEnvironment(Lazy globalSettings) { _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); - _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); - SiteName = HostingEnvironment.SiteName; ApplicationId = HostingEnvironment.ApplicationID; ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath; ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath; - - IsDebugMode = HttpContext.Current?.IsDebuggingEnabled ?? globalSettings.DebugMode; } public string SiteName { get; } @@ -32,9 +27,16 @@ namespace Umbraco.Web.Hosting public string ApplicationPhysicalPath { get; } public string ApplicationVirtualPath { get; } - public bool IsDebugMode { get; } - public bool IsHosted => HostingEnvironment.IsHosted; - public string MapPath(string path) => HostingEnvironment.MapPath(path); + public bool IsDebugMode => HttpContext.Current?.IsDebuggingEnabled ?? _globalSettings.Value.DebugMode; + /// + public bool IsHosted => (HttpContext.Current != null || HostingEnvironment.IsHosted); + public string MapPath(string path) + { + return HostingEnvironment.MapPath(path); + } + + public string ToAbsolute(string virtualPath, string root) => VirtualPathUtility.ToAbsolute(virtualPath, root); + public string LocalTempPath { @@ -43,7 +45,7 @@ namespace Umbraco.Web.Hosting if (_localTempPath != null) return _localTempPath; - switch (_globalSettings.LocalTempStorageLocation) + switch (_globalSettings.Value.LocalTempStorageLocation) { case LocalTempStorage.AspNetTemp: return _localTempPath = System.IO.Path.Combine(HttpRuntime.CodegenDir, "UmbracoData"); @@ -69,7 +71,7 @@ namespace Umbraco.Web.Hosting //case LocalTempStorage.Default: //case LocalTempStorage.Unknown: default: - return _localTempPath = _ioHelper.MapPath("~/App_Data/TEMP"); + return _localTempPath = MapPath("~/App_Data/TEMP"); } } } diff --git a/src/Umbraco.Web/Mvc/RenderViewEngine.cs b/src/Umbraco.Web/Mvc/RenderViewEngine.cs index ff8eec3bd2..2253bde03c 100644 --- a/src/Umbraco.Web/Mvc/RenderViewEngine.cs +++ b/src/Umbraco.Web/Mvc/RenderViewEngine.cs @@ -15,6 +15,8 @@ namespace Umbraco.Web.Mvc /// public class RenderViewEngine : RazorViewEngine { + private readonly IIOHelper _ioHelper; + private readonly IEnumerable _supplementedViewLocations = new[] { "/{0}.cshtml" }; //NOTE: we will make the main view location the last to be searched since if it is the first to be searched and there is both a view and a partial // view in both locations and the main view is rendering a partial view with the same name, we will get a stack overflow exception. @@ -24,8 +26,10 @@ namespace Umbraco.Web.Mvc /// /// Constructor /// - public RenderViewEngine() + public RenderViewEngine(IIOHelper ioHelper) { + _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); + const string templateFolder = Constants.ViewLocation; // the Render view engine doesn't support Area's so make those blank @@ -41,9 +45,9 @@ namespace Umbraco.Web.Mvc /// /// Ensures that the correct web.config for razor exists in the /Views folder, the partials folder exist and the ViewStartPage exists. /// - private static void EnsureFoldersAndFiles() + private void EnsureFoldersAndFiles() { - var viewFolder = Current.IOHelper.MapPath(Constants.ViewLocation); + var viewFolder = _ioHelper.MapPath(Constants.ViewLocation); // ensure the web.config file is in the ~/Views folder Directory.CreateDirectory(viewFolder); diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPage.cs b/src/Umbraco.Web/Mvc/UmbracoViewPage.cs index 4095c11a62..a41d692b86 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPage.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPage.cs @@ -1,7 +1,10 @@ -using Umbraco.Core.Models.PublishedContent; +using System.Web.WebPages; +using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Web.Mvc { public abstract class UmbracoViewPage : UmbracoViewPage - { } + { + + } } diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index 8664f0a13c..8e231de38d 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Dictionary; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Web.Models; using Umbraco.Web.Routing; using Umbraco.Web.Security; @@ -235,6 +236,18 @@ namespace Umbraco.Web.Mvc base.WriteLiteral(value); } + public override void Write(object value) + { + if (value is IHtmlEncodedString) + { + base.WriteLiteral(value); + } + else + { + base.Write(value); + } + } + public HelperResult RenderSection(string name, Func defaultContents) { return WebViewPageExtensions.RenderSection(this, name, defaultContents); diff --git a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs index f28acd5e90..01bdf569ec 100644 --- a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -19,20 +20,22 @@ namespace Umbraco.Web.PropertyEditors private readonly ILocalizedTextService _textService; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public CheckBoxListPropertyEditor(ILogger logger, ILocalizedTextService textService, IDataTypeService dataTypeService, ILocalizationService localizationService) + public CheckBoxListPropertyEditor(ILogger logger, ILocalizedTextService textService, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base(logger) { _textService = textService; _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; } /// - protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); + protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService, _ioHelper); /// protected override IDataValueEditor CreateValueEditor() => new MultipleValueEditor(Logger, _dataTypeService, _localizationService, Attribute); diff --git a/src/Umbraco.Web/PropertyEditors/ColorPickerConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorPickerConfigurationEditor.cs index a4d894c551..e2cc93bd7c 100644 --- a/src/Umbraco.Web/PropertyEditors/ColorPickerConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ColorPickerConfigurationEditor.cs @@ -5,13 +5,14 @@ using System.Text.RegularExpressions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { internal class ColorPickerConfigurationEditor : ConfigurationEditor { - public ColorPickerConfigurationEditor() + public ColorPickerConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) { var items = Fields.First(x => x.Key == "items"); @@ -109,7 +110,7 @@ namespace Umbraco.Web.PropertyEditors var convertBool = useLabelObj.TryConvertTo(); if (convertBool.Success) output.UseLabel = convertBool.Result; - } + } // auto-assigning our ids, get next id from existing values var nextId = 1; diff --git a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs index be6bde248f..aae71f429e 100644 --- a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -12,11 +13,15 @@ namespace Umbraco.Web.PropertyEditors Group = Constants.PropertyEditors.Groups.Pickers)] public class ColorPickerPropertyEditor : DataEditor { - public ColorPickerPropertyEditor(ILogger logger) + private readonly IIOHelper _ioHelper; + + public ColorPickerPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// - protected override IConfigurationEditor CreateConfigurationEditor() => new ColorPickerConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new ColorPickerConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/ContentPickerConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/ContentPickerConfigurationEditor.cs index 1e7e2d79ce..9e434bb279 100644 --- a/src/Umbraco.Web/PropertyEditors/ContentPickerConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ContentPickerConfigurationEditor.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { internal class ContentPickerConfigurationEditor : ConfigurationEditor { - public ContentPickerConfigurationEditor() + public ContentPickerConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) { // configure fields // this is not part of ContentPickerConfiguration, @@ -23,7 +24,7 @@ namespace Umbraco.Web.PropertyEditors // not part of ContentPickerConfiguration but used to configure the UI editor d["showEditButton"] = false; d["showPathOnHover"] = false; - d["idType"] = "udi"; + d["idType"] = "udi"; return d; } diff --git a/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs index c6de91f560..f462c3f9db 100644 --- a/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -17,13 +18,17 @@ namespace Umbraco.Web.PropertyEditors Group = Constants.PropertyEditors.Groups.Pickers)] public class ContentPickerPropertyEditor : DataEditor { - public ContentPickerPropertyEditor(ILogger logger) + private readonly IIOHelper _ioHelper; + + public ContentPickerPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } protected override IConfigurationEditor CreateConfigurationEditor() { - return new ContentPickerConfigurationEditor(); + return new ContentPickerConfigurationEditor(_ioHelper); } } } diff --git a/src/Umbraco.Web/PropertyEditors/DateTimeConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/DateTimeConfigurationEditor.cs index 91707d6122..2758064973 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimeConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimeConfigurationEditor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -19,5 +20,9 @@ namespace Umbraco.Web.PropertyEditors return d; } + + public DateTimeConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } } } diff --git a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs index 31fbc9e3f1..dbc0b96bb2 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -15,13 +16,17 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-time")] public class DateTimePropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// Initializes a new instance of the class. /// /// - public DateTimePropertyEditor(ILogger logger) + public DateTimePropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// protected override IDataValueEditor CreateValueEditor() @@ -32,6 +37,6 @@ namespace Umbraco.Web.PropertyEditors } /// - protected override IConfigurationEditor CreateConfigurationEditor() => new DateTimeConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new DateTimeConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/DropDownFlexibleConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownFlexibleConfigurationEditor.cs index dbdedebd0a..f3ad0e6335 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownFlexibleConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownFlexibleConfigurationEditor.cs @@ -2,6 +2,7 @@ using System.Linq; using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -9,7 +10,7 @@ namespace Umbraco.Web.PropertyEditors { internal class DropDownFlexibleConfigurationEditor : ConfigurationEditor { - public DropDownFlexibleConfigurationEditor(ILocalizedTextService textService) + public DropDownFlexibleConfigurationEditor(ILocalizedTextService textService, IIOHelper ioHelper): base(ioHelper) { var items = Fields.First(x => x.Key == "items"); @@ -33,7 +34,7 @@ namespace Umbraco.Web.PropertyEditors { output.Multiple = convertBool.Result; } - } + } // auto-assigning our ids, get next id from existing values var nextId = 1; @@ -65,7 +66,7 @@ namespace Umbraco.Web.PropertyEditors // map to what the editor expects var i = 1; var items = configuration?.Items.ToDictionary(x => x.Id.ToString(), x => new { value = x.Value, sortOrder = i++ }) ?? new object(); - + var multiple = configuration?.Multiple ?? false; return new Dictionary diff --git a/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs index 0b0a0f6d06..60c0c04c4f 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownFlexiblePropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -16,13 +17,15 @@ namespace Umbraco.Web.PropertyEditors private readonly ILocalizedTextService _textService; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; - public DropDownFlexiblePropertyEditor(ILocalizedTextService textService, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) + public DropDownFlexiblePropertyEditor(ILocalizedTextService textService, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base(logger) { _textService = textService; _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; } protected override IDataValueEditor CreateValueEditor() @@ -30,6 +33,6 @@ namespace Umbraco.Web.PropertyEditors return new MultipleValueEditor(Logger, _dataTypeService, _localizationService, Attribute); } - protected override IConfigurationEditor CreateConfigurationEditor() => new DropDownFlexibleConfigurationEditor(_textService); + protected override IConfigurationEditor CreateConfigurationEditor() => new DropDownFlexibleConfigurationEditor(_textService, _ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/EmailAddressConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/EmailAddressConfigurationEditor.cs index 27e7bffab8..27287881ff 100644 --- a/src/Umbraco.Web/PropertyEditors/EmailAddressConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/EmailAddressConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the email address value editor. /// public class EmailAddressConfigurationEditor : ConfigurationEditor - { } -} \ No newline at end of file + { + public EmailAddressConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } +} diff --git a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs index cd3a830c72..faf7291cf5 100644 --- a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; @@ -13,11 +14,14 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-message")] public class EmailAddressPropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// The constructor will setup the property editor based on the attribute if one is found /// - public EmailAddressPropertyEditor(ILogger logger) : base(logger) + public EmailAddressPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) { + _ioHelper = ioHelper; } protected override IDataValueEditor CreateValueEditor() @@ -30,7 +34,7 @@ namespace Umbraco.Web.PropertyEditors protected override IConfigurationEditor CreateConfigurationEditor() { - return new EmailAddressConfigurationEditor(); + return new EmailAddressConfigurationEditor(_ioHelper); } } } diff --git a/src/Umbraco.Web/PropertyEditors/GridConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/GridConfigurationEditor.cs index e6b1462df0..8a275b69cd 100644 --- a/src/Umbraco.Web/PropertyEditors/GridConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridConfigurationEditor.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using Newtonsoft.Json; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; @@ -12,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors /// public class GridConfigurationEditor : ConfigurationEditor { - public GridConfigurationEditor() + public GridConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) { var items = Fields.First(x => x.Key == "items"); diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 6f6f1d911d..ca4fc32fd0 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; @@ -30,9 +31,10 @@ namespace Umbraco.Web.PropertyEditors private IUmbracoContextAccessor _umbracoContextAccessor; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; private ILogger _logger; - public GridPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService) + public GridPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base(logger) { _mediaService = mediaService; @@ -40,6 +42,7 @@ namespace Umbraco.Web.PropertyEditors _umbracoContextAccessor = umbracoContextAccessor; _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; _logger = logger; } @@ -51,7 +54,7 @@ namespace Umbraco.Web.PropertyEditors /// protected override IDataValueEditor CreateValueEditor() => new GridPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger, _dataTypeService, _localizationService); - protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(_ioHelper); internal class GridPropertyValueEditor : DataValueEditor { diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperConfigurationEditor.cs index 2751b3bdc1..42abfa0307 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperConfigurationEditor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -16,5 +17,9 @@ namespace Umbraco.Web.PropertyEditors if (!d.ContainsKey("src")) d["src"] = ""; return d; } + + public ImageCropperConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs index fe1f026417..f0e046ed83 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs @@ -33,18 +33,20 @@ namespace Umbraco.Web.PropertyEditors private readonly IContentSection _contentSettings; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; private readonly UploadAutoFillProperties _autoFillProperties; /// /// Initializes a new instance of the class. /// - public ImageCropperPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSettings, IDataTypeService dataTypeService, ILocalizationService localizationService) + public ImageCropperPropertyEditor(ILogger logger, IMediaFileSystem mediaFileSystem, IContentSection contentSettings, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base(logger) { _mediaFileSystem = mediaFileSystem ?? throw new ArgumentNullException(nameof(mediaFileSystem)); _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; // TODO: inject? _autoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, _contentSettings); @@ -60,7 +62,7 @@ namespace Umbraco.Web.PropertyEditors /// Creates the corresponding preValue editor. /// /// The corresponding preValue editor. - protected override IConfigurationEditor CreateConfigurationEditor() => new ImageCropperConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new ImageCropperConfigurationEditor(_ioHelper); /// /// Gets a value indicating whether a property is an image cropper field. diff --git a/src/Umbraco.Web/PropertyEditors/ListViewConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/ListViewConfigurationEditor.cs index 8239c981d0..d6b1b6f533 100644 --- a/src/Umbraco.Web/PropertyEditors/ListViewConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ListViewConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the listview value editor. /// public class ListViewConfigurationEditor : ConfigurationEditor - { } + { + public ListViewConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } } diff --git a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs index 53f9cb94ef..1394a7477e 100644 --- a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -17,15 +18,19 @@ namespace Umbraco.Web.PropertyEditors Icon = Constants.Icons.ListView)] public class ListViewPropertyEditor : DataEditor { + private readonly IIOHelper _iioHelper; + /// /// Initializes a new instance of the class. /// /// - public ListViewPropertyEditor(ILogger logger) + public ListViewPropertyEditor(ILogger logger, IIOHelper iioHelper) : base(logger) - { } + { + _iioHelper = iioHelper; + } /// - protected override IConfigurationEditor CreateConfigurationEditor() => new ListViewConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new ListViewConfigurationEditor(_iioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/MarkdownConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/MarkdownConfigurationEditor.cs index 9b08c3ac7b..adff49c040 100644 --- a/src/Umbraco.Web/PropertyEditors/MarkdownConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MarkdownConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editorfor the markdown value editor. /// internal class MarkdownConfigurationEditor : ConfigurationEditor - { } -} \ No newline at end of file + { + public MarkdownConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } +} diff --git a/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs index 2d66da5461..530fabeb11 100644 --- a/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -16,14 +17,18 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-code")] public class MarkdownPropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// Initializes a new instance of the class. /// - public MarkdownPropertyEditor(ILogger logger) + public MarkdownPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// - protected override IConfigurationEditor CreateConfigurationEditor() => new MarkdownConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new MarkdownConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/MediaPickerConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/MediaPickerConfigurationEditor.cs index 70f38e654c..98cc3c51b8 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPickerConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPickerConfigurationEditor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -11,7 +12,7 @@ namespace Umbraco.Web.PropertyEditors /// /// Initializes a new instance of the class. /// - public MediaPickerConfigurationEditor() + public MediaPickerConfigurationEditor(IIOHelper ioHelper): base(ioHelper) { // configure fields // this is not part of ContentPickerConfiguration, diff --git a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs index dd755ee0ba..6021eb3169 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -17,14 +18,18 @@ namespace Umbraco.Web.PropertyEditors Icon = Constants.Icons.MediaImage)] public class MediaPickerPropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// Initializes a new instance of the class. /// - public MediaPickerPropertyEditor(ILogger logger) + public MediaPickerPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// - protected override IConfigurationEditor CreateConfigurationEditor() => new MediaPickerConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new MediaPickerConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiNodePickerConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiNodePickerConfigurationEditor.cs index c6e4cbfa98..ba0375c691 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiNodePickerConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiNodePickerConfigurationEditor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -8,7 +9,7 @@ namespace Umbraco.Web.PropertyEditors /// public class MultiNodePickerConfigurationEditor : ConfigurationEditor { - public MultiNodePickerConfigurationEditor() + public MultiNodePickerConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) { Field(nameof(MultiNodePickerConfiguration.TreeSource)) .Config = new Dictionary { { "idType", "udi" } }; diff --git a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs index 742acbeca2..808387155e 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -13,10 +14,14 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-page-add")] public class MultiNodeTreePickerPropertyEditor : DataEditor { - public MultiNodeTreePickerPropertyEditor(ILogger logger) - : base(logger) - { } + private readonly IIOHelper _ioHelper; - protected override IConfigurationEditor CreateConfigurationEditor() => new MultiNodePickerConfigurationEditor(); + public MultiNodeTreePickerPropertyEditor(ILogger logger, IIOHelper ioHelper) + : base(logger) + { + _ioHelper = ioHelper; + } + + protected override IConfigurationEditor CreateConfigurationEditor() => new MultiNodePickerConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerConfigurationEditor.cs index e780e410a7..6cedae94fe 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerConfigurationEditor.cs @@ -1,8 +1,12 @@ +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { public class MultiUrlPickerConfigurationEditor : ConfigurationEditor { + public MultiUrlPickerConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs index a5da833501..f91f56e9e9 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs @@ -1,5 +1,6 @@ using System; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Logging; using Umbraco.Core.Services; @@ -21,16 +22,18 @@ namespace Umbraco.Web.PropertyEditors private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; - public MultiUrlPickerPropertyEditor(ILogger logger, IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService) : base(logger, EditorType.PropertyValue) + public MultiUrlPickerPropertyEditor(ILogger logger, IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base(logger, EditorType.PropertyValue) { _entityService = entityService ?? throw new ArgumentNullException(nameof(entityService)); _publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor)); _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; } - protected override IConfigurationEditor CreateConfigurationEditor() => new MultiUrlPickerConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new MultiUrlPickerConfigurationEditor(_ioHelper); protected override IDataValueEditor CreateValueEditor() => new MultiUrlPickerValueEditor(_entityService, _publishedSnapshotAccessor, Logger, _dataTypeService, _localizationService, Attribute); } diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs index e7da4ca113..243f668cb3 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringConfigurationEditor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; @@ -10,7 +11,7 @@ namespace Umbraco.Web.PropertyEditors /// internal class MultipleTextStringConfigurationEditor : ConfigurationEditor { - public MultipleTextStringConfigurationEditor() + public MultipleTextStringConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) { Fields.Add(new ConfigurationField(new IntegerValidator()) { diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs index 29ec8530d9..4bcb868253 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; @@ -27,18 +28,22 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-ordered-list")] public class MultipleTextStringPropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// Initializes a new instance of the class. /// - public MultipleTextStringPropertyEditor(ILogger logger) + public MultipleTextStringPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// protected override IDataValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService,Attribute); /// - protected override IConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(_ioHelper); /// /// Custom value editor so we can format the value for the editor and the database diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentConfigurationEditor.cs index 5daed5c0aa..566c800b3d 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/NestedContentConfigurationEditor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Umbraco.Core.IO; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -7,5 +8,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the nested content value editor. /// public class NestedContentConfigurationEditor : ConfigurationEditor - { } -} \ No newline at end of file + { + public NestedContentConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } +} diff --git a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs index d7486ee17b..bcb0580a1a 100644 --- a/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; @@ -30,15 +31,17 @@ namespace Umbraco.Web.PropertyEditors private readonly Lazy _propertyEditors; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; internal const string ContentTypeAliasPropertyKey = "ncContentTypeAlias"; - public NestedContentPropertyEditor(ILogger logger, Lazy propertyEditors, IDataTypeService dataTypeService, ILocalizationService localizationService) + public NestedContentPropertyEditor(ILogger logger, Lazy propertyEditors, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base (logger) { _propertyEditors = propertyEditors; _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; } // has to be lazy else circular dep in ctor @@ -46,7 +49,7 @@ namespace Umbraco.Web.PropertyEditors #region Pre Value Editor - protected override IConfigurationEditor CreateConfigurationEditor() => new NestedContentConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new NestedContentConfigurationEditor(_ioHelper); #endregion diff --git a/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs index f729decd2c..8e86c21493 100644 --- a/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -18,20 +19,22 @@ namespace Umbraco.Web.PropertyEditors public class RadioButtonsPropertyEditor : DataEditor { private readonly ILocalizedTextService _textService; + private readonly IIOHelper _ioHelper; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public RadioButtonsPropertyEditor(ILogger logger, ILocalizedTextService textService) + public RadioButtonsPropertyEditor(ILogger logger, ILocalizedTextService textService, IIOHelper ioHelper) : base(logger) { _textService = textService; + _ioHelper = ioHelper; } /// /// Return a custom pre-value editor /// /// - protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService); + protected override IConfigurationEditor CreateConfigurationEditor() => new ValueListConfigurationEditor(_textService, _ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/RichTextConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextConfigurationEditor.cs index 4777b5ebb0..c6d0b95483 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the rich text value editor. /// internal class RichTextConfigurationEditor : ConfigurationEditor - { } + { + public RichTextConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } } diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index aa6876df39..343ae39fd3 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -29,6 +30,7 @@ namespace Umbraco.Web.PropertyEditors private IUmbracoContextAccessor _umbracoContextAccessor; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; private ILogger _logger; /// @@ -40,13 +42,15 @@ namespace Umbraco.Web.PropertyEditors IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, IDataTypeService dataTypeService, - ILocalizationService localizationService) : base(logger) + ILocalizationService localizationService, + IIOHelper ioHelper) : base(logger) { _mediaService = mediaService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; _umbracoContextAccessor = umbracoContextAccessor; _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; _logger = logger; } @@ -56,7 +60,7 @@ namespace Umbraco.Web.PropertyEditors /// protected override IDataValueEditor CreateValueEditor() => new RichTextPropertyValueEditor(Attribute, _mediaService, _contentTypeBaseServiceProvider, _umbracoContextAccessor, _logger, _dataTypeService, _localizationService); - protected override IConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new RichTextConfigurationEditor(_ioHelper); public override IPropertyIndexValueFactory PropertyIndexValueFactory => new RichTextPropertyIndexValueFactory(); diff --git a/src/Umbraco.Web/PropertyEditors/SliderConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/SliderConfigurationEditor.cs index c243c05985..fe34c16449 100644 --- a/src/Umbraco.Web/PropertyEditors/SliderConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/SliderConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the slider value editor. /// public class SliderConfigurationEditor : ConfigurationEditor - { } -} \ No newline at end of file + { + public SliderConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } +} diff --git a/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs index 8a98f15081..d91ba2041e 100644 --- a/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -14,17 +15,21 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-navigation-horizontal")] public class SliderPropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// Initializes a new instance of the class. /// - public SliderPropertyEditor(ILogger logger) + public SliderPropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// protected override IConfigurationEditor CreateConfigurationEditor() { - return new SliderConfigurationEditor(); + return new SliderConfigurationEditor(_ioHelper); } } } diff --git a/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs index 5d396980e3..ae7cdb1e40 100644 --- a/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Converters; +using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; @@ -13,7 +14,7 @@ namespace Umbraco.Web.PropertyEditors /// public class TagConfigurationEditor : ConfigurationEditor { - public TagConfigurationEditor(ManifestValueValidatorCollection validators) + public TagConfigurationEditor(ManifestValueValidatorCollection validators, IIOHelper ioHelper) : base(ioHelper) { Field(nameof(TagConfiguration.Group)).Validators.Add(new RequiredValidator()); Field(nameof(TagConfiguration.StorageType)).Validators.Add(new RequiredValidator()); diff --git a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs index 74338ba3fa..932497d297 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs @@ -5,6 +5,7 @@ using System.Linq; using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; @@ -25,16 +26,18 @@ namespace Umbraco.Web.PropertyEditors public class TagsPropertyEditor : DataEditor { private readonly ManifestValueValidatorCollection _validators; + private readonly IIOHelper _ioHelper; - public TagsPropertyEditor(ManifestValueValidatorCollection validators, ILogger logger) + public TagsPropertyEditor(ManifestValueValidatorCollection validators, ILogger logger, IIOHelper ioHelper) : base(logger) { _validators = validators; + _ioHelper = ioHelper; } protected override IDataValueEditor CreateValueEditor() => new TagPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService, Attribute); - protected override IConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators); + protected override IConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators, _ioHelper); internal class TagPropertyValueEditor : DataValueEditor { diff --git a/src/Umbraco.Web/PropertyEditors/TextAreaConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/TextAreaConfigurationEditor.cs index 210a571c17..3a90354339 100644 --- a/src/Umbraco.Web/PropertyEditors/TextAreaConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextAreaConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the textarea value editor. /// public class TextAreaConfigurationEditor : ConfigurationEditor - { } + { + public TextAreaConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } } diff --git a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs index 28698e2c5c..c5a848855c 100644 --- a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -19,21 +20,23 @@ namespace Umbraco.Web.PropertyEditors { private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; /// /// Initializes a new instance of the class. /// - public TextAreaPropertyEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) + public TextAreaPropertyEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base(logger) { _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; } /// protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(_dataTypeService, _localizationService, Attribute); /// - protected override IConfigurationEditor CreateConfigurationEditor() => new TextAreaConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new TextAreaConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/TextboxConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxConfigurationEditor.cs index aee2a8261d..0696d7238c 100644 --- a/src/Umbraco.Web/PropertyEditors/TextboxConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the textbox value editor. /// public class TextboxConfigurationEditor : ConfigurationEditor - { } -} \ No newline at end of file + { + public TextboxConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } +} diff --git a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs index c7c13b4caf..6823c62e9c 100644 --- a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -18,21 +19,23 @@ namespace Umbraco.Web.PropertyEditors { private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly IIOHelper _ioHelper; /// /// Initializes a new instance of the class. /// - public TextboxPropertyEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService) + public TextboxPropertyEditor(ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, IIOHelper ioHelper) : base(logger) { _dataTypeService = dataTypeService; _localizationService = localizationService; + _ioHelper = ioHelper; } /// protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(_dataTypeService, _localizationService, Attribute); /// - protected override IConfigurationEditor CreateConfigurationEditor() => new TextboxConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new TextboxConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/TrueFalseConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/TrueFalseConfigurationEditor.cs index 73fb9b9c3f..594a3f4d6e 100644 --- a/src/Umbraco.Web/PropertyEditors/TrueFalseConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TrueFalseConfigurationEditor.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.PropertyEditors; +using Umbraco.Core.IO; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors { @@ -6,5 +7,9 @@ namespace Umbraco.Web.PropertyEditors /// Represents the configuration editor for the boolean value editor. /// public class TrueFalseConfigurationEditor : ConfigurationEditor - { } -} \ No newline at end of file + { + public TrueFalseConfigurationEditor(IIOHelper ioHelper) : base(ioHelper) + { + } + } +} diff --git a/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs index fb2d2b29fe..0313172fac 100644 --- a/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -17,15 +18,19 @@ namespace Umbraco.Web.PropertyEditors Icon = "icon-checkbox")] public class TrueFalsePropertyEditor : DataEditor { + private readonly IIOHelper _ioHelper; + /// /// Initializes a new instance of the class. /// - public TrueFalsePropertyEditor(ILogger logger) + public TrueFalsePropertyEditor(ILogger logger, IIOHelper ioHelper) : base(logger) - { } + { + _ioHelper = ioHelper; + } /// - protected override IConfigurationEditor CreateConfigurationEditor() => new TrueFalseConfigurationEditor(); + protected override IConfigurationEditor CreateConfigurationEditor() => new TrueFalseConfigurationEditor(_ioHelper); } } diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs index d5e1f841ea..330f580ca2 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.Macros; using System.Web; +using Umbraco.Core.Strings; namespace Umbraco.Web.PropertyEditors.ValueConverters { @@ -68,7 +69,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters { var converted = Convert(inter, preview); - return new HtmlString(converted == null ? string.Empty : converted); + return new HtmlEncodedString(converted == null ? string.Empty : converted); } private string Convert(object source, bool preview) diff --git a/src/Umbraco.Web/PropertyEditors/ValueListConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/ValueListConfigurationEditor.cs index abfde3646a..6facc69f40 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueListConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueListConfigurationEditor.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json.Linq; +using Umbraco.Core.IO; using Umbraco.Core.Services; using Umbraco.Core.PropertyEditors; @@ -14,7 +15,7 @@ namespace Umbraco.Web.PropertyEditors /// public class ValueListConfigurationEditor : ConfigurationEditor { - public ValueListConfigurationEditor(ILocalizedTextService textService) + public ValueListConfigurationEditor(ILocalizedTextService textService, IIOHelper ioHelper) : base(ioHelper) { var items = Fields.First(x => x.Key == "items"); diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index f02a3686ac..550a9c2743 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -32,14 +32,16 @@ namespace Umbraco.Web.Runtime private readonly UmbracoApiControllerTypeCollection _apiControllerTypes; private readonly IGlobalSettings _globalSettings; private readonly IHostingEnvironment _hostingEnvironment; + private readonly IIOHelper _ioHelper; - public WebInitialComponent(IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) + public WebInitialComponent(IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment, IIOHelper ioHelper) { _umbracoContextAccessor = umbracoContextAccessor; _surfaceControllerTypes = surfaceControllerTypes; _apiControllerTypes = apiControllerTypes; _globalSettings = globalSettings; _hostingEnvironment = hostingEnvironment; + _ioHelper = ioHelper; } public void Initialize() @@ -49,7 +51,7 @@ namespace Umbraco.Web.Runtime // When using a non-web runtime and this component is loaded ClientDependency explodes because it'll // want to access HttpContext.Current, which doesn't exist - if (Current.IOHelper.IsHosted) + if (Current.HostingEnvironment.IsHosted) { ConfigureClientDependency(); } @@ -89,7 +91,7 @@ namespace Umbraco.Web.Runtime } } - private static void SetupMvcAndWebApi() + private void SetupMvcAndWebApi() { //don't output the MVC version header (security) MvcHandler.DisableMvcResponseHeader = true; @@ -99,7 +101,7 @@ namespace Umbraco.Web.Runtime ControllerBuilder.Current.SetControllerFactory(controllerFactory); // set the render & plugin view engines - ViewEngines.Engines.Add(new RenderViewEngine()); + ViewEngines.Engines.Add(new RenderViewEngine(_ioHelper)); ViewEngines.Engines.Add(new PluginViewEngine()); //set model binder diff --git a/src/Umbraco.Web/Runtime/WebRuntime.cs b/src/Umbraco.Web/Runtime/WebRuntime.cs index 8e83afada1..9a42c19e0a 100644 --- a/src/Umbraco.Web/Runtime/WebRuntime.cs +++ b/src/Umbraco.Web/Runtime/WebRuntime.cs @@ -84,7 +84,7 @@ namespace Umbraco.Web.Runtime #region Getters - protected override ITypeFinder GetTypeFinder() => _typeFinder ?? (_typeFinder = new BuildManagerTypeFinder(IOHelper, Logger, new BuildManagerTypeFinder.TypeFinderConfig())); + protected override ITypeFinder GetTypeFinder() => _typeFinder ?? (_typeFinder = new BuildManagerTypeFinder(IOHelper, HostingEnvironment, Logger, new BuildManagerTypeFinder.TypeFinderConfig())); protected override AppCaches GetAppCaches() => new AppCaches( // we need to have the dep clone runtime cache provider to ensure diff --git a/src/Umbraco.Web/Security/AppBuilderExtensions.cs b/src/Umbraco.Web/Security/AppBuilderExtensions.cs index d252b4bc57..ede574671f 100644 --- a/src/Umbraco.Web/Security/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/Security/AppBuilderExtensions.cs @@ -13,6 +13,7 @@ using Owin; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; using Umbraco.Core.Mapping; using Umbraco.Core.Models.Identity; using Umbraco.Core.Security; @@ -143,9 +144,15 @@ namespace Umbraco.Web.Security /// /// By default this will be configured to execute on PipelineStage.Authenticate /// - public static IAppBuilder UseUmbracoBackOfficeCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IUserService userService, IGlobalSettings globalSettings, ISecuritySection securitySection) + public static IAppBuilder UseUmbracoBackOfficeCookieAuthentication(this IAppBuilder app, + IUmbracoContextAccessor umbracoContextAccessor, + IRuntimeState runtimeState, + IUserService userService, + IGlobalSettings globalSettings, + ISecuritySection securitySection, + IIOHelper ioHelper) { - return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, userService, globalSettings, securitySection, PipelineStage.Authenticate); + return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, userService, globalSettings, securitySection, ioHelper, PipelineStage.Authenticate); } /// @@ -157,16 +164,24 @@ namespace Umbraco.Web.Security /// /// /// + /// /// /// Configurable pipeline stage /// /// - public static IAppBuilder UseUmbracoBackOfficeCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IUserService userService, IGlobalSettings globalSettings, ISecuritySection securitySection, PipelineStage stage) + public static IAppBuilder UseUmbracoBackOfficeCookieAuthentication(this IAppBuilder app, + IUmbracoContextAccessor umbracoContextAccessor, + IRuntimeState runtimeState, + IUserService userService, + IGlobalSettings globalSettings, + ISecuritySection securitySection, + IIOHelper ioHelper, + PipelineStage stage) { //Create the default options and provider - var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySection); + var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySection, ioHelper); - authOptions.Provider = new BackOfficeCookieAuthenticationProvider(userService, runtimeState, globalSettings) + authOptions.Provider = new BackOfficeCookieAuthenticationProvider(userService, runtimeState, globalSettings, ioHelper) { // Enables the application to validate the security stamp when the user // logs in. This is a security feature which is used when you @@ -179,7 +194,7 @@ namespace Umbraco.Web.Security }; - return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySection, authOptions, stage); + return app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySection, ioHelper, authOptions, stage); } /// @@ -190,12 +205,13 @@ namespace Umbraco.Web.Security /// /// /// + /// /// Custom auth cookie options can be specified to have more control over the cookie authentication logic /// /// Configurable pipeline stage /// /// - public static IAppBuilder UseUmbracoBackOfficeCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySection securitySection, CookieAuthenticationOptions cookieOptions, PipelineStage stage) + public static IAppBuilder UseUmbracoBackOfficeCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySection securitySection, IIOHelper ioHelper, CookieAuthenticationOptions cookieOptions, PipelineStage stage) { if (app == null) throw new ArgumentNullException(nameof(app)); if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState)); @@ -213,7 +229,7 @@ namespace Umbraco.Web.Security var cookieAuthOptions = app.CreateUmbracoCookieAuthOptions( umbracoContextAccessor, globalSettings, runtimeState, securitySection, //This defines the explicit path read cookies from for this middleware - new[] {$"{globalSettings.Path}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"}); + ioHelper, new[] {$"{globalSettings.Path}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"}); cookieAuthOptions.Provider = cookieOptions.Provider; //This is a custom middleware, we need to return the user's remaining logged in seconds @@ -291,9 +307,9 @@ namespace Umbraco.Web.Security /// /// By default this will be configured to execute on PipelineStage.Authenticate /// - public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IGlobalSettings globalSettings) + public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState,IGlobalSettings globalSettings, IIOHelper ioHelper) { - return app.UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, PipelineStage.Authenticate); + return app.UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, globalSettings, ioHelper, PipelineStage.Authenticate); } /// @@ -304,14 +320,16 @@ namespace Umbraco.Web.Security /// /// /// + /// /// /// public static IAppBuilder UseUmbracoBackOfficeExternalCookieAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, - IGlobalSettings globalSettings, PipelineStage stage) + IGlobalSettings globalSettings, IIOHelper ioHelper, PipelineStage stage) { if (app == null) throw new ArgumentNullException(nameof(app)); if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState)); + if (ioHelper == null) throw new ArgumentNullException(nameof(ioHelper)); app.UseCookieAuthentication(new CookieAuthenticationOptions { @@ -320,7 +338,7 @@ namespace Umbraco.Web.Security CookieName = Constants.Security.BackOfficeExternalCookieName, ExpireTimeSpan = TimeSpan.FromMinutes(5), //Custom cookie manager so we can filter requests - CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, globalSettings), + CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, globalSettings, ioHelper), CookiePath = "/", CookieSecure = globalSettings.UseHttps ? CookieSecureOption.Always : CookieSecureOption.SameAsRequest, CookieHttpOnly = true, @@ -338,6 +356,7 @@ namespace Umbraco.Web.Security /// /// /// + /// /// /// /// This ensures that during a preview request that the back office use is also Authenticated and that the back office Identity @@ -346,9 +365,9 @@ namespace Umbraco.Web.Security /// /// By default this will be configured to execute on PipelineStage.PostAuthenticate /// - public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySection securitySettings) + public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySection securitySettings, IIOHelper ioHelper) { - return app.UseUmbracoPreviewAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySettings, PipelineStage.PostAuthenticate); + return app.UseUmbracoPreviewAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySettings, ioHelper, PipelineStage.PostAuthenticate); } /// @@ -359,18 +378,19 @@ namespace Umbraco.Web.Security /// /// /// + /// /// /// /// /// This ensures that during a preview request that the back office use is also Authenticated and that the back office Identity /// is added as a secondary identity to the current IPrincipal so it can be used to Authorize the previewed document. /// - public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySection securitySettings, PipelineStage stage) + public static IAppBuilder UseUmbracoPreviewAuthentication(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, IGlobalSettings globalSettings, ISecuritySection securitySettings, IIOHelper ioHelper, PipelineStage stage) { if (runtimeState.Level != RuntimeLevel.Run) return app; - var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySettings); - app.Use(typeof(PreviewAuthenticationMiddleware), authOptions, Current.Configs.Global()); + var authOptions = app.CreateUmbracoCookieAuthOptions(umbracoContextAccessor, globalSettings, runtimeState, securitySettings, ioHelper); + app.Use(typeof(PreviewAuthenticationMiddleware), authOptions, Current.Configs.Global(), ioHelper); // This middleware must execute at least on PostAuthentication, by default it is on Authorize // The middleware needs to execute after the RoleManagerModule executes which is during PostAuthenticate, @@ -400,7 +420,7 @@ namespace Umbraco.Web.Security /// public static UmbracoBackOfficeCookieAuthOptions CreateUmbracoCookieAuthOptions(this IAppBuilder app, IUmbracoContextAccessor umbracoContextAccessor, - IGlobalSettings globalSettings, IRuntimeState runtimeState, ISecuritySection securitySettings, string[] explicitPaths = null) + IGlobalSettings globalSettings, IRuntimeState runtimeState, ISecuritySection securitySettings, IIOHelper ioHelper, string[] explicitPaths = null) { //this is how aspnet wires up the default AuthenticationTicket protector so we'll use the same code var ticketDataFormat = new TicketDataFormat( @@ -414,7 +434,8 @@ namespace Umbraco.Web.Security securitySettings, globalSettings, runtimeState, - ticketDataFormat); + ticketDataFormat, + ioHelper); return authOptions; } diff --git a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs index e7aef4be03..e56e35ba2a 100644 --- a/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs +++ b/src/Umbraco.Web/Security/BackOfficeCookieAuthenticationProvider.cs @@ -11,6 +11,7 @@ using Microsoft.Owin.Security.Cookies; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Core.Security; using Umbraco.Core.Services; @@ -21,12 +22,14 @@ namespace Umbraco.Web.Security private readonly IUserService _userService; private readonly IRuntimeState _runtimeState; private readonly IGlobalSettings _globalSettings; + private readonly IIOHelper _ioHelper; - public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings) + public BackOfficeCookieAuthenticationProvider(IUserService userService, IRuntimeState runtimeState, IGlobalSettings globalSettings, IIOHelper ioHelper) { _userService = userService; _runtimeState = runtimeState; _globalSettings = globalSettings; + _ioHelper = ioHelper; } public override void ResponseSignIn(CookieResponseSignInContext context) @@ -113,7 +116,7 @@ namespace Umbraco.Web.Security protected virtual async Task EnsureValidSessionId(CookieValidateIdentityContext context) { if (_runtimeState.Level == RuntimeLevel.Run) - await SessionIdValidator.ValidateSessionAsync(TimeSpan.FromMinutes(1), context, _globalSettings); + await SessionIdValidator.ValidateSessionAsync(TimeSpan.FromMinutes(1), context, _globalSettings, _ioHelper); } diff --git a/src/Umbraco.Web/Security/BackOfficeCookieManager.cs b/src/Umbraco.Web/Security/BackOfficeCookieManager.cs index 5da86204f3..5d70b9b09c 100644 --- a/src/Umbraco.Web/Security/BackOfficeCookieManager.cs +++ b/src/Umbraco.Web/Security/BackOfficeCookieManager.cs @@ -6,6 +6,7 @@ using Microsoft.Owin; using Microsoft.Owin.Infrastructure; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Core.Security; namespace Umbraco.Web.Security @@ -22,18 +23,20 @@ namespace Umbraco.Web.Security private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly IRuntimeState _runtime; private readonly IGlobalSettings _globalSettings; + private readonly IIOHelper _ioHelper; private readonly string[] _explicitPaths; private readonly string _getRemainingSecondsPath; - public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IGlobalSettings globalSettings) - : this(umbracoContextAccessor, runtime, globalSettings, null) + public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IGlobalSettings globalSettings, IIOHelper ioHelper) + : this(umbracoContextAccessor, runtime, globalSettings, ioHelper,null) { } - public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IGlobalSettings globalSettings, IEnumerable explicitPaths) + public BackOfficeCookieManager(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtime, IGlobalSettings globalSettings, IIOHelper ioHelper, IEnumerable explicitPaths) { _umbracoContextAccessor = umbracoContextAccessor; _runtime = runtime; _globalSettings = globalSettings; + _ioHelper = ioHelper; _explicitPaths = explicitPaths?.ToArray(); _getRemainingSecondsPath = $"{globalSettings.Path}/backoffice/UmbracoApi/Authentication/GetRemainingTimeoutSeconds"; } @@ -101,9 +104,9 @@ namespace Umbraco.Web.Security (checkForceAuthTokens && owinContext.Get(Constants.Security.ForceReAuthFlag) != null) || (checkForceAuthTokens && httpContext.Success && httpContext.Result.Items[Constants.Security.ForceReAuthFlag] != null) //check back office - || request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings) + || request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings, _ioHelper) //check installer - || request.Uri.IsInstallerRequest()) + || request.Uri.IsInstallerRequest(_ioHelper)) { return true; } diff --git a/src/Umbraco.Web/Security/PreviewAuthenticationMiddleware.cs b/src/Umbraco.Web/Security/PreviewAuthenticationMiddleware.cs index ccb2a81e51..18deeafcbf 100644 --- a/src/Umbraco.Web/Security/PreviewAuthenticationMiddleware.cs +++ b/src/Umbraco.Web/Security/PreviewAuthenticationMiddleware.cs @@ -4,6 +4,7 @@ using System.Web; using Microsoft.Owin; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Core.Security; namespace Umbraco.Web.Security @@ -12,6 +13,7 @@ namespace Umbraco.Web.Security { private readonly UmbracoBackOfficeCookieAuthOptions _cookieOptions; private readonly IGlobalSettings _globalSettings; + private readonly IIOHelper _ioHelper; /// /// Instantiates the middleware with an optional pointer to the next component. @@ -20,10 +22,11 @@ namespace Umbraco.Web.Security /// /// public PreviewAuthenticationMiddleware(OwinMiddleware next, - UmbracoBackOfficeCookieAuthOptions cookieOptions, IGlobalSettings globalSettings) : base(next) + UmbracoBackOfficeCookieAuthOptions cookieOptions, IGlobalSettings globalSettings, IIOHelper ioHelper) : base(next) { _cookieOptions = cookieOptions; _globalSettings = globalSettings; + _ioHelper = ioHelper; } /// @@ -40,7 +43,7 @@ namespace Umbraco.Web.Security var isPreview = request.HasPreviewCookie() && claimsPrincipal != null && request.Uri != null - && request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings) == false; + && request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings, _ioHelper) == false; if (isPreview) { //If we've gotten this far it means a preview cookie has been set and a front-end umbraco document request is executing. diff --git a/src/Umbraco.Web/Security/SessionIdValidator.cs b/src/Umbraco.Web/Security/SessionIdValidator.cs index 30c5ea98c9..8f6782aac2 100644 --- a/src/Umbraco.Web/Security/SessionIdValidator.cs +++ b/src/Umbraco.Web/Security/SessionIdValidator.cs @@ -9,6 +9,7 @@ using Microsoft.Owin.Infrastructure; using Microsoft.Owin.Security.Cookies; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Core.Security; using Constants = Umbraco.Core.Constants; @@ -28,9 +29,9 @@ namespace Umbraco.Web.Security { public const string CookieName = "UMB_UCONTEXT_C"; - public static async Task ValidateSessionAsync(TimeSpan validateInterval, CookieValidateIdentityContext context, IGlobalSettings globalSettings) + public static async Task ValidateSessionAsync(TimeSpan validateInterval, CookieValidateIdentityContext context, IGlobalSettings globalSettings, IIOHelper ioHelper) { - if (context.Request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, globalSettings) == false) + if (context.Request.Uri.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, globalSettings, ioHelper) == false) return; var valid = await ValidateSessionAsync(validateInterval, context.OwinContext, context.Options.CookieManager, context.Options.SystemClock, context.Properties.IssuedUtc, context.Identity, globalSettings); diff --git a/src/Umbraco.Web/Security/UmbracoBackOfficeCookieAuthOptions.cs b/src/Umbraco.Web/Security/UmbracoBackOfficeCookieAuthOptions.cs index 83735ad93f..1ad2535c2f 100644 --- a/src/Umbraco.Web/Security/UmbracoBackOfficeCookieAuthOptions.cs +++ b/src/Umbraco.Web/Security/UmbracoBackOfficeCookieAuthOptions.cs @@ -5,6 +5,7 @@ using Microsoft.Owin.Security.Cookies; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; namespace Umbraco.Web.Security { @@ -21,7 +22,8 @@ namespace Umbraco.Web.Security ISecuritySection securitySection, IGlobalSettings globalSettings, IRuntimeState runtimeState, - ISecureDataFormat secureDataFormat) + ISecureDataFormat secureDataFormat, + IIOHelper ioHelper) { var secureDataFormat1 = secureDataFormat ?? throw new ArgumentNullException(nameof(secureDataFormat)); LoginTimeoutMinutes = globalSettings.TimeOutInMinutes; @@ -38,7 +40,7 @@ namespace Umbraco.Web.Security TicketDataFormat = new UmbracoSecureDataFormat(LoginTimeoutMinutes, secureDataFormat1); //Custom cookie manager so we can filter requests - CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, globalSettings, explicitPaths); + CookieManager = new BackOfficeCookieManager(umbracoContextAccessor, runtimeState, globalSettings, ioHelper, explicitPaths); } /// diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 731132d8bf..0e0e9aba39 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -27,16 +27,21 @@ namespace Umbraco.Web private readonly IProfiler _profiler; private readonly IHostingEnvironment _hostingEnvironment; private readonly IBackOfficeInfo _backOfficeInfo; + private IFactory _factory; protected UmbracoApplicationBase() { - _ioHelper = new IOHelper(); + + + IGlobalSettings globalSettings = null; //TODO, cleanup this circular dependency + _hostingEnvironment = new AspNetHostingEnvironment(new Lazy(() => globalSettings)); + _ioHelper = new IOHelper(_hostingEnvironment); _configs = new ConfigsFactory(_ioHelper).Create(); - var globalSettings = _configs.Global(); + globalSettings = _configs.Global(); _profiler = new LogProfiler(_logger); - _hostingEnvironment = new AspNetHostingEnvironment(globalSettings, _ioHelper); - _logger = SerilogLogger.CreateWithDefaultConfiguration(_hostingEnvironment); + + _logger = SerilogLogger.CreateWithDefaultConfiguration(_hostingEnvironment, new AspNetSessionIdResolver(), () => _factory); _backOfficeInfo = new AspNetBackOfficeInfo(globalSettings, _ioHelper, _configs.Settings(), _logger); } @@ -100,7 +105,7 @@ namespace Umbraco.Web // the boot manager is responsible for registrations var register = GetRegister(globalSettings); _runtime = GetRuntime(_configs, umbracoVersion, _ioHelper, _logger, _profiler, _hostingEnvironment, _backOfficeInfo); - _runtime.Boot(register); + _factory = _runtime.Boot(register); } // called by ASP.NET (auto event wireup) once per app domain diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 547bd517d8..40db02b44c 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; +using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web; using Umbraco.Web.PublishedCache; @@ -23,6 +24,7 @@ namespace Umbraco.Web public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd { private readonly IGlobalSettings _globalSettings; + private readonly IIOHelper _ioHelper; private readonly Lazy _publishedSnapshot; private string _previewToken; private bool? _previewing; @@ -38,7 +40,8 @@ namespace Umbraco.Web IEnumerable urlProviders, IEnumerable mediaUrlProviders, IGlobalSettings globalSettings, - IVariationContextAccessor variationContextAccessor) + IVariationContextAccessor variationContextAccessor, + IIOHelper ioHelper) { if (httpContext == null) throw new ArgumentNullException(nameof(httpContext)); if (publishedSnapshotService == null) throw new ArgumentNullException(nameof(publishedSnapshotService)); @@ -48,6 +51,7 @@ namespace Umbraco.Web if (mediaUrlProviders == null) throw new ArgumentNullException(nameof(mediaUrlProviders)); VariationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); // ensure that this instance is disposed when the request terminates, though we *also* ensure // this happens in the Umbraco module since the UmbracoCOntext is added to the HttpContext items. @@ -282,7 +286,7 @@ namespace Umbraco.Web { var request = GetRequestFromContext(); if (request?.Url != null - && request.Url.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings) == false + && request.Url.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings, _ioHelper) == false && Security.CurrentUser != null) { var previewToken = request.GetPreviewCookieValue(); // may be null or empty diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index dcd810d0e0..cc618bfc82 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -6,6 +6,7 @@ using System.Web; using System.Web.Hosting; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Web.PublishedCache; @@ -31,11 +32,12 @@ namespace Umbraco.Web private readonly UrlProviderCollection _urlProviders; private readonly MediaUrlProviderCollection _mediaUrlProviders; private readonly IUserService _userService; + private readonly IIOHelper _ioHelper; /// /// Initializes a new instance of the class. /// - public UmbracoContextFactory(IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, IUmbracoSettingsSection umbracoSettings, IGlobalSettings globalSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IUserService userService) + public UmbracoContextFactory(IUmbracoContextAccessor umbracoContextAccessor, IPublishedSnapshotService publishedSnapshotService, IVariationContextAccessor variationContextAccessor, IDefaultCultureAccessor defaultCultureAccessor, IUmbracoSettingsSection umbracoSettings, IGlobalSettings globalSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IUserService userService, IIOHelper ioHelper) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); @@ -47,6 +49,7 @@ namespace Umbraco.Web _urlProviders = urlProviders ?? throw new ArgumentNullException(nameof(urlProviders)); _mediaUrlProviders = mediaUrlProviders ?? throw new ArgumentNullException(nameof(mediaUrlProviders)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); + _ioHelper = ioHelper; } private UmbracoContext CreateUmbracoContext(HttpContextBase httpContext) @@ -65,7 +68,7 @@ namespace Umbraco.Web var webSecurity = new WebSecurity(httpContext, _userService, _globalSettings); - return new UmbracoContext(httpContext, _publishedSnapshotService, webSecurity, _umbracoSettings, _urlProviders, _mediaUrlProviders, _globalSettings, _variationContextAccessor); + return new UmbracoContext(httpContext, _publishedSnapshotService, webSecurity, _umbracoSettings, _urlProviders, _mediaUrlProviders, _globalSettings, _variationContextAccessor, _ioHelper); } /// diff --git a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs index 3ddedd9ea4..bd3ca2a156 100644 --- a/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs +++ b/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs @@ -4,6 +4,7 @@ using Owin; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; using Umbraco.Core.Mapping; using Umbraco.Core.Security; using Umbraco.Core.Services; @@ -33,6 +34,7 @@ namespace Umbraco.Web protected ServiceContext Services => Current.Services; protected UmbracoMapper Mapper => Current.Mapper; protected IIpResolver IpResolver => Current.IpResolver; + protected IIOHelper IOHelper => Current.IOHelper; /// /// Main startup method @@ -101,9 +103,9 @@ namespace Umbraco.Web // Ensure owin is configured for Umbraco back office authentication. // Front-end OWIN cookie configuration must be declared after this code. app - .UseUmbracoBackOfficeCookieAuthentication(UmbracoContextAccessor, RuntimeState, Services.UserService, GlobalSettings, UmbracoSettings.Security, PipelineStage.Authenticate) - .UseUmbracoBackOfficeExternalCookieAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, PipelineStage.Authenticate) - .UseUmbracoPreviewAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, UmbracoSettings.Security, PipelineStage.Authorize); + .UseUmbracoBackOfficeCookieAuthentication(UmbracoContextAccessor, RuntimeState, Services.UserService, GlobalSettings, UmbracoSettings.Security, IOHelper, PipelineStage.Authenticate) + .UseUmbracoBackOfficeExternalCookieAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, IOHelper, PipelineStage.Authenticate) + .UseUmbracoPreviewAuthentication(UmbracoContextAccessor, RuntimeState, GlobalSettings, UmbracoSettings.Security, IOHelper, PipelineStage.Authorize); } public static event EventHandler MiddlewareConfigured; diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index 0226c35885..4b66c605a7 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -375,7 +375,7 @@ namespace Umbraco.Web { var httpContext = ((HttpApplication) sender).Context; - LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId); + LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId, Current.AppCaches.RequestCache); _logger.Verbose("Begin request [{HttpRequestId}]: {RequestUrl}", httpRequestId, httpContext.Request.Url); BeginRequest(new HttpContextWrapper(httpContext)); @@ -420,7 +420,7 @@ namespace Umbraco.Web if (Current.UmbracoContext != null && Current.UmbracoContext.IsFrontEndUmbracoRequest) { - LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId); + LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId, Current.AppCaches.RequestCache); _logger.Verbose("End Request [{HttpRequestId}]: {RequestUrl} ({RequestDuration}ms)", httpRequestId, httpContext.Request.Url, DateTime.Now.Subtract(Current.UmbracoContext.ObjectCreated).TotalMilliseconds); }