From 1c50ece9862d76d82af8870d88e6f055a3ec22d7 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 2 Mar 2021 16:20:44 +0100 Subject: [PATCH 1/4] Use c#9 + namespace fix --- src/Umbraco.Core/HybridAccessorBase.cs | 2 +- .../Security/IBackOfficeSecurityFactory.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 5 ---- .../Umbraco.Examine.Lucene.csproj | 1 - .../HostedServices/ScheduledPublishing.cs | 1 - .../Runtime/SqlMainDomLock.cs | 1 + .../Umbraco.Infrastructure.csproj | 1 - .../Umbraco.PublishedCache.NuCache.csproj | 2 -- .../Umbraco.Tests.Common.csproj | 1 - .../UmbracoTestServerTestBase.cs | 4 ++-- .../Testing/UmbracoIntegrationTest.cs | 3 +-- .../Umbraco.Tests.Integration.csproj | 1 - .../Filters/ContentModelValidatorTests.cs | 2 +- .../ScheduledPublishingTests.cs | 2 +- .../Umbraco.Web.BackOffice.csproj | 1 - .../UmbracoBuilderExtensions.cs | 1 - .../Macros/MacroRenderer.cs | 3 +-- .../Middleware/UmbracoRequestMiddleware.cs | 1 - .../Security/BackofficeSecurityFactory.cs | 3 +-- .../Umbraco.Web.Common.csproj | 1 - .../BergViewComponent.cs | 23 +++++++++++++++++++ .../Umbraco.Web.UI.NetCore.csproj | 2 -- .../Umbraco.Web.Website.csproj | 1 - 23 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 src/Umbraco.Web.UI.NetCore/BergViewComponent.cs diff --git a/src/Umbraco.Core/HybridAccessorBase.cs b/src/Umbraco.Core/HybridAccessorBase.cs index 9843efdfe1..06713aa59e 100644 --- a/src/Umbraco.Core/HybridAccessorBase.cs +++ b/src/Umbraco.Core/HybridAccessorBase.cs @@ -77,7 +77,7 @@ namespace Umbraco.Cms.Core return; } - if (!(o is T value)) + if (o is not T value) { throw new ArgumentException($"Expected type {typeof(T).FullName}, got {o.GetType().FullName}", nameof(o)); } diff --git a/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs b/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs index 423332ed42..ee553e85e6 100644 --- a/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs +++ b/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Core.Security +namespace Umbraco.Cms.Core.Security { /// /// Creates and manages instances. diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 2f38e4953b..1166bc1270 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -2,13 +2,8 @@ netstandard2.0 - 8 Umbraco.Cms.Core - 0.5.0 - 0.5.0 - 0.5.0 Umbraco CMS - Umbraco.Core diff --git a/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj b/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj index 71f10f003b..d0419abe6b 100644 --- a/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj +++ b/src/Umbraco.Examine.Lucene/Umbraco.Examine.Lucene.csproj @@ -4,7 +4,6 @@ net472 Umbraco.Cms.Infrastructure.Examine Umbraco CMS - Umbraco.Examine Umbraco.Examine.Lucene diff --git a/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs b/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs index f5f5ee22a2..0fc1809250 100644 --- a/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs +++ b/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs @@ -12,7 +12,6 @@ using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Sync; using Umbraco.Cms.Core.Web; -using Umbraco.Core.Security; namespace Umbraco.Cms.Infrastructure.HostedServices { diff --git a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs index 22fa172874..e8f5072e18 100644 --- a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs @@ -80,6 +80,7 @@ _hostingEnvironment = hostingEnvironment; { db = _dbFactory.CreateDatabase(); + _hasTable = db.HasTable(Cms.Core.Constants.DatabaseSchema.Tables.KeyValue); if (!_hasTable) { diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index cd49b2abb1..61bd171336 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -2,7 +2,6 @@ netstandard2.0 - 8 Umbraco.Cms.Infrastructure diff --git a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj index 8973054260..fe3ce47de4 100644 --- a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj +++ b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj @@ -3,8 +3,6 @@ netstandard2.0 Umbraco.Cms.Infrastructure.PublishedCache - 8 - Umbraco.Infrastructure.PublishedCache diff --git a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj index b02c1a5a29..870e33e3cb 100644 --- a/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj +++ b/src/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj @@ -2,7 +2,6 @@ netstandard2.0 - latest Umbraco.Cms.Tests.Common diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index 60a48f3f4c..dbb2adef89 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -14,9 +14,11 @@ using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.DependencyInjection; @@ -24,9 +26,7 @@ using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Cms.Web.BackOffice.Controllers; using Umbraco.Cms.Web.Common.Controllers; using Umbraco.Cms.Web.Website.Controllers; -using Umbraco.Core.Security; using Umbraco.Extensions; -using Constants = Umbraco.Cms.Core.Constants; namespace Umbraco.Cms.Tests.Integration.TestServerTest { diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index d3625d109a..133320b853 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -25,6 +25,7 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Core.Web; @@ -36,9 +37,7 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.DependencyInjection; using Umbraco.Cms.Tests.Integration.Extensions; using Umbraco.Cms.Tests.Integration.Implementations; -using Umbraco.Core.Security; using Umbraco.Extensions; -using Constants = Umbraco.Cms.Core.Constants; namespace Umbraco.Cms.Tests.Integration.Testing { diff --git a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj index 18cc68996d..f45a7bc444 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj +++ b/src/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj @@ -4,7 +4,6 @@ Exe net5.0 false - 8 Umbraco.Cms.Tests.Integration diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs index 3e54039714..91432f142e 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs @@ -16,6 +16,7 @@ using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.ContentEditing; using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; @@ -24,7 +25,6 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Cms.Web.BackOffice.Filters; using Umbraco.Cms.Web.BackOffice.ModelBinders; -using Umbraco.Core.Security; using Umbraco.Extensions; using DataType = Umbraco.Cms.Core.Models.DataType; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs index 3782a8aece..3ef434edab 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs @@ -8,12 +8,12 @@ using Moq; using NUnit.Framework; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Runtime; +using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Sync; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Infrastructure; using Umbraco.Cms.Infrastructure.HostedServices; -using Umbraco.Core.Security; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices { diff --git a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj index 8a1a0ebcdf..e66bfb1577 100644 --- a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj +++ b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj @@ -3,7 +3,6 @@ net5.0 Library - latest Umbraco.Cms.Web.BackOffice diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs index 1d636706f7..6c11b91a95 100644 --- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs @@ -53,7 +53,6 @@ using Umbraco.Cms.Web.Common.Routing; using Umbraco.Cms.Web.Common.Security; using Umbraco.Cms.Web.Common.Templates; using Umbraco.Cms.Web.Common.UmbracoContext; -using Umbraco.Core.Security; using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; namespace Umbraco.Extensions diff --git a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs index 389267cd61..129936071c 100644 --- a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs @@ -353,13 +353,12 @@ namespace Umbraco.Cms.Web.Common.Macros return Attempt.Fail(new MacroContent { Text = "[macro failed (no content)]" }); } - ILocalizedTextService textService = _textService; return ExecuteMacroWithErrorWrapper(model, $"Executing PartialView: MacroSource=\"{model.MacroSource}\".", "Executed PartialView.", () => _partialViewMacroEngine.Execute(model, content), - () => textService.Localize("errors/macroErrorLoadingPartialView", new[] { model.MacroSource })); + () => _textService.Localize("errors/macroErrorLoadingPartialView", new[] { model.MacroSource })); } diff --git a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs index 2515948bea..467ec29451 100644 --- a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs +++ b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs @@ -14,7 +14,6 @@ using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Infrastructure.PublishedCache; using Umbraco.Cms.Web.Common.Profiler; -using Umbraco.Core.Security; using Umbraco.Extensions; namespace Umbraco.Cms.Web.Common.Middleware diff --git a/src/Umbraco.Web.Common/Security/BackofficeSecurityFactory.cs b/src/Umbraco.Web.Common/Security/BackofficeSecurityFactory.cs index eda7f4b98e..ad0731f790 100644 --- a/src/Umbraco.Web.Common/Security/BackofficeSecurityFactory.cs +++ b/src/Umbraco.Web.Common/Security/BackofficeSecurityFactory.cs @@ -1,7 +1,6 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; -using Umbraco.Core.Security; namespace Umbraco.Cms.Web.Common.Security { diff --git a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj index 2bcf4a3e55..c08204f1cf 100644 --- a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj +++ b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj @@ -3,7 +3,6 @@ net5.0 Library - latest Umbraco.Cms.Web.Common diff --git a/src/Umbraco.Web.UI.NetCore/BergViewComponent.cs b/src/Umbraco.Web.UI.NetCore/BergViewComponent.cs new file mode 100644 index 0000000000..17d9fe6cf1 --- /dev/null +++ b/src/Umbraco.Web.UI.NetCore/BergViewComponent.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNetCore.Mvc; +using Umbraco.Cms.Core.Web; + +namespace Umbraco.Cms.Web.UI.NetCore +{ + public class BergViewComponent : ViewComponent + { + private readonly IUmbracoContextAccessor _umbracoContextAccessor; + + public BergViewComponent(IUmbracoContextAccessor umbracoContextAccessor) + { + _umbracoContextAccessor = umbracoContextAccessor; + } + + public IViewComponentResult Invoke() + { + TempData["BERG"] = "coool"; + + var currentPage = _umbracoContextAccessor.UmbracoContext.PublishedRequest?.PublishedContent; + return View(currentPage); + } + } +} diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj index 4f6bb1240f..104035ed84 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -3,7 +3,6 @@ net5.0 Umbraco.Cms.Web.UI.NetCore - latest Umbraco.Cms.Web.UI.NetCore @@ -22,7 +21,6 @@ - diff --git a/src/Umbraco.Web.Website/Umbraco.Web.Website.csproj b/src/Umbraco.Web.Website/Umbraco.Web.Website.csproj index 8b940ba47b..c38670f45d 100644 --- a/src/Umbraco.Web.Website/Umbraco.Web.Website.csproj +++ b/src/Umbraco.Web.Website/Umbraco.Web.Website.csproj @@ -3,7 +3,6 @@ net5.0 Library - latest Umbraco.Cms.Web.Website From cf6d33f8433bd924409f3e0699b07225cc27847b Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 3 Mar 2021 09:38:02 +1100 Subject: [PATCH 2/4] Update src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs Co-authored-by: Bjarke Berg --- src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs b/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs index 423332ed42..ee553e85e6 100644 --- a/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs +++ b/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Core.Security +namespace Umbraco.Cms.Core.Security { /// /// Creates and manages instances. From e7b96a5214d27974553c55542406ba7c7f57a9d3 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 3 Mar 2021 06:05:42 +0100 Subject: [PATCH 3/4] Change static fields to instance, in singleton --- src/Umbraco.Core/HybridAccessorBase.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/HybridAccessorBase.cs b/src/Umbraco.Core/HybridAccessorBase.cs index 06713aa59e..51a51e0d01 100644 --- a/src/Umbraco.Core/HybridAccessorBase.cs +++ b/src/Umbraco.Core/HybridAccessorBase.cs @@ -18,15 +18,12 @@ namespace Umbraco.Cms.Core { private readonly IRequestCache _requestCache; - // TODO: Do they need to be static?? These are singleton instances IMO they shouldn't be static - // ReSharper disable StaticMemberInGenericType - private static readonly object s_locker = new object(); - private static bool s_registered; - // ReSharper restore StaticMemberInGenericType + private readonly object _locker = new object(); + private readonly bool _registered; private string _itemKey; - protected string ItemKey => _itemKey ?? (_itemKey = GetType().FullName); + protected string ItemKey => _itemKey ??= GetType().FullName; // read // http://blog.stephencleary.com/2013/04/implicit-async-context-asynclocal.html @@ -53,15 +50,15 @@ namespace Umbraco.Cms.Core { _requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache)); - lock (s_locker) + lock (_locker) { // register the itemKey once with SafeCallContext - if (s_registered) + if (_registered) { return; } - s_registered = true; + _registered = true; } // ReSharper disable once VirtualMemberCallInConstructor From c3d6cc0dcd0fe9394aa41fb6a5cd889af1cbb793 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 3 Mar 2021 07:09:49 +0100 Subject: [PATCH 4/4] Revert test view component --- .../BergViewComponent.cs | 23 ------------------- .../Umbraco.Web.UI.NetCore.csproj | 1 + 2 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 src/Umbraco.Web.UI.NetCore/BergViewComponent.cs diff --git a/src/Umbraco.Web.UI.NetCore/BergViewComponent.cs b/src/Umbraco.Web.UI.NetCore/BergViewComponent.cs deleted file mode 100644 index 17d9fe6cf1..0000000000 --- a/src/Umbraco.Web.UI.NetCore/BergViewComponent.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Umbraco.Cms.Core.Web; - -namespace Umbraco.Cms.Web.UI.NetCore -{ - public class BergViewComponent : ViewComponent - { - private readonly IUmbracoContextAccessor _umbracoContextAccessor; - - public BergViewComponent(IUmbracoContextAccessor umbracoContextAccessor) - { - _umbracoContextAccessor = umbracoContextAccessor; - } - - public IViewComponentResult Invoke() - { - TempData["BERG"] = "coool"; - - var currentPage = _umbracoContextAccessor.UmbracoContext.PublishedRequest?.PublishedContent; - return View(currentPage); - } - } -} diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj index 104035ed84..066a27ccee 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -21,6 +21,7 @@ +