From 402867f115c49a01fbd7213499b488fb5d8418b0 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 17 Feb 2020 09:15:48 +0100 Subject: [PATCH 01/10] Moved lots of mapping files --- .../MediaTypeExtensions.cs | 4 ++-- .../Models/ContentEditing/Permission.cs | 2 +- .../Models/DataTypeExtensions.cs | 4 ++-- .../Mapping/ContentPropertyBasicMapper.cs | 0 .../Mapping/ContentPropertyDisplayMapper.cs | 0 .../Models/Mapping/ContentPropertyDtoMapper.cs | 0 .../Mapping/ContentPropertyMapDefinition.cs | 0 .../Models/Mapping/MapperContextExtensions.cs | 0 .../PasswordConfigurationExtensions.cs | 2 +- .../Models/ContentEditing/UserInvite.cs | 2 +- .../Models/Mapping/ContentTypeMapDefinition.cs | 4 ++-- .../Models/Mapping/DataTypeMapDefinition.cs | 5 ++--- .../Mapping/MemberTabsAndPropertiesMapper.cs | 18 ++++++++++++++---- .../Models/Mapping/PropertyTypeGroupMapper.cs | 1 - .../Models/Mapping/RedirectUrlMapDefinition.cs | 2 +- .../Models/Mapping/TabsAndPropertiesMapper.cs | 5 ++--- .../Models/Mapping/UserMapDefinition.cs | 3 +-- .../PublishedContentTestBase.cs | 2 -- .../PublishedContent/PublishedContentTests.cs | 2 +- .../Web/Mvc/SurfaceControllerTests.cs | 4 ---- src/Umbraco.Web/Models/Mapping/CommonMapper.cs | 6 ++---- .../Models/Mapping/MediaMapDefinition.cs | 2 +- .../Models/Mapping/MemberMapDefinition.cs | 2 +- .../PropertyEditors/GridPropertyEditor.cs | 4 ---- .../PropertyEditors/RichTextPropertyEditor.cs | 2 -- .../RteMacroRenderingValueConverter.cs | 5 ----- src/Umbraco.Web/Umbraco.Web.csproj | 13 ------------- 27 files changed, 34 insertions(+), 60 deletions(-) rename src/{Umbraco.Web => Umbraco.Abstractions}/Models/Mapping/ContentPropertyBasicMapper.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Models/Mapping/ContentPropertyDisplayMapper.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Models/Mapping/ContentPropertyDtoMapper.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Models/Mapping/ContentPropertyMapDefinition.cs (100%) rename src/{Umbraco.Infrastructure => Umbraco.Abstractions}/Models/Mapping/MapperContextExtensions.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/PasswordConfigurationExtensions.cs (96%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/ContentEditing/UserInvite.cs (97%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/Mapping/ContentTypeMapDefinition.cs (99%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/Mapping/DataTypeMapDefinition.cs (98%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/Mapping/MemberTabsAndPropertiesMapper.cs (93%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/Mapping/PropertyTypeGroupMapper.cs (99%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/Mapping/RedirectUrlMapDefinition.cs (95%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/Mapping/TabsAndPropertiesMapper.cs (97%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Models/Mapping/UserMapDefinition.cs (99%) diff --git a/src/Umbraco.Abstractions/MediaTypeExtensions.cs b/src/Umbraco.Abstractions/MediaTypeExtensions.cs index 4e2ae5822a..3a2a3ba6e2 100644 --- a/src/Umbraco.Abstractions/MediaTypeExtensions.cs +++ b/src/Umbraco.Abstractions/MediaTypeExtensions.cs @@ -1,8 +1,8 @@ namespace Umbraco.Core.Models { - internal static class MediaTypeExtensions + public static class MediaTypeExtensions { - internal static bool IsSystemMediaType(this IMediaType mediaType) => + public static bool IsSystemMediaType(this IMediaType mediaType) => mediaType.Alias == Constants.Conventions.MediaTypes.File || mediaType.Alias == Constants.Conventions.MediaTypes.Folder || mediaType.Alias == Constants.Conventions.MediaTypes.Image; diff --git a/src/Umbraco.Abstractions/Models/ContentEditing/Permission.cs b/src/Umbraco.Abstractions/Models/ContentEditing/Permission.cs index 7b444e5959..2bb905200a 100644 --- a/src/Umbraco.Abstractions/Models/ContentEditing/Permission.cs +++ b/src/Umbraco.Abstractions/Models/ContentEditing/Permission.cs @@ -22,7 +22,7 @@ namespace Umbraco.Web.Models.ContentEditing /// We'll use this to map the categories but it wont' be returned in the json /// [IgnoreDataMember] - internal string Category { get; set; } + public string Category { get; set; } /// /// The letter from the IAction diff --git a/src/Umbraco.Abstractions/Models/DataTypeExtensions.cs b/src/Umbraco.Abstractions/Models/DataTypeExtensions.cs index c2116c6c45..4f4bd4d6c3 100644 --- a/src/Umbraco.Abstractions/Models/DataTypeExtensions.cs +++ b/src/Umbraco.Abstractions/Models/DataTypeExtensions.cs @@ -75,7 +75,7 @@ namespace Umbraco.Core.Models /// /// The data type definition. /// - internal static bool IsBuildInDataType(this IDataType dataType) + public static bool IsBuildInDataType(this IDataType dataType) { return IsBuildInDataType(dataType.Key); } @@ -83,7 +83,7 @@ namespace Umbraco.Core.Models /// /// Returns true if this date type is build-in/default. /// - internal static bool IsBuildInDataType(Guid key) + public static bool IsBuildInDataType(Guid key) { return IdsOfBuildInDataTypes.Contains(key); } diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyBasicMapper.cs b/src/Umbraco.Abstractions/Models/Mapping/ContentPropertyBasicMapper.cs similarity index 100% rename from src/Umbraco.Web/Models/Mapping/ContentPropertyBasicMapper.cs rename to src/Umbraco.Abstractions/Models/Mapping/ContentPropertyBasicMapper.cs diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayMapper.cs b/src/Umbraco.Abstractions/Models/Mapping/ContentPropertyDisplayMapper.cs similarity index 100% rename from src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayMapper.cs rename to src/Umbraco.Abstractions/Models/Mapping/ContentPropertyDisplayMapper.cs diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyDtoMapper.cs b/src/Umbraco.Abstractions/Models/Mapping/ContentPropertyDtoMapper.cs similarity index 100% rename from src/Umbraco.Web/Models/Mapping/ContentPropertyDtoMapper.cs rename to src/Umbraco.Abstractions/Models/Mapping/ContentPropertyDtoMapper.cs diff --git a/src/Umbraco.Web/Models/Mapping/ContentPropertyMapDefinition.cs b/src/Umbraco.Abstractions/Models/Mapping/ContentPropertyMapDefinition.cs similarity index 100% rename from src/Umbraco.Web/Models/Mapping/ContentPropertyMapDefinition.cs rename to src/Umbraco.Abstractions/Models/Mapping/ContentPropertyMapDefinition.cs diff --git a/src/Umbraco.Infrastructure/Models/Mapping/MapperContextExtensions.cs b/src/Umbraco.Abstractions/Models/Mapping/MapperContextExtensions.cs similarity index 100% rename from src/Umbraco.Infrastructure/Models/Mapping/MapperContextExtensions.cs rename to src/Umbraco.Abstractions/Models/Mapping/MapperContextExtensions.cs diff --git a/src/Umbraco.Web/PasswordConfigurationExtensions.cs b/src/Umbraco.Abstractions/PasswordConfigurationExtensions.cs similarity index 96% rename from src/Umbraco.Web/PasswordConfigurationExtensions.cs rename to src/Umbraco.Abstractions/PasswordConfigurationExtensions.cs index 1105fc31a7..be13b574ed 100644 --- a/src/Umbraco.Web/PasswordConfigurationExtensions.cs +++ b/src/Umbraco.Abstractions/PasswordConfigurationExtensions.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web { - internal static class PasswordConfigurationExtensions + public static class PasswordConfigurationExtensions { /// /// Returns the configuration of the membership provider used to configure change password editors diff --git a/src/Umbraco.Web/Models/ContentEditing/UserInvite.cs b/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs similarity index 97% rename from src/Umbraco.Web/Models/ContentEditing/UserInvite.cs rename to src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs index 3adf10c467..f1c6cf6c04 100644 --- a/src/Umbraco.Web/Models/ContentEditing/UserInvite.cs +++ b/src/Umbraco.Infrastructure/Models/ContentEditing/UserInvite.cs @@ -2,8 +2,8 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Runtime.Serialization; +using Umbraco.Composing; using Umbraco.Core; -using Umbraco.Web.Composing; namespace Umbraco.Web.Models.ContentEditing { diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs similarity index 99% rename from src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs rename to src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs index de64b15a0f..f7a2d6376b 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/ContentTypeMapDefinition.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.Models.Mapping /// /// Defines mappings for content/media/members type mappings /// - internal class ContentTypeMapDefinition : IMapDefinition + public class ContentTypeMapDefinition : IMapDefinition { private readonly PropertyEditorCollection _propertyEditors; private readonly IDataTypeService _dataTypeService; @@ -591,7 +591,7 @@ namespace Umbraco.Web.Models.Mapping return aliases.OrderBy(x => x); } - internal static Udi MapContentTypeUdi(IContentTypeComposition source) + public static Udi MapContentTypeUdi(IContentTypeComposition source) { if (source == null) return null; diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs similarity index 98% rename from src/Umbraco.Web/Models/Mapping/DataTypeMapDefinition.cs rename to src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs index 0446c397bc..d57809c844 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/DataTypeMapDefinition.cs @@ -7,12 +7,11 @@ using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; -using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Models.Mapping { - internal class DataTypeMapDefinition : IMapDefinition + public class DataTypeMapDefinition : IMapDefinition { private readonly PropertyEditorCollection _propertyEditors; private readonly ILogger _logger; @@ -142,7 +141,7 @@ namespace Umbraco.Web.Models.Mapping // an empty fields list, which made no sense since there would be nothing to map to - and besides, // a datatype without an editor alias is a serious issue - v8 wants an editor here - if (string.IsNullOrWhiteSpace(dataType.EditorAlias) || !Current.PropertyEditors.TryGet(dataType.EditorAlias, out var editor)) + if (string.IsNullOrWhiteSpace(dataType.EditorAlias) || !_propertyEditors.TryGet(dataType.EditorAlias, out var editor)) throw new InvalidOperationException($"Could not find a property editor with alias \"{dataType.EditorAlias}\"."); var configurationEditor = editor.GetConfigurationEditor(); diff --git a/src/Umbraco.Web/Models/Mapping/MemberTabsAndPropertiesMapper.cs b/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs similarity index 93% rename from src/Umbraco.Web/Models/Mapping/MemberTabsAndPropertiesMapper.cs rename to src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs index 7dc3d55087..2cb226bec2 100644 --- a/src/Umbraco.Web/Models/Mapping/MemberTabsAndPropertiesMapper.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/MemberTabsAndPropertiesMapper.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Core; using Umbraco.Core.Mapping; -using Umbraco.Web.Composing; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; using Umbraco.Core.Dictionary; using Umbraco.Core.Configuration; +using Umbraco.Core.PropertyEditors; namespace Umbraco.Web.Models.Mapping { @@ -20,7 +20,7 @@ namespace Umbraco.Web.Models.Mapping /// This also ensures that the IsLocked out property is readonly when the member is not locked out - this is because /// an admin cannot actually set isLockedOut = true, they can only unlock. /// - internal class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper + public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper { private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly ILocalizedTextService _localizedTextService; @@ -28,8 +28,17 @@ namespace Umbraco.Web.Models.Mapping private readonly IMemberService _memberService; private readonly IMemberGroupService _memberGroupService; private readonly IMemberPasswordConfiguration _memberPasswordConfiguration; + private readonly PropertyEditorCollection _propertyEditorCollection; - public MemberTabsAndPropertiesMapper(ICultureDictionary cultureDictionary, IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IMemberTypeService memberTypeService, IMemberService memberService, IMemberGroupService memberGroupService, IMemberPasswordConfiguration memberPasswordConfiguration, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) + public MemberTabsAndPropertiesMapper(ICultureDictionary cultureDictionary, + IUmbracoContextAccessor umbracoContextAccessor, + ILocalizedTextService localizedTextService, + IMemberTypeService memberTypeService, + IMemberService memberService, + IMemberGroupService memberGroupService, + IMemberPasswordConfiguration memberPasswordConfiguration, + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, + PropertyEditorCollection propertyEditorCollection) : base(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); @@ -38,6 +47,7 @@ namespace Umbraco.Web.Models.Mapping _memberService = memberService ?? throw new ArgumentNullException(nameof(memberService)); _memberGroupService = memberGroupService ?? throw new ArgumentNullException(nameof(memberGroupService)); _memberPasswordConfiguration = memberPasswordConfiguration; + _propertyEditorCollection = propertyEditorCollection; } /// @@ -108,7 +118,7 @@ namespace Umbraco.Web.Models.Mapping Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}doctype", Label = _localizedTextService.Localize("content/membertype"), Value = _localizedTextService.UmbracoDictionaryTranslate(CultureDictionary, member.ContentType.Name), - View = Current.PropertyEditors[Constants.PropertyEditors.Aliases.Label].GetValueEditor().View + View = _propertyEditorCollection[Constants.PropertyEditors.Aliases.Label].GetValueEditor().View }, GetLoginProperty(_memberTypeService, member, _localizedTextService), new ContentPropertyDisplay diff --git a/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupMapper.cs b/src/Umbraco.Infrastructure/Models/Mapping/PropertyTypeGroupMapper.cs similarity index 99% rename from src/Umbraco.Web/Models/Mapping/PropertyTypeGroupMapper.cs rename to src/Umbraco.Infrastructure/Models/Mapping/PropertyTypeGroupMapper.cs index 000e37f31f..5cdc9c5fa4 100644 --- a/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupMapper.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/PropertyTypeGroupMapper.cs @@ -7,7 +7,6 @@ using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Core.Strings; -using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Models.Mapping diff --git a/src/Umbraco.Web/Models/Mapping/RedirectUrlMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/RedirectUrlMapDefinition.cs similarity index 95% rename from src/Umbraco.Web/Models/Mapping/RedirectUrlMapDefinition.cs rename to src/Umbraco.Infrastructure/Models/Mapping/RedirectUrlMapDefinition.cs index 9386c60918..08c89b34f8 100644 --- a/src/Umbraco.Web/Models/Mapping/RedirectUrlMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/RedirectUrlMapDefinition.cs @@ -5,7 +5,7 @@ using Umbraco.Web.Routing; namespace Umbraco.Web.Models.Mapping { - internal class RedirectUrlMapDefinition : IMapDefinition + public class RedirectUrlMapDefinition : IMapDefinition { private readonly IPublishedUrlProvider _publishedUrlProvider; diff --git a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesMapper.cs b/src/Umbraco.Infrastructure/Models/Mapping/TabsAndPropertiesMapper.cs similarity index 97% rename from src/Umbraco.Web/Models/Mapping/TabsAndPropertiesMapper.cs rename to src/Umbraco.Infrastructure/Models/Mapping/TabsAndPropertiesMapper.cs index ea062de9eb..d9c76b5ebc 100644 --- a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesMapper.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/TabsAndPropertiesMapper.cs @@ -6,12 +6,11 @@ using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Composing; using Umbraco.Core.Dictionary; namespace Umbraco.Web.Models.Mapping { - internal abstract class TabsAndPropertiesMapper + public abstract class TabsAndPropertiesMapper { protected ICultureDictionary CultureDictionary { get; } protected ILocalizedTextService LocalizedTextService { get; } @@ -115,7 +114,7 @@ namespace Umbraco.Web.Models.Mapping /// /// Creates the tabs collection with properties assigned for display models /// - internal class TabsAndPropertiesMapper : TabsAndPropertiesMapper + public class TabsAndPropertiesMapper : TabsAndPropertiesMapper where TSource : IContentBase { private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; diff --git a/src/Umbraco.Web/Models/Mapping/UserMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs similarity index 99% rename from src/Umbraco.Web/Models/Mapping/UserMapDefinition.cs rename to src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs index 556b15d72b..19a78bcbe4 100644 --- a/src/Umbraco.Web/Models/Mapping/UserMapDefinition.cs +++ b/src/Umbraco.Infrastructure/Models/Mapping/UserMapDefinition.cs @@ -4,7 +4,6 @@ using System.Globalization; using System.Linq; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Web.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Mapping; @@ -20,7 +19,7 @@ using Umbraco.Web.Services; namespace Umbraco.Web.Models.Mapping { - internal class UserMapDefinition : IMapDefinition + public class UserMapDefinition : IMapDefinition { private readonly ISectionService _sectionService; private readonly IEntityService _entityService; diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index fc184e8da0..704ce3fff4 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -53,8 +53,6 @@ namespace Umbraco.Tests.PublishedContent var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new RichTextPropertyEditor( Mock.Of(), - Mock.Of(), - Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index ecfcca0e0d..04dbcc454c 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -59,7 +59,7 @@ namespace Umbraco.Tests.PublishedContent var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new VoidEditor(logger, Mock.Of(), localizationService, LocalizedTextService, ShortStringHelper)) { Id = 1 }, new DataType(new TrueFalsePropertyEditor(logger, Mock.Of(), localizationService, IOHelper, ShortStringHelper, LocalizedTextService)) { Id = 1001 }, - new DataType(new RichTextPropertyEditor(logger, mediaService, contentTypeBaseServiceProvider, umbracoContextAccessor, Mock.Of(), localizationService, imageSourceParser, linkParser, pastedImages, ShortStringHelper, IOHelper, LocalizedTextService, Mock.Of())) { Id = 1002 }, + new DataType(new RichTextPropertyEditor(logger,umbracoContextAccessor, Mock.Of(), localizationService, imageSourceParser, linkParser, pastedImages, ShortStringHelper, IOHelper, LocalizedTextService, Mock.Of())) { Id = 1002 }, new DataType(new IntegerPropertyEditor(logger, Mock.Of(), localizationService, ShortStringHelper, LocalizedTextService)) { Id = 1003 }, new DataType(new TextboxPropertyEditor(logger, Mock.Of(), localizationService, IOHelper, ShortStringHelper, LocalizedTextService)) { Id = 1004 }, new DataType(new MediaPickerPropertyEditor(logger, Mock.Of(), localizationService, IOHelper, ShortStringHelper, LocalizedTextService)) { Id = 1005 }); diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index b6d2d92da0..e44a3cc5f2 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; @@ -7,7 +6,6 @@ using System.Web.Security; using Moq; using NUnit.Framework; using Umbraco.Core.Cache; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Dictionary; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; @@ -18,7 +16,6 @@ using Umbraco.Tests.Testing.Objects.Accessors; using Umbraco.Web; using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; -using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.Security.Providers; using Current = Umbraco.Web.Composing.Current; @@ -134,7 +131,6 @@ namespace Umbraco.Tests.Web.Mvc [Test] public void Mock_Current_Page() { - var webRoutingSettings = Mock.Of(section => section.UrlProviderMode == "Auto"); var globalSettings = TestObjects.GetGlobalSettings(); var httpContextAccessor = TestHelper.GetHttpContextAccessor(); diff --git a/src/Umbraco.Web/Models/Mapping/CommonMapper.cs b/src/Umbraco.Web/Models/Mapping/CommonMapper.cs index f8b99a444c..81a3fcb4cb 100644 --- a/src/Umbraco.Web/Models/Mapping/CommonMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/CommonMapper.cs @@ -17,22 +17,20 @@ using UserProfile = Umbraco.Web.Models.ContentEditing.UserProfile; namespace Umbraco.Web.Models.Mapping { - internal class CommonMapper + public class CommonMapper { private readonly IUserService _userService; private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; - private readonly IUmbracoContextAccessor _umbracoContextAccessor; private readonly ContentAppFactoryCollection _contentAppDefinitions; private readonly ILocalizedTextService _localizedTextService; private readonly IHttpContextAccessor _httpContextAccessor; private readonly ICurrentUserAccessor _currentUserAccessor; - public CommonMapper(IUserService userService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, + public CommonMapper(IUserService userService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, ContentAppFactoryCollection contentAppDefinitions, ILocalizedTextService localizedTextService, IHttpContextAccessor httpContextAccessor, ICurrentUserAccessor currentUserAccessor) { _userService = userService; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; - _umbracoContextAccessor = umbracoContextAccessor; _contentAppDefinitions = contentAppDefinitions; _localizedTextService = localizedTextService; _httpContextAccessor = httpContextAccessor; diff --git a/src/Umbraco.Web/Models/Mapping/MediaMapDefinition.cs b/src/Umbraco.Web/Models/Mapping/MediaMapDefinition.cs index 3298f3bd1e..0523cbeda9 100644 --- a/src/Umbraco.Web/Models/Mapping/MediaMapDefinition.cs +++ b/src/Umbraco.Web/Models/Mapping/MediaMapDefinition.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.Models.Mapping /// /// Declares model mappings for media. /// - internal class MediaMapDefinition : IMapDefinition + public class MediaMapDefinition : IMapDefinition { private readonly CommonMapper _commonMapper; private readonly ILogger _logger; diff --git a/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs b/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs index ee241f3245..d47f9df7c7 100644 --- a/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs +++ b/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs @@ -8,7 +8,7 @@ namespace Umbraco.Web.Models.Mapping /// /// Declares model mappings for members. /// - internal class MemberMapDefinition : IMapDefinition + public class MemberMapDefinition : IMapDefinition { private readonly CommonMapper _commonMapper; private readonly MemberTabsAndPropertiesMapper _tabsAndPropertiesMapper; diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 7ab2ed2a36..8b8b118038 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -30,8 +30,6 @@ namespace Umbraco.Web.PropertyEditors public class GridPropertyEditor : DataEditor { private readonly IUmbracoContextAccessor _umbracoContextAccessor; - private readonly IDataTypeService _dataTypeService; - private readonly ILocalizationService _localizationService; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; private readonly IMediaService _mediaService; @@ -58,8 +56,6 @@ namespace Umbraco.Web.PropertyEditors : base(logger, dataTypeService, localizationService, localizedTextService, shortStringHelper) { _umbracoContextAccessor = umbracoContextAccessor; - _dataTypeService = dataTypeService; - _localizationService = localizationService; _ioHelper = ioHelper; _logger = logger; _mediaService = mediaService; diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index 766a811fb1..50f514efe5 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -40,8 +40,6 @@ namespace Umbraco.Web.PropertyEditors /// public RichTextPropertyEditor( ILogger logger, - IMediaService mediaService, - IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService, diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs index 67031faaa0..60857fd76c 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs @@ -1,17 +1,12 @@ using System.Text; using Umbraco.Core; -using Umbraco.Core.Macros; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors.ValueConverters; using Umbraco.Web.Templates; using System.Linq; using HtmlAgilityPack; -using Umbraco.Core.Cache; -using Umbraco.Core.Services; -using Umbraco.Web.Composing; using Umbraco.Web.Macros; -using System.Web; using Umbraco.Core.Strings; namespace Umbraco.Web.PropertyEditors.ValueConverters diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 7f40c33dda..b079026984 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -168,26 +168,15 @@ - - - - - - - - - - - @@ -466,14 +455,12 @@ - - From 43b33f9e6b819aede7e4fd2f8b7f21376a8c0438 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 17 Feb 2020 14:58:34 +0100 Subject: [PATCH 02/10] Move features - Introduced IUmbracoFeature Move Install Move Tree Items - Introduced IMenuItemCollectionFactory - to insure injection of ActionCollection --- .../Configuration/IConnectionStrings.cs | 2 + .../Features/DisabledFeatures.cs | 7 +-- .../Features/EnabledFeatures.cs | 0 .../Features/IUmbracoFeatureController.cs | 7 +++ .../Features/UmbracoFeatures.cs | 5 +- .../IUmbracoContextFactory.cs | 0 .../Install/InstallException.cs | 0 .../Install/InstallStatusTracker.cs | 46 +++++++++------- .../InstallSteps/FilePermissionsStep.cs | 1 - .../InstallSteps/StarterKitCleanupStep.cs | 0 .../Install/InstallSteps/UpgradeStep.cs | 12 ++-- .../Install/Models/DatabaseModel.cs | 0 .../Install/Models/DatabaseType.cs | 0 .../Install/Models/InstallInstructions.cs | 3 +- .../Models/InstallProgressResultModel.cs | 0 .../Install/Models/InstallSetup.cs | 0 .../Install/Models/InstallSetupResult.cs | 0 .../Install/Models/InstallSetupStep.cs | 0 .../Models/InstallSetupStepAttribute.cs | 0 .../Install/Models/InstallTrackingItem.cs | 2 +- .../Install/Models/InstallationType.cs | 0 .../Install/Models/Package.cs | 0 .../Install/Models/UserModel.cs | 0 .../Trees/IMenuItemCollectionFactory.cs | 9 +++ .../Trees/MenuItemCollection.cs | 12 ++-- .../Trees/MenuItemCollectionFactory.cs | 21 +++++++ .../Trees/MenuItemList.cs | 11 ++-- src/Umbraco.Configuration/ConfigsFactory.cs | 7 +-- .../ConnectionStrings.cs | 24 ++++++++ src/Umbraco.Configuration/GlobalSettings.cs | 22 +------- .../Cache/DistributedCacheBinder.cs | 2 - .../Cache/DistributedCacheBinderComposer.cs | 0 .../Cache/DistributedCacheBinder_Handlers.cs | 2 - .../InstallSteps/DatabaseConfigureStep.cs | 2 +- .../InstallSteps/DatabaseInstallStep.cs | 21 ++++--- .../InstallSteps/DatabaseUpgradeStep.cs | 5 +- .../Runtime/CoreInitialComposer.cs | 4 ++ .../Trees/TreeNode.cs | 4 +- .../Trees/TreeNodeCollection.cs | 0 .../Trees/TreeNodeExtensions.cs | 0 .../Trees/TreeRootNode.cs | 0 src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 4 ++ .../{Net => AspNet}/AspNetBackOfficeInfo.cs | 0 .../{Net => AspNet}/AspNetCookieManager.cs | 0 .../AspNetHostingEnvironment.cs | 0 .../AspNetHttpContextAccessor.cs | 0 .../{Net => AspNet}/AspNetIpResolver.cs | 0 .../{Net => AspNet}/AspNetPasswordHasher.cs | 0 .../AspNetSessionIdResolver.cs | 0 .../{ => AspNet}/FrameworkMarchal.cs | 0 src/Umbraco.Web/Composing/Current.cs | 2 + .../Controllers/InstallApiController.cs | 26 +++++---- .../Install/FilePermissionHelper.cs | 11 ++-- src/Umbraco.Web/Install/InstallHelper.cs | 16 +++--- .../Security/IdentityAuditEventArgs.cs | 2 +- .../Trees/ContentBlueprintTreeController.cs | 27 ++++++++- .../Trees/ContentTreeController.cs | 15 +++-- .../Trees/ContentTreeControllerBase.cs | 8 ++- .../Trees/ContentTypeTreeController.cs | 7 ++- .../Trees/DataTypeTreeController.cs | 7 ++- .../Trees/DictionaryTreeController.cs | 28 +++++++++- .../Trees/FileSystemTreeController.cs | 40 ++++++++++++-- src/Umbraco.Web/Trees/MacrosTreeController.cs | 30 +++++++++- src/Umbraco.Web/Trees/MediaTreeController.cs | 7 ++- .../Trees/MediaTypeTreeController.cs | 7 ++- src/Umbraco.Web/Trees/MemberTreeController.cs | 33 +++++++++-- .../MemberTypeAndGroupTreeControllerBase.cs | 34 +++++++++++- .../Trees/PackagesTreeController.cs | 28 +++++++++- .../Trees/PartialViewsTreeController.cs | 1 - .../Trees/RelationTypeTreeController.cs | 29 +++++++++- .../Trees/TemplatesTreeController.cs | 9 ++- src/Umbraco.Web/Trees/UserTreeController.cs | 28 +++++++++- src/Umbraco.Web/Umbraco.Web.csproj | 55 ++++--------------- .../WebApi/UmbracoApiControllerBase.cs | 5 +- 74 files changed, 492 insertions(+), 198 deletions(-) rename src/{Umbraco.Web => Umbraco.Abstractions}/Features/DisabledFeatures.cs (82%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Features/EnabledFeatures.cs (100%) create mode 100644 src/Umbraco.Abstractions/Features/IUmbracoFeatureController.cs rename src/{Umbraco.Web => Umbraco.Abstractions}/Features/UmbracoFeatures.cs (90%) rename src/{Umbraco.Web => Umbraco.Abstractions}/IUmbracoContextFactory.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/InstallException.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/InstallStatusTracker.cs (69%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/InstallSteps/FilePermissionsStep.cs (98%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/InstallSteps/StarterKitCleanupStep.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/InstallSteps/UpgradeStep.cs (84%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/DatabaseModel.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/DatabaseType.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallInstructions.cs (80%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallProgressResultModel.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallSetup.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallSetupResult.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallSetupStep.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallSetupStepAttribute.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallTrackingItem.cs (96%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/InstallationType.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/Package.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Install/Models/UserModel.cs (100%) create mode 100644 src/Umbraco.Abstractions/Trees/IMenuItemCollectionFactory.cs rename src/{Umbraco.Web/Models => Umbraco.Abstractions}/Trees/MenuItemCollection.cs (72%) create mode 100644 src/Umbraco.Abstractions/Trees/MenuItemCollectionFactory.cs rename src/{Umbraco.Web/Models => Umbraco.Abstractions}/Trees/MenuItemList.cs (82%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Cache/DistributedCacheBinder.cs (98%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Cache/DistributedCacheBinderComposer.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Cache/DistributedCacheBinder_Handlers.cs (99%) rename src/{Umbraco.Web/Install => Umbraco.Infrastructure/Intall}/InstallSteps/DatabaseConfigureStep.cs (98%) rename src/{Umbraco.Web/Install => Umbraco.Infrastructure/Intall}/InstallSteps/DatabaseInstallStep.cs (79%) rename src/{Umbraco.Web/Install => Umbraco.Infrastructure/Intall}/InstallSteps/DatabaseUpgradeStep.cs (97%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Trees/TreeNode.cs (97%) rename src/{Umbraco.Web/Models => Umbraco.Infrastructure}/Trees/TreeNodeCollection.cs (100%) rename src/{Umbraco.Web/Models => Umbraco.Infrastructure}/Trees/TreeNodeExtensions.cs (100%) rename src/{Umbraco.Web/Models => Umbraco.Infrastructure}/Trees/TreeRootNode.cs (100%) rename src/Umbraco.Web/{Net => AspNet}/AspNetBackOfficeInfo.cs (100%) rename src/Umbraco.Web/{Net => AspNet}/AspNetCookieManager.cs (100%) rename src/Umbraco.Web/{Hosting => AspNet}/AspNetHostingEnvironment.cs (100%) rename src/Umbraco.Web/{Net => AspNet}/AspNetHttpContextAccessor.cs (100%) rename src/Umbraco.Web/{Net => AspNet}/AspNetIpResolver.cs (100%) rename src/Umbraco.Web/{Net => AspNet}/AspNetPasswordHasher.cs (100%) rename src/Umbraco.Web/{Net => AspNet}/AspNetSessionIdResolver.cs (100%) rename src/Umbraco.Web/{ => AspNet}/FrameworkMarchal.cs (100%) diff --git a/src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs b/src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs index 0d33378669..acd2281a1e 100644 --- a/src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs +++ b/src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs @@ -6,5 +6,7 @@ namespace Umbraco.Core.Configuration { get; } + + void RemoveConnectionString(string umbracoConnectionName); } } diff --git a/src/Umbraco.Web/Features/DisabledFeatures.cs b/src/Umbraco.Abstractions/Features/DisabledFeatures.cs similarity index 82% rename from src/Umbraco.Web/Features/DisabledFeatures.cs rename to src/Umbraco.Abstractions/Features/DisabledFeatures.cs index 62fb019c70..9bd091a570 100644 --- a/src/Umbraco.Web/Features/DisabledFeatures.cs +++ b/src/Umbraco.Abstractions/Features/DisabledFeatures.cs @@ -1,5 +1,4 @@ using Umbraco.Core.Collections; -using Umbraco.Web.WebApi; namespace Umbraco.Web.Features { @@ -13,19 +12,19 @@ namespace Umbraco.Web.Features /// public DisabledFeatures() { - Controllers = new TypeList(); + Controllers = new TypeList(); } /// /// Gets the disabled controllers. /// - public TypeList Controllers { get; } + public TypeList Controllers { get; } /// /// Disables the device preview feature of previewing. /// public bool DisableDevicePreview { get; set; } - + /// /// If true, all references to templates will be removed in the back office and routing /// diff --git a/src/Umbraco.Web/Features/EnabledFeatures.cs b/src/Umbraco.Abstractions/Features/EnabledFeatures.cs similarity index 100% rename from src/Umbraco.Web/Features/EnabledFeatures.cs rename to src/Umbraco.Abstractions/Features/EnabledFeatures.cs diff --git a/src/Umbraco.Abstractions/Features/IUmbracoFeatureController.cs b/src/Umbraco.Abstractions/Features/IUmbracoFeatureController.cs new file mode 100644 index 0000000000..0187cdecb0 --- /dev/null +++ b/src/Umbraco.Abstractions/Features/IUmbracoFeatureController.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Web.Features +{ + public interface IUmbracoFeature + { + + } +} diff --git a/src/Umbraco.Web/Features/UmbracoFeatures.cs b/src/Umbraco.Abstractions/Features/UmbracoFeatures.cs similarity index 90% rename from src/Umbraco.Web/Features/UmbracoFeatures.cs rename to src/Umbraco.Abstractions/Features/UmbracoFeatures.cs index d1c3899271..69fe58f76d 100644 --- a/src/Umbraco.Web/Features/UmbracoFeatures.cs +++ b/src/Umbraco.Abstractions/Features/UmbracoFeatures.cs @@ -1,5 +1,4 @@ using System; -using Umbraco.Web.WebApi; namespace Umbraco.Web.Features { @@ -16,7 +15,7 @@ namespace Umbraco.Web.Features Disabled = new DisabledFeatures(); Enabled = new EnabledFeatures(); } - + /// /// Gets the disabled features. /// @@ -32,7 +31,7 @@ namespace Umbraco.Web.Features /// internal bool IsControllerEnabled(Type feature) { - if (typeof(UmbracoApiControllerBase).IsAssignableFrom(feature)) + if (typeof(IUmbracoFeature).IsAssignableFrom(feature)) return Disabled.Controllers.Contains(feature) == false; throw new NotSupportedException("Not a supported feature type."); diff --git a/src/Umbraco.Web/IUmbracoContextFactory.cs b/src/Umbraco.Abstractions/IUmbracoContextFactory.cs similarity index 100% rename from src/Umbraco.Web/IUmbracoContextFactory.cs rename to src/Umbraco.Abstractions/IUmbracoContextFactory.cs diff --git a/src/Umbraco.Web/Install/InstallException.cs b/src/Umbraco.Abstractions/Install/InstallException.cs similarity index 100% rename from src/Umbraco.Web/Install/InstallException.cs rename to src/Umbraco.Abstractions/Install/InstallException.cs diff --git a/src/Umbraco.Web/Install/InstallStatusTracker.cs b/src/Umbraco.Abstractions/Install/InstallStatusTracker.cs similarity index 69% rename from src/Umbraco.Web/Install/InstallStatusTracker.cs rename to src/Umbraco.Abstractions/Install/InstallStatusTracker.cs index 58e8507ec8..c0c9a696fd 100644 --- a/src/Umbraco.Web/Install/InstallStatusTracker.cs +++ b/src/Umbraco.Abstractions/Install/InstallStatusTracker.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.Collections; -using Umbraco.Web.Composing; +using Umbraco.Core.IO; +using Umbraco.Core.Serialization; using Umbraco.Web.Install.Models; namespace Umbraco.Web.Install @@ -13,29 +13,37 @@ namespace Umbraco.Web.Install /// /// An internal in-memory status tracker for the current installation /// - internal static class InstallStatusTracker + public class InstallStatusTracker { + private readonly IIOHelper _ioHelper; + private readonly IJsonSerializer _jsonSerializer; + + public InstallStatusTracker(IIOHelper ioHelper, IJsonSerializer jsonSerializer) + { + _ioHelper = ioHelper; + _jsonSerializer = jsonSerializer; + } private static ConcurrentHashSet _steps = new ConcurrentHashSet(); - private static string GetFile(Guid installId) + private string GetFile(Guid installId) { - var file = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "Install/" - + "install_" - + installId.ToString("N") - + ".txt"); + var file = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "Install/" + + "install_" + + installId.ToString("N") + + ".txt"); return file; } - public static void Reset() + public void Reset() { _steps = new ConcurrentHashSet(); ClearFiles(); } - public static void ClearFiles() + public void ClearFiles() { - var dir = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "Install/"); + var dir = _ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "Install/"); if (Directory.Exists(dir)) { var files = Directory.GetFiles(dir); @@ -50,13 +58,13 @@ namespace Umbraco.Web.Install } } - public static IEnumerable InitializeFromFile(Guid installId) + public IEnumerable InitializeFromFile(Guid installId) { //check if we have our persisted file and read it var file = GetFile(installId); if (File.Exists(file)) { - var deserialized = JsonConvert.DeserializeObject>( + var deserialized = _jsonSerializer.Deserialize>( File.ReadAllText(file)); foreach (var item in deserialized) { @@ -70,7 +78,7 @@ namespace Umbraco.Web.Install return new List(_steps); } - public static IEnumerable Initialize(Guid installId, IEnumerable steps) + public IEnumerable Initialize(Guid installId, IEnumerable steps) { //if there are no steps in memory if (_steps.Count == 0) @@ -79,7 +87,7 @@ namespace Umbraco.Web.Install var file = GetFile(installId); if (File.Exists(file)) { - var deserialized = JsonConvert.DeserializeObject>( + var deserialized = _jsonSerializer.Deserialize>( File.ReadAllText(file)); foreach (var item in deserialized) { @@ -96,7 +104,7 @@ namespace Umbraco.Web.Install _steps.Add(new InstallTrackingItem(step.Name, step.ServerOrder)); } //save the file - var serialized = JsonConvert.SerializeObject(new List(_steps)); + var serialized = _jsonSerializer.Serialize(new List(_steps)); Directory.CreateDirectory(Path.GetDirectoryName(file)); File.WriteAllText(file, serialized); } @@ -110,7 +118,7 @@ namespace Umbraco.Web.Install ClearFiles(); //save the correct file - var serialized = JsonConvert.SerializeObject(new List(_steps)); + var serialized = _jsonSerializer.Serialize(new List(_steps)); Directory.CreateDirectory(Path.GetDirectoryName(file)); File.WriteAllText(file, serialized); } @@ -119,7 +127,7 @@ namespace Umbraco.Web.Install return new List(_steps); } - public static void SetComplete(Guid installId, string name, IDictionary additionalData = null) + public void SetComplete(Guid installId, string name, IDictionary additionalData = null) { var trackingItem = _steps.Single(x => x.Name == name); if (additionalData != null) @@ -130,7 +138,7 @@ namespace Umbraco.Web.Install //save the file var file = GetFile(installId); - var serialized = JsonConvert.SerializeObject(new List(_steps)); + var serialized = _jsonSerializer.Serialize(new List(_steps)); File.WriteAllText(file, serialized); } diff --git a/src/Umbraco.Web/Install/InstallSteps/FilePermissionsStep.cs b/src/Umbraco.Abstractions/Install/InstallSteps/FilePermissionsStep.cs similarity index 98% rename from src/Umbraco.Web/Install/InstallSteps/FilePermissionsStep.cs rename to src/Umbraco.Abstractions/Install/InstallSteps/FilePermissionsStep.cs index b4be0b0a21..c3d7493084 100644 --- a/src/Umbraco.Web/Install/InstallSteps/FilePermissionsStep.cs +++ b/src/Umbraco.Abstractions/Install/InstallSteps/FilePermissionsStep.cs @@ -4,7 +4,6 @@ using System.IO; using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Install; -using Umbraco.Core.IO; using Umbraco.Web.Install.Models; namespace Umbraco.Web.Install.InstallSteps diff --git a/src/Umbraco.Web/Install/InstallSteps/StarterKitCleanupStep.cs b/src/Umbraco.Abstractions/Install/InstallSteps/StarterKitCleanupStep.cs similarity index 100% rename from src/Umbraco.Web/Install/InstallSteps/StarterKitCleanupStep.cs rename to src/Umbraco.Abstractions/Install/InstallSteps/StarterKitCleanupStep.cs diff --git a/src/Umbraco.Web/Install/InstallSteps/UpgradeStep.cs b/src/Umbraco.Abstractions/Install/InstallSteps/UpgradeStep.cs similarity index 84% rename from src/Umbraco.Web/Install/InstallSteps/UpgradeStep.cs rename to src/Umbraco.Abstractions/Install/InstallSteps/UpgradeStep.cs index a59d7394f0..0979f31dc5 100644 --- a/src/Umbraco.Web/Install/InstallSteps/UpgradeStep.cs +++ b/src/Umbraco.Abstractions/Install/InstallSteps/UpgradeStep.cs @@ -1,6 +1,6 @@ using System; using System.Threading.Tasks; -using Umbraco.Web.Composing; +using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Web.Install.Models; @@ -14,10 +14,12 @@ namespace Umbraco.Web.Install.InstallSteps { public override bool RequiresExecution(object model) => true; private readonly IUmbracoVersion _umbracoVersion; + private readonly IRuntimeState _runtimeState; - public UpgradeStep(IUmbracoVersion umbracoVersion) + public UpgradeStep(IUmbracoVersion umbracoVersion, IRuntimeState runtimeState) { _umbracoVersion = umbracoVersion; + _runtimeState = runtimeState; } public override Task ExecuteAsync(object model) => Task.FromResult(null); @@ -43,9 +45,9 @@ namespace Umbraco.Web.Install.InstallSteps return value; } - var state = Current.RuntimeState; // TODO: inject - var currentState = FormatGuidState(state.CurrentMigrationState); - var newState = FormatGuidState(state.FinalMigrationState); + + var currentState = FormatGuidState(_runtimeState.CurrentMigrationState); + var newState = FormatGuidState(_runtimeState.FinalMigrationState); var reportUrl = $"https://our.umbraco.com/contribute/releases/compare?from={currentVersion}&to={newVersion}¬es=1"; diff --git a/src/Umbraco.Web/Install/Models/DatabaseModel.cs b/src/Umbraco.Abstractions/Install/Models/DatabaseModel.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/DatabaseModel.cs rename to src/Umbraco.Abstractions/Install/Models/DatabaseModel.cs diff --git a/src/Umbraco.Web/Install/Models/DatabaseType.cs b/src/Umbraco.Abstractions/Install/Models/DatabaseType.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/DatabaseType.cs rename to src/Umbraco.Abstractions/Install/Models/DatabaseType.cs diff --git a/src/Umbraco.Web/Install/Models/InstallInstructions.cs b/src/Umbraco.Abstractions/Install/Models/InstallInstructions.cs similarity index 80% rename from src/Umbraco.Web/Install/Models/InstallInstructions.cs rename to src/Umbraco.Abstractions/Install/Models/InstallInstructions.cs index da4dfb1671..159edda9e6 100644 --- a/src/Umbraco.Web/Install/Models/InstallInstructions.cs +++ b/src/Umbraco.Abstractions/Install/Models/InstallInstructions.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Runtime.Serialization; -using Newtonsoft.Json.Linq; namespace Umbraco.Web.Install.Models { @@ -9,7 +8,7 @@ namespace Umbraco.Web.Install.Models public class InstallInstructions { [DataMember(Name = "instructions")] - public IDictionary Instructions { get; set; } + public IDictionary Instructions { get; set; } [DataMember(Name = "installId")] public Guid InstallId { get; set; } diff --git a/src/Umbraco.Web/Install/Models/InstallProgressResultModel.cs b/src/Umbraco.Abstractions/Install/Models/InstallProgressResultModel.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/InstallProgressResultModel.cs rename to src/Umbraco.Abstractions/Install/Models/InstallProgressResultModel.cs diff --git a/src/Umbraco.Web/Install/Models/InstallSetup.cs b/src/Umbraco.Abstractions/Install/Models/InstallSetup.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/InstallSetup.cs rename to src/Umbraco.Abstractions/Install/Models/InstallSetup.cs diff --git a/src/Umbraco.Web/Install/Models/InstallSetupResult.cs b/src/Umbraco.Abstractions/Install/Models/InstallSetupResult.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/InstallSetupResult.cs rename to src/Umbraco.Abstractions/Install/Models/InstallSetupResult.cs diff --git a/src/Umbraco.Web/Install/Models/InstallSetupStep.cs b/src/Umbraco.Abstractions/Install/Models/InstallSetupStep.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/InstallSetupStep.cs rename to src/Umbraco.Abstractions/Install/Models/InstallSetupStep.cs diff --git a/src/Umbraco.Web/Install/Models/InstallSetupStepAttribute.cs b/src/Umbraco.Abstractions/Install/Models/InstallSetupStepAttribute.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/InstallSetupStepAttribute.cs rename to src/Umbraco.Abstractions/Install/Models/InstallSetupStepAttribute.cs diff --git a/src/Umbraco.Web/Install/Models/InstallTrackingItem.cs b/src/Umbraco.Abstractions/Install/Models/InstallTrackingItem.cs similarity index 96% rename from src/Umbraco.Web/Install/Models/InstallTrackingItem.cs rename to src/Umbraco.Abstractions/Install/Models/InstallTrackingItem.cs index 1b1985dd1e..9bc8201ba9 100644 --- a/src/Umbraco.Web/Install/Models/InstallTrackingItem.cs +++ b/src/Umbraco.Abstractions/Install/Models/InstallTrackingItem.cs @@ -3,7 +3,7 @@ using System.Runtime.Serialization; namespace Umbraco.Web.Install.Models { - internal class InstallTrackingItem + public class InstallTrackingItem { public InstallTrackingItem(string name, int serverOrder) { diff --git a/src/Umbraco.Web/Install/Models/InstallationType.cs b/src/Umbraco.Abstractions/Install/Models/InstallationType.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/InstallationType.cs rename to src/Umbraco.Abstractions/Install/Models/InstallationType.cs diff --git a/src/Umbraco.Web/Install/Models/Package.cs b/src/Umbraco.Abstractions/Install/Models/Package.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/Package.cs rename to src/Umbraco.Abstractions/Install/Models/Package.cs diff --git a/src/Umbraco.Web/Install/Models/UserModel.cs b/src/Umbraco.Abstractions/Install/Models/UserModel.cs similarity index 100% rename from src/Umbraco.Web/Install/Models/UserModel.cs rename to src/Umbraco.Abstractions/Install/Models/UserModel.cs diff --git a/src/Umbraco.Abstractions/Trees/IMenuItemCollectionFactory.cs b/src/Umbraco.Abstractions/Trees/IMenuItemCollectionFactory.cs new file mode 100644 index 0000000000..64feba8cd8 --- /dev/null +++ b/src/Umbraco.Abstractions/Trees/IMenuItemCollectionFactory.cs @@ -0,0 +1,9 @@ +using Umbraco.Web.Models.Trees; + +namespace Umbraco.Web.Trees +{ + public interface IMenuItemCollectionFactory + { + MenuItemCollection Create(); + } +} diff --git a/src/Umbraco.Web/Models/Trees/MenuItemCollection.cs b/src/Umbraco.Abstractions/Trees/MenuItemCollection.cs similarity index 72% rename from src/Umbraco.Web/Models/Trees/MenuItemCollection.cs rename to src/Umbraco.Abstractions/Trees/MenuItemCollection.cs index e6a75b15d4..84d46c0d11 100644 --- a/src/Umbraco.Web/Models/Trees/MenuItemCollection.cs +++ b/src/Umbraco.Abstractions/Trees/MenuItemCollection.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Runtime.Serialization; +using Umbraco.Web.Actions; namespace Umbraco.Web.Models.Trees { @@ -9,17 +10,16 @@ namespace Umbraco.Web.Models.Trees [DataContract(Name = "menuItems", Namespace = "")] public class MenuItemCollection { - public static MenuItemCollection Empty => new MenuItemCollection(); + private readonly MenuItemList _menuItems; - private readonly MenuItemList _menuItems = new MenuItemList(); - - public MenuItemCollection() + public MenuItemCollection(ActionCollection actionCollection) { + _menuItems = new MenuItemList(actionCollection); } - public MenuItemCollection(IEnumerable items) + public MenuItemCollection(ActionCollection actionCollection, IEnumerable items) { - _menuItems = new MenuItemList(items); + _menuItems = new MenuItemList(actionCollection, items); } /// diff --git a/src/Umbraco.Abstractions/Trees/MenuItemCollectionFactory.cs b/src/Umbraco.Abstractions/Trees/MenuItemCollectionFactory.cs new file mode 100644 index 0000000000..0a8ea000e3 --- /dev/null +++ b/src/Umbraco.Abstractions/Trees/MenuItemCollectionFactory.cs @@ -0,0 +1,21 @@ +using Umbraco.Web.Actions; +using Umbraco.Web.Models.Trees; + +namespace Umbraco.Web.Trees +{ + public class MenuItemCollectionFactory: IMenuItemCollectionFactory + { + private readonly ActionCollection _actionCollection; + + public MenuItemCollectionFactory(ActionCollection actionCollection) + { + _actionCollection = actionCollection; + } + + public MenuItemCollection Create() + { + return new MenuItemCollection(_actionCollection); + } + + } +} diff --git a/src/Umbraco.Web/Models/Trees/MenuItemList.cs b/src/Umbraco.Abstractions/Trees/MenuItemList.cs similarity index 82% rename from src/Umbraco.Web/Models/Trees/MenuItemList.cs rename to src/Umbraco.Abstractions/Trees/MenuItemList.cs index 7bfa5eca48..546fa0390f 100644 --- a/src/Umbraco.Web/Models/Trees/MenuItemList.cs +++ b/src/Umbraco.Abstractions/Trees/MenuItemList.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Umbraco.Core.Services; using Umbraco.Web.Actions; -using Umbraco.Web.Composing; namespace Umbraco.Web.Models.Trees { @@ -13,13 +12,17 @@ namespace Umbraco.Web.Models.Trees /// public class MenuItemList : List { - public MenuItemList() + private readonly ActionCollection _actionCollection; + + public MenuItemList(ActionCollection actionCollection) { + _actionCollection = actionCollection; } - public MenuItemList( IEnumerable items) + public MenuItemList(ActionCollection actionCollection, IEnumerable items) : base(items) { + _actionCollection = actionCollection; } /// @@ -44,7 +47,7 @@ namespace Umbraco.Web.Models.Trees private MenuItem CreateMenuItem(ILocalizedTextService textService, bool hasSeparator = false, bool opensDialog = false) where T : IAction { - var item = Current.Actions.GetAction(); + var item = _actionCollection.GetAction(); if (item == null) return null; var menuItem = new MenuItem(item, textService.Localize($"actions/{item.Alias}")) diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Configuration/ConfigsFactory.cs index fea0c23f29..c09dc7b9f6 100644 --- a/src/Umbraco.Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Configuration/ConfigsFactory.cs @@ -7,11 +7,6 @@ namespace Umbraco.Core.Configuration { public class ConfigsFactory : IConfigsFactory { - - public ConfigsFactory() - { - } - public IHostingSettings HostingSettings { get; } = new HostingSettings(); public ICoreDebug CoreDebug { get; } = new CoreDebug(); @@ -32,7 +27,7 @@ namespace Umbraco.Core.Configuration configs.AddPasswordConfigurations(); configs.Add(() => CoreDebug); - configs.Add(() => new ConnectionStrings()); + configs.Add(() => new ConnectionStrings(ioHelper)); configs.AddCoreConfigs(ioHelper); return configs; } diff --git a/src/Umbraco.Configuration/ConnectionStrings.cs b/src/Umbraco.Configuration/ConnectionStrings.cs index 707f58c7b7..6a00974831 100644 --- a/src/Umbraco.Configuration/ConnectionStrings.cs +++ b/src/Umbraco.Configuration/ConnectionStrings.cs @@ -8,6 +8,13 @@ namespace Umbraco.Core.Configuration { public class ConnectionStrings : IConnectionStrings { + private readonly IIOHelper _ioHelper; + + public ConnectionStrings(IIOHelper ioHelper) + { + _ioHelper = ioHelper; + } + public ConfigConnectionString this[string key] { get @@ -17,5 +24,22 @@ namespace Umbraco.Core.Configuration return new ConfigConnectionString(settings.ConnectionString, settings.ProviderName, settings.Name); } } + + public void RemoveConnectionString(string key) + { + var fileName = _ioHelper.MapPath(string.Format("{0}/web.config", _ioHelper.Root)); + var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); + + var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); + var setting = appSettings.Descendants("add").FirstOrDefault(s => s.Attribute("key").Value == key); + + if (setting != null) + { + setting.Remove(); + xml.Save(fileName, SaveOptions.DisableFormatting); + ConfigurationManager.RefreshSection("appSettings"); + } + var settings = ConfigurationManager.ConnectionStrings[key]; + } } } diff --git a/src/Umbraco.Configuration/GlobalSettings.cs b/src/Umbraco.Configuration/GlobalSettings.cs index 6cd1ea58a5..a44f7ae636 100644 --- a/src/Umbraco.Configuration/GlobalSettings.cs +++ b/src/Umbraco.Configuration/GlobalSettings.cs @@ -254,27 +254,7 @@ namespace Umbraco.Core.Configuration ConfigurationManager.RefreshSection("appSettings"); } - /// - /// Removes a setting from the configuration file. - /// - /// Key of the setting to be removed. - public static void RemoveSetting(string key, IIOHelper ioHelper) - { - var fileName = ioHelper.MapPath(string.Format("{0}/web.config", ioHelper.Root)); - var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); - - var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); - var setting = appSettings.Descendants("add").FirstOrDefault(s => s.Attribute("key").Value == key); - - if (setting != null) - { - setting.Remove(); - xml.Save(fileName, SaveOptions.DisableFormatting); - ConfigurationManager.RefreshSection("appSettings"); - } - } - - + /// /// Gets the time out in minutes. /// diff --git a/src/Umbraco.Web/Cache/DistributedCacheBinder.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder.cs similarity index 98% rename from src/Umbraco.Web/Cache/DistributedCacheBinder.cs rename to src/Umbraco.Infrastructure/Cache/DistributedCacheBinder.cs index e56d2bfe88..92ed7de881 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheBinder.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder.cs @@ -4,10 +4,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Umbraco.Core; -using Umbraco.Core.Cache; using Umbraco.Core.Events; using Umbraco.Core.Logging; -using Umbraco.Core.Serialization; namespace Umbraco.Web.Cache { diff --git a/src/Umbraco.Web/Cache/DistributedCacheBinderComposer.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs similarity index 100% rename from src/Umbraco.Web/Cache/DistributedCacheBinderComposer.cs rename to src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs diff --git a/src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs similarity index 99% rename from src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs rename to src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index b9de06c2d3..c0200933ab 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Umbraco.Core.Cache; using Umbraco.Core.Events; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -9,7 +8,6 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Core.Services.Implement; -using Umbraco.Web.Services; namespace Umbraco.Web.Cache { diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseConfigureStep.cs similarity index 98% rename from src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs rename to src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseConfigureStep.cs index dbf664bc93..3a978cc47a 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseConfigureStep.cs @@ -11,7 +11,7 @@ namespace Umbraco.Web.Install.InstallSteps [InstallSetupStep(InstallationType.NewInstall, "DatabaseConfigure", "database", 10, "Setting up a database, so Umbraco has a place to store your website", PerformsAppRestart = true)] - internal class DatabaseConfigureStep : InstallSetupStep + public class DatabaseConfigureStep : InstallSetupStep { private readonly DatabaseBuilder _databaseBuilder; private readonly ILogger _logger; diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs similarity index 79% rename from src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs rename to src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs index 843b5ff887..a7b3dcc218 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseInstallStep.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Configuration; using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Configuration; @@ -13,19 +12,21 @@ namespace Umbraco.Web.Install.InstallSteps { [InstallSetupStep(InstallationType.NewInstall | InstallationType.Upgrade, "DatabaseInstall", 11, "")] - internal class DatabaseInstallStep : InstallSetupStep + public class DatabaseInstallStep : InstallSetupStep { private readonly DatabaseBuilder _databaseBuilder; private readonly IRuntimeState _runtime; private readonly ILogger _logger; private readonly IIOHelper _ioHelper; + private readonly IConnectionStrings _connectionStrings; - public DatabaseInstallStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger, IIOHelper ioHelper) + public DatabaseInstallStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger, IIOHelper ioHelper, IConnectionStrings connectionStrings) { _databaseBuilder = databaseBuilder; _runtime = runtime; _logger = logger; _ioHelper = ioHelper; + _connectionStrings = connectionStrings; } public override Task ExecuteAsync(object model) @@ -42,7 +43,7 @@ namespace Umbraco.Web.Install.InstallSteps if (result.RequiresUpgrade == false) { - HandleConnectionStrings(_logger, _ioHelper); + HandleConnectionStrings(_logger, _ioHelper, _connectionStrings); return Task.FromResult(null); } @@ -53,12 +54,18 @@ namespace Umbraco.Web.Install.InstallSteps })); } - internal static void HandleConnectionStrings(ILogger logger, IIOHelper ioHelper) + internal static void HandleConnectionStrings(ILogger logger, IIOHelper ioHelper, IConnectionStrings connectionStrings) { + + + var databaseSettings = connectionStrings[Constants.System.UmbracoConnectionName]; + + + // Remove legacy umbracoDbDsn configuration setting if it exists and connectionstring also exists - if (ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName] != null) + if (databaseSettings != null) { - GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, ioHelper); + connectionStrings.RemoveConnectionString(Constants.System.UmbracoConnectionName); } else { diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseUpgradeStep.cs similarity index 97% rename from src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs rename to src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseUpgradeStep.cs index 603fbd726c..3cd3c1ca56 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs +++ b/src/Umbraco.Infrastructure/Intall/InstallSteps/DatabaseUpgradeStep.cs @@ -7,7 +7,6 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Migrations.Upgrade; -using Umbraco.Web.Composing; using Umbraco.Web.Install.Models; using Umbraco.Web.Migrations.PostMigrations; @@ -15,7 +14,7 @@ namespace Umbraco.Web.Install.InstallSteps { [InstallSetupStep(InstallationType.Upgrade | InstallationType.NewInstall, "DatabaseUpgrade", 12, "")] - internal class DatabaseUpgradeStep : InstallSetupStep + public class DatabaseUpgradeStep : InstallSetupStep { private readonly DatabaseBuilder _databaseBuilder; private readonly IRuntimeState _runtime; @@ -56,7 +55,7 @@ namespace Umbraco.Web.Install.InstallSteps throw new InstallException("The database failed to upgrade. ERROR: " + result.Message); } - DatabaseInstallStep.HandleConnectionStrings(_logger, _ioHelper); + DatabaseInstallStep.HandleConnectionStrings(_logger, _ioHelper, _connectionStrings); } return Task.FromResult(null); diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs index 2e9df383bf..e2a7d7a5cc 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs @@ -23,6 +23,8 @@ using Umbraco.Core.Sync; using Umbraco.Web.Models.PublishedContent; using Umbraco.Web.PublishedCache; using Umbraco.Web; +using Umbraco.Web.Install; +using Umbraco.Web.Trees; using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator; namespace Umbraco.Core.Runtime @@ -54,6 +56,8 @@ namespace Umbraco.Core.Runtime composition.RegisterUnique(f => f.GetInstance()); composition.RegisterUnique(); + composition.RegisterUnique(); + composition.RegisterUnique(); // register database builder // *not* a singleton, don't want to keep it around diff --git a/src/Umbraco.Web/Trees/TreeNode.cs b/src/Umbraco.Infrastructure/Trees/TreeNode.cs similarity index 97% rename from src/Umbraco.Web/Trees/TreeNode.cs rename to src/Umbraco.Infrastructure/Trees/TreeNode.cs index 7661387b3d..cc130b1b97 100644 --- a/src/Umbraco.Web/Trees/TreeNode.cs +++ b/src/Umbraco.Infrastructure/Trees/TreeNode.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Runtime.Serialization; +using Umbraco.Composing; using Umbraco.Core; -using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Models.Trees @@ -23,7 +23,7 @@ namespace Umbraco.Web.Models.Trees /// The parent id for the current node /// /// - internal TreeNode(string nodeId, string parentId, string getChildNodesUrl, string menuUrl) + public TreeNode(string nodeId, string parentId, string getChildNodesUrl, string menuUrl) { if (nodeId == null) throw new ArgumentNullException(nameof(nodeId)); if (string.IsNullOrWhiteSpace(nodeId)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(nodeId)); diff --git a/src/Umbraco.Web/Models/Trees/TreeNodeCollection.cs b/src/Umbraco.Infrastructure/Trees/TreeNodeCollection.cs similarity index 100% rename from src/Umbraco.Web/Models/Trees/TreeNodeCollection.cs rename to src/Umbraco.Infrastructure/Trees/TreeNodeCollection.cs diff --git a/src/Umbraco.Web/Models/Trees/TreeNodeExtensions.cs b/src/Umbraco.Infrastructure/Trees/TreeNodeExtensions.cs similarity index 100% rename from src/Umbraco.Web/Models/Trees/TreeNodeExtensions.cs rename to src/Umbraco.Infrastructure/Trees/TreeNodeExtensions.cs diff --git a/src/Umbraco.Web/Models/Trees/TreeRootNode.cs b/src/Umbraco.Infrastructure/Trees/TreeRootNode.cs similarity index 100% rename from src/Umbraco.Web/Models/Trees/TreeRootNode.cs rename to src/Umbraco.Infrastructure/Trees/TreeRootNode.cs diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index f10c18492a..255c7d53cf 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -55,7 +55,9 @@ using Umbraco.Core.Models.Identity; using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Net; +using Umbraco.Web.Install; using Umbraco.Web.Security; +using Umbraco.Web.Trees; using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Tests.Testing { @@ -412,6 +414,8 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(); Composition.RegisterUnique(); + Composition.RegisterUnique(); + Composition.RegisterUnique(); // register filesystems Composition.RegisterUnique(factory => TestObjects.GetFileSystemsMock()); diff --git a/src/Umbraco.Web/Net/AspNetBackOfficeInfo.cs b/src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs similarity index 100% rename from src/Umbraco.Web/Net/AspNetBackOfficeInfo.cs rename to src/Umbraco.Web/AspNet/AspNetBackOfficeInfo.cs diff --git a/src/Umbraco.Web/Net/AspNetCookieManager.cs b/src/Umbraco.Web/AspNet/AspNetCookieManager.cs similarity index 100% rename from src/Umbraco.Web/Net/AspNetCookieManager.cs rename to src/Umbraco.Web/AspNet/AspNetCookieManager.cs diff --git a/src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs b/src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs similarity index 100% rename from src/Umbraco.Web/Hosting/AspNetHostingEnvironment.cs rename to src/Umbraco.Web/AspNet/AspNetHostingEnvironment.cs diff --git a/src/Umbraco.Web/Net/AspNetHttpContextAccessor.cs b/src/Umbraco.Web/AspNet/AspNetHttpContextAccessor.cs similarity index 100% rename from src/Umbraco.Web/Net/AspNetHttpContextAccessor.cs rename to src/Umbraco.Web/AspNet/AspNetHttpContextAccessor.cs diff --git a/src/Umbraco.Web/Net/AspNetIpResolver.cs b/src/Umbraco.Web/AspNet/AspNetIpResolver.cs similarity index 100% rename from src/Umbraco.Web/Net/AspNetIpResolver.cs rename to src/Umbraco.Web/AspNet/AspNetIpResolver.cs diff --git a/src/Umbraco.Web/Net/AspNetPasswordHasher.cs b/src/Umbraco.Web/AspNet/AspNetPasswordHasher.cs similarity index 100% rename from src/Umbraco.Web/Net/AspNetPasswordHasher.cs rename to src/Umbraco.Web/AspNet/AspNetPasswordHasher.cs diff --git a/src/Umbraco.Web/Net/AspNetSessionIdResolver.cs b/src/Umbraco.Web/AspNet/AspNetSessionIdResolver.cs similarity index 100% rename from src/Umbraco.Web/Net/AspNetSessionIdResolver.cs rename to src/Umbraco.Web/AspNet/AspNetSessionIdResolver.cs diff --git a/src/Umbraco.Web/FrameworkMarchal.cs b/src/Umbraco.Web/AspNet/FrameworkMarchal.cs similarity index 100% rename from src/Umbraco.Web/FrameworkMarchal.cs rename to src/Umbraco.Web/AspNet/FrameworkMarchal.cs diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index 40985e97bf..8d4af6703e 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -27,6 +27,7 @@ using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Services; +using Umbraco.Web.Trees; using Umbraco.Web.WebApi; namespace Umbraco.Web.Composing @@ -260,6 +261,7 @@ namespace Umbraco.Web.Composing public static IIpResolver IpResolver => Factory.GetInstance(); public static IUmbracoVersion UmbracoVersion => Factory.GetInstance(); public static IPublishedUrlProvider PublishedUrlProvider => Factory.GetInstance(); + public static IMenuItemCollectionFactory MenuItemCollectionFactory => Factory.GetInstance(); #endregion } diff --git a/src/Umbraco.Web/Install/Controllers/InstallApiController.cs b/src/Umbraco.Web/Install/Controllers/InstallApiController.cs index d151df46f7..c69766cc9d 100644 --- a/src/Umbraco.Web/Install/Controllers/InstallApiController.cs +++ b/src/Umbraco.Web/Install/Controllers/InstallApiController.cs @@ -20,13 +20,15 @@ namespace Umbraco.Web.Install.Controllers private readonly DatabaseBuilder _databaseBuilder; private readonly IProfilingLogger _proflog; private readonly InstallStepCollection _installSteps; + private readonly InstallStatusTracker _installStatusTracker; private readonly ILogger _logger; - public InstallApiController(DatabaseBuilder databaseBuilder, IProfilingLogger proflog, InstallHelper installHelper, InstallStepCollection installSteps) + public InstallApiController(DatabaseBuilder databaseBuilder, IProfilingLogger proflog, InstallHelper installHelper, InstallStepCollection installSteps, InstallStatusTracker installStatusTracker) { _databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder)); _proflog = proflog ?? throw new ArgumentNullException(nameof(proflog)); _installSteps = installSteps; + _installStatusTracker = installStatusTracker; InstallHelper = installHelper; _logger = _proflog; } @@ -56,7 +58,7 @@ namespace Umbraco.Web.Install.Controllers steps.AddRange(installSteps); setup.Steps = steps; - InstallStatusTracker.Initialize(setup.InstallId, installSteps); + _installStatusTracker.Initialize(setup.InstallId, installSteps); return setup; } @@ -78,7 +80,7 @@ namespace Umbraco.Web.Install.Controllers //there won't be any statuses returned if the app pool has restarted so we need to re-read from file. if (status.Any() == false) { - status = InstallStatusTracker.InitializeFromFile(installModel.InstallId).ToArray(); + status = _installStatusTracker.InitializeFromFile(installModel.InstallId).ToArray(); } //create a new queue of the non-finished ones @@ -95,7 +97,7 @@ namespace Umbraco.Web.Install.Controllers if (StepRequiresExecution(step, instruction) == false) { // set this as complete and continue - InstallStatusTracker.SetComplete(installModel.InstallId, item.Name); + _installStatusTracker.SetComplete(installModel.InstallId, item.Name); continue; } @@ -104,7 +106,7 @@ namespace Umbraco.Web.Install.Controllers var setupData = await ExecuteStepAsync(step, instruction); // update the status - InstallStatusTracker.SetComplete(installModel.InstallId, step.Name, setupData?.SavedStepData); + _installStatusTracker.SetComplete(installModel.InstallId, step.Name, setupData?.SavedStepData); // determine's the next step in the queue and dequeue's any items that don't need to execute var nextStep = IterateSteps(step, queue, installModel.InstallId, installModel); @@ -147,7 +149,7 @@ namespace Umbraco.Web.Install.Controllers } } - InstallStatusTracker.Reset(); + _installStatusTracker.Reset(); return new InstallProgressResultModel(true, "", ""); } @@ -175,7 +177,7 @@ namespace Umbraco.Web.Install.Controllers var step = _installSteps.GetAllSteps().Single(x => x.Name == item.Name); // if this step has any instructions then extract them - JToken instruction; + object instruction; installModel.Instructions.TryGetValue(item.Name, out instruction); // else null // if the step requires execution then return its name @@ -187,7 +189,7 @@ namespace Umbraco.Web.Install.Controllers queue.Dequeue(); // complete - InstallStatusTracker.SetComplete(installId, step.Name); + _installStatusTracker.SetComplete(installId, step.Name); // and continue current = step; @@ -197,9 +199,9 @@ namespace Umbraco.Web.Install.Controllers } // determines whether the step requires execution - internal bool StepRequiresExecution(InstallSetupStep step, JToken instruction) + internal bool StepRequiresExecution(InstallSetupStep step, object instruction) { - var model = instruction?.ToObject(step.StepType); + var model = Convert.ChangeType(instruction, step.StepType); var genericStepType = typeof(InstallSetupStep<>); Type[] typeArgs = { step.StepType }; var typedStepType = genericStepType.MakeGenericType(typeArgs); @@ -216,11 +218,11 @@ namespace Umbraco.Web.Install.Controllers } // executes the step - internal async Task ExecuteStepAsync(InstallSetupStep step, JToken instruction) + internal async Task ExecuteStepAsync(InstallSetupStep step, object instruction) { using (_proflog.TraceDuration($"Executing installation step: '{step.Name}'.", "Step completed")) { - var model = instruction?.ToObject(step.StepType); + var model = Convert.ChangeType(instruction, step.StepType); var genericStepType = typeof(InstallSetupStep<>); Type[] typeArgs = { step.StepType }; var typedStepType = genericStepType.MakeGenericType(typeArgs); diff --git a/src/Umbraco.Web/Install/FilePermissionHelper.cs b/src/Umbraco.Web/Install/FilePermissionHelper.cs index 7fc40a1202..16de66554f 100644 --- a/src/Umbraco.Web/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Web/Install/FilePermissionHelper.cs @@ -7,7 +7,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Install; using Umbraco.Core.IO; -using Umbraco.Web.Composing; +using Umbraco.Web.PublishedCache; namespace Umbraco.Web.Install { @@ -21,11 +21,13 @@ namespace Umbraco.Web.Install private readonly string[] _permissionFiles = { }; private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; + private readonly IPublishedSnapshotService _publishedSnapshotService; - public FilePermissionHelper(IGlobalSettings globalSettings, IIOHelper ioHelper) + public FilePermissionHelper(IGlobalSettings globalSettings, IIOHelper ioHelper, IPublishedSnapshotService publishedSnapshotService) { _globalSettings = globalSettings; _ioHelper = ioHelper; + _publishedSnapshotService = publishedSnapshotService; _permissionDirs = new[] { _globalSettings.UmbracoCssPath, Constants.SystemDirectories.Config, Constants.SystemDirectories.Data, _globalSettings.UmbracoMediaPath, Constants.SystemDirectories.Preview }; _packagesPermissionsDirs = new[] { Constants.SystemDirectories.Bin, _globalSettings.UmbracoPath, Constants.SystemDirectories.Packages }; } @@ -48,7 +50,7 @@ namespace Umbraco.Web.Install if (TestPublishedSnapshotService(out errors) == false) report["Published snapshot environment check failed"] = errors.ToList(); - if (EnsureCanCreateSubDirectory(Current.Configs.Global().UmbracoMediaPath, out errors) == false) + if (EnsureCanCreateSubDirectory(_globalSettings.UmbracoMediaPath, out errors) == false) report["Media folder creation failed"] = errors.ToList(); } @@ -129,8 +131,7 @@ namespace Umbraco.Web.Install public bool TestPublishedSnapshotService(out IEnumerable errors) { - var publishedSnapshotService = Current.PublishedSnapshotService; - return publishedSnapshotService.EnsureEnvironment(out errors); + return _publishedSnapshotService.EnsureEnvironment(out errors); } // tries to create a sub-directory diff --git a/src/Umbraco.Web/Install/InstallHelper.cs b/src/Umbraco.Web/Install/InstallHelper.cs index fb809d1bfc..8be0af629e 100644 --- a/src/Umbraco.Web/Install/InstallHelper.cs +++ b/src/Umbraco.Web/Install/InstallHelper.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.Install { private static HttpClient _httpClient; private readonly DatabaseBuilder _databaseBuilder; - private readonly HttpContextBase _httpContext; + private readonly IHttpContextAccessor _httpContextAccessor; private readonly ILogger _logger; private readonly IGlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; @@ -29,7 +29,7 @@ namespace Umbraco.Web.Install DatabaseBuilder databaseBuilder, ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IConnectionStrings connectionStrings) { - _httpContext = httpContextAccessor.HttpContext; + _httpContextAccessor = httpContextAccessor; _logger = logger; _globalSettings = globalSettings; _umbracoVersion = umbracoVersion; @@ -42,16 +42,18 @@ namespace Umbraco.Web.Install return _installationType ?? (_installationType = IsBrandNewInstall ? InstallationType.NewInstall : InstallationType.Upgrade).Value; } - internal void InstallStatus(bool isCompleted, string errorMsg) + public void InstallStatus(bool isCompleted, string errorMsg) { + + var httpContext = _httpContextAccessor.HttpContext; try { - var userAgent = _httpContext.Request.UserAgent; + var userAgent = httpContext.Request.UserAgent; // Check for current install Id var installId = Guid.NewGuid(); - var installCookie = _httpContext.Request.GetCookieValue(Constants.Web.InstallerCookieName); + var installCookie = httpContext.Request.GetCookieValue(Constants.Web.InstallerCookieName); if (string.IsNullOrEmpty(installCookie) == false) { if (Guid.TryParse(installCookie, out installId)) @@ -61,7 +63,7 @@ namespace Umbraco.Web.Install installId = Guid.NewGuid(); } } - _httpContext.Response.Cookies.Set(new HttpCookie(Constants.Web.InstallerCookieName, "1")); + httpContext.Response.Cookies.Set(new HttpCookie(Constants.Web.InstallerCookieName, "1")); var dbProvider = string.Empty; if (IsBrandNewInstall == false) @@ -134,7 +136,7 @@ namespace Umbraco.Web.Install } } - internal IEnumerable GetStarterKits() + public IEnumerable GetStarterKits() { if (_httpClient == null) _httpClient = new HttpClient(); diff --git a/src/Umbraco.Web/Security/IdentityAuditEventArgs.cs b/src/Umbraco.Web/Security/IdentityAuditEventArgs.cs index 81407afe50..5847250b41 100644 --- a/src/Umbraco.Web/Security/IdentityAuditEventArgs.cs +++ b/src/Umbraco.Web/Security/IdentityAuditEventArgs.cs @@ -1,6 +1,6 @@ using System; using System.Threading; -using Umbraco.Core.Security; + namespace Umbraco.Web.Security { diff --git a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs index fd05f7cfbd..843a1cef0c 100644 --- a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs @@ -1,11 +1,18 @@ using System.Linq; using System.Net.Http.Formatting; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Web.Actions; using Umbraco.Web.Models.Trees; using Umbraco.Web.Mvc; +using Umbraco.Web.Routing; using Umbraco.Web.WebApi.Filters; using Constants = Umbraco.Core.Constants; @@ -23,6 +30,24 @@ namespace Umbraco.Web.Trees [CoreTree] public class ContentBlueprintTreeController : TreeController { + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + public ContentBlueprintTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _menuItemCollectionFactory = menuItemCollectionFactory; + } protected override TreeNode CreateRootNode(FormDataCollection queryStrings) { @@ -89,7 +114,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { diff --git a/src/Umbraco.Web/Trees/ContentTreeController.cs b/src/Umbraco.Web/Trees/ContentTreeController.cs index bb7613422e..9b64111b85 100644 --- a/src/Umbraco.Web/Trees/ContentTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentTreeController.cs @@ -42,6 +42,7 @@ namespace Umbraco.Web.Trees private readonly UmbracoTreeSearcher _treeSearcher; private readonly ActionCollection _actions; private readonly IGlobalSettings _globalSettings; + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; protected override int RecycleBinId => Constants.System.RecycleBinContent; @@ -64,12 +65,14 @@ namespace Umbraco.Web.Trees IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) - : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider, menuItemCollectionFactory) { _treeSearcher = treeSearcher; _actions = actions; _globalSettings = globalSettings; + _menuItemCollectionFactory = menuItemCollectionFactory; } /// @@ -133,7 +136,7 @@ namespace Umbraco.Web.Trees { if (id == Constants.System.RootString) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); // if the user's start node is not the root then the only menu item to display is refresh if (UserStartNodes.Contains(Constants.System.Root) == false) @@ -184,7 +187,7 @@ namespace Umbraco.Web.Trees //if the user has no path access for this node, all they can do is refresh if (!Security.CurrentUser.HasContentPathAccess(item, Services.EntityService)) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); menu.Items.Add(new RefreshNode(Services.TextService, true)); return menu; } @@ -246,7 +249,7 @@ namespace Umbraco.Web.Trees /// protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); AddActionNode(item, menu, opensDialog: true); AddActionNode(item, menu, opensDialog: true); AddActionNode(item, menu, opensDialog: true); @@ -282,7 +285,7 @@ namespace Umbraco.Web.Trees /// protected MenuItemCollection GetNodeMenuItemsForDeletedContent(IUmbracoEntity item) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); menu.Items.Add(Services.TextService, opensDialog: true); menu.Items.Add(Services.TextService, opensDialog: true); menu.Items.Add(Services.TextService, opensDialog: true); diff --git a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs index 71196b84c3..7646a71e7d 100644 --- a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs @@ -28,6 +28,8 @@ namespace Umbraco.Web.Trees { public abstract class ContentTreeControllerBase : TreeController { + public IMenuItemCollectionFactory MenuItemCollectionFactory { get; } + protected ContentTreeControllerBase( IGlobalSettings globalSettings, @@ -39,9 +41,11 @@ namespace Umbraco.Web.Trees IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) { + MenuItemCollectionFactory = menuItemCollectionFactory; } protected ContentTreeControllerBase() @@ -430,7 +434,7 @@ namespace Umbraco.Web.Trees deleteAllowed = perms.FirstOrDefault(x => x.Contains(deleteAction.Letter)) != null; } - var menu = new MenuItemCollection(); + var menu = MenuItemCollectionFactory.Create(); // only add empty recycle bin if the current user is allowed to delete by default if (deleteAllowed) { diff --git a/src/Umbraco.Web/Trees/ContentTypeTreeController.cs b/src/Umbraco.Web/Trees/ContentTypeTreeController.cs index f150eb8ba0..afd89f967a 100644 --- a/src/Umbraco.Web/Trees/ContentTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentTypeTreeController.cs @@ -27,6 +27,7 @@ namespace Umbraco.Web.Trees public class ContentTypeTreeController : TreeController, ISearchableTree { private readonly UmbracoTreeSearcher _treeSearcher; + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; public ContentTypeTreeController( UmbracoTreeSearcher treeSearcher, @@ -39,10 +40,12 @@ namespace Umbraco.Web.Trees IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) { _treeSearcher = treeSearcher; + _menuItemCollectionFactory = menuItemCollectionFactory; } protected override TreeNode CreateRootNode(FormDataCollection queryStrings) @@ -103,7 +106,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { diff --git a/src/Umbraco.Web/Trees/DataTypeTreeController.cs b/src/Umbraco.Web/Trees/DataTypeTreeController.cs index 7c4da2cf0f..100a5ffe7a 100644 --- a/src/Umbraco.Web/Trees/DataTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/DataTypeTreeController.cs @@ -29,6 +29,7 @@ namespace Umbraco.Web.Trees public class DataTypeTreeController : TreeController, ISearchableTree { private readonly UmbracoTreeSearcher _treeSearcher; + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; public DataTypeTreeController( UmbracoTreeSearcher treeSearcher, @@ -41,10 +42,12 @@ namespace Umbraco.Web.Trees IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) { _treeSearcher = treeSearcher; + _menuItemCollectionFactory = menuItemCollectionFactory; } protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) @@ -128,7 +131,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { diff --git a/src/Umbraco.Web/Trees/DictionaryTreeController.cs b/src/Umbraco.Web/Trees/DictionaryTreeController.cs index 3f7b89bcdf..b8d16062ba 100644 --- a/src/Umbraco.Web/Trees/DictionaryTreeController.cs +++ b/src/Umbraco.Web/Trees/DictionaryTreeController.cs @@ -2,9 +2,16 @@ using System.Linq; using System.Net.Http.Formatting; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; using Umbraco.Core.Models; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Web.Actions; using Umbraco.Web.Models.Trees; +using Umbraco.Web.Routing; using Umbraco.Web.WebApi.Filters; namespace Umbraco.Web.Trees @@ -21,6 +28,25 @@ namespace Umbraco.Web.Trees [Tree(Constants.Applications.Translation, Constants.Trees.Dictionary, TreeGroup = Constants.Trees.Groups.Settings)] public class DictionaryTreeController : TreeController { + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + public DictionaryTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _menuItemCollectionFactory = menuItemCollectionFactory; + } + protected override TreeNode CreateRootNode(FormDataCollection queryStrings) { var root = base.CreateRootNode(queryStrings); @@ -100,7 +126,7 @@ namespace Umbraco.Web.Trees /// protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); menu.Items.Add(Services.TextService, opensDialog: true); diff --git a/src/Umbraco.Web/Trees/FileSystemTreeController.cs b/src/Umbraco.Web/Trees/FileSystemTreeController.cs index 9bbe05b0ce..bacfc820d6 100644 --- a/src/Umbraco.Web/Trees/FileSystemTreeController.cs +++ b/src/Umbraco.Web/Trees/FileSystemTreeController.cs @@ -4,14 +4,46 @@ using System.Linq; using System.Net.Http.Formatting; using System.Web; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Web.Actions; +using Umbraco.Web.Composing; using Umbraco.Web.Models.Trees; +using Umbraco.Web.Routing; namespace Umbraco.Web.Trees { public abstract class FileSystemTreeController : TreeController { + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + protected FileSystemTreeController() + { + _menuItemCollectionFactory = Current.MenuItemCollectionFactory; + } + + protected FileSystemTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _menuItemCollectionFactory = menuItemCollectionFactory; + } + protected abstract IFileSystem FileSystem { get; } protected abstract string[] Extensions { get; } protected abstract string FileIcon { get; } @@ -88,7 +120,7 @@ namespace Umbraco.Web.Trees protected virtual MenuItemCollection GetMenuForRootNode(FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); //set the default to create menu.DefaultMenuAlias = ActionNew.ActionAlias; @@ -102,7 +134,7 @@ namespace Umbraco.Web.Trees protected virtual MenuItemCollection GetMenuForFolder(string path, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); //set the default to create menu.DefaultMenuAlias = ActionNew.ActionAlias; @@ -126,7 +158,7 @@ namespace Umbraco.Web.Trees protected virtual MenuItemCollection GetMenuForFile(string path, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); //if it's not a directory then we only allow to delete the item menu.Items.Add(Services.TextService, opensDialog: true); @@ -142,7 +174,7 @@ namespace Umbraco.Web.Trees return GetMenuForRootNode(queryStrings); } - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); var path = string.IsNullOrEmpty(id) == false && id != Constants.System.RootString ? HttpUtility.UrlDecode(id).TrimStart("/") diff --git a/src/Umbraco.Web/Trees/MacrosTreeController.cs b/src/Umbraco.Web/Trees/MacrosTreeController.cs index cbe1946779..5c03e11c37 100644 --- a/src/Umbraco.Web/Trees/MacrosTreeController.cs +++ b/src/Umbraco.Web/Trees/MacrosTreeController.cs @@ -1,10 +1,17 @@ using System.Linq; using System.Net.Http.Formatting; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Web.Models.Trees; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi.Filters; using Umbraco.Web.Actions; +using Umbraco.Web.Routing; using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees @@ -15,6 +22,25 @@ namespace Umbraco.Web.Trees [CoreTree] public class MacrosTreeController : TreeController { + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + public MacrosTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _menuItemCollectionFactory = menuItemCollectionFactory; + } + protected override TreeNode CreateRootNode(FormDataCollection queryStrings) { var root = base.CreateRootNode(queryStrings); @@ -46,7 +72,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { @@ -60,7 +86,7 @@ namespace Umbraco.Web.Trees } var macro = Services.MacroService.GetById(int.Parse(id)); - if (macro == null) return new MenuItemCollection(); + if (macro == null) return menu; //add delete option for all macros menu.Items.Add(Services.TextService, opensDialog: true); diff --git a/src/Umbraco.Web/Trees/MediaTreeController.cs b/src/Umbraco.Web/Trees/MediaTreeController.cs index 6983e84dd8..05b7e0e2ad 100644 --- a/src/Umbraco.Web/Trees/MediaTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTreeController.cs @@ -52,8 +52,9 @@ namespace Umbraco.Web.Trees IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) - : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider, menuItemCollectionFactory) { _treeSearcher = treeSearcher; } @@ -99,7 +100,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = MenuItemCollectionFactory.Create(); //set the default menu.DefaultMenuAlias = ActionNew.ActionAlias; diff --git a/src/Umbraco.Web/Trees/MediaTypeTreeController.cs b/src/Umbraco.Web/Trees/MediaTypeTreeController.cs index 1c7f6ca3ae..d89e93bb49 100644 --- a/src/Umbraco.Web/Trees/MediaTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTypeTreeController.cs @@ -27,6 +27,7 @@ namespace Umbraco.Web.Trees public class MediaTypeTreeController : TreeController, ISearchableTree { private readonly UmbracoTreeSearcher _treeSearcher; + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; public MediaTypeTreeController( UmbracoTreeSearcher treeSearcher, @@ -39,10 +40,12 @@ namespace Umbraco.Web.Trees IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) { _treeSearcher = treeSearcher; + _menuItemCollectionFactory = menuItemCollectionFactory; } protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) @@ -87,7 +90,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { diff --git a/src/Umbraco.Web/Trees/MemberTreeController.cs b/src/Umbraco.Web/Trees/MemberTreeController.cs index 84909d5fda..490fe3d646 100644 --- a/src/Umbraco.Web/Trees/MemberTreeController.cs +++ b/src/Umbraco.Web/Trees/MemberTreeController.cs @@ -7,7 +7,12 @@ using System.Net.Http.Formatting; using System.Web.Http; using System.Web.Http.ModelBinding; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; using Umbraco.Core.Models; +using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Core.Security; using Umbraco.Web.Actions; @@ -15,6 +20,7 @@ using Umbraco.Web.Models.Trees; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi.Filters; using Umbraco.Web.Models.ContentEditing; +using Umbraco.Web.Routing; using Umbraco.Web.Search; using Constants = Umbraco.Core.Constants; using Umbraco.Web.Security; @@ -33,12 +39,29 @@ namespace Umbraco.Web.Trees [SearchableTree("searchResultFormatter", "configureMemberResult")] public class MemberTreeController : TreeController, ISearchableTree { - public MemberTreeController(UmbracoTreeSearcher treeSearcher) - { - _treeSearcher = treeSearcher; - } + private readonly UmbracoTreeSearcher _treeSearcher; + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + public MemberTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + UmbracoTreeSearcher treeSearcher, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _treeSearcher = treeSearcher; + _menuItemCollectionFactory = menuItemCollectionFactory; + } /// /// Gets an individual tree node @@ -111,7 +134,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { diff --git a/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs b/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs index 5e71266bca..e54b200fea 100644 --- a/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs @@ -1,8 +1,16 @@ using System.Collections.Generic; using System.Net.Http.Formatting; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Web.Actions; +using Umbraco.Web.Composing; using Umbraco.Web.Models.Trees; +using Umbraco.Web.Routing; namespace Umbraco.Web.Trees { @@ -10,6 +18,30 @@ namespace Umbraco.Web.Trees [CoreTree] public abstract class MemberTypeAndGroupTreeControllerBase : TreeController { + public IMenuItemCollectionFactory MenuItemCollectionFactory { get; } + + protected MemberTypeAndGroupTreeControllerBase() + { + MenuItemCollectionFactory = Current.MenuItemCollectionFactory; + } + + protected MemberTypeAndGroupTreeControllerBase( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + MenuItemCollectionFactory = menuItemCollectionFactory; + } + protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) { var nodes = new TreeNodeCollection(); @@ -19,7 +51,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = MenuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { diff --git a/src/Umbraco.Web/Trees/PackagesTreeController.cs b/src/Umbraco.Web/Trees/PackagesTreeController.cs index 90a41c050c..5608196109 100644 --- a/src/Umbraco.Web/Trees/PackagesTreeController.cs +++ b/src/Umbraco.Web/Trees/PackagesTreeController.cs @@ -1,7 +1,14 @@ using System.Net.Http.Formatting; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Web.Models.Trees; using Umbraco.Web.Mvc; +using Umbraco.Web.Routing; using Umbraco.Web.WebApi.Filters; using Constants = Umbraco.Core.Constants; @@ -13,6 +20,25 @@ namespace Umbraco.Web.Trees [CoreTree] public class PackagesTreeController : TreeController { + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + public PackagesTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _menuItemCollectionFactory = menuItemCollectionFactory; + } + /// /// Helper method to create a root model for a tree /// @@ -39,7 +65,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { //doesn't have a menu, this is a full screen app without tree nodes - return MenuItemCollection.Empty; + return _menuItemCollectionFactory.Create(); } } } diff --git a/src/Umbraco.Web/Trees/PartialViewsTreeController.cs b/src/Umbraco.Web/Trees/PartialViewsTreeController.cs index 9fa0c025d6..e1e848df76 100644 --- a/src/Umbraco.Web/Trees/PartialViewsTreeController.cs +++ b/src/Umbraco.Web/Trees/PartialViewsTreeController.cs @@ -1,6 +1,5 @@ using Umbraco.Core.IO; using Umbraco.Web.Composing; -using Umbraco.Web.Models.Trees; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi.Filters; using Constants = Umbraco.Core.Constants; diff --git a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs index d2d2253f20..5601af0da3 100644 --- a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs @@ -3,8 +3,14 @@ using System.Net.Http.Formatting; using Umbraco.Web.Models.Trees; using Umbraco.Web.WebApi.Filters; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Web.Actions; +using Umbraco.Web.Routing; namespace Umbraco.Web.Trees { @@ -14,11 +20,30 @@ namespace Umbraco.Web.Trees [CoreTree] public class RelationTypeTreeController : TreeController { + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + public RelationTypeTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _menuItemCollectionFactory = menuItemCollectionFactory; + } + protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { //TODO: Do not allow deleting built in types - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); if (id == Constants.System.RootString) { @@ -32,7 +57,7 @@ namespace Umbraco.Web.Trees } var relationType = Services.RelationService.GetRelationTypeById(int.Parse(id)); - if (relationType == null) return new MenuItemCollection(); + if (relationType == null) return menu; menu.Items.Add(Services.TextService); diff --git a/src/Umbraco.Web/Trees/TemplatesTreeController.cs b/src/Umbraco.Web/Trees/TemplatesTreeController.cs index 6c8b23030e..647683e5c5 100644 --- a/src/Umbraco.Web/Trees/TemplatesTreeController.cs +++ b/src/Umbraco.Web/Trees/TemplatesTreeController.cs @@ -29,6 +29,7 @@ namespace Umbraco.Web.Trees public class TemplatesTreeController : TreeController, ISearchableTree { private readonly UmbracoTreeSearcher _treeSearcher; + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; public TemplatesTreeController( UmbracoTreeSearcher treeSearcher, @@ -41,10 +42,12 @@ namespace Umbraco.Web.Trees IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) { _treeSearcher = treeSearcher; + _menuItemCollectionFactory = menuItemCollectionFactory; } protected override TreeNode CreateRootNode(FormDataCollection queryStrings) @@ -97,7 +100,7 @@ namespace Umbraco.Web.Trees /// protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { - var menu = new MenuItemCollection(); + var menu = _menuItemCollectionFactory.Create(); //Create the normal create action var item = menu.Items.Add(Services.TextService, opensDialog: true); @@ -112,7 +115,7 @@ namespace Umbraco.Web.Trees } var template = Services.FileService.GetTemplate(int.Parse(id)); - if (template == null) return new MenuItemCollection(); + if (template == null) return menu; var entity = FromTemplate(template); //don't allow delete if it has child layouts diff --git a/src/Umbraco.Web/Trees/UserTreeController.cs b/src/Umbraco.Web/Trees/UserTreeController.cs index 475fbad2a8..648e9ef29c 100644 --- a/src/Umbraco.Web/Trees/UserTreeController.cs +++ b/src/Umbraco.Web/Trees/UserTreeController.cs @@ -1,7 +1,14 @@ using System.Net.Http.Formatting; using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Mapping; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; using Umbraco.Web.Models.Trees; using Umbraco.Web.Mvc; +using Umbraco.Web.Routing; using Umbraco.Web.WebApi.Filters; using Constants = Umbraco.Core.Constants; @@ -13,6 +20,25 @@ namespace Umbraco.Web.Trees [CoreTree] public class UserTreeController : TreeController { + private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; + + public UserTreeController( + IGlobalSettings globalSettings, + IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, + ServiceContext services, + AppCaches appCaches, + IProfilingLogger logger, + IRuntimeState runtimeState, + UmbracoHelper umbracoHelper, + UmbracoMapper umbracoMapper, + IPublishedUrlProvider publishedUrlProvider, + IMenuItemCollectionFactory menuItemCollectionFactory) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) + { + _menuItemCollectionFactory = menuItemCollectionFactory; + } + /// /// Helper method to create a root model for a tree /// @@ -38,7 +64,7 @@ namespace Umbraco.Web.Trees protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { //doesn't have a menu, this is a full screen app without tree nodes - return MenuItemCollection.Empty; + return _menuItemCollectionFactory.Create(); } } } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index b6b48e7755..f549ae4622 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -134,17 +134,16 @@ - - - + + + - @@ -154,12 +153,11 @@ - - - + + @@ -178,22 +176,17 @@ - - - - - - - - - - - + + + + + + @@ -222,7 +215,6 @@ - @@ -290,9 +282,6 @@ - - - @@ -399,30 +388,8 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs index 3087630edd..b20ebe7e09 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs @@ -10,18 +10,21 @@ using Umbraco.Core.Logging; using Umbraco.Core.Mapping; using Umbraco.Core.Persistence; using Umbraco.Core.Services; +using Umbraco.Web.Features; using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi.Filters; namespace Umbraco.Web.WebApi { + + /// /// Provides a base class for Umbraco API controllers. /// /// These controllers are NOT auto-routed. [FeatureAuthorize] - public abstract class UmbracoApiControllerBase : ApiController + public abstract class UmbracoApiControllerBase : ApiController, IUmbracoFeature { // note: all Umbraco controllers have two constructors: one with all dependencies, which should be used, From accef6d96aef2c71549195f9b15efda883cd3640 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 18 Feb 2020 13:34:31 +0100 Subject: [PATCH 03/10] Merged Umbraco.Examine and Umbraco.Infrastructure and moved more files into Infrastructure --- .../Properties/AssemblyInfo.cs | 1 - src/Umbraco.Abstractions/Scheduling/KeepAlive.cs | 2 +- .../Scheduling/TempFileCleanup.cs | 2 +- .../Sync/IBatchedDatabaseServerMessenger.cs | 7 +++++++ src/Umbraco.Abstractions/UmbracoEvents.cs | 10 ++++++++++ .../Umbraco.Examine.Lucene.csproj | 1 - src/Umbraco.Examine/Umbraco.Examine.csproj | 1 - .../Examine}/BaseValueSetBuilder.cs | 0 .../Examine}/ContentIndexPopulator.cs | 0 .../Examine}/ContentValueSetBuilder.cs | 0 .../Examine}/ContentValueSetValidator.cs | 0 .../Examine}/ExamineExtensions.cs | 0 .../Examine}/GenericIndexDiagnostics.cs | 0 .../Examine}/IBackOfficeExamineSearcher.cs | 0 .../Examine}/IContentValueSetBuilder.cs | 0 .../Examine}/IContentValueSetValidator.cs | 0 .../Examine}/IIndexCreator.cs | 0 .../Examine}/IIndexDiagnostics.cs | 0 .../Examine}/IIndexDiagnosticsFactory.cs | 0 .../Examine}/IIndexPopulator.cs | 0 .../Examine}/IPublishedContentValueSetBuilder.cs | 0 .../Examine}/IUmbracoContentIndex.cs | 0 .../Examine}/IUmbracoIndex.cs | 0 .../Examine}/IUmbracoIndexConfig.cs | 0 .../Examine}/IUmbracoIndexesCreator.cs | 0 .../Examine}/IUmbracoMemberIndex.cs | 0 .../Examine}/IUmbracoTreeSearcherFields.cs | 0 .../Examine}/IValueSetBuilder.cs | 0 .../Examine}/IndexDiagnosticsFactory.cs | 0 .../Examine}/IndexPopulator.cs | 0 .../Examine}/IndexRebuilder.cs | 0 .../Examine}/IndexRebuildingEventArgs.cs | 0 .../Examine}/IndexTypes.cs | 0 .../Examine}/MediaIndexPopulator.cs | 0 .../Examine}/MediaValueSetBuilder.cs | 0 .../Examine}/MemberIndexPopulator.cs | 0 .../Examine}/MemberValueSetBuilder.cs | 0 .../Examine}/MemberValueSetValidator.cs | 0 .../Examine}/PublishedContentIndexPopulator.cs | 0 .../Examine}/UmbracoExamineExtensions.cs | 0 .../Examine}/UmbracoExamineFieldNames.cs | 0 .../Examine}/UmbracoFieldDefinitionCollection.cs | 0 .../Examine}/UmbracoIndexConfig.cs | 0 .../Examine}/ValueSetValidator.cs | 0 .../IPublishedContentQuery.cs | 2 -- .../PublishedContentQuery.cs | 0 .../Scheduling/ScheduledPublishing.cs | 8 +++++--- .../Search/BackgroundIndexRebuilder.cs | 0 .../Search/ExamineComponent.cs | 0 .../Search/ExamineComposer.cs | 0 .../Suspendable.cs | 12 ++++++------ .../Umbraco.Infrastructure.csproj | 5 +++++ .../BatchedDatabaseServerMessenger.cs | 2 +- src/Umbraco.Web/Scheduling/SchedulerComponent.cs | 8 +++++--- src/Umbraco.Web/Umbraco.Web.csproj | 16 ++-------------- src/umbraco.sln | 6 ------ 56 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 src/Umbraco.Abstractions/Sync/IBatchedDatabaseServerMessenger.cs create mode 100644 src/Umbraco.Abstractions/UmbracoEvents.cs rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/BaseValueSetBuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/ContentIndexPopulator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/ContentValueSetBuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/ContentValueSetValidator.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure/Examine}/ExamineExtensions.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/GenericIndexDiagnostics.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IBackOfficeExamineSearcher.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IContentValueSetBuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IContentValueSetValidator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IIndexCreator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IIndexDiagnostics.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IIndexDiagnosticsFactory.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IIndexPopulator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IPublishedContentValueSetBuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IUmbracoContentIndex.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IUmbracoIndex.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IUmbracoIndexConfig.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IUmbracoIndexesCreator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IUmbracoMemberIndex.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IUmbracoTreeSearcherFields.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IValueSetBuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IndexDiagnosticsFactory.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IndexPopulator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IndexRebuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IndexRebuildingEventArgs.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/IndexTypes.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/MediaIndexPopulator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/MediaValueSetBuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/MemberIndexPopulator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/MemberValueSetBuilder.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/MemberValueSetValidator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/PublishedContentIndexPopulator.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/UmbracoExamineExtensions.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/UmbracoExamineFieldNames.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/UmbracoFieldDefinitionCollection.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/UmbracoIndexConfig.cs (100%) rename src/{Umbraco.Examine => Umbraco.Infrastructure/Examine}/ValueSetValidator.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/IPublishedContentQuery.cs (99%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/PublishedContentQuery.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Scheduling/ScheduledPublishing.cs (91%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/BackgroundIndexRebuilder.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineComponent.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineComposer.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Suspendable.cs (88%) diff --git a/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs b/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs index 6d5520f975..f129ca7731 100644 --- a/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs +++ b/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs @@ -8,7 +8,6 @@ using System.Runtime.InteropServices; // Umbraco Cms [assembly: InternalsVisibleTo("Umbraco.Web")] [assembly: InternalsVisibleTo("Umbraco.Web.UI")] -[assembly: InternalsVisibleTo("Umbraco.Examine")] [assembly: InternalsVisibleTo("Umbraco.ModelsBuilder.Embedded")] [assembly: InternalsVisibleTo("Umbraco.Tests")] diff --git a/src/Umbraco.Abstractions/Scheduling/KeepAlive.cs b/src/Umbraco.Abstractions/Scheduling/KeepAlive.cs index d1d9352ed6..c677c66b83 100644 --- a/src/Umbraco.Abstractions/Scheduling/KeepAlive.cs +++ b/src/Umbraco.Abstractions/Scheduling/KeepAlive.cs @@ -9,7 +9,7 @@ using Umbraco.Core.Sync; namespace Umbraco.Web.Scheduling { - internal class KeepAlive : RecurringTaskBase + public class KeepAlive : RecurringTaskBase { private readonly IRuntimeState _runtime; private readonly IKeepAliveSection _keepAliveSection; diff --git a/src/Umbraco.Abstractions/Scheduling/TempFileCleanup.cs b/src/Umbraco.Abstractions/Scheduling/TempFileCleanup.cs index 5d28bbfdb1..aefaf605db 100644 --- a/src/Umbraco.Abstractions/Scheduling/TempFileCleanup.cs +++ b/src/Umbraco.Abstractions/Scheduling/TempFileCleanup.cs @@ -10,7 +10,7 @@ namespace Umbraco.Web.Scheduling /// /// Used to cleanup temporary file locations /// - internal class TempFileCleanup : RecurringTaskBase + public class TempFileCleanup : RecurringTaskBase { private readonly DirectoryInfo[] _tempFolders; private readonly TimeSpan _age; diff --git a/src/Umbraco.Abstractions/Sync/IBatchedDatabaseServerMessenger.cs b/src/Umbraco.Abstractions/Sync/IBatchedDatabaseServerMessenger.cs new file mode 100644 index 0000000000..f1b887ca3f --- /dev/null +++ b/src/Umbraco.Abstractions/Sync/IBatchedDatabaseServerMessenger.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Core.Sync +{ + public interface IBatchedDatabaseServerMessenger : IServerMessenger + { + void FlushBatch(); + } +} diff --git a/src/Umbraco.Abstractions/UmbracoEvents.cs b/src/Umbraco.Abstractions/UmbracoEvents.cs new file mode 100644 index 0000000000..fe138425aa --- /dev/null +++ b/src/Umbraco.Abstractions/UmbracoEvents.cs @@ -0,0 +1,10 @@ +using System; +using Umbraco.Web.Routing; + +namespace Umbraco.Core +{ + public interface IUmbracoRouteEventSender + { + event EventHandler RouteAttempt; + } +} diff --git a/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj b/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj index 264f487b70..32ee1bdc4e 100644 --- a/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj +++ b/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj @@ -26,7 +26,6 @@ - diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj index 03fab50692..f548d7ac61 100644 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ b/src/Umbraco.Examine/Umbraco.Examine.csproj @@ -12,7 +12,6 @@ - diff --git a/src/Umbraco.Examine/BaseValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/BaseValueSetBuilder.cs similarity index 100% rename from src/Umbraco.Examine/BaseValueSetBuilder.cs rename to src/Umbraco.Infrastructure/Examine/BaseValueSetBuilder.cs diff --git a/src/Umbraco.Examine/ContentIndexPopulator.cs b/src/Umbraco.Infrastructure/Examine/ContentIndexPopulator.cs similarity index 100% rename from src/Umbraco.Examine/ContentIndexPopulator.cs rename to src/Umbraco.Infrastructure/Examine/ContentIndexPopulator.cs diff --git a/src/Umbraco.Examine/ContentValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/ContentValueSetBuilder.cs similarity index 100% rename from src/Umbraco.Examine/ContentValueSetBuilder.cs rename to src/Umbraco.Infrastructure/Examine/ContentValueSetBuilder.cs diff --git a/src/Umbraco.Examine/ContentValueSetValidator.cs b/src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs similarity index 100% rename from src/Umbraco.Examine/ContentValueSetValidator.cs rename to src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs diff --git a/src/Umbraco.Web/ExamineExtensions.cs b/src/Umbraco.Infrastructure/Examine/ExamineExtensions.cs similarity index 100% rename from src/Umbraco.Web/ExamineExtensions.cs rename to src/Umbraco.Infrastructure/Examine/ExamineExtensions.cs diff --git a/src/Umbraco.Examine/GenericIndexDiagnostics.cs b/src/Umbraco.Infrastructure/Examine/GenericIndexDiagnostics.cs similarity index 100% rename from src/Umbraco.Examine/GenericIndexDiagnostics.cs rename to src/Umbraco.Infrastructure/Examine/GenericIndexDiagnostics.cs diff --git a/src/Umbraco.Examine/IBackOfficeExamineSearcher.cs b/src/Umbraco.Infrastructure/Examine/IBackOfficeExamineSearcher.cs similarity index 100% rename from src/Umbraco.Examine/IBackOfficeExamineSearcher.cs rename to src/Umbraco.Infrastructure/Examine/IBackOfficeExamineSearcher.cs diff --git a/src/Umbraco.Examine/IContentValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/IContentValueSetBuilder.cs similarity index 100% rename from src/Umbraco.Examine/IContentValueSetBuilder.cs rename to src/Umbraco.Infrastructure/Examine/IContentValueSetBuilder.cs diff --git a/src/Umbraco.Examine/IContentValueSetValidator.cs b/src/Umbraco.Infrastructure/Examine/IContentValueSetValidator.cs similarity index 100% rename from src/Umbraco.Examine/IContentValueSetValidator.cs rename to src/Umbraco.Infrastructure/Examine/IContentValueSetValidator.cs diff --git a/src/Umbraco.Examine/IIndexCreator.cs b/src/Umbraco.Infrastructure/Examine/IIndexCreator.cs similarity index 100% rename from src/Umbraco.Examine/IIndexCreator.cs rename to src/Umbraco.Infrastructure/Examine/IIndexCreator.cs diff --git a/src/Umbraco.Examine/IIndexDiagnostics.cs b/src/Umbraco.Infrastructure/Examine/IIndexDiagnostics.cs similarity index 100% rename from src/Umbraco.Examine/IIndexDiagnostics.cs rename to src/Umbraco.Infrastructure/Examine/IIndexDiagnostics.cs diff --git a/src/Umbraco.Examine/IIndexDiagnosticsFactory.cs b/src/Umbraco.Infrastructure/Examine/IIndexDiagnosticsFactory.cs similarity index 100% rename from src/Umbraco.Examine/IIndexDiagnosticsFactory.cs rename to src/Umbraco.Infrastructure/Examine/IIndexDiagnosticsFactory.cs diff --git a/src/Umbraco.Examine/IIndexPopulator.cs b/src/Umbraco.Infrastructure/Examine/IIndexPopulator.cs similarity index 100% rename from src/Umbraco.Examine/IIndexPopulator.cs rename to src/Umbraco.Infrastructure/Examine/IIndexPopulator.cs diff --git a/src/Umbraco.Examine/IPublishedContentValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/IPublishedContentValueSetBuilder.cs similarity index 100% rename from src/Umbraco.Examine/IPublishedContentValueSetBuilder.cs rename to src/Umbraco.Infrastructure/Examine/IPublishedContentValueSetBuilder.cs diff --git a/src/Umbraco.Examine/IUmbracoContentIndex.cs b/src/Umbraco.Infrastructure/Examine/IUmbracoContentIndex.cs similarity index 100% rename from src/Umbraco.Examine/IUmbracoContentIndex.cs rename to src/Umbraco.Infrastructure/Examine/IUmbracoContentIndex.cs diff --git a/src/Umbraco.Examine/IUmbracoIndex.cs b/src/Umbraco.Infrastructure/Examine/IUmbracoIndex.cs similarity index 100% rename from src/Umbraco.Examine/IUmbracoIndex.cs rename to src/Umbraco.Infrastructure/Examine/IUmbracoIndex.cs diff --git a/src/Umbraco.Examine/IUmbracoIndexConfig.cs b/src/Umbraco.Infrastructure/Examine/IUmbracoIndexConfig.cs similarity index 100% rename from src/Umbraco.Examine/IUmbracoIndexConfig.cs rename to src/Umbraco.Infrastructure/Examine/IUmbracoIndexConfig.cs diff --git a/src/Umbraco.Examine/IUmbracoIndexesCreator.cs b/src/Umbraco.Infrastructure/Examine/IUmbracoIndexesCreator.cs similarity index 100% rename from src/Umbraco.Examine/IUmbracoIndexesCreator.cs rename to src/Umbraco.Infrastructure/Examine/IUmbracoIndexesCreator.cs diff --git a/src/Umbraco.Examine/IUmbracoMemberIndex.cs b/src/Umbraco.Infrastructure/Examine/IUmbracoMemberIndex.cs similarity index 100% rename from src/Umbraco.Examine/IUmbracoMemberIndex.cs rename to src/Umbraco.Infrastructure/Examine/IUmbracoMemberIndex.cs diff --git a/src/Umbraco.Examine/IUmbracoTreeSearcherFields.cs b/src/Umbraco.Infrastructure/Examine/IUmbracoTreeSearcherFields.cs similarity index 100% rename from src/Umbraco.Examine/IUmbracoTreeSearcherFields.cs rename to src/Umbraco.Infrastructure/Examine/IUmbracoTreeSearcherFields.cs diff --git a/src/Umbraco.Examine/IValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/IValueSetBuilder.cs similarity index 100% rename from src/Umbraco.Examine/IValueSetBuilder.cs rename to src/Umbraco.Infrastructure/Examine/IValueSetBuilder.cs diff --git a/src/Umbraco.Examine/IndexDiagnosticsFactory.cs b/src/Umbraco.Infrastructure/Examine/IndexDiagnosticsFactory.cs similarity index 100% rename from src/Umbraco.Examine/IndexDiagnosticsFactory.cs rename to src/Umbraco.Infrastructure/Examine/IndexDiagnosticsFactory.cs diff --git a/src/Umbraco.Examine/IndexPopulator.cs b/src/Umbraco.Infrastructure/Examine/IndexPopulator.cs similarity index 100% rename from src/Umbraco.Examine/IndexPopulator.cs rename to src/Umbraco.Infrastructure/Examine/IndexPopulator.cs diff --git a/src/Umbraco.Examine/IndexRebuilder.cs b/src/Umbraco.Infrastructure/Examine/IndexRebuilder.cs similarity index 100% rename from src/Umbraco.Examine/IndexRebuilder.cs rename to src/Umbraco.Infrastructure/Examine/IndexRebuilder.cs diff --git a/src/Umbraco.Examine/IndexRebuildingEventArgs.cs b/src/Umbraco.Infrastructure/Examine/IndexRebuildingEventArgs.cs similarity index 100% rename from src/Umbraco.Examine/IndexRebuildingEventArgs.cs rename to src/Umbraco.Infrastructure/Examine/IndexRebuildingEventArgs.cs diff --git a/src/Umbraco.Examine/IndexTypes.cs b/src/Umbraco.Infrastructure/Examine/IndexTypes.cs similarity index 100% rename from src/Umbraco.Examine/IndexTypes.cs rename to src/Umbraco.Infrastructure/Examine/IndexTypes.cs diff --git a/src/Umbraco.Examine/MediaIndexPopulator.cs b/src/Umbraco.Infrastructure/Examine/MediaIndexPopulator.cs similarity index 100% rename from src/Umbraco.Examine/MediaIndexPopulator.cs rename to src/Umbraco.Infrastructure/Examine/MediaIndexPopulator.cs diff --git a/src/Umbraco.Examine/MediaValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/MediaValueSetBuilder.cs similarity index 100% rename from src/Umbraco.Examine/MediaValueSetBuilder.cs rename to src/Umbraco.Infrastructure/Examine/MediaValueSetBuilder.cs diff --git a/src/Umbraco.Examine/MemberIndexPopulator.cs b/src/Umbraco.Infrastructure/Examine/MemberIndexPopulator.cs similarity index 100% rename from src/Umbraco.Examine/MemberIndexPopulator.cs rename to src/Umbraco.Infrastructure/Examine/MemberIndexPopulator.cs diff --git a/src/Umbraco.Examine/MemberValueSetBuilder.cs b/src/Umbraco.Infrastructure/Examine/MemberValueSetBuilder.cs similarity index 100% rename from src/Umbraco.Examine/MemberValueSetBuilder.cs rename to src/Umbraco.Infrastructure/Examine/MemberValueSetBuilder.cs diff --git a/src/Umbraco.Examine/MemberValueSetValidator.cs b/src/Umbraco.Infrastructure/Examine/MemberValueSetValidator.cs similarity index 100% rename from src/Umbraco.Examine/MemberValueSetValidator.cs rename to src/Umbraco.Infrastructure/Examine/MemberValueSetValidator.cs diff --git a/src/Umbraco.Examine/PublishedContentIndexPopulator.cs b/src/Umbraco.Infrastructure/Examine/PublishedContentIndexPopulator.cs similarity index 100% rename from src/Umbraco.Examine/PublishedContentIndexPopulator.cs rename to src/Umbraco.Infrastructure/Examine/PublishedContentIndexPopulator.cs diff --git a/src/Umbraco.Examine/UmbracoExamineExtensions.cs b/src/Umbraco.Infrastructure/Examine/UmbracoExamineExtensions.cs similarity index 100% rename from src/Umbraco.Examine/UmbracoExamineExtensions.cs rename to src/Umbraco.Infrastructure/Examine/UmbracoExamineExtensions.cs diff --git a/src/Umbraco.Examine/UmbracoExamineFieldNames.cs b/src/Umbraco.Infrastructure/Examine/UmbracoExamineFieldNames.cs similarity index 100% rename from src/Umbraco.Examine/UmbracoExamineFieldNames.cs rename to src/Umbraco.Infrastructure/Examine/UmbracoExamineFieldNames.cs diff --git a/src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs b/src/Umbraco.Infrastructure/Examine/UmbracoFieldDefinitionCollection.cs similarity index 100% rename from src/Umbraco.Examine/UmbracoFieldDefinitionCollection.cs rename to src/Umbraco.Infrastructure/Examine/UmbracoFieldDefinitionCollection.cs diff --git a/src/Umbraco.Examine/UmbracoIndexConfig.cs b/src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs similarity index 100% rename from src/Umbraco.Examine/UmbracoIndexConfig.cs rename to src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs diff --git a/src/Umbraco.Examine/ValueSetValidator.cs b/src/Umbraco.Infrastructure/Examine/ValueSetValidator.cs similarity index 100% rename from src/Umbraco.Examine/ValueSetValidator.cs rename to src/Umbraco.Infrastructure/Examine/ValueSetValidator.cs diff --git a/src/Umbraco.Web/IPublishedContentQuery.cs b/src/Umbraco.Infrastructure/IPublishedContentQuery.cs similarity index 99% rename from src/Umbraco.Web/IPublishedContentQuery.cs rename to src/Umbraco.Infrastructure/IPublishedContentQuery.cs index 7066475dc9..6a1621b229 100644 --- a/src/Umbraco.Web/IPublishedContentQuery.cs +++ b/src/Umbraco.Infrastructure/IPublishedContentQuery.cs @@ -8,8 +8,6 @@ using Umbraco.Core.Xml; namespace Umbraco.Web { - using Examine = global::Examine; - /// /// Query methods used for accessing strongly typed content in templates /// diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Infrastructure/PublishedContentQuery.cs similarity index 100% rename from src/Umbraco.Web/PublishedContentQuery.cs rename to src/Umbraco.Infrastructure/PublishedContentQuery.cs diff --git a/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs b/src/Umbraco.Infrastructure/Scheduling/ScheduledPublishing.cs similarity index 91% rename from src/Umbraco.Web/Scheduling/ScheduledPublishing.cs rename to src/Umbraco.Infrastructure/Scheduling/ScheduledPublishing.cs index 2e79e40d7a..b074704033 100644 --- a/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs +++ b/src/Umbraco.Infrastructure/Scheduling/ScheduledPublishing.cs @@ -7,21 +7,23 @@ using Umbraco.Core.Sync; namespace Umbraco.Web.Scheduling { - internal class ScheduledPublishing : RecurringTaskBase + public class ScheduledPublishing : RecurringTaskBase { private readonly IRuntimeState _runtime; private readonly IContentService _contentService; private readonly IUmbracoContextFactory _umbracoContextFactory; private readonly ILogger _logger; + private readonly IServerMessenger _serverMessenger; public ScheduledPublishing(IBackgroundTaskRunner runner, int delayMilliseconds, int periodMilliseconds, - IRuntimeState runtime, IContentService contentService, IUmbracoContextFactory umbracoContextFactory, ILogger logger) + IRuntimeState runtime, IContentService contentService, IUmbracoContextFactory umbracoContextFactory, ILogger logger, IServerMessenger serverMessenger) : base(runner, delayMilliseconds, periodMilliseconds) { _runtime = runtime; _contentService = contentService; _umbracoContextFactory = umbracoContextFactory; _logger = logger; + _serverMessenger = serverMessenger; } public override bool PerformRun() @@ -76,7 +78,7 @@ namespace Umbraco.Web.Scheduling finally { // if running on a temp context, we have to flush the messenger - if (contextReference.IsRoot && Composing.Current.ServerMessenger is BatchedDatabaseServerMessenger m) + if (contextReference.IsRoot && _serverMessenger is IBatchedDatabaseServerMessenger m) m.FlushBatch(); } } diff --git a/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs b/src/Umbraco.Infrastructure/Search/BackgroundIndexRebuilder.cs similarity index 100% rename from src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs rename to src/Umbraco.Infrastructure/Search/BackgroundIndexRebuilder.cs diff --git a/src/Umbraco.Web/Search/ExamineComponent.cs b/src/Umbraco.Infrastructure/Search/ExamineComponent.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineComponent.cs rename to src/Umbraco.Infrastructure/Search/ExamineComponent.cs diff --git a/src/Umbraco.Web/Search/ExamineComposer.cs b/src/Umbraco.Infrastructure/Search/ExamineComposer.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineComposer.cs rename to src/Umbraco.Infrastructure/Search/ExamineComposer.cs diff --git a/src/Umbraco.Web/Suspendable.cs b/src/Umbraco.Infrastructure/Suspendable.cs similarity index 88% rename from src/Umbraco.Web/Suspendable.cs rename to src/Umbraco.Infrastructure/Suspendable.cs index a1d79d3619..7287d1c364 100644 --- a/src/Umbraco.Web/Suspendable.cs +++ b/src/Umbraco.Infrastructure/Suspendable.cs @@ -1,6 +1,6 @@ -using Umbraco.Core; +using Umbraco.Composing; +using Umbraco.Core.Cache; using Umbraco.Core.Logging; -using Umbraco.Web.Composing; using Umbraco.Examine; using Umbraco.Web.Cache; using Umbraco.Web.Search; @@ -34,7 +34,7 @@ namespace Umbraco.Web _suspended = true; } - public static void ResumeDocumentCache() + public static void ResumeDocumentCache(CacheRefresherCollection cacheRefresherCollection) { _suspended = false; @@ -43,7 +43,7 @@ namespace Umbraco.Web if (_tried == false) return; _tried = false; - var pageRefresher = Current.CacheRefreshers[ContentCacheRefresher.UniqueId]; + var pageRefresher = cacheRefresherCollection[ContentCacheRefresher.UniqueId]; pageRefresher.RefreshAll(); } } @@ -70,7 +70,7 @@ namespace Umbraco.Web _suspended = true; } - public static void ResumeIndexers(IndexRebuilder indexRebuilder, ILogger logger) + public static void ResumeIndexers(IndexRebuilder indexRebuilder, ILogger logger, BackgroundIndexRebuilder backgroundIndexRebuilder) { _suspended = false; @@ -79,7 +79,7 @@ namespace Umbraco.Web if (_tried == false) return; _tried = false; - Current.Factory.GetInstance().RebuildIndexes(false); + backgroundIndexRebuilder.RebuildIndexes(false); } } diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index b3b291a286..2421711773 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -27,6 +27,7 @@ + @@ -63,4 +64,8 @@ + + + + diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs index a893fa6b49..a62aad3e5d 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web /// /// This binds to appropriate umbraco events in order to trigger the Boot(), Sync() & FlushBatch() calls /// - public class BatchedDatabaseServerMessenger : DatabaseServerMessenger + public class BatchedDatabaseServerMessenger : DatabaseServerMessenger, IBatchedDatabaseServerMessenger { private readonly IUmbracoDatabaseFactory _databaseFactory; private readonly IRequestCache _requestCache; diff --git a/src/Umbraco.Web/Scheduling/SchedulerComponent.cs b/src/Umbraco.Web/Scheduling/SchedulerComponent.cs index ca6f0729eb..061f42b9ba 100644 --- a/src/Umbraco.Web/Scheduling/SchedulerComponent.cs +++ b/src/Umbraco.Web/Scheduling/SchedulerComponent.cs @@ -11,9 +11,9 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Scoping; using Umbraco.Core.Services; +using Umbraco.Core.Sync; using Umbraco.Web.HealthCheck; using Umbraco.Web.Routing; -using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Web.Scheduling { @@ -36,6 +36,7 @@ namespace Umbraco.Web.Scheduling private readonly IHealthChecks _healthChecksConfig; private readonly IUmbracoSettingsSection _umbracoSettingsSection; private readonly IIOHelper _ioHelper; + private readonly IServerMessenger _serverMessenger; private BackgroundTaskRunner _keepAliveRunner; private BackgroundTaskRunner _publishingRunner; @@ -53,7 +54,7 @@ namespace Umbraco.Web.Scheduling HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger, IHostingEnvironment hostingEnvironment, IHealthChecks healthChecksConfig, - IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper) + IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, IServerMessenger serverMessenger) { _runtime = runtime; _contentService = contentService; @@ -68,6 +69,7 @@ namespace Umbraco.Web.Scheduling _healthChecksConfig = healthChecksConfig ?? throw new ArgumentNullException(nameof(healthChecksConfig)); _umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection)); _ioHelper = ioHelper; + _serverMessenger = serverMessenger; } public void Initialize() @@ -140,7 +142,7 @@ namespace Umbraco.Web.Scheduling { // scheduled publishing/unpublishing // install on all, will only run on non-replica servers - var task = new ScheduledPublishing(_publishingRunner, DefaultDelayMilliseconds, OneMinuteMilliseconds, _runtime, _contentService, _umbracoContextFactory, _logger); + var task = new ScheduledPublishing(_publishingRunner, DefaultDelayMilliseconds, OneMinuteMilliseconds, _runtime, _contentService, _umbracoContextFactory, _logger, _serverMessenger); _publishingRunner.TryAdd(task); return task; } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index f549ae4622..cb4c3cf69a 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -111,10 +111,6 @@ {fbe7c065-dac0-4025-a78b-63b24d3ab00b} Umbraco.Configuration - - {f9b7fe05-0f93-4d0d-9c10-690b33ecbbd8} - Umbraco.Examine - {3ae7bf57-966b-45a5-910a-954d7c554441} Umbraco.Infrastructure @@ -194,7 +190,8 @@ - + + @@ -226,8 +223,6 @@ - - @@ -289,7 +284,6 @@ - @@ -315,7 +309,6 @@ - @@ -416,7 +409,6 @@ - @@ -463,7 +455,6 @@ - @@ -541,9 +532,7 @@ - - @@ -568,7 +557,6 @@ - diff --git a/src/umbraco.sln b/src/umbraco.sln index 2b9f9d004b..9b2dd71399 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -113,8 +113,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.TestData", "Umbraco EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.PublishedCache.NuCache", "Umbraco.PublishedCache.NuCache\Umbraco.PublishedCache.NuCache.csproj", "{F6DE8DA0-07CC-4EF2-8A59-2BC81DBB3830}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco.Examine", "Umbraco.Examine\Umbraco.Examine.csproj", "{F9B7FE05-0F93-4D0D-9C10-690B33ECBBD8}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Examine.Lucene", "Umbraco.Examine.Lucene\Umbraco.Examine.Lucene.csproj", "{0FAD7D2A-D7DD-45B1-91FD-488BB6CDACEA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Web.BackOffice", "Umbraco.Web.BackOffice\Umbraco.Web.BackOffice.csproj", "{9B95EEF7-63FE-4432-8C63-166BE9C1A929}" @@ -171,10 +169,6 @@ Global {F6DE8DA0-07CC-4EF2-8A59-2BC81DBB3830}.Debug|Any CPU.Build.0 = Debug|Any CPU {F6DE8DA0-07CC-4EF2-8A59-2BC81DBB3830}.Release|Any CPU.ActiveCfg = Release|Any CPU {F6DE8DA0-07CC-4EF2-8A59-2BC81DBB3830}.Release|Any CPU.Build.0 = Release|Any CPU - {F9B7FE05-0F93-4D0D-9C10-690B33ECBBD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F9B7FE05-0F93-4D0D-9C10-690B33ECBBD8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F9B7FE05-0F93-4D0D-9C10-690B33ECBBD8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F9B7FE05-0F93-4D0D-9C10-690B33ECBBD8}.Release|Any CPU.Build.0 = Release|Any CPU {0FAD7D2A-D7DD-45B1-91FD-488BB6CDACEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0FAD7D2A-D7DD-45B1-91FD-488BB6CDACEA}.Debug|Any CPU.Build.0 = Debug|Any CPU {0FAD7D2A-D7DD-45B1-91FD-488BB6CDACEA}.Release|Any CPU.ActiveCfg = Release|Any CPU From 750b6f6a1805245b89607dda6f51b61a87bae659 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 19 Feb 2020 09:26:51 +0100 Subject: [PATCH 04/10] Move more files and fixed circular dependency --- .../Cookie/ICookieManager.cs | 5 +++- .../Install/IFilePermissionHelper.cs | 5 ---- .../IPublishedSnapshotService.cs | 2 +- .../Routing/DomainUtilities.cs | 2 +- .../Templates/ITemplateRenderer.cs | 0 .../Routing/ContentFinderByConfigured404.cs | 0 .../Routing/NotFoundHandlerHelper.cs | 2 +- .../Search/ExamineFinalComponent.cs | 0 .../Search/ExamineFinalComposer.cs | 0 .../Search/ExamineIndexModel.cs | 0 .../Search/ExamineSearcherModel.cs | 0 .../Search/ExamineUserComponent.cs | 0 .../Search/UmbracoTreeSearcher.cs | 0 .../Search/UmbracoTreeSearcherFields.cs | 0 .../TagQuery.cs | 0 .../Umbraco.Infrastructure.csproj | 4 --- .../PublishedSnapshotService.cs | 10 +++++--- .../Umbraco.PublishedCache.NuCache.csproj | 1 + .../Cache/DistributedCacheBinderTests.cs | 3 ++- .../PublishedContentCacheTests.cs | 3 ++- .../PublishedContent/NuCacheChildrenTests.cs | 6 ++--- .../PublishedContent/NuCacheTests.cs | 4 +-- .../PublishedContentSnapshotTestBase.cs | 3 ++- .../Scoping/ScopedNuCacheTests.cs | 6 ++--- .../Security/BackOfficeCookieManagerTests.cs | 6 +++-- .../ContentTypeServiceVariantsTests.cs | 3 +-- .../TestControllerActivatorBase.cs | 3 ++- .../TestHelpers/TestObjects-Mocks.cs | 3 ++- .../TestHelpers/TestWithDatabaseBase.cs | 3 ++- .../Objects/TestUmbracoContextFactory.cs | 3 ++- ...RenderIndexActionSelectorAttributeTests.cs | 12 ++++++--- .../Web/Mvc/SurfaceControllerTests.cs | 12 ++++++--- .../Web/Mvc/UmbracoViewPageTests.cs | 3 ++- .../Web/WebExtensionMethodTests.cs | 9 ++++--- src/Umbraco.Web/AspNet/AspNetCookieManager.cs | 16 ++++++++++++ src/Umbraco.Web/Editors/PreviewController.cs | 8 ++++-- src/Umbraco.Web/HttpCookieExtensions.cs | 25 ++++--------------- .../Install/FilePermissionHelper.cs | 8 +++--- src/Umbraco.Web/Install/InstallHelper.cs | 10 +++++--- src/Umbraco.Web/Macros/MacroRenderer.cs | 7 ++++-- src/Umbraco.Web/Umbraco.Web.csproj | 11 -------- src/Umbraco.Web/UmbracoContext.cs | 8 ++++-- src/Umbraco.Web/UmbracoContextFactory.cs | 8 ++++-- 43 files changed, 119 insertions(+), 95 deletions(-) rename src/{Umbraco.Web => Umbraco.Abstractions}/Templates/ITemplateRenderer.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Routing/ContentFinderByConfigured404.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Routing/NotFoundHandlerHelper.cs (99%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineFinalComponent.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineFinalComposer.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineIndexModel.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineSearcherModel.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineUserComponent.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/UmbracoTreeSearcher.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/UmbracoTreeSearcherFields.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/TagQuery.cs (100%) diff --git a/src/Umbraco.Abstractions/Cookie/ICookieManager.cs b/src/Umbraco.Abstractions/Cookie/ICookieManager.cs index 4822d8ce74..af0ee7b1f6 100644 --- a/src/Umbraco.Abstractions/Cookie/ICookieManager.cs +++ b/src/Umbraco.Abstractions/Cookie/ICookieManager.cs @@ -2,6 +2,9 @@ namespace Umbraco.Core.Cookie { public interface ICookieManager { - void ExpireCookie(string angularCookieName); + void ExpireCookie(string cookieName); + string GetCookieValue(string cookieName); + void SetCookieValue(string cookieName, string value); + bool HasCookie(string cookieName); } } diff --git a/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs b/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs index 90f550f2c9..b60839cb00 100644 --- a/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs +++ b/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs @@ -7,10 +7,5 @@ namespace Umbraco.Core.Install bool RunFilePermissionTestSuite(out Dictionary> report); bool EnsureDirectories(string[] dirs, out IEnumerable errors, bool writeCausesRestart = false); bool EnsureFiles(string[] files, out IEnumerable errors); - bool EnsureCanCreateSubDirectory(string dir, out IEnumerable errors); - bool EnsureCanCreateSubDirectories(IEnumerable dirs, out IEnumerable errors); - bool TestPublishedSnapshotService(out IEnumerable errors); - bool TryCreateDirectory(string dir); - bool TryAccessDirectory(string dir, bool canWrite); } } diff --git a/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs index a1894c902c..b23c8ae10f 100644 --- a/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs +++ b/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs @@ -167,7 +167,7 @@ namespace Umbraco.Web.PublishedCache string StatusUrl { get; } - #endregion + #endregion void Collect(); } diff --git a/src/Umbraco.Abstractions/Routing/DomainUtilities.cs b/src/Umbraco.Abstractions/Routing/DomainUtilities.cs index 26801cfd27..c459ae4d14 100644 --- a/src/Umbraco.Abstractions/Routing/DomainUtilities.cs +++ b/src/Umbraco.Abstractions/Routing/DomainUtilities.cs @@ -344,7 +344,7 @@ namespace Umbraco.Web.Routing /// The current domain root node identifier, or null. /// The deepest wildcard Domain in the path, or null. /// Looks _under_ rootNodeId but not _at_ rootNodeId. - internal static Domain FindWildcardDomainInPath(IEnumerable domains, string path, int? rootNodeId) + public static Domain FindWildcardDomainInPath(IEnumerable domains, string path, int? rootNodeId) { var stopNodeId = rootNodeId ?? -1; diff --git a/src/Umbraco.Web/Templates/ITemplateRenderer.cs b/src/Umbraco.Abstractions/Templates/ITemplateRenderer.cs similarity index 100% rename from src/Umbraco.Web/Templates/ITemplateRenderer.cs rename to src/Umbraco.Abstractions/Templates/ITemplateRenderer.cs diff --git a/src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs similarity index 100% rename from src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs rename to src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs diff --git a/src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs similarity index 99% rename from src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs rename to src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs index 38ecb09b2b..335e1f868a 100644 --- a/src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs +++ b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs @@ -1,13 +1,13 @@ using System; using System.Globalization; using System.Linq; +using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Core.Xml; -using Umbraco.Web.Composing; namespace Umbraco.Web.Routing { diff --git a/src/Umbraco.Web/Search/ExamineFinalComponent.cs b/src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineFinalComponent.cs rename to src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs diff --git a/src/Umbraco.Web/Search/ExamineFinalComposer.cs b/src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineFinalComposer.cs rename to src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs diff --git a/src/Umbraco.Web/Search/ExamineIndexModel.cs b/src/Umbraco.Infrastructure/Search/ExamineIndexModel.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineIndexModel.cs rename to src/Umbraco.Infrastructure/Search/ExamineIndexModel.cs diff --git a/src/Umbraco.Web/Search/ExamineSearcherModel.cs b/src/Umbraco.Infrastructure/Search/ExamineSearcherModel.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineSearcherModel.cs rename to src/Umbraco.Infrastructure/Search/ExamineSearcherModel.cs diff --git a/src/Umbraco.Web/Search/ExamineUserComponent.cs b/src/Umbraco.Infrastructure/Search/ExamineUserComponent.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineUserComponent.cs rename to src/Umbraco.Infrastructure/Search/ExamineUserComponent.cs diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs similarity index 100% rename from src/Umbraco.Web/Search/UmbracoTreeSearcher.cs rename to src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs b/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcherFields.cs similarity index 100% rename from src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs rename to src/Umbraco.Infrastructure/Search/UmbracoTreeSearcherFields.cs diff --git a/src/Umbraco.Web/TagQuery.cs b/src/Umbraco.Infrastructure/TagQuery.cs similarity index 100% rename from src/Umbraco.Web/TagQuery.cs rename to src/Umbraco.Infrastructure/TagQuery.cs diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index 2421711773..92601f9ddd 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -64,8 +64,4 @@ - - - - diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index 5d99aa6aaa..e383eb0223 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.Install; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; @@ -26,6 +27,7 @@ using Umbraco.Core.Services.Changes; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; using Umbraco.Web.Cache; +using Umbraco.Web.Install; using Umbraco.Web.PublishedCache.NuCache.DataSource; using Umbraco.Web.Routing; using File = System.IO.File; @@ -50,7 +52,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private readonly ITypeFinder _typeFinder; private readonly IHostingEnvironment _hostingEnvironment; private readonly IShortStringHelper _shortStringHelper; - private readonly IFilePermissionHelper _filePermissionHelper; + private readonly IIOHelper _ioHelper; // volatile because we read it with no lock private volatile bool _isReady; @@ -88,7 +90,7 @@ namespace Umbraco.Web.PublishedCache.NuCache ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper, - IFilePermissionHelper filePermissionHelper) + IIOHelper ioHelper) : base(publishedSnapshotAccessor, variationContextAccessor) { //if (Interlocked.Increment(ref _singletonCheck) > 1) @@ -108,7 +110,7 @@ namespace Umbraco.Web.PublishedCache.NuCache _typeFinder = typeFinder; _hostingEnvironment = hostingEnvironment; _shortStringHelper = shortStringHelper; - _filePermissionHelper = filePermissionHelper; + _ioHelper = ioHelper; // we need an Xml serializer here so that the member cache can support XPath, // for members this is done by navigating the serialized-to-xml member @@ -362,7 +364,7 @@ namespace Umbraco.Web.PublishedCache.NuCache public override bool EnsureEnvironment(out IEnumerable errors) { // must have app_data and be able to write files into it - var ok = _filePermissionHelper.TryCreateDirectory(GetLocalFilesPath()); + var ok = FilePermissionHelper.TryCreateDirectory(GetLocalFilesPath(), _ioHelper); errors = ok ? Enumerable.Empty() : new[] { "NuCache local files." }; return ok; } diff --git a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj index 4c369ec2fa..2001309138 100644 --- a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj +++ b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs index 8db6b970bc..5f5fdaacc1 100644 --- a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs @@ -165,7 +165,8 @@ namespace Umbraco.Tests.Cache Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); // 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 a7ef0ff721..b096235708 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -83,7 +83,8 @@ namespace Umbraco.Tests.Cache.PublishedCache globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); _cache = _umbracoContext.Content; } diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 42e446c4d3..1f153a0a5e 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.Hosting; using Umbraco.Core.Install; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; @@ -144,7 +145,6 @@ namespace Umbraco.Tests.PublishedContent var typeFinder = new TypeFinder(Mock.Of()); - var filePermissionHelper = Mock.Of(); // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; @@ -169,7 +169,7 @@ namespace Umbraco.Tests.PublishedContent typeFinder, hostingEnvironment, new MockShortStringHelper(), - filePermissionHelper); + TestHelper.IOHelper); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); @@ -971,7 +971,7 @@ namespace Umbraco.Tests.PublishedContent documents = snapshot.Content.GetById(2).Children(_variationAccesor).ToArray(); AssertDocuments(documents, "N9", "N8", "N7"); - + } [Test] diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 08e68ce652..b0f0eb7722 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -186,8 +186,6 @@ namespace Umbraco.Tests.PublishedContent var typeFinder = new TypeFinder(Mock.Of()); - var filePermissionHelper = Mock.Of(); - // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; _snapshotService = new PublishedSnapshotService(options, @@ -211,7 +209,7 @@ namespace Umbraco.Tests.PublishedContent typeFinder, TestHelper.GetHostingEnvironment(), new MockShortStringHelper(), - filePermissionHelper); + TestHelper.IOHelper); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs index 9281db2d29..d36eb0013a 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs @@ -77,7 +77,8 @@ namespace Umbraco.Tests.PublishedContent globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); return umbracoContext; } diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index d0b63f8492..1e148d33c6 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -84,7 +84,6 @@ namespace Umbraco.Tests.Scoping var mediaRepository = Mock.Of(); var memberRepository = Mock.Of(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); - var filePermissionHelper = Mock.Of(); var typeFinder = new TypeFinder(Mock.Of()); @@ -108,7 +107,7 @@ namespace Umbraco.Tests.Scoping typeFinder, hostingEnvironment, new MockShortStringHelper(), - filePermissionHelper); + IOHelper); } protected IUmbracoContext GetUmbracoContextNu(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable urlProviders = null) @@ -126,7 +125,8 @@ namespace Umbraco.Tests.Scoping globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); 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 30c61350b9..eeff707618 100644 --- a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs @@ -37,7 +37,8 @@ namespace Umbraco.Tests.Security new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper), globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Install); var mgr = new BackOfficeCookieManager( @@ -60,7 +61,8 @@ namespace Umbraco.Tests.Security globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); var mgr = new BackOfficeCookieManager(Mock.Of(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings(), IOHelper, AppCaches.RequestCache); diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index 2c22b98262..1a485ec546 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -57,7 +57,6 @@ namespace Umbraco.Tests.Services var mediaRepository = Mock.Of(); var memberRepository = Mock.Of(); var hostingEnvironment = Mock.Of(); - var filePermissionHelper = Mock.Of(); var typeFinder = new TypeFinder(Mock.Of()); @@ -81,7 +80,7 @@ namespace Umbraco.Tests.Services typeFinder, hostingEnvironment, new MockShortStringHelper(), - filePermissionHelper); + IOHelper); } public class LocalServerMessenger : ServerMessengerBase diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index 2eb8decd1c..9ab9cc8640 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -144,7 +144,8 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting globalSettings, new TestVariationContextAccessor(), TestHelper.IOHelper, - TestHelper.UriUtility); + TestHelper.UriUtility, + new AspNetCookieManager(httpContextAccessor)); //replace it umbracoContextAccessor.UmbracoContext = umbCtx; diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index 25588bed62..5dabb7ed06 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -134,7 +134,8 @@ namespace Umbraco.Tests.TestHelpers Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); return umbracoContextFactory.EnsureUmbracoContext().UmbracoContext; } diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index c2a44026d6..6172c63650 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -382,7 +382,8 @@ namespace Umbraco.Tests.TestHelpers globalSettings ?? Factory.GetInstance(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); if (setSingleton) Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext; diff --git a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs index 26bed55cbc..20b18fa728 100644 --- a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs +++ b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs @@ -45,7 +45,8 @@ namespace Umbraco.Tests.Testing.Objects Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); return umbracoContextFactory; } diff --git a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs index 98301076ef..bdd7c6eb93 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs @@ -74,7 +74,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -105,7 +106,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -136,7 +138,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -167,7 +170,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index 089dfea592..652a95ed2b 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -47,7 +47,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbracoContext = umbracoContextReference.UmbracoContext; @@ -76,7 +77,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -108,7 +110,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbracoContext = umbracoContextReference.UmbracoContext; @@ -146,7 +149,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbracoContext = umbracoContextReference.UmbracoContext; diff --git a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs index a03c84f0b0..9b11feb170 100644 --- a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs @@ -445,7 +445,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); //if (setSingleton) //{ diff --git a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs index 76edcd4152..b126c823cd 100644 --- a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs +++ b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs @@ -36,7 +36,8 @@ namespace Umbraco.Tests.Web TestObjects.GetGlobalSettings(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var r1 = new RouteData(); r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx); @@ -56,7 +57,8 @@ namespace Umbraco.Tests.Web TestObjects.GetGlobalSettings(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var r1 = new RouteData(); r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx); @@ -86,7 +88,8 @@ namespace Umbraco.Tests.Web TestObjects.GetGlobalSettings(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var httpContext = Mock.Of(); diff --git a/src/Umbraco.Web/AspNet/AspNetCookieManager.cs b/src/Umbraco.Web/AspNet/AspNetCookieManager.cs index 2b5318110d..d8fcefa0e1 100644 --- a/src/Umbraco.Web/AspNet/AspNetCookieManager.cs +++ b/src/Umbraco.Web/AspNet/AspNetCookieManager.cs @@ -1,3 +1,4 @@ +using System.Web; using Umbraco.Core.Cookie; namespace Umbraco.Web @@ -15,5 +16,20 @@ namespace Umbraco.Web { _httpContextAccessor.HttpContext?.ExpireCookie(cookieName); } + + public string GetCookieValue(string cookieName) + { + return _httpContextAccessor.HttpContext?.Request.GetCookieValue(cookieName); + } + + public void SetCookieValue(string cookieName, string value) + { + _httpContextAccessor.HttpContext?.Response.Cookies.Set(new HttpCookie(cookieName, value)); + } + + public bool HasCookie(string cookieName) + { + return !(GetCookieValue(cookieName) is null); + } } } diff --git a/src/Umbraco.Web/Editors/PreviewController.cs b/src/Umbraco.Web/Editors/PreviewController.cs index 0b7b4e2b43..eedc134d36 100644 --- a/src/Umbraco.Web/Editors/PreviewController.cs +++ b/src/Umbraco.Web/Editors/PreviewController.cs @@ -6,6 +6,7 @@ using System.Web.UI; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Cookie; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Services; @@ -34,6 +35,7 @@ namespace Umbraco.Web.Editors private readonly TreeCollection _treeCollection; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; + private readonly ICookieManager _cookieManager; public PreviewController( UmbracoFeatures features, @@ -46,7 +48,8 @@ namespace Umbraco.Web.Editors IIOHelper ioHelper, TreeCollection treeCollection, IHttpContextAccessor httpContextAccessor, - IHostingEnvironment hostingEnvironment) + IHostingEnvironment hostingEnvironment, + ICookieManager cookieManager) { _features = features; _globalSettings = globalSettings; @@ -59,6 +62,7 @@ namespace Umbraco.Web.Editors _treeCollection = treeCollection; _httpContextAccessor = httpContextAccessor; _hostingEnvironment = hostingEnvironment; + _cookieManager = cookieManager; } [UmbracoAuthorize(redirectToUmbracoLogin: true)] @@ -117,7 +121,7 @@ namespace Umbraco.Web.Editors public ActionResult End(string redir = null) { - var previewToken = Request.GetPreviewCookieValue(); + var previewToken = _cookieManager.GetPreviewCookieValue(); var service = Current.PublishedSnapshotService; service.ExitPreview(previewToken); diff --git a/src/Umbraco.Web/HttpCookieExtensions.cs b/src/Umbraco.Web/HttpCookieExtensions.cs index 5f520653f5..26490771cd 100644 --- a/src/Umbraco.Web/HttpCookieExtensions.cs +++ b/src/Umbraco.Web/HttpCookieExtensions.cs @@ -5,6 +5,7 @@ using System.Net.Http.Headers; using System.Web; using Microsoft.Owin; using Umbraco.Core; +using Umbraco.Core.Cookie; namespace Umbraco.Web { @@ -97,34 +98,18 @@ namespace Umbraco.Web return null; } - public static string GetPreviewCookieValue(this HttpRequestBase request) + public static string GetPreviewCookieValue(this ICookieManager cookieManager) { - return request.GetCookieValue(Constants.Web.PreviewCookieName); + return cookieManager.GetCookieValue(Constants.Web.PreviewCookieName); } - - public static string GetPreviewCookieValue(this HttpRequest request) - { - return new HttpRequestWrapper(request).GetPreviewCookieValue(); - } - /// /// Does a preview cookie exist ? /// /// /// - public static bool HasPreviewCookie(this HttpRequestBase request) + public static bool HasPreviewCookie(this ICookieManager cookieManager) { - return request.Cookies[Constants.Web.PreviewCookieName] != null; - } - - /// - /// Does a preview cookie exist ? - /// - /// - /// - public static bool HasPreviewCookie(this HttpRequest request) - { - return new HttpRequestWrapper(request).HasPreviewCookie(); + return cookieManager.HasCookie(Constants.Web.PreviewCookieName); } /// diff --git a/src/Umbraco.Web/Install/FilePermissionHelper.cs b/src/Umbraco.Web/Install/FilePermissionHelper.cs index 16de66554f..be7c88729a 100644 --- a/src/Umbraco.Web/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Web/Install/FilePermissionHelper.cs @@ -11,7 +11,7 @@ using Umbraco.Web.PublishedCache; namespace Umbraco.Web.Install { - internal class FilePermissionHelper : IFilePermissionHelper + public class FilePermissionHelper : IFilePermissionHelper { // ensure that these directories exist and Umbraco can write to them private readonly string[] _permissionDirs; @@ -155,11 +155,11 @@ namespace Umbraco.Web.Install // tries to create a file // if successful, the file is deleted // creates the directory if needed - does not delete it - public bool TryCreateDirectory(string dir) + public static bool TryCreateDirectory(string dir, IIOHelper ioHelper) { try { - var dirPath = _ioHelper.MapPath(dir); + var dirPath = ioHelper.MapPath(dir); if (Directory.Exists(dirPath) == false) Directory.CreateDirectory(dirPath); @@ -262,7 +262,7 @@ namespace Umbraco.Web.Install } } - private string CreateRandomName() + private static string CreateRandomName() { return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8); } diff --git a/src/Umbraco.Web/Install/InstallHelper.cs b/src/Umbraco.Web/Install/InstallHelper.cs index 8be0af629e..fb37246a21 100644 --- a/src/Umbraco.Web/Install/InstallHelper.cs +++ b/src/Umbraco.Web/Install/InstallHelper.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Cookie; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Persistence; @@ -23,11 +24,12 @@ namespace Umbraco.Web.Install private readonly IGlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; private readonly IConnectionStrings _connectionStrings; + private readonly ICookieManager _cookieManager; private InstallationType? _installationType; public InstallHelper(IHttpContextAccessor httpContextAccessor, DatabaseBuilder databaseBuilder, - ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IConnectionStrings connectionStrings) + ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IConnectionStrings connectionStrings, ICookieManager cookieManager) { _httpContextAccessor = httpContextAccessor; _logger = logger; @@ -35,6 +37,7 @@ namespace Umbraco.Web.Install _umbracoVersion = umbracoVersion; _databaseBuilder = databaseBuilder; _connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings)); + _cookieManager = cookieManager; } public InstallationType GetInstallationType() @@ -53,7 +56,7 @@ namespace Umbraco.Web.Install // Check for current install Id var installId = Guid.NewGuid(); - var installCookie = httpContext.Request.GetCookieValue(Constants.Web.InstallerCookieName); + var installCookie = _cookieManager.GetCookieValue(Constants.Web.InstallerCookieName); if (string.IsNullOrEmpty(installCookie) == false) { if (Guid.TryParse(installCookie, out installId)) @@ -63,7 +66,8 @@ namespace Umbraco.Web.Install installId = Guid.NewGuid(); } } - httpContext.Response.Cookies.Set(new HttpCookie(Constants.Web.InstallerCookieName, "1")); + + _cookieManager.SetCookieValue(Constants.Web.InstallerCookieName, "1"); var dbProvider = string.Empty; if (IsBrandNewInstall == false) diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index a776c4f65e..013f54c5fc 100755 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -7,6 +7,7 @@ using System.Text; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Cookie; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -27,10 +28,11 @@ namespace Umbraco.Web.Macros private readonly AppCaches _appCaches; private readonly IMacroService _macroService; private readonly IIOHelper _ioHelper; + private readonly ICookieManager _cookieManager; private readonly IUserService _userService; private readonly IHttpContextAccessor _httpContextAccessor; - public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService, IHttpContextAccessor httpContextAccessor, IIOHelper ioHelper) + public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService, IHttpContextAccessor httpContextAccessor, IIOHelper ioHelper, ICookieManager cookieManager) { _plogger = plogger ?? throw new ArgumentNullException(nameof(plogger)); _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); @@ -39,6 +41,7 @@ namespace Umbraco.Web.Macros _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); + _cookieManager = cookieManager; _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _httpContextAccessor = httpContextAccessor; } @@ -419,7 +422,7 @@ namespace Umbraco.Web.Macros case '%': attributeValue = context?.Session[name]?.ToString(); if (string.IsNullOrEmpty(attributeValue)) - attributeValue = context?.Request.GetCookieValue(name); + attributeValue = _cookieManager.GetCookieValue(name); break; case '#': attributeValue = pageElements[name]?.ToString(); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index cb4c3cf69a..fdb00827b8 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -192,9 +192,6 @@ - - - @@ -209,7 +206,6 @@ - @@ -219,7 +215,6 @@ - @@ -302,7 +297,6 @@ - @@ -334,7 +328,6 @@ - @@ -416,7 +409,6 @@ - @@ -490,7 +482,6 @@ - True @@ -553,10 +544,8 @@ - - diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 2dacc60e73..6a51157285 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -2,6 +2,7 @@ using System; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Cookie; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; @@ -20,6 +21,7 @@ namespace Umbraco.Web private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly UriUtility _uriUtility; + private readonly ICookieManager _cookieManager; private readonly Lazy _publishedSnapshot; private string _previewToken; private bool? _previewing; @@ -34,7 +36,8 @@ namespace Umbraco.Web IGlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor, IIOHelper ioHelper, - UriUtility uriUtility) + UriUtility uriUtility, + ICookieManager cookieManager) { if (httpContextAccessor == null) throw new ArgumentNullException(nameof(httpContextAccessor)); if (publishedSnapshotService == null) throw new ArgumentNullException(nameof(publishedSnapshotService)); @@ -44,6 +47,7 @@ namespace Umbraco.Web _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); _uriUtility = uriUtility; + _cookieManager = cookieManager; // 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. @@ -183,7 +187,7 @@ namespace Umbraco.Web && request.Url.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings, _ioHelper) == false && Security.CurrentUser != null) { - var previewToken = request.GetPreviewCookieValue(); // may be null or empty + var previewToken = _cookieManager.GetPreviewCookieValue(); // may be null or empty _previewToken = previewToken.IsNullOrWhiteSpace() ? null : previewToken; } diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index d627d9e823..edbf7d1196 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text; using Umbraco.Core.Configuration; +using Umbraco.Core.Cookie; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -26,6 +27,7 @@ namespace Umbraco.Web private readonly IUserService _userService; private readonly IIOHelper _ioHelper; private readonly IHttpContextAccessor _httpContextAccessor; + private readonly ICookieManager _cookieManager; private readonly UriUtility _uriUtility; /// @@ -40,7 +42,8 @@ namespace Umbraco.Web IUserService userService, IIOHelper ioHelper, UriUtility uriUtility, - IHttpContextAccessor httpContextAccessor) + IHttpContextAccessor httpContextAccessor, + ICookieManager cookieManager) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); @@ -51,6 +54,7 @@ namespace Umbraco.Web _ioHelper = ioHelper; _uriUtility = uriUtility; _httpContextAccessor = httpContextAccessor; + _cookieManager = cookieManager; } private IUmbracoContext CreateUmbracoContext() @@ -69,7 +73,7 @@ namespace Umbraco.Web var webSecurity = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper); - return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility); + return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility, _cookieManager); } /// From e69ef327a93d8a8398f7110ca41f44d263305a7e Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 19 Feb 2020 13:33:04 +0100 Subject: [PATCH 05/10] Moved Editor stuff that was not controllers --- .../Editors/EditorModelEventArgs.cs | 0 .../Editors/EditorValidatorCollection.cs | 0 .../EditorValidatorCollectionBuilder.cs | 0 .../Editors/EditorValidatorOfT.cs | 0 .../Editors/IEditorValidator.cs | 0 .../Editors/UserEditorAuthorizationHelper.cs | 2 +- .../Editors/ContentTypeController.cs | 5 ++-- .../Editors/ContentTypeControllerBase.cs | 23 +++++++++++++-- src/Umbraco.Web/Editors/EditorValidator.cs | 29 ------------------- .../DataTypeValidateAttribute.cs | 0 .../Editors/MediaTypeController.cs | 5 ++-- .../Editors/MemberTypeController.cs | 5 ++-- src/Umbraco.Web/Umbraco.Web.csproj | 18 ++---------- 13 files changed, 33 insertions(+), 54 deletions(-) rename src/{Umbraco.Web => Umbraco.Abstractions}/Editors/EditorModelEventArgs.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Editors/EditorValidatorCollection.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Editors/EditorValidatorCollectionBuilder.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Editors/EditorValidatorOfT.cs (100%) rename src/{Umbraco.Web => Umbraco.Abstractions}/Editors/IEditorValidator.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Editors/UserEditorAuthorizationHelper.cs (99%) delete mode 100644 src/Umbraco.Web/Editors/EditorValidator.cs rename src/Umbraco.Web/Editors/{ => Filters}/DataTypeValidateAttribute.cs (100%) diff --git a/src/Umbraco.Web/Editors/EditorModelEventArgs.cs b/src/Umbraco.Abstractions/Editors/EditorModelEventArgs.cs similarity index 100% rename from src/Umbraco.Web/Editors/EditorModelEventArgs.cs rename to src/Umbraco.Abstractions/Editors/EditorModelEventArgs.cs diff --git a/src/Umbraco.Web/Editors/EditorValidatorCollection.cs b/src/Umbraco.Abstractions/Editors/EditorValidatorCollection.cs similarity index 100% rename from src/Umbraco.Web/Editors/EditorValidatorCollection.cs rename to src/Umbraco.Abstractions/Editors/EditorValidatorCollection.cs diff --git a/src/Umbraco.Web/Editors/EditorValidatorCollectionBuilder.cs b/src/Umbraco.Abstractions/Editors/EditorValidatorCollectionBuilder.cs similarity index 100% rename from src/Umbraco.Web/Editors/EditorValidatorCollectionBuilder.cs rename to src/Umbraco.Abstractions/Editors/EditorValidatorCollectionBuilder.cs diff --git a/src/Umbraco.Web/Editors/EditorValidatorOfT.cs b/src/Umbraco.Abstractions/Editors/EditorValidatorOfT.cs similarity index 100% rename from src/Umbraco.Web/Editors/EditorValidatorOfT.cs rename to src/Umbraco.Abstractions/Editors/EditorValidatorOfT.cs diff --git a/src/Umbraco.Web/Editors/IEditorValidator.cs b/src/Umbraco.Abstractions/Editors/IEditorValidator.cs similarity index 100% rename from src/Umbraco.Web/Editors/IEditorValidator.cs rename to src/Umbraco.Abstractions/Editors/IEditorValidator.cs diff --git a/src/Umbraco.Web/Editors/UserEditorAuthorizationHelper.cs b/src/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelper.cs similarity index 99% rename from src/Umbraco.Web/Editors/UserEditorAuthorizationHelper.cs rename to src/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelper.cs index 320580aaf9..63b5cc90dc 100644 --- a/src/Umbraco.Web/Editors/UserEditorAuthorizationHelper.cs +++ b/src/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelper.cs @@ -8,7 +8,7 @@ using Umbraco.Core.Services; namespace Umbraco.Web.Editors { - internal class UserEditorAuthorizationHelper + public class UserEditorAuthorizationHelper { private readonly IContentService _contentService; private readonly IMediaService _mediaService; diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 8cbe51054a..fc7189cf6f 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -68,8 +68,9 @@ namespace Umbraco.Web.Editors IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper, IIOHelper ioHelper, - IPublishedUrlProvider publishedUrlProvider) - : base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + EditorValidatorCollection editorValidatorCollection) + : base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider, editorValidatorCollection) { _serializer = serializer; _globalSettings = globalSettings; diff --git a/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs b/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs index 4abd7d8c02..bca8c28f64 100644 --- a/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs +++ b/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs @@ -5,6 +5,7 @@ using System.Net; using System.Net.Http; using System.Text; using System.Web.Http; +using System.Web.Http.ModelBinding; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; @@ -31,6 +32,8 @@ namespace Umbraco.Web.Editors public abstract class ContentTypeControllerBase : UmbracoAuthorizedJsonController where TContentType : class, IContentTypeComposition { + private readonly EditorValidatorCollection _editorValidatorCollection; + protected ContentTypeControllerBase( ICultureDictionary cultureDictionary, IGlobalSettings globalSettings, @@ -43,9 +46,11 @@ namespace Umbraco.Web.Editors UmbracoHelper umbracoHelper, IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + EditorValidatorCollection editorValidatorCollection) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider) { + _editorValidatorCollection = editorValidatorCollection; CultureDictionary = cultureDictionary; } @@ -272,7 +277,7 @@ namespace Umbraco.Web.Editors } // execute the external validators - EditorValidator.Validate(ModelState, contentTypeSave); + ValidateExternalValidators(ModelState, contentTypeSave); if (ModelState.IsValid == false) { @@ -364,6 +369,20 @@ namespace Umbraco.Web.Editors } } + private void ValidateExternalValidators(ModelStateDictionary modelState, object model) + { + var modelType = model.GetType(); + + var validationResults = _editorValidatorCollection + .Where(x => x.ModelType == modelType) + .SelectMany(x => x.Validate(model)) + .Where(x => !string.IsNullOrWhiteSpace(x.ErrorMessage) && x.MemberNames.Any()); + + foreach (var r in validationResults) + foreach (var m in r.MemberNames) + modelState.AddModelError(m, r.ErrorMessage); + } + /// /// Move /// diff --git a/src/Umbraco.Web/Editors/EditorValidator.cs b/src/Umbraco.Web/Editors/EditorValidator.cs deleted file mode 100644 index af355206a5..0000000000 --- a/src/Umbraco.Web/Editors/EditorValidator.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Linq; -using System.Web.Http.ModelBinding; -using Umbraco.Web.Composing; - -namespace Umbraco.Web.Editors -{ - /// - /// Provides a method to validate an object using validation. - /// - internal static class EditorValidator - { - /// - /// Validates an object. - /// - public static void Validate(ModelStateDictionary modelState, object model) - { - var modelType = model.GetType(); - - var validationResults = Current.EditorValidators // TODO: inject - .Where(x => x.ModelType == modelType) - .SelectMany(x => x.Validate(model)) - .Where(x => !string.IsNullOrWhiteSpace(x.ErrorMessage) && x.MemberNames.Any()); - - foreach (var r in validationResults) - foreach (var m in r.MemberNames) - modelState.AddModelError(m, r.ErrorMessage); - } - } -} diff --git a/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs b/src/Umbraco.Web/Editors/Filters/DataTypeValidateAttribute.cs similarity index 100% rename from src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs rename to src/Umbraco.Web/Editors/Filters/DataTypeValidateAttribute.cs diff --git a/src/Umbraco.Web/Editors/MediaTypeController.cs b/src/Umbraco.Web/Editors/MediaTypeController.cs index 7aa2c028a2..f4c8f89e28 100644 --- a/src/Umbraco.Web/Editors/MediaTypeController.cs +++ b/src/Umbraco.Web/Editors/MediaTypeController.cs @@ -55,8 +55,9 @@ namespace Umbraco.Web.Editors IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper, IEntityService entityService, - IPublishedUrlProvider publishedUrlProvider) - : base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + EditorValidatorCollection editorValidatorCollection) + : base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider, editorValidatorCollection) { _shortStringHelper = shortStringHelper; _entityService = entityService ?? throw new ArgumentNullException(nameof(entityService)); diff --git a/src/Umbraco.Web/Editors/MemberTypeController.cs b/src/Umbraco.Web/Editors/MemberTypeController.cs index 9176de3e37..fd071d5e5c 100644 --- a/src/Umbraco.Web/Editors/MemberTypeController.cs +++ b/src/Umbraco.Web/Editors/MemberTypeController.cs @@ -42,8 +42,9 @@ namespace Umbraco.Web.Editors UmbracoHelper umbracoHelper, IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper, - IPublishedUrlProvider publishedUrlProvider) - : base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider) + IPublishedUrlProvider publishedUrlProvider, + EditorValidatorCollection editorValidatorCollection) + : base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider, editorValidatorCollection) { } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 065dd1da96..aa32de01bc 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -141,7 +141,9 @@ + + @@ -149,8 +151,6 @@ - - @@ -195,11 +195,6 @@ - - - - - @@ -258,10 +253,6 @@ - - - - @@ -273,7 +264,6 @@ - @@ -288,14 +278,11 @@ - - - @@ -375,7 +362,6 @@ - From 46a68d1b865d311f1d82e46bbb7f3ed09837f71f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 20 Feb 2020 09:00:50 +0100 Subject: [PATCH 06/10] Rename file to align with class name --- .../Features/{IUmbracoFeatureController.cs => IUmbracoFeature.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Umbraco.Abstractions/Features/{IUmbracoFeatureController.cs => IUmbracoFeature.cs} (100%) diff --git a/src/Umbraco.Abstractions/Features/IUmbracoFeatureController.cs b/src/Umbraco.Abstractions/Features/IUmbracoFeature.cs similarity index 100% rename from src/Umbraco.Abstractions/Features/IUmbracoFeatureController.cs rename to src/Umbraco.Abstractions/Features/IUmbracoFeature.cs From bbe9aa184897cf8cec79ffcab40e95fad0c6f8fc Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 20 Feb 2020 09:05:42 +0100 Subject: [PATCH 07/10] Fix issue with NuCache knowing the web project --- .../Install/FilePermissionDirectoryHelper.cs | 39 +++++++++++++++++++ .../PublishedSnapshotService.cs | 2 +- .../Umbraco.PublishedCache.NuCache.csproj | 1 - .../Install/FilePermissionHelper.cs | 32 +-------------- 4 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 src/Umbraco.Abstractions/Install/FilePermissionDirectoryHelper.cs diff --git a/src/Umbraco.Abstractions/Install/FilePermissionDirectoryHelper.cs b/src/Umbraco.Abstractions/Install/FilePermissionDirectoryHelper.cs new file mode 100644 index 0000000000..bc57083cbd --- /dev/null +++ b/src/Umbraco.Abstractions/Install/FilePermissionDirectoryHelper.cs @@ -0,0 +1,39 @@ +using System; +using System.IO; +using Umbraco.Core.IO; + +namespace Umbraco.Web.Install +{ + public class FilePermissionDirectoryHelper + { + + + // tries to create a file + // if successful, the file is deleted + // creates the directory if needed - does not delete it + public static bool TryCreateDirectory(string dir, IIOHelper ioHelper) + { + try + { + var dirPath = ioHelper.MapPath(dir); + + if (Directory.Exists(dirPath) == false) + Directory.CreateDirectory(dirPath); + + var filePath = dirPath + "/" + CreateRandomFileName() + ".tmp"; + File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it."); + File.Delete(filePath); + return true; + } + catch + { + return false; + } + } + + public static string CreateRandomFileName() + { + return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8); + } + } +} diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index e383eb0223..029978347a 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -364,7 +364,7 @@ namespace Umbraco.Web.PublishedCache.NuCache public override bool EnsureEnvironment(out IEnumerable errors) { // must have app_data and be able to write files into it - var ok = FilePermissionHelper.TryCreateDirectory(GetLocalFilesPath(), _ioHelper); + var ok = FilePermissionDirectoryHelper.TryCreateDirectory(GetLocalFilesPath(), _ioHelper); errors = ok ? Enumerable.Empty() : new[] { "NuCache local files." }; return ok; } diff --git a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj index 2001309138..4c369ec2fa 100644 --- a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj +++ b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj @@ -13,7 +13,6 @@ - diff --git a/src/Umbraco.Web/Install/FilePermissionHelper.cs b/src/Umbraco.Web/Install/FilePermissionHelper.cs index be7c88729a..be4c2b1dd0 100644 --- a/src/Umbraco.Web/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Web/Install/FilePermissionHelper.cs @@ -141,7 +141,7 @@ namespace Umbraco.Web.Install { try { - var path = _ioHelper.MapPath(dir + "/" + CreateRandomName()); + var path = _ioHelper.MapPath(dir + "/" + FilePermissionDirectoryHelper.CreateRandomFileName()); Directory.CreateDirectory(path); Directory.Delete(path); return true; @@ -152,29 +152,6 @@ namespace Umbraco.Web.Install } } - // tries to create a file - // if successful, the file is deleted - // creates the directory if needed - does not delete it - public static bool TryCreateDirectory(string dir, IIOHelper ioHelper) - { - try - { - var dirPath = ioHelper.MapPath(dir); - - if (Directory.Exists(dirPath) == false) - Directory.CreateDirectory(dirPath); - - var filePath = dirPath + "/" + CreateRandomName() + ".tmp"; - File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it."); - File.Delete(filePath); - return true; - } - catch - { - return false; - } - } - // tries to create a file // if successful, the file is deleted // @@ -194,7 +171,7 @@ namespace Umbraco.Web.Install if (canWrite) { - var filePath = dirPath + "/" + CreateRandomName() + ".tmp"; + var filePath = dirPath + "/" + FilePermissionDirectoryHelper.CreateRandomFileName() + ".tmp"; File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it."); File.Delete(filePath); return true; @@ -261,10 +238,5 @@ namespace Umbraco.Web.Install return false; } } - - private static string CreateRandomName() - { - return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8); - } } } From 8c0e50ccd6bfa43be0df387d6ef00ef46b4cc540 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 20 Feb 2020 09:25:26 +0100 Subject: [PATCH 08/10] Fix issue in Test project still referencing Umbraco.Examine --- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 16e4ca2c11..a490ba8b6a 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -569,10 +569,6 @@ {0fad7d2a-d7dd-45b1-91fd-488bb6cdacea} Umbraco.Examine.Lucene - - {f9b7fe05-0f93-4d0d-9c10-690b33ecbbd8} - Umbraco.Examine - {3ae7bf57-966b-45a5-910a-954d7c554441} Umbraco.Infrastructure From 329ad4324e6da3cb370614a8b910a7b873ae7856 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 24 Feb 2020 10:53:54 +0100 Subject: [PATCH 09/10] Removed file --- src/Umbraco.Examine/Umbraco.Examine.csproj | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/Umbraco.Examine/Umbraco.Examine.csproj diff --git a/src/Umbraco.Examine/Umbraco.Examine.csproj b/src/Umbraco.Examine/Umbraco.Examine.csproj deleted file mode 100644 index afccc5762f..0000000000 --- a/src/Umbraco.Examine/Umbraco.Examine.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - netstandard2.0 - Umbraco.Examine - Umbraco.Examine - - - - - - - - - - - - - From 6bb920b457701967892489107803847b1250e3c7 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 25 Feb 2020 07:57:59 +0100 Subject: [PATCH 10/10] Added comments, and replaced a static helper with extension methods --- src/Umbraco.Core/Features/IUmbracoFeature.cs | 3 +++ src/Umbraco.Core/IO/IIOHelper.cs | 1 + .../IOHelperExtensions.cs} | 24 +++++++++---------- .../Sync/IBatchedDatabaseServerMessenger.cs | 3 +++ .../Trees/IMenuItemCollectionFactory.cs | 8 +++++++ src/Umbraco.Core/UmbracoEvents.cs | 10 -------- .../PublishedSnapshotService.cs | 2 +- .../Controllers/InstallApiController.cs | 10 +++++++- .../Install/FilePermissionHelper.cs | 4 ++-- .../Trees/FileSystemTreeController.cs | 15 ++++++------ 10 files changed, 46 insertions(+), 34 deletions(-) rename src/Umbraco.Core/{Install/FilePermissionDirectoryHelper.cs => IO/IOHelperExtensions.cs} (55%) delete mode 100644 src/Umbraco.Core/UmbracoEvents.cs diff --git a/src/Umbraco.Core/Features/IUmbracoFeature.cs b/src/Umbraco.Core/Features/IUmbracoFeature.cs index 0187cdecb0..ccb80b0a9f 100644 --- a/src/Umbraco.Core/Features/IUmbracoFeature.cs +++ b/src/Umbraco.Core/Features/IUmbracoFeature.cs @@ -1,5 +1,8 @@ namespace Umbraco.Web.Features { + /// + /// This is a marker interface to allow controllers to be disabled if also marked with FeatureAuthorizeAttribute. + /// public interface IUmbracoFeature { diff --git a/src/Umbraco.Core/IO/IIOHelper.cs b/src/Umbraco.Core/IO/IIOHelper.cs index e8ef6d2973..11f5c6c565 100644 --- a/src/Umbraco.Core/IO/IIOHelper.cs +++ b/src/Umbraco.Core/IO/IIOHelper.cs @@ -75,5 +75,6 @@ namespace Umbraco.Core.IO get; set; //Only required for unit tests } + } } diff --git a/src/Umbraco.Core/Install/FilePermissionDirectoryHelper.cs b/src/Umbraco.Core/IO/IOHelperExtensions.cs similarity index 55% rename from src/Umbraco.Core/Install/FilePermissionDirectoryHelper.cs rename to src/Umbraco.Core/IO/IOHelperExtensions.cs index bc57083cbd..64b57e7dc1 100644 --- a/src/Umbraco.Core/Install/FilePermissionDirectoryHelper.cs +++ b/src/Umbraco.Core/IO/IOHelperExtensions.cs @@ -1,17 +1,17 @@ -using System; +using System; using System.IO; -using Umbraco.Core.IO; -namespace Umbraco.Web.Install +namespace Umbraco.Core.IO { - public class FilePermissionDirectoryHelper + public static class IOHelperExtensions { - - - // tries to create a file - // if successful, the file is deleted - // creates the directory if needed - does not delete it - public static bool TryCreateDirectory(string dir, IIOHelper ioHelper) + /// + /// Tries to create a directory. + /// + /// The IOHelper. + /// the directory path. + /// true if the directory was created, false otherwise. + public static bool TryCreateDirectory(this IIOHelper ioHelper, string dir) { try { @@ -20,7 +20,7 @@ namespace Umbraco.Web.Install if (Directory.Exists(dirPath) == false) Directory.CreateDirectory(dirPath); - var filePath = dirPath + "/" + CreateRandomFileName() + ".tmp"; + var filePath = dirPath + "/" + CreateRandomFileName(ioHelper) + ".tmp"; File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it."); File.Delete(filePath); return true; @@ -31,7 +31,7 @@ namespace Umbraco.Web.Install } } - public static string CreateRandomFileName() + public static string CreateRandomFileName(this IIOHelper ioHelper) { return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8); } diff --git a/src/Umbraco.Core/Sync/IBatchedDatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/IBatchedDatabaseServerMessenger.cs index f1b887ca3f..d63478ef96 100644 --- a/src/Umbraco.Core/Sync/IBatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/IBatchedDatabaseServerMessenger.cs @@ -1,5 +1,8 @@ namespace Umbraco.Core.Sync { + /// + /// An implementation that works by storing messages in the database. + /// public interface IBatchedDatabaseServerMessenger : IServerMessenger { void FlushBatch(); diff --git a/src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs b/src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs index 64feba8cd8..dc4c53bac9 100644 --- a/src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs +++ b/src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs @@ -2,8 +2,16 @@ using Umbraco.Web.Models.Trees; namespace Umbraco.Web.Trees { + + /// + /// Represents a factory to create . + /// public interface IMenuItemCollectionFactory { + /// + /// Creates an empty . + /// + /// An empty . MenuItemCollection Create(); } } diff --git a/src/Umbraco.Core/UmbracoEvents.cs b/src/Umbraco.Core/UmbracoEvents.cs deleted file mode 100644 index fe138425aa..0000000000 --- a/src/Umbraco.Core/UmbracoEvents.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using Umbraco.Web.Routing; - -namespace Umbraco.Core -{ - public interface IUmbracoRouteEventSender - { - event EventHandler RouteAttempt; - } -} diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index 029978347a..68b7ee596a 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -364,7 +364,7 @@ namespace Umbraco.Web.PublishedCache.NuCache public override bool EnsureEnvironment(out IEnumerable errors) { // must have app_data and be able to write files into it - var ok = FilePermissionDirectoryHelper.TryCreateDirectory(GetLocalFilesPath(), _ioHelper); + var ok = _ioHelper.TryCreateDirectory(GetLocalFilesPath()); errors = ok ? Enumerable.Empty() : new[] { "NuCache local files." }; return ok; } diff --git a/src/Umbraco.Web/Install/Controllers/InstallApiController.cs b/src/Umbraco.Web/Install/Controllers/InstallApiController.cs index c69766cc9d..3b8e9b48d3 100644 --- a/src/Umbraco.Web/Install/Controllers/InstallApiController.cs +++ b/src/Umbraco.Web/Install/Controllers/InstallApiController.cs @@ -201,7 +201,15 @@ namespace Umbraco.Web.Install.Controllers // determines whether the step requires execution internal bool StepRequiresExecution(InstallSetupStep step, object instruction) { - var model = Convert.ChangeType(instruction, step.StepType); + if (step == null) throw new ArgumentNullException(nameof(step)); + + var modelAttempt = instruction.TryConvertTo(step.StepType); + if (!modelAttempt.Success) + { + throw new InvalidCastException($"Cannot cast/convert {step.GetType().FullName} into {step.StepType.FullName}"); + } + + var model = modelAttempt.Result; var genericStepType = typeof(InstallSetupStep<>); Type[] typeArgs = { step.StepType }; var typedStepType = genericStepType.MakeGenericType(typeArgs); diff --git a/src/Umbraco.Web/Install/FilePermissionHelper.cs b/src/Umbraco.Web/Install/FilePermissionHelper.cs index be4c2b1dd0..24649b4391 100644 --- a/src/Umbraco.Web/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Web/Install/FilePermissionHelper.cs @@ -141,7 +141,7 @@ namespace Umbraco.Web.Install { try { - var path = _ioHelper.MapPath(dir + "/" + FilePermissionDirectoryHelper.CreateRandomFileName()); + var path = _ioHelper.MapPath(dir + "/" + _ioHelper.CreateRandomFileName()); Directory.CreateDirectory(path); Directory.Delete(path); return true; @@ -171,7 +171,7 @@ namespace Umbraco.Web.Install if (canWrite) { - var filePath = dirPath + "/" + FilePermissionDirectoryHelper.CreateRandomFileName() + ".tmp"; + var filePath = dirPath + "/" + _ioHelper.CreateRandomFileName() + ".tmp"; File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it."); File.Delete(filePath); return true; diff --git a/src/Umbraco.Web/Trees/FileSystemTreeController.cs b/src/Umbraco.Web/Trees/FileSystemTreeController.cs index bacfc820d6..e4bfbc53f7 100644 --- a/src/Umbraco.Web/Trees/FileSystemTreeController.cs +++ b/src/Umbraco.Web/Trees/FileSystemTreeController.cs @@ -20,11 +20,9 @@ namespace Umbraco.Web.Trees { public abstract class FileSystemTreeController : TreeController { - private readonly IMenuItemCollectionFactory _menuItemCollectionFactory; - protected FileSystemTreeController() { - _menuItemCollectionFactory = Current.MenuItemCollectionFactory; + MenuItemCollectionFactory = Current.MenuItemCollectionFactory; } protected FileSystemTreeController( @@ -41,10 +39,11 @@ namespace Umbraco.Web.Trees IMenuItemCollectionFactory menuItemCollectionFactory) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) { - _menuItemCollectionFactory = menuItemCollectionFactory; + MenuItemCollectionFactory = menuItemCollectionFactory; } protected abstract IFileSystem FileSystem { get; } + protected IMenuItemCollectionFactory MenuItemCollectionFactory { get; } protected abstract string[] Extensions { get; } protected abstract string FileIcon { get; } @@ -120,7 +119,7 @@ namespace Umbraco.Web.Trees protected virtual MenuItemCollection GetMenuForRootNode(FormDataCollection queryStrings) { - var menu = _menuItemCollectionFactory.Create(); + var menu = MenuItemCollectionFactory.Create(); //set the default to create menu.DefaultMenuAlias = ActionNew.ActionAlias; @@ -134,7 +133,7 @@ namespace Umbraco.Web.Trees protected virtual MenuItemCollection GetMenuForFolder(string path, FormDataCollection queryStrings) { - var menu = _menuItemCollectionFactory.Create(); + var menu = MenuItemCollectionFactory.Create(); //set the default to create menu.DefaultMenuAlias = ActionNew.ActionAlias; @@ -158,7 +157,7 @@ namespace Umbraco.Web.Trees protected virtual MenuItemCollection GetMenuForFile(string path, FormDataCollection queryStrings) { - var menu = _menuItemCollectionFactory.Create(); + var menu = MenuItemCollectionFactory.Create(); //if it's not a directory then we only allow to delete the item menu.Items.Add(Services.TextService, opensDialog: true); @@ -174,7 +173,7 @@ namespace Umbraco.Web.Trees return GetMenuForRootNode(queryStrings); } - var menu = _menuItemCollectionFactory.Create(); + var menu = MenuItemCollectionFactory.Create(); var path = string.IsNullOrEmpty(id) == false && id != Constants.System.RootString ? HttpUtility.UrlDecode(id).TrimStart("/")