diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 885cb4bb78..550c02ea19 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using AutoMapper; @@ -8,6 +9,7 @@ using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.LightInject; using Umbraco.Core.Logging; +using Umbraco.Core.Manifest; using Umbraco.Core.Models.Mapping; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.ObjectResolution; @@ -126,10 +128,14 @@ namespace Umbraco.Core /// private void ConfigureCoreServices(ServiceContainer container) { + container.Register(factory => container); container.Register(factory => _umbracoApplication.Logger, new PerContainerLifetime()); container.Register(factory => ProfilingLogger.Profiler, new PerContainerLifetime()); container.Register(factory => ProfilingLogger, new PerContainerLifetime()); - container.Register(factory => UmbracoConfig.For.UmbracoSettings()); + var settings = UmbracoConfig.For.UmbracoSettings(); + container.Register(factory => settings); + container.Register(factory => settings.Content); + //TODO: Add the other config areas... container.Register(factory => _cacheHelper, new PerContainerLifetime()); container.Register(factory => _cacheHelper.RuntimeCache, new PerContainerLifetime()); container.Register(); @@ -149,6 +155,7 @@ namespace Umbraco.Core factory.GetInstance(), factory.GetInstance())); container.Register(new PerContainerLifetime()); + container.Register(factory => FileSystemProviderManager.Current.GetFileSystemProvider()); } /// @@ -157,7 +164,7 @@ namespace Umbraco.Core /// internal virtual void ConfigureServices(ServiceContainer container) { - container.Register(factory => FileSystemProviderManager.Current.GetFileSystemProvider()); + } /// @@ -299,8 +306,15 @@ namespace Umbraco.Core /// protected virtual void InitializeResolvers() { - PropertyEditorResolver.Current = new PropertyEditorResolver(ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolvePropertyEditors()); - ParameterEditorResolver.Current = new ParameterEditorResolver(ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolveParameterEditors()); + var manifestParser = new ManifestParser(ProfilingLogger.Logger, new DirectoryInfo(IOHelper.MapPath("~/App_Plugins"))); + var manifestBuilder = new ManifestBuilder(manifestParser); + + PropertyEditorResolver.Current = new PropertyEditorResolver( + Container, ProfilingLogger.Logger, () => PluginManager.ResolvePropertyEditors(), + manifestBuilder); + ParameterEditorResolver.Current = new ParameterEditorResolver( + ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolveParameterEditors(), + manifestBuilder); //setup the validators resolver with our predefined validators ValidatorsResolver.Current = new ValidatorsResolver( @@ -322,7 +336,7 @@ namespace Umbraco.Core ServerMessengerResolver.Current = new ServerMessengerResolver(Container, typeof (DefaultServerMessenger)); MappingResolver.Current = new MappingResolver( - ServiceProvider, ProfilingLogger.Logger, + Container, ProfilingLogger.Logger, () => PluginManager.ResolveAssignedMapperTypes()); diff --git a/src/Umbraco.Core/Manifest/ManifestBuilder.cs b/src/Umbraco.Core/Manifest/ManifestBuilder.cs index d62c215c8d..6942582ad4 100644 --- a/src/Umbraco.Core/Manifest/ManifestBuilder.cs +++ b/src/Umbraco.Core/Manifest/ManifestBuilder.cs @@ -1,7 +1,9 @@ -using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Core.Manifest @@ -11,9 +13,14 @@ namespace Umbraco.Core.Manifest /// internal class ManifestBuilder { + public ManifestBuilder(ManifestParser parser) + { + if (parser == null) throw new ArgumentNullException("parser"); + _parser = parser; + } - private static readonly ConcurrentDictionary StaticCache = new ConcurrentDictionary(); - + private readonly ManifestParser _parser; + private static readonly ConcurrentDictionary StaticCache = new ConcurrentDictionary(); private const string ManifestKey = "manifests"; private const string PropertyEditorsKey = "propertyeditors"; private const string ParameterEditorsKey = "parametereditors"; @@ -21,7 +28,7 @@ namespace Umbraco.Core.Manifest /// /// Returns all property editors found in the manfifests /// - internal static IEnumerable PropertyEditors + internal IEnumerable PropertyEditors { get { @@ -34,7 +41,7 @@ namespace Umbraco.Core.Manifest { if (manifest.PropertyEditors != null) { - editors.AddRange(ManifestParser.GetPropertyEditors(manifest.PropertyEditors)); + editors.AddRange(_parser.GetPropertyEditors(manifest.PropertyEditors)); } } @@ -46,7 +53,7 @@ namespace Umbraco.Core.Manifest /// /// Returns all parameter editors found in the manfifests and all property editors that are flagged to be parameter editors /// - internal static IEnumerable ParameterEditors + internal IEnumerable ParameterEditors { get { @@ -59,7 +66,7 @@ namespace Umbraco.Core.Manifest { if (manifest.ParameterEditors != null) { - editors.AddRange(ManifestParser.GetParameterEditors(manifest.ParameterEditors)); + editors.AddRange(_parser.GetParameterEditors(manifest.ParameterEditors)); } } return editors; @@ -70,13 +77,9 @@ namespace Umbraco.Core.Manifest /// /// Ensures the manifests are found and loaded into memory /// - private static IEnumerable GetManifests() + private IEnumerable GetManifests() { - return (IEnumerable) StaticCache.GetOrAdd(ManifestKey, s => - { - var parser = new ManifestParser(new DirectoryInfo(IOHelper.MapPath("~/App_Plugins"))); - return parser.GetManifests(); - }); + return (IEnumerable) StaticCache.GetOrAdd(ManifestKey, s => _parser.GetManifests()); } } diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index fbc91de898..ebc6794710 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -16,16 +16,20 @@ namespace Umbraco.Core.Manifest /// internal class ManifestParser { + private readonly ILogger _logger; + private readonly DirectoryInfo _pluginsDir; //used to strip comments private static readonly Regex CommentsSurround = new Regex(@"/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/", RegexOptions.Compiled); private static readonly Regex CommentsLine = new Regex(@"//.*?$", RegexOptions.Compiled | RegexOptions.Multiline); - public ManifestParser(DirectoryInfo pluginsDir) + public ManifestParser(ILogger logger, DirectoryInfo pluginsDir) { + if (logger == null) throw new ArgumentNullException("logger"); if (pluginsDir == null) throw new ArgumentNullException("pluginsDir"); _pluginsDir = pluginsDir; + _logger = logger; } /// @@ -33,11 +37,11 @@ namespace Umbraco.Core.Manifest /// /// /// - internal static IEnumerable GetPropertyEditors(JArray jsonEditors) + internal IEnumerable GetPropertyEditors(JArray jsonEditors) { return JsonConvert.DeserializeObject>( - jsonEditors.ToString(), - new PropertyEditorConverter(), + jsonEditors.ToString(), + new PropertyEditorConverter(_logger), new PreValueFieldConverter()); } @@ -46,7 +50,7 @@ namespace Umbraco.Core.Manifest /// /// /// - internal static IEnumerable GetParameterEditors(JArray jsonEditors) + internal IEnumerable GetParameterEditors(JArray jsonEditors) { return JsonConvert.DeserializeObject>( jsonEditors.ToString(), @@ -96,7 +100,7 @@ namespace Umbraco.Core.Manifest /// /// /// - internal static int FolderDepth(DirectoryInfo baseDir, DirectoryInfo currDir) + internal int FolderDepth(DirectoryInfo baseDir, DirectoryInfo currDir) { var removed = currDir.FullName.Remove(0, baseDir.FullName.Length).TrimStart('\\').TrimEnd('\\'); return removed.Split(new char[] {'\\'}, StringSplitOptions.RemoveEmptyEntries).Length; @@ -111,7 +115,7 @@ namespace Umbraco.Core.Manifest /// This ensures that comments are removed (but they have to be /* */ style comments /// and ensures that virtual paths are replaced with real ones /// - internal static IEnumerable CreateManifests(params string[] manifestFileContents) + internal IEnumerable CreateManifests(params string[] manifestFileContents) { var result = new List(); foreach (var m in manifestFileContents) @@ -129,7 +133,7 @@ namespace Umbraco.Core.Manifest } catch (Exception ex) { - LogHelper.Error("An error occurred parsing manifest with contents: " + m, ex); + _logger.Error("An error occurred parsing manifest with contents: " + m, ex); continue; } @@ -192,7 +196,7 @@ namespace Umbraco.Core.Manifest /// Replaces any virtual paths found in properties /// /// - private static void ReplaceVirtualPaths(JArray jarr) + private void ReplaceVirtualPaths(JArray jarr) { foreach (var i in jarr) { @@ -204,7 +208,7 @@ namespace Umbraco.Core.Manifest /// Replaces any virtual paths found in properties /// /// - private static void ReplaceVirtualPaths(JToken jToken) + private void ReplaceVirtualPaths(JToken jToken) { if (jToken.Type == JTokenType.Object) { @@ -232,7 +236,7 @@ namespace Umbraco.Core.Manifest /// Replaces any virtual paths found in properties /// /// - private static void ReplaceVirtualPaths(JObject jObj) + private void ReplaceVirtualPaths(JObject jObj) { foreach (var p in jObj.Properties().Select(x => x.Value)) { diff --git a/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs b/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs index be99c2f241..3a166c2c26 100644 --- a/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs +++ b/src/Umbraco.Core/Manifest/PropertyEditorConverter.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Serialization; @@ -13,9 +14,16 @@ namespace Umbraco.Core.Manifest /// internal class PropertyEditorConverter : JsonCreationConverter { + private readonly ILogger _logger; + + public PropertyEditorConverter(ILogger logger) + { + _logger = logger; + } + protected override PropertyEditor Create(Type objectType, JObject jObject) { - return new PropertyEditor(); + return new PropertyEditor(_logger); } protected override void Deserialize(JObject jObject, PropertyEditor target, JsonSerializer serializer) diff --git a/src/Umbraco.Core/ObjectResolution/ContainerLazyManyObjectsResolver.cs b/src/Umbraco.Core/ObjectResolution/ContainerLazyManyObjectsResolver.cs new file mode 100644 index 0000000000..22db5fc776 --- /dev/null +++ b/src/Umbraco.Core/ObjectResolution/ContainerLazyManyObjectsResolver.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using Umbraco.Core.LightInject; +using Umbraco.Core.Logging; + +namespace Umbraco.Core.ObjectResolution +{ + + /// + /// A lazy many objects resolver that uses IoC + /// + /// + /// + public abstract class ContainerLazyManyObjectsResolver : LazyManyObjectsResolverBase + where TResolved : class + where TResolver : ResolverBase + { + private IServiceContainer _container; + private object _locker = new object(); + private bool _isInitialized = false; + + internal ContainerLazyManyObjectsResolver(IServiceContainer container, ILogger logger, Func> typeListProducerList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application) + : base(logger, typeListProducerList, scope) + { + _container = container; + } + + /// + /// Creates the instances from IoC + /// + /// A list of objects of type . + protected override IEnumerable CreateValues(ObjectLifetimeScope scope) + { + //Before we can do anything, the first time this happens we need to setup the container with the resolved types + LazyInitializer.EnsureInitialized(ref _container, ref _isInitialized, ref _locker, () => + { + foreach (var type in InstanceTypes) + { + _container.Register(type, GetLifetime(LifetimeScope)); + } + return _container; + }); + + //NOTE: we ignore scope because objects are registered under this scope and not build based on the scope. + + return _container.GetAllInstances(); + } + + /// + /// Convert the ObjectLifetimeScope to ILifetime + /// + /// + /// + private static ILifetime GetLifetime(ObjectLifetimeScope scope) + { + switch (scope) + { + case ObjectLifetimeScope.HttpRequest: + return new PerRequestLifeTime(); + case ObjectLifetimeScope.Application: + return new PerContainerLifetime(); + case ObjectLifetimeScope.Transient: + default: + return null; + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs b/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs index fcac5c01f8..244367b718 100644 --- a/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs +++ b/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs @@ -19,6 +19,8 @@ namespace Umbraco.Core.ObjectResolution { private readonly IServiceContainer _container; + //TODO: Get rid of these - pretty sure all tests will still fail with these pass throughs, need to update + // all tests that use resolvers to use a real container - then update most tests that are not integration tests to not use any resolvers! #region Constructors used for test - ONLY so that a container is not required and will just revert to using the normal ManyObjectsResolverBase [Obsolete("Used for tests only - should remove")] internal ContainerManyObjectsResolver(ILogger logger, IEnumerable types, ObjectLifetimeScope scope = ObjectLifetimeScope.Application) diff --git a/src/Umbraco.Core/ObjectResolution/LazyManyObjectsResolverbase.cs b/src/Umbraco.Core/ObjectResolution/LazyManyObjectsResolverbase.cs index 0a3c9a98e7..d8d6cfbf2d 100644 --- a/src/Umbraco.Core/ObjectResolution/LazyManyObjectsResolverbase.cs +++ b/src/Umbraco.Core/ObjectResolution/LazyManyObjectsResolverbase.cs @@ -25,6 +25,20 @@ namespace Umbraco.Core.ObjectResolution { #region Constructors + /// + /// Hack: This is purely here to allow for the lazy container resolver to be used, we'll need to refactor all of this slowly till we're + /// happy with the outcome + /// + /// + /// + /// + internal LazyManyObjectsResolverBase(ILogger logger, Func> typeListProducerList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application) + : base(logger, scope) + { + _typeListProducerList.Add(typeListProducerList); + Initialize(); + } + /// /// Initializes a new instance of the class with an empty list of objects, /// and an optional lifetime scope. @@ -39,7 +53,7 @@ namespace Umbraco.Core.ObjectResolution { Initialize(); } - + protected LazyManyObjectsResolverBase(IServiceProvider serviceProvider, ILogger logger, IEnumerable> lazyTypeList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application) : this(serviceProvider, logger, scope) { @@ -62,7 +76,7 @@ namespace Umbraco.Core.ObjectResolution : this(serviceProvider, logger, httpContext) { _typeListProducerList.Add(typeListProducerList); - } + } #endregion diff --git a/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs b/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs index 8eec5b1163..d74d03ea05 100644 --- a/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs +++ b/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs @@ -39,11 +39,28 @@ namespace Umbraco.Core.ObjectResolution { if (logger == null) throw new ArgumentNullException("logger"); if (types == null) throw new ArgumentNullException("types"); + CanResolveBeforeFrozen = false; _instanceTypes = types.ToList(); LifetimeScope = scope; Logger = logger; } + /// + /// Hack: This is purely here to allow for the lazy container resolver to be used, we'll need to refactor all of this slowly till we're + /// happy with the outcome + /// + /// + /// + internal ManyObjectsResolverBase(ILogger logger, ObjectLifetimeScope scope = ObjectLifetimeScope.Application) + { + if (logger == null) throw new ArgumentNullException("logger"); + CanResolveBeforeFrozen = false; + Logger = logger; + LifetimeScope = scope; + _instanceTypes = new List(); + } + + /// /// Initializes a new instance of the class with an empty list of objects, /// and an optional lifetime scope. diff --git a/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs b/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs index ebd39d95a3..017875a425 100644 --- a/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/DictionaryTranslationMapper.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.Persistence.Mappers /// [MapperFor(typeof(DictionaryTranslation))] [MapperFor(typeof(IDictionaryTranslation))] - public class DictionaryTranslationMapper : BaseMapper + public sealed class DictionaryTranslationMapper : BaseMapper { private static readonly ConcurrentDictionary PropertyInfoCacheInstance = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs b/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs index ea44964219..0fe0e75b6c 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs @@ -2,21 +2,22 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using Umbraco.Core.LightInject; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; namespace Umbraco.Core.Persistence.Mappers { - internal class MappingResolver : LazyManyObjectsResolverBase + internal class MappingResolver : ContainerLazyManyObjectsResolver { /// /// Constructor accepting a list of BaseMapper types that are attributed with the MapperFor attribute /// - /// + /// /// /// - public MappingResolver(IServiceProvider serviceProvider, ILogger logger, Func> assignedMapperTypes) - : base(serviceProvider, logger, assignedMapperTypes) + public MappingResolver(IServiceContainer container, ILogger logger, Func> assignedMapperTypes) + : base(container, logger, assignedMapperTypes) { } diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs index 3c8d04fcf0..0edcc636c7 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorResolver.cs @@ -16,11 +16,14 @@ namespace Umbraco.Core.PropertyEditors /// internal class ParameterEditorResolver : LazyManyObjectsResolverBase { - public ParameterEditorResolver(IServiceProvider serviceProvider, ILogger logger, Func> typeListProducerList) + private readonly ManifestBuilder _builder; + + public ParameterEditorResolver(IServiceProvider serviceProvider, ILogger logger, Func> typeListProducerList, ManifestBuilder builder) : base(serviceProvider, logger, typeListProducerList, ObjectLifetimeScope.Application) { + _builder = builder; } - + /// /// Returns the parameter editors /// @@ -39,9 +42,9 @@ namespace Umbraco.Core.PropertyEditors //exclude the non parameter editor c# property editors .Except(filtered) //include the manifest parameter editors - .Union(ManifestBuilder.ParameterEditors) + .Union(_builder.ParameterEditors) //include the manifest prop editors that are parameter editors - .Union(ManifestBuilder.PropertyEditors.Where(x => x.IsParameterEditor)); + .Union(_builder.PropertyEditors.Where(x => x.IsParameterEditor)); } } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs index baa1431f29..58835cb8c8 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Core.Models; namespace Umbraco.Core.PropertyEditors @@ -15,13 +16,20 @@ namespace Umbraco.Core.PropertyEditors /// public class PropertyEditor : IParameterEditor { + /// + /// Exposes a logger + /// + protected ILogger Logger { get; private set; } + private readonly PropertyEditorAttribute _attribute; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public PropertyEditor() + public PropertyEditor(ILogger logger) { + if (logger == null) throw new ArgumentNullException("logger"); + Logger = logger; //assign properties based on the attribute if it is found _attribute = GetType().GetCustomAttribute(false); if (_attribute != null) diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorResolver.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorResolver.cs index 95d3316635..f86e86893a 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorResolver.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorResolver.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Umbraco.Core.LightInject; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; using Umbraco.Core.ObjectResolution; @@ -13,11 +14,14 @@ namespace Umbraco.Core.PropertyEditors /// /// This resolver will contain any property editors defined in manifests as well! /// - public class PropertyEditorResolver : LazyManyObjectsResolverBase + public class PropertyEditorResolver : ContainerLazyManyObjectsResolver { - public PropertyEditorResolver(IServiceProvider serviceProvider, ILogger logger, Func> typeListProducerList) - : base(serviceProvider, logger, typeListProducerList, ObjectLifetimeScope.Application) + private readonly ManifestBuilder _builder; + + internal PropertyEditorResolver(IServiceContainer container, ILogger logger, Func> typeListProducerList, ManifestBuilder builder) + : base(container, logger, typeListProducerList, ObjectLifetimeScope.Application) { + _builder = builder; } /// @@ -25,7 +29,7 @@ namespace Umbraco.Core.PropertyEditors /// public IEnumerable PropertyEditors { - get { return Values.Union(ManifestBuilder.PropertyEditors); } + get { return Values.Union(_builder.PropertyEditors); } } /// diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 4674468efc..12d9b45710 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -304,6 +304,7 @@ + diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index b51d5b84c9..c2c70bf588 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -1,17 +1,28 @@ using System; using System.IO; using System.Linq; +using Moq; using NUnit.Framework; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Umbraco.Core.Logging; using Umbraco.Core.Manifest; using Umbraco.Core.PropertyEditors; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Manifest { [TestFixture] public class ManifestParserTests { + + private ManifestParser _parser; + + [SetUp] + public void Setup() + { + _parser = new ManifestParser(Mock.Of(), new DirectoryInfo(TestHelper.MapPathForTest("~/App_Plugins"))); + } [Test] public void Parse_Property_Editors_With_Pre_Vals() @@ -48,7 +59,7 @@ namespace Umbraco.Tests.Manifest } } ]"); - var parser = ManifestParser.GetPropertyEditors(a); + var parser = _parser.GetPropertyEditors(a); Assert.AreEqual(1, parser.Count()); Assert.AreEqual(2, parser.ElementAt(0).PreValueEditor.Fields.Count()); @@ -90,7 +101,7 @@ namespace Umbraco.Tests.Manifest } } ]"); - var parser = ManifestParser.GetPropertyEditors(a); + var parser = _parser.GetPropertyEditors(a); Assert.AreEqual(2, parser.Count()); @@ -142,7 +153,7 @@ namespace Umbraco.Tests.Manifest } } ]"); - var parser = ManifestParser.GetPropertyEditors(a); + var parser = _parser.GetPropertyEditors(a); Assert.AreEqual(1, parser.Count(x => x.IsParameterEditor)); @@ -169,7 +180,7 @@ namespace Umbraco.Tests.Manifest view: '~/App_Plugins/MyPackage/PropertyEditors/CsvEditor.html' } ]"); - var parser = ManifestParser.GetParameterEditors(a); + var parser = _parser.GetParameterEditors(a); Assert.AreEqual(2, parser.Count()); Assert.AreEqual("parameter1", parser.ElementAt(0).Alias); @@ -246,7 +257,7 @@ namespace Umbraco.Tests.Manifest public void Get_Folder_Depth(string baseFolder, string currFolder, int expected) { Assert.AreEqual(expected, - ManifestParser.FolderDepth( + _parser.FolderDepth( new DirectoryInfo(baseFolder), new DirectoryInfo(currFolder))); } @@ -268,7 +279,7 @@ propertyEditors: [], //and here's the javascript javascript: ['~/test.js', '~/test2.js']}"; - var result = ManifestParser.CreateManifests(null, content4); + var result = _parser.CreateManifests(null, content4); Assert.AreEqual(1, result.Count()); } @@ -280,7 +291,7 @@ javascript: ['~/test.js', '~/test2.js']}"; propertyEditors: []/*we have empty property editors**/, javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2.js']}"; - var result = ManifestParser.CreateManifests(null, content4); + var result = _parser.CreateManifests(null, content4); Assert.AreEqual(1, result.Count()); } @@ -293,7 +304,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 propertyEditors: []/*we have empty property editors**/, javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2.js' }"; - var result = ManifestParser.CreateManifests(null, content4); + var result = _parser.CreateManifests(null, content4); //an error has occurred and been logged but processing continues Assert.AreEqual(0, result.Count()); @@ -307,7 +318,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 var content3 = "{javascript: ['~/test.js', '~/test2.js']}"; var content4 = "{propertyEditors: [], javascript: ['~/test.js', '~/test2.js']}"; - var result = ManifestParser.CreateManifests(null, content1, content2, content3, content4); + var result = _parser.CreateManifests(null, content1, content2, content3, content4); Assert.AreEqual(4, result.Count()); Assert.AreEqual(0, result.ElementAt(1).JavaScriptInitialize.Count); @@ -323,7 +334,7 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 var content3 = "{css: ['~/style.css', '~/folder-name/sdsdsd/stylesheet.css']}"; var content4 = "{propertyEditors: [], css: ['~/stylesheet.css', '~/random-long-name.css']}"; - var result = ManifestParser.CreateManifests(null, content1, content2, content3, content4); + var result = _parser.CreateManifests(null, content1, content2, content3, content4); Assert.AreEqual(4, result.Count()); Assert.AreEqual(0, result.ElementAt(1).StylesheetInitialize.Count); diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index 669a1ee5c7..2e08882322 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -8,6 +8,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Dictionary; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Tests.TestHelpers; @@ -35,7 +36,12 @@ namespace Umbraco.Tests.Models.Mapping [PropertyEditor("Test.Test", "Test", "~/Test.html")] public class TestPropertyEditor : PropertyEditor { - + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public TestPropertyEditor(ILogger logger) : base(logger) + { + } } //protected override void FreezeResolution() diff --git a/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs b/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs index 942b4970af..900b8399e7 100644 --- a/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ColorListValidatorTest.cs @@ -1,6 +1,8 @@ using System.Linq; +using Moq; using NUnit.Framework; using Newtonsoft.Json.Linq; +using Umbraco.Core.Logging; using Umbraco.Web.PropertyEditors; namespace Umbraco.Tests.PropertyEditors @@ -12,7 +14,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray() { var validator = new ColorListPreValueEditor.ColorListValidator(); - var result = validator.Validate("hello", null, new ColorPickerPropertyEditor()); + var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(0, result.Count()); } @@ -20,7 +22,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray_Of_Item_JObject() { var validator = new ColorListPreValueEditor.ColorListValidator(); - var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor()); + var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(0, result.Count()); } @@ -33,7 +35,7 @@ namespace Umbraco.Tests.PropertyEditors JObject.FromObject(new { value = "zxcvzxcvxzcv" }), JObject.FromObject(new { value = "ABC" }), JObject.FromObject(new { value = "1234567" })), - null, new ColorPickerPropertyEditor()); + null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(2, result.Count()); } } diff --git a/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs b/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs index 91ddcf8523..c24aa65846 100644 --- a/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/EnsureUniqueValuesValidatorTest.cs @@ -1,6 +1,8 @@ using System.Linq; +using Moq; using NUnit.Framework; using Newtonsoft.Json.Linq; +using Umbraco.Core.Logging; using Umbraco.Web.PropertyEditors; namespace Umbraco.Tests.PropertyEditors @@ -12,7 +14,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray() { var validator = new ValueListPreValueEditor.EnsureUniqueValuesValidator(); - var result = validator.Validate("hello", null, new ColorPickerPropertyEditor()); + var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(0, result.Count()); } @@ -20,7 +22,7 @@ namespace Umbraco.Tests.PropertyEditors public void Only_Tests_On_JArray_Of_Item_JObject() { var validator = new ValueListPreValueEditor.EnsureUniqueValuesValidator(); - var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor()); + var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(0, result.Count()); } @@ -28,7 +30,7 @@ namespace Umbraco.Tests.PropertyEditors public void Allows_Unique_Values() { var validator = new ValueListPreValueEditor.EnsureUniqueValuesValidator(); - var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" })), null, new ColorPickerPropertyEditor()); + var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" })), null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(0, result.Count()); } @@ -37,7 +39,7 @@ namespace Umbraco.Tests.PropertyEditors { var validator = new ValueListPreValueEditor.EnsureUniqueValuesValidator(); var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "hello" })), - null, new ColorPickerPropertyEditor()); + null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(1, result.Count()); } @@ -49,8 +51,8 @@ namespace Umbraco.Tests.PropertyEditors JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" }), - JObject.FromObject(new { value = "world" })), - null, new ColorPickerPropertyEditor()); + JObject.FromObject(new { value = "world" })), + null, new ColorPickerPropertyEditor(Mock.Of())); Assert.AreEqual(2, result.Count()); } } diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index e0e1e5fa14..a6d439b7af 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; +using Umbraco.Core.Manifest; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence; @@ -194,6 +195,7 @@ namespace Umbraco.Tests.TestHelpers } } + /// /// sets up resolvers before resolution is frozen @@ -201,11 +203,12 @@ namespace Umbraco.Tests.TestHelpers protected override void FreezeResolution() { PropertyEditorResolver.Current = new PropertyEditorResolver( - new ActivatorServiceProvider(), Logger, - () => PluginManager.Current.ResolvePropertyEditors()); + Container, Logger, + () => PluginManager.Current.ResolvePropertyEditors(), + new ManifestBuilder(new ManifestParser(Logger, new DirectoryInfo(TestHelper.MapPathForTest("~/App_Plugins"))))); MappingResolver.Current = new MappingResolver( - new ActivatorServiceProvider(), Logger, + Container, Logger, () => PluginManager.Current.ResolveAssignedMapperTypes()); if (PropertyValueConvertersResolver.HasCurrent == false) diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 8692dc68e3..8ccb1c5af5 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -1,10 +1,14 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; using AutoMapper; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.LightInject; using Umbraco.Core.Logging; using Umbraco.Core.Models.Mapping; using Umbraco.Core.ObjectResolution; @@ -43,6 +47,8 @@ namespace Umbraco.Tests.TestHelpers { base.Initialize(); + Container = new ServiceContainer(); + TestHelper.InitializeContentDirectories(); SetupCacheHelper(); @@ -55,6 +61,15 @@ namespace Umbraco.Tests.TestHelpers InitializeMappers(); + //register basic stuff that might need to be there for some container resolvers to work, we can + // add more to this in base classes in resolution freezing + Container.Register(factory => Logger); + Container.Register(factory => CacheHelper); + Container.Register(factory => ProfilingLogger); + Container.Register(factory => SettingsForTests.GetDefault(), new PerContainerLifetime()); + Container.Register(factory => CacheHelper.RuntimeCache); + Container.Register(); + FreezeResolution(); } @@ -75,6 +90,8 @@ namespace Umbraco.Tests.TestHelpers ApplicationContext.Current = null; ResetPluginManager(); + Container.Dispose(); + } private static readonly object Locker = new object(); @@ -212,5 +229,9 @@ namespace Umbraco.Tests.TestHelpers } protected ProfilingLogger ProfilingLogger { get; private set; } protected CacheHelper CacheHelper { get; private set; } + + //I know tests shouldn't use IoC, but for all these tests inheriting from this class are integration tests + // and the number of these will hopefully start getting greatly reduced now that most things are mockable. + internal IServiceContainer Container { get; private set; } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index b77b915ac7..777be67736 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.LightInject; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence.Mappers; @@ -16,13 +17,15 @@ namespace Umbraco.Tests.TestHelpers [SetUp] public virtual void Initialize() { + var container = new ServiceContainer(); + var logger = new ProfilingLogger(Mock.Of(), Mock.Of()); SqlSyntaxContext.SqlSyntaxProvider = new SqlCeSyntaxProvider(); PluginManager.Current = new PluginManager(new ActivatorServiceProvider(), new NullCacheProvider(), logger, false); MappingResolver.Current = new MappingResolver( - new ActivatorServiceProvider(), logger.Logger, + container, logger.Logger, () => PluginManager.Current.ResolveAssignedMapperTypes()); Resolution.Freeze(); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index eccc2bd815..64902b12b1 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -82,7 +82,7 @@ namespace Umbraco.Web.Editors public JavaScriptResult Application() { var plugins = new DirectoryInfo(Server.MapPath("~/App_Plugins")); - var parser = new ManifestParser(plugins); + var parser = new ManifestParser(Logger, plugins); var initJs = new JsInitialization(parser); var initCss = new CssInitialization(parser); @@ -104,7 +104,7 @@ namespace Umbraco.Web.Editors public JsonNetResult GetManifestAssetList() { var plugins = new DirectoryInfo(Server.MapPath("~/App_Plugins")); - var parser = new ManifestParser(plugins); + var parser = new ManifestParser(Logger, plugins); var initJs = new JsInitialization(parser); var initCss = new CssInitialization(parser); var jsResult = initJs.GetJavascriptInitializationArray(HttpContext, new JArray()); diff --git a/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/CheckBoxListPropertyEditor.cs index d4c5cdbaf1..6bf1519ab0 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -14,6 +15,12 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.CheckBoxListAlias, "Checkbox list", "checkboxlist")] public class CheckBoxListPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public CheckBoxListPropertyEditor(ILogger logger) : base(logger) + { + } /// /// Return a custom pre-value editor diff --git a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs index 40b719020f..3a1cb8f509 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,6 +7,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.ColorPickerAlias, "Color Picker", "colorpicker")] public class ColorPickerPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public ColorPickerPropertyEditor(ILogger logger) : base(logger) + { + } + /// /// Return a custom pre-value editor /// diff --git a/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ContentPickerPropertyEditor.cs index 10e63c8900..e3a9f2a21b 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -8,7 +9,7 @@ namespace Umbraco.Web.PropertyEditors public class ContentPickerPropertyEditor : PropertyEditor { - public ContentPickerPropertyEditor() + public ContentPickerPropertyEditor(ILogger logger) : base(logger) { _internalPreValues = new Dictionary { diff --git a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs index 04a5890c2c..7b8830269e 100644 --- a/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.RegularExpressions; using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -12,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.DateAlias, "Date", "DATE", "datepicker")] public class DatePropertyEditor : PropertyEditor { - public DatePropertyEditor() + public DatePropertyEditor(ILogger logger): base(logger) { _defaultPreVals = new Dictionary { diff --git a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs index a3c51f6273..06795caa88 100644 --- a/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DateTimePropertyEditor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -8,7 +9,7 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.DateTimeAlias, "Date/Time", "datepicker", ValueType = "DATETIME")] public class DateTimePropertyEditor : PropertyEditor { - public DateTimePropertyEditor() + public DateTimePropertyEditor(ILogger logger): base(logger) { _defaultPreVals = new Dictionary { diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs index 02324f7d84..c51ef91258 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultiplePropertyEditor.cs @@ -18,6 +18,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.DropDownListMultipleAlias, "Dropdown list multiple", "dropdown")] public class DropDownMultiplePropertyEditor : DropDownMultipleWithKeysPropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public DropDownMultiplePropertyEditor(ILogger logger) : base(logger) + { + } + protected override PropertyValueEditor CreateValueEditor() { return new PublishValuesMultipleValueEditor(false, base.CreateValueEditor()); diff --git a/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs index b0a1c859d6..10b638d5a3 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownMultipleWithKeysPropertyEditor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -15,6 +16,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.DropdownlistMultiplePublishKeysAlias, "Dropdown list multiple, publish keys", "dropdown")] public class DropDownMultipleWithKeysPropertyEditor : DropDownPropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public DropDownMultipleWithKeysPropertyEditor(ILogger logger) : base(logger) + { + } + protected override PropertyValueEditor CreateValueEditor() { return new PublishValuesMultipleValueEditor(true, base.CreateValueEditor()); diff --git a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs index 4cc8f068cf..9c0217d054 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; using umbraco; using ClientDependency.Core; @@ -19,6 +20,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.DropDownListAlias, "Dropdown list", "dropdown", ValueType = "STRING")] public class DropDownPropertyEditor : DropDownWithKeysPropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public DropDownPropertyEditor(ILogger logger) : base(logger) + { + } + /// /// We need to override the value editor so that we can ensure the string value is published in cache and not the integer ID value. /// diff --git a/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs index f0d695a7eb..c9f5f093a7 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownWithKeysPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -14,6 +15,12 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.DropdownlistPublishingKeysAlias, "Dropdown list, publishing keys", "dropdown", ValueType = "INT")] public class DropDownWithKeysPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public DropDownWithKeysPropertyEditor(ILogger logger) : base(logger) + { + } /// /// Return a custom pre-value editor diff --git a/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/EmailAddressPropertyEditor.cs index b4b702f935..2045c59c9b 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,6 +7,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.EmailAddressAlias, "Email address", "email")] public class EmailAddressPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public EmailAddressPropertyEditor(ILogger logger) : base(logger) + { + } + protected override PropertyValueEditor CreateValueEditor() { var editor = base.CreateValueEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index 9eff763dda..d59c3c5b2b 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -21,29 +21,18 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { [PropertyEditor(Constants.PropertyEditors.UploadFieldAlias, "File upload", "fileupload")] - public class FileUploadPropertyEditor : PropertyEditor + public class FileUploadPropertyEditor : PropertyEditor, IApplicationEventHandler { - /// - /// We're going to bind to the MediaService Saving event so that we can populate the umbracoFile size, type, etc... label fields - /// if we find any attached to the current media item. - /// - /// - /// I think this kind of logic belongs on this property editor, I guess it could exist elsewhere but it all has to do with the upload field. - /// - static FileUploadPropertyEditor() + private readonly MediaFileSystem _mediaFileSystem; + private readonly IContentSection _contentSettings; + + public FileUploadPropertyEditor(ILogger logger, MediaFileSystem mediaFileSystem, IContentSection contentSettings) + : base(logger) { - MediaService.Saving += MediaServiceSaving; - MediaService.Created += MediaServiceCreating; - ContentService.Copied += ContentServiceCopied; - - MediaService.Deleted += (sender, args) => - args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); - MediaService.EmptiedRecycleBin += (sender, args) => - args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); - ContentService.Deleted += (sender, args) => - args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); - ContentService.EmptiedRecycleBin += (sender, args) => - args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); + if (mediaFileSystem == null) throw new ArgumentNullException("mediaFileSystem"); + if (contentSettings == null) throw new ArgumentNullException("contentSettings"); + _mediaFileSystem = mediaFileSystem; + _contentSettings = contentSettings; } /// @@ -54,7 +43,7 @@ namespace Umbraco.Web.PropertyEditors { var baseEditor = base.CreateValueEditor(); baseEditor.Validators.Add(new UploadFileTypeValidator()); - return new FileUploadPropertyValueEditor(baseEditor); + return new FileUploadPropertyValueEditor(baseEditor, _mediaFileSystem, _contentSettings); } protected override PreValueEditor CreatePreValueEditor() @@ -110,12 +99,12 @@ namespace Umbraco.Web.PropertyEditors /// /// /// - static void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs e) + void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs e) { if (e.Original.Properties.Any(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias)) { bool isUpdated = false; - var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); + var fs = _mediaFileSystem; //Loop through properties to check if the content contains media that should be deleted foreach (var property in e.Original.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias @@ -149,12 +138,12 @@ namespace Umbraco.Web.PropertyEditors } } - static void MediaServiceCreating(IMediaService sender, Core.Events.NewEventArgs e) + void MediaServiceCreating(IMediaService sender, Core.Events.NewEventArgs e) { AutoFillProperties(e.Entity); } - static void MediaServiceSaving(IMediaService sender, Core.Events.SaveEventArgs e) + void MediaServiceSaving(IMediaService sender, Core.Events.SaveEventArgs e) { foreach (var m in e.SavedEntities) { @@ -162,12 +151,12 @@ namespace Umbraco.Web.PropertyEditors } } - static void AutoFillProperties(IContentBase model) + void AutoFillProperties(IContentBase model) { foreach (var p in model.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias)) { var uploadFieldConfigNode = - UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties + _contentSettings.ImageAutoFillProperties .FirstOrDefault(x => x.Alias == p.Alias); if (uploadFieldConfigNode != null) @@ -273,5 +262,37 @@ namespace Umbraco.Web.PropertyEditors } } + #region Application event handler, used to bind to events on startup + public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + } + + public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + } + + /// + /// We're going to bind to the MediaService Saving event so that we can populate the umbracoFile size, type, etc... label fields + /// if we find any attached to the current media item. + /// + /// + /// I think this kind of logic belongs on this property editor, I guess it could exist elsewhere but it all has to do with the upload field. + /// + public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + MediaService.Saving += MediaServiceSaving; + MediaService.Created += MediaServiceCreating; + ContentService.Copied += ContentServiceCopied; + + MediaService.Deleted += (sender, args) => + args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); + MediaService.EmptiedRecycleBin += (sender, args) => + args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); + ContentService.Deleted += (sender, args) => + args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); + ContentService.EmptiedRecycleBin += (sender, args) => + args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); + } + #endregion } } diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs index 8692744089..1fd223611a 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs @@ -7,6 +7,7 @@ using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Media; @@ -24,8 +25,16 @@ namespace Umbraco.Web.PropertyEditors /// internal class FileUploadPropertyValueEditor : PropertyValueEditorWrapper { - public FileUploadPropertyValueEditor(PropertyValueEditor wrapped) : base(wrapped) + private readonly MediaFileSystem _mediaFileSystem; + private readonly IContentSection _contentSettings; + + public FileUploadPropertyValueEditor(PropertyValueEditor wrapped, MediaFileSystem mediaFileSystem, IContentSection contentSettings) + : base(wrapped) { + if (mediaFileSystem == null) throw new ArgumentNullException("mediaFileSystem"); + if (contentSettings == null) throw new ArgumentNullException("contentSettings"); + _mediaFileSystem = mediaFileSystem; + _contentSettings = contentSettings; } /// @@ -63,15 +72,15 @@ namespace Umbraco.Web.PropertyEditors clear = json["clearFiles"].Value(); } - var currentPersistedValues = new string[] {}; + var currentPersistedValues = new string[] { }; if (string.IsNullOrEmpty(currentValue.ToString()) == false) { - currentPersistedValues = currentValue.ToString().Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); + currentPersistedValues = currentValue.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } var newValue = new List(); - var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); + var fs = _mediaFileSystem; if (clear) { @@ -82,7 +91,7 @@ namespace Umbraco.Web.PropertyEditors } return ""; } - + //check for any files if (editorValue.AdditionalData.ContainsKey("files")) { @@ -111,7 +120,7 @@ namespace Umbraco.Web.PropertyEditors var name = IOHelper.SafeFileName(file.FileName.Substring(file.FileName.LastIndexOf(IOHelper.DirSepChar) + 1, file.FileName.Length - file.FileName.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower()); - var subfolder = UmbracoConfig.For.UmbracoSettings().Content.UploadAllowDirectories + var subfolder = _contentSettings.UploadAllowDirectories ? currentPersistedFile.Replace(fs.GetUrl("/"), "").Split('/')[0] : currentPersistedFile.Substring(currentPersistedFile.LastIndexOf("/", StringComparison.Ordinal) + 1).Split('-')[0]; @@ -120,7 +129,7 @@ namespace Umbraco.Web.PropertyEditors ? subfolderId.ToString(CultureInfo.InvariantCulture) : MediaSubfolderCounter.Current.Increment().ToString(CultureInfo.InvariantCulture); - var fileName = UmbracoConfig.For.UmbracoSettings().Content.UploadAllowDirectories + var fileName = _contentSettings.UploadAllowDirectories ? Path.Combine(numberedFolder, name) : numberedFolder + "-" + name; @@ -157,15 +166,15 @@ namespace Umbraco.Web.PropertyEditors savedFilePaths.Add(umbracoFile.Url); } //now remove the temp file - File.Delete(file.TempFilePath); + File.Delete(file.TempFilePath); } - + //Remove any files that are no longer saved for this item foreach (var toRemove in currentPersistedValues.Except(savedFilePaths)) { fs.DeleteFile(fs.GetRelativePath(toRemove), true); } - + return string.Join(",", newValue); } diff --git a/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs index 7d13977dd3..96b516434a 100644 --- a/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FolderBrowserPropertyEditor.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Web.Mvc; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -8,8 +9,11 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.FolderBrowserAlias, "Folder Browser", "folderbrowser", HideLabel=true)] public class FolderBrowserPropertyEditor : PropertyEditor { - - - + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public FolderBrowserPropertyEditor(ILogger logger) : base(logger) + { + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 8603b6887a..073730b1ff 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -10,6 +11,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Core.Constants.PropertyEditors.GridAlias, "Grid layout", "grid", HideLabel=true, IsParameterEditor = false, ValueType="JSON")] public class GridPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public GridPropertyEditor(ILogger logger) : base(logger) + { + } + /// /// Overridden to ensure that the value is validated /// diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs index ea1fd8dfe9..2667bc91d6 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyEditor.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -16,30 +17,24 @@ using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { [PropertyEditor(Constants.PropertyEditors.ImageCropperAlias, "Image Cropper", "imagecropper", ValueType = "JSON", HideLabel = false)] - public class ImageCropperPropertyEditor : PropertyEditor + public class ImageCropperPropertyEditor : PropertyEditor, IApplicationEventHandler { + private readonly MediaFileSystem _mediaFileSystem; + private readonly IContentSection _contentSettings; - /// - /// We're going to bind to the MediaService Saving event so that we can populate the umbracoFile size, type, etc... label fields - /// if we find any attached to the current media item. - /// - /// - /// I think this kind of logic belongs on this property editor, I guess it could exist elsewhere but it all has to do with the cropper. - /// - static ImageCropperPropertyEditor() + public ImageCropperPropertyEditor(ILogger logger, MediaFileSystem mediaFileSystem, IContentSection contentSettings) + : base(logger) { - MediaService.Saving += MediaServiceSaving; - MediaService.Created += MediaServiceCreated; - ContentService.Copied += ContentServiceCopied; + if (mediaFileSystem == null) throw new ArgumentNullException("mediaFileSystem"); + if (contentSettings == null) throw new ArgumentNullException("contentSettings"); + _mediaFileSystem = mediaFileSystem; + _contentSettings = contentSettings; - MediaService.Deleted += (sender, args) => - args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); - MediaService.EmptiedRecycleBin += (sender, args) => - args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); - ContentService.Deleted += (sender, args) => - args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); - ContentService.EmptiedRecycleBin += (sender, args) => - args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); + _internalPreValues = new Dictionary + { + {"focalPoint", "{left: 0.5, top: 0.5}"}, + {"src", ""} + }; } /// @@ -49,7 +44,7 @@ namespace Umbraco.Web.PropertyEditors protected override PropertyValueEditor CreateValueEditor() { var baseEditor = base.CreateValueEditor(); - return new ImageCropperPropertyValueEditor(baseEditor); + return new ImageCropperPropertyValueEditor(baseEditor, Logger, _mediaFileSystem, _contentSettings); } protected override PreValueEditor CreatePreValueEditor() @@ -58,20 +53,11 @@ namespace Umbraco.Web.PropertyEditors } - public ImageCropperPropertyEditor() - { - _internalPreValues = new Dictionary - { - {"focalPoint", "{left: 0.5, top: 0.5}"}, - {"src", ""} - }; - } - /// /// Ensures any files associated are removed /// /// - static IEnumerable ServiceEmptiedRecycleBin(Dictionary> allPropertyData) + IEnumerable ServiceEmptiedRecycleBin(Dictionary> allPropertyData) { var list = new List(); //Get all values for any image croppers found @@ -88,7 +74,7 @@ namespace Umbraco.Web.PropertyEditors } catch (Exception ex) { - LogHelper.Error("An error occurred parsing the value stored in the image cropper value: " + cropperVal, ex); + Logger.Error("An error occurred parsing the value stored in the image cropper value: " + cropperVal, ex); continue; } @@ -104,7 +90,7 @@ namespace Umbraco.Web.PropertyEditors /// Ensures any files associated are removed /// /// - static IEnumerable ServiceDeleted(IEnumerable deletedEntities) + IEnumerable ServiceDeleted(IEnumerable deletedEntities) { var list = new List(); foreach (var property in deletedEntities.SelectMany(deletedEntity => deletedEntity @@ -120,7 +106,7 @@ namespace Umbraco.Web.PropertyEditors } catch (Exception ex) { - LogHelper.Error("An error occurred parsing the value stored in the image cropper value: " + property.Value, ex); + Logger.Error("An error occurred parsing the value stored in the image cropper value: " + property.Value, ex); continue; } @@ -137,12 +123,12 @@ namespace Umbraco.Web.PropertyEditors /// /// /// - static void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs e) + void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs e) { if (e.Original.Properties.Any(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.ImageCropperAlias)) { bool isUpdated = false; - var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); + var fs = _mediaFileSystem; //Loop through properties to check if the content contains media that should be deleted foreach (var property in e.Original.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.ImageCropperAlias @@ -156,7 +142,7 @@ namespace Umbraco.Web.PropertyEditors } catch (Exception ex) { - LogHelper.Error("An error occurred parsing the value stored in the image cropper value: " + property.Value.ToString(), ex); + Logger.Error("An error occurred parsing the value stored in the image cropper value: " + property.Value.ToString(), ex); continue; } @@ -193,12 +179,12 @@ namespace Umbraco.Web.PropertyEditors } } - static void MediaServiceCreated(IMediaService sender, Core.Events.NewEventArgs e) + void MediaServiceCreated(IMediaService sender, Core.Events.NewEventArgs e) { AutoFillProperties(e.Entity); } - static void MediaServiceSaving(IMediaService sender, Core.Events.SaveEventArgs e) + void MediaServiceSaving(IMediaService sender, Core.Events.SaveEventArgs e) { foreach (var m in e.SavedEntities) { @@ -206,12 +192,12 @@ namespace Umbraco.Web.PropertyEditors } } - static void AutoFillProperties(IContentBase model) + void AutoFillProperties(IContentBase model) { foreach (var p in model.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.ImageCropperAlias)) { var uploadFieldConfigNode = - UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties + _contentSettings.ImageAutoFillProperties .FirstOrDefault(x => x.Alias == p.Alias); if (uploadFieldConfigNode != null) @@ -263,5 +249,38 @@ namespace Umbraco.Web.PropertyEditors [PreValueField("crops", "Crop sizes", "views/propertyeditors/imagecropper/imagecropper.prevalues.html")] public string Crops { get; set; } } + + #region Application event handler, used to bind to events on startup + public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + } + + public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + } + + /// + /// We're going to bind to the MediaService Saving event so that we can populate the umbracoFile size, type, etc... label fields + /// if we find any attached to the current media item. + /// + /// + /// I think this kind of logic belongs on this property editor, I guess it could exist elsewhere but it all has to do with the cropper. + /// + public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + MediaService.Saving += MediaServiceSaving; + MediaService.Created += MediaServiceCreated; + ContentService.Copied += ContentServiceCopied; + + MediaService.Deleted += (sender, args) => + args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); + MediaService.EmptiedRecycleBin += (sender, args) => + args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); + ContentService.Deleted += (sender, args) => + args.MediaFilesToDelete.AddRange(ServiceDeleted(args.DeletedEntities.Cast())); + ContentService.EmptiedRecycleBin += (sender, args) => + args.Files.AddRange(ServiceEmptiedRecycleBin(args.AllPropertyData)); + } + #endregion } } diff --git a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs index 7c84ff7026..07482fa1bf 100644 --- a/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Media; @@ -21,12 +22,21 @@ namespace Umbraco.Web.PropertyEditors { internal class ImageCropperPropertyValueEditor : PropertyValueEditorWrapper { - public ImageCropperPropertyValueEditor(PropertyValueEditor wrapped) : base(wrapped) + private readonly ILogger _logger; + private readonly MediaFileSystem _mediaFileSystem; + private readonly IContentSection _contentConfig; + + public ImageCropperPropertyValueEditor(PropertyValueEditor wrapped, ILogger logger, MediaFileSystem mediaFileSystem, IContentSection contentConfig) + : base(wrapped) { - + if (logger == null) throw new ArgumentNullException("logger"); + if (mediaFileSystem == null) throw new ArgumentNullException("mediaFileSystem"); + if (contentConfig == null) throw new ArgumentNullException("contentConfig"); + _logger = logger; + _mediaFileSystem = mediaFileSystem; + _contentConfig = contentConfig; } - /// /// Overrides the deserialize value so that we can save the file accordingly /// @@ -43,8 +53,6 @@ namespace Umbraco.Web.PropertyEditors /// public override object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue) { - - string oldFile = string.Empty; string newFile = string.Empty; JObject newJson = null; @@ -60,7 +68,7 @@ namespace Umbraco.Web.PropertyEditors catch (Exception ex) { //for some reason the value is invalid so continue as if there was no value there - LogHelper.WarnWithException("Could not parse current db value to a JObject", ex); + _logger.WarnWithException("Could not parse current db value to a JObject", ex); } if (oldJson != null && oldJson["src"] != null) @@ -83,7 +91,7 @@ namespace Umbraco.Web.PropertyEditors //if not alike, that means we have a new file, or delete the current one... if (string.IsNullOrEmpty(newFile) || editorValue.AdditionalData.ContainsKey("files")) { - var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); + var fs = _mediaFileSystem; //if we have an existing file, delete it if (string.IsNullOrEmpty(oldFile) == false) @@ -106,7 +114,7 @@ namespace Umbraco.Web.PropertyEditors var name = IOHelper.SafeFileName(file.FileName.Substring(file.FileName.LastIndexOf(IOHelper.DirSepChar) + 1, file.FileName.Length - file.FileName.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower()); //try to reuse the folder number from the current file - var subfolder = UmbracoConfig.For.UmbracoSettings().Content.UploadAllowDirectories + var subfolder = _contentConfig.UploadAllowDirectories ? oldFile.Replace(fs.GetUrl("/"), "").Split('/')[0] : oldFile.Substring(oldFile.LastIndexOf("/", StringComparison.Ordinal) + 1).Split('-')[0]; @@ -117,7 +125,7 @@ namespace Umbraco.Web.PropertyEditors : MediaSubfolderCounter.Current.Increment().ToString(CultureInfo.InvariantCulture); //set a file name or full path - var fileName = UmbracoConfig.For.UmbracoSettings().Content.UploadAllowDirectories + var fileName = _contentConfig.UploadAllowDirectories ? Path.Combine(numberedFolder, name) : numberedFolder + "-" + name; @@ -140,13 +148,13 @@ namespace Umbraco.Web.PropertyEditors return editorValue.Value.ToString(); } - - + + public override string ConvertDbToString(Property property, PropertyType propertyType, Core.Services.IDataTypeService dataTypeService) { - if(property.Value == null || string.IsNullOrEmpty(property.Value.ToString())) - return null; + if (property.Value == null || string.IsNullOrEmpty(property.Value.ToString())) + return null; //if we dont have a json structure, we will get it from the property type var val = property.Value.ToString(); @@ -155,10 +163,10 @@ namespace Umbraco.Web.PropertyEditors var config = dataTypeService.GetPreValuesByDataTypeId(propertyType.DataTypeDefinitionId).FirstOrDefault(); var crops = !string.IsNullOrEmpty(config) ? config : "[]"; - var newVal = "{src: '" + val + "', crops: " + crops + "}"; + var newVal = "{src: '" + val + "', crops: " + crops + "}"; return newVal; } } - + } diff --git a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs index 81d91ef10a..fbb9d36de3 100644 --- a/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/IntegerPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,6 +7,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.IntegerAlias, "Numeric", "integer", IsParameterEditor = true)] public class IntegerPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public IntegerPropertyEditor(ILogger logger) : base(logger) + { + } + /// /// Overridden to ensure that the value is validated /// diff --git a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs index 0e421f5b14..209a8b43e5 100644 --- a/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/LabelPropertyEditor.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Linq; using System.Web.Mvc; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -11,6 +12,12 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.NoEditAlias, "Label", "readonlyvalue")] public class LabelPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public LabelPropertyEditor(ILogger logger) : base(logger) + { + } protected override PropertyValueEditor CreateValueEditor() { diff --git a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs index 09dfacc94f..f105f9f699 100644 --- a/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -12,6 +13,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.ListViewAlias, "List view", "listview", HideLabel = true)] public class ListViewPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public ListViewPropertyEditor(ILogger logger) : base(logger) + { + } + protected override PreValueEditor CreatePreValueEditor() { return new ListViewPreValueEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs index b8f328f7fa..b2836e599d 100644 --- a/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -12,6 +13,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MacroContainerAlias, "Macro container", "macrocontainer", ValueType = "TEXT")] public class MacroContainerPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public MacroContainerPropertyEditor(ILogger logger) : base(logger) + { + } + /// /// Creates a pre value editor instance /// diff --git a/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MarkdownPropertyEditor.cs index bc9258c5e0..0773ba8df1 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,6 +7,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MarkdownEditorAlias, "Markdown editor", "markdowneditor", ValueType = "TEXT")] public class MarkdownPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public MarkdownPropertyEditor(ILogger logger) : base(logger) + { + } + protected override PreValueEditor CreatePreValueEditor() { return new MarkdownPreValueEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs index 947c9f0062..82d02300ed 100644 --- a/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; @@ -12,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MediaPickerAlias, "Legacy Media Picker", "INT", "mediapicker")] public class MediaPickerPropertyEditor : PropertyEditor { - public MediaPickerPropertyEditor() + public MediaPickerPropertyEditor(ILogger logger) : base(logger) { InternalPreValues = new Dictionary { diff --git a/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs index 92f7c106d9..7a5b58c5bf 100644 --- a/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MemberGroupPickerPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -11,5 +12,11 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MemberGroupPickerAlias, "Member Group Picker", "membergrouppicker")] public class MemberGroupPickerPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public MemberGroupPickerPropertyEditor(ILogger logger) : base(logger) + { + } } } diff --git a/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs index a1c99b83a5..3f6374763b 100644 --- a/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -11,5 +12,11 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MemberPickerAlias, "Member Picker", "INT", "memberpicker")] public class MemberPickerPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public MemberPickerPropertyEditor(ILogger logger) : base(logger) + { + } } } diff --git a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs index 673e721b70..6c291a474a 100644 --- a/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -12,7 +13,7 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MultiNodeTreePickerAlias, "Multinode Treepicker", "contentpicker")] public class MultiNodeTreePickerPropertyEditor : PropertyEditor { - public MultiNodeTreePickerPropertyEditor() + public MultiNodeTreePickerPropertyEditor(ILogger logger) : base(logger) { _internalPreValues = new Dictionary { diff --git a/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs index 1ce77804fa..5c8048cf7f 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleMediaPickerPropertyEditor.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,7 +7,7 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MultipleMediaPickerAlias, "Media Picker", "mediapicker")] public class MultipleMediaPickerPropertyEditor : MediaPickerPropertyEditor { - public MultipleMediaPickerPropertyEditor() + public MultipleMediaPickerPropertyEditor(ILogger logger): base(logger) { //clear the pre-values so it defaults to a multiple picker. InternalPreValues.Clear(); diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs index cc6c0468a3..c514008c66 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -17,6 +17,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MultipleTextstringAlias, "Multiple Textbox", "multipletextbox", ValueType = "TEXT")] public class MultipleTextStringPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public MultipleTextStringPropertyEditor(ILogger logger) : base(logger) + { + } + protected override PropertyValueEditor CreateValueEditor() { return new MultipleTextStringPropertyValueEditor(base.CreateValueEditor()); diff --git a/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RadioButtonsPropertyEditor.cs index eb482e714e..92db979edb 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -14,6 +15,11 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.RadioButtonListAlias, "Radio button list", "radiobuttons", ValueType = "INT")] public class RadioButtonsPropertyEditor : DropDownWithKeysPropertyEditor { - + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public RadioButtonsPropertyEditor(ILogger logger) : base(logger) + { + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/RelatedLinksPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RelatedLinksPropertyEditor.cs index cbc332d66e..43d0b05d70 100644 --- a/src/Umbraco.Web/PropertyEditors/RelatedLinksPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RelatedLinksPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -11,5 +12,11 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.RelatedLinksAlias, "Related links", "relatedlinks", ValueType ="JSON")] public class RelatedLinksPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public RelatedLinksPropertyEditor(ILogger logger) : base(logger) + { + } } } diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 6610c0e12c..2d900beb91 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Macros; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -10,6 +11,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.TinyMCEAlias, "Rich Text Editor", "rte", ValueType = "TEXT", HideLabel = false)] public class RichTextPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public RichTextPropertyEditor(ILogger logger) : base(logger) + { + } + /// /// Create a custom value editor /// diff --git a/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/SliderPropertyEditor.cs index 509739c354..c501752e3c 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,6 +7,13 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.SliderAlias, "Slider", "slider")] public class SliderPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public SliderPropertyEditor(ILogger logger) : base(logger) + { + } + protected override PreValueEditor CreatePreValueEditor() { return new SliderPreValueEditor(); diff --git a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs index 581186f61d..faef1d126d 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Runtime.InteropServices; using Newtonsoft.Json.Linq; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Editors; using Umbraco.Core.PropertyEditors; @@ -14,7 +15,7 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.TagsAlias, "Tags", "tags")] public class TagsPropertyEditor : PropertyEditor { - public TagsPropertyEditor() + public TagsPropertyEditor(ILogger logger) : base(logger) { _defaultPreVals = new Dictionary { diff --git a/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs index 45a1f24aec..13084e1939 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,5 +7,11 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.TextboxMultipleAlias, "Textarea", "textarea", IsParameterEditor = true, ValueType = "TEXT")] public class TextAreaPropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public TextAreaPropertyEditor(ILogger logger) : base(logger) + { + } } } diff --git a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs index 69bc1452cf..5bbd6dc062 100644 --- a/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TextboxPropertyEditor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -12,6 +13,12 @@ namespace Umbraco.Web.PropertyEditors { [PropertyEditor(Constants.PropertyEditors.TextboxAlias, "Textbox", "textbox", IsParameterEditor = true)] public class TextboxPropertyEditor : PropertyEditor - { + { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public TextboxPropertyEditor(ILogger logger) : base(logger) + { + } } } diff --git a/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs index 94561e5858..56de9a382d 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.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -6,5 +7,11 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.TrueFalseAlias, "True/False", "INT", "boolean", IsParameterEditor = true)] public class TrueFalsePropertyEditor : PropertyEditor { + /// + /// The constructor will setup the property editor based on the attribute if one is found + /// + public TrueFalsePropertyEditor(ILogger logger) : base(logger) + { + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs index 830fdec6a7..75efb0718e 100644 --- a/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/UserPickerPropertyEditor.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Web.Mvc; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.PropertyEditors @@ -11,7 +12,8 @@ namespace Umbraco.Web.PropertyEditors { private IDictionary _defaultPreValues; - public UserPickerPropertyEditor() + public UserPickerPropertyEditor(ILogger logger) + : base(logger) { _defaultPreValues = new Dictionary {