From 5e7958514941dd2763e4c714bdb5392515423d48 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 18 Feb 2020 08:32:06 +0100 Subject: [PATCH] Introduced Umbraco.Web.UI.Backoffice --- .../CompositionExtensions.cs | 13 +++-- .../Dashboards/DashboardCollectionBuilder.cs | 0 .../Umbraco.ModelsBuilder.Embedded.csproj | 4 -- .../AspNetCoreHostingEnvironment.cs | 55 +++++++++++++++++++ .../AspNetCoreHttpContextAccessor.cs | 18 ++++++ .../AspNetCore/AspNetCoreIpResolver.cs | 18 ++++++ .../AspNetCore/AspNetCoreSessionIdResolver.cs | 17 ++++++ ...oBackOfficeApplicationBuilderExtensions.cs | 18 ++++++ ...coBackOfficeServiceCollectionExtensions.cs | 13 +++++ .../AspNetCore/UmbracoMiddleware.cs | 21 +++++++ .../CompositionExtensions.cs | 24 -------- .../Umbraco.Web.BackOffice.csproj | 4 +- src/Umbraco.Web.UI.BackOffice/Program.cs | 23 ++++++++ .../Properties/launchSettings.json | 27 +++++++++ src/Umbraco.Web.UI.BackOffice/Startup.cs | 41 ++++++++++++++ .../Umbraco.Web.UI.BackOffice.csproj | 11 ++++ .../appsettings.Development.json | 9 +++ .../appsettings.json | 10 ++++ src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 4 -- src/umbraco.sln | 6 ++ 20 files changed, 298 insertions(+), 38 deletions(-) rename src/{Umbraco.Web.BackOffice => Umbraco.Abstractions}/Dashboards/DashboardCollectionBuilder.cs (100%) create mode 100644 src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs create mode 100644 src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs create mode 100644 src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs create mode 100644 src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreSessionIdResolver.cs create mode 100644 src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs create mode 100644 src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs create mode 100644 src/Umbraco.Web.BackOffice/AspNetCore/UmbracoMiddleware.cs delete mode 100644 src/Umbraco.Web.BackOffice/CompositionExtensions.cs create mode 100644 src/Umbraco.Web.UI.BackOffice/Program.cs create mode 100644 src/Umbraco.Web.UI.BackOffice/Properties/launchSettings.json create mode 100644 src/Umbraco.Web.UI.BackOffice/Startup.cs create mode 100644 src/Umbraco.Web.UI.BackOffice/Umbraco.Web.UI.BackOffice.csproj create mode 100644 src/Umbraco.Web.UI.BackOffice/appsettings.Development.json create mode 100644 src/Umbraco.Web.UI.BackOffice/appsettings.json diff --git a/src/Umbraco.Abstractions/CompositionExtensions.cs b/src/Umbraco.Abstractions/CompositionExtensions.cs index c65cff50d6..10789ef85c 100644 --- a/src/Umbraco.Abstractions/CompositionExtensions.cs +++ b/src/Umbraco.Abstractions/CompositionExtensions.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Umbraco.Core.Composing; +using Umbraco.Core.Composing; +using Umbraco.Web.Dashboards; namespace Umbraco.Core { @@ -16,6 +14,13 @@ namespace Umbraco.Core public static ComponentCollectionBuilder Components(this Composition composition) => composition.WithCollectionBuilder(); + /// + /// Gets the backoffice dashboards collection builder. + /// + /// The composition. + public static DashboardCollectionBuilder Dashboards(this Composition composition) + => composition.WithCollectionBuilder(); + #endregion } } diff --git a/src/Umbraco.Web.BackOffice/Dashboards/DashboardCollectionBuilder.cs b/src/Umbraco.Abstractions/Dashboards/DashboardCollectionBuilder.cs similarity index 100% rename from src/Umbraco.Web.BackOffice/Dashboards/DashboardCollectionBuilder.cs rename to src/Umbraco.Abstractions/Dashboards/DashboardCollectionBuilder.cs diff --git a/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj b/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj index 0ed95c3283..9107c0f9d4 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj +++ b/src/Umbraco.ModelsBuilder.Embedded/Umbraco.ModelsBuilder.Embedded.csproj @@ -109,10 +109,6 @@ {3ae7bf57-966b-45a5-910a-954d7c554441} Umbraco.Infrastructure - - {9b95eef7-63fe-4432-8c63-166be9c1a929} - Umbraco.Web.BackOffice - {651e1350-91b6-44b7-bd60-7207006d7003} Umbraco.Web diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs new file mode 100644 index 0000000000..dbd5ce4f15 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -0,0 +1,55 @@ + +using System; +using Microsoft.AspNetCore.Hosting; +using Umbraco.Core; +using Umbraco.Core.Configuration; + + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + public class AspNetCoreHostingEnvironment : Umbraco.Core.Hosting.IHostingEnvironment + { + private readonly IHostingSettings _hostingSettings; + + public AspNetCoreHostingEnvironment(IHostingSettings hostingSettings, IHostingEnvironment hostingEnvironment) + { + // _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings)); + // SiteName = hostingEnvironment.ApplicationName; + // ApplicationId = hostingEnvironment.ApplicationID; + // ApplicationPhysicalPath = hostingEnvironment.WebRootPath; + // ApplicationVirtualPath = hostingEnvironment.ApplicationVirtualPath; + // CurrentDomainId = AppDomain.CurrentDomain.Id; + // IISVersion = HttpRuntime.IISVersion; + } + + public string SiteName { get; } + public string ApplicationId { get; } + public string ApplicationPhysicalPath { get; } + public string LocalTempPath { get; } + public string ApplicationVirtualPath { get; } + public int CurrentDomainId { get; } + public bool IsDebugMode { get; } + public bool IsHosted { get; } + public Version IISVersion { get; } + public string MapPath(string path) => throw new NotImplementedException(); + + public string ToAbsolute(string virtualPath, string root) => throw new NotImplementedException(); + + public void LazyRestartApplication() + { + throw new NotImplementedException(); + } + + public void RegisterObject(IRegisteredObject registeredObject) + { + throw new NotImplementedException(); + } + + public void UnregisterObject(IRegisteredObject registeredObject) + { + throw new NotImplementedException(); + } + } + + +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs new file mode 100644 index 0000000000..31aefdee89 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs @@ -0,0 +1,18 @@ +using System; +using System.Web; +using Microsoft.AspNetCore.Http; + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + internal class AspNetCoreHttpContextAccessor //: IHttpContextAccessor + { + private readonly IHttpContextAccessor _httpContextAccessor; + + public AspNetCoreHttpContextAccessor(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + public HttpContext HttpContext => _httpContextAccessor.HttpContext; + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs new file mode 100644 index 0000000000..e6be7449e1 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs @@ -0,0 +1,18 @@ +using System; +using Microsoft.AspNetCore.Http; +using Umbraco.Net; + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + internal class AspNetIpResolver : IIpResolver + { + private readonly IHttpContextAccessor _httpContextAccessor; + + public AspNetIpResolver(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + public string GetCurrentRequestIpAddress() => _httpContextAccessor?.HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? String.Empty; + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreSessionIdResolver.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreSessionIdResolver.cs new file mode 100644 index 0000000000..abc043f9c5 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreSessionIdResolver.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Http; +using Umbraco.Net; + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + internal class AspNetSessionIdResolver : ISessionIdResolver + { + private readonly IHttpContextAccessor _httpContextAccessor; + + public AspNetSessionIdResolver(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + public string SessionId => _httpContextAccessor?.HttpContext.Session?.Id; + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs new file mode 100644 index 0000000000..b1339c476f --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs @@ -0,0 +1,18 @@ +using System; +using Microsoft.AspNetCore.Builder; + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + public static class UmbracoBackOfficeApplicationBuilderExtensions + { + public static IApplicationBuilder UseUmbracoBackOffice(this IApplicationBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + return builder.UseMiddleware(); + } + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs new file mode 100644 index 0000000000..700398b9c1 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + public static class UmbracoBackOfficeServiceCollectionExtensions + { + public static IServiceCollection AddUmbracoBackOffice(this IServiceCollection services) + { + return services; + } + + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoMiddleware.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoMiddleware.cs new file mode 100644 index 0000000000..8c1eac78dd --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoMiddleware.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + public class UmbracoMiddleware + { + private readonly RequestDelegate _next; + public UmbracoMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task InvokeAsync(HttpContext context) + { + + // Call the next delegate/middleware in the pipeline + await _next(context); + } + } +} diff --git a/src/Umbraco.Web.BackOffice/CompositionExtensions.cs b/src/Umbraco.Web.BackOffice/CompositionExtensions.cs deleted file mode 100644 index eaf75bd7e5..0000000000 --- a/src/Umbraco.Web.BackOffice/CompositionExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Umbraco.Core.Composing; -using Umbraco.Web.Dashboards; - -// ReSharper disable once CheckNamespace -namespace Umbraco.Web -{ - /// - /// Provides extension methods to the class. - /// - public static class WebCompositionExtensions - { - #region Collection Builders - - /// - /// Gets the backoffice dashboards collection builder. - /// - /// The composition. - public static DashboardCollectionBuilder Dashboards(this Composition composition) - => composition.WithCollectionBuilder(); - - #endregion - - } -} diff --git a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj index 06939a3266..96417c85bf 100644 --- a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj +++ b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj @@ -1,7 +1,7 @@ - + - netstandard2.0 + netcoreapp3.1 diff --git a/src/Umbraco.Web.UI.BackOffice/Program.cs b/src/Umbraco.Web.UI.BackOffice/Program.cs new file mode 100644 index 0000000000..736649bb51 --- /dev/null +++ b/src/Umbraco.Web.UI.BackOffice/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Umbraco.Web.UI.BackOffice +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); + } +} diff --git a/src/Umbraco.Web.UI.BackOffice/Properties/launchSettings.json b/src/Umbraco.Web.UI.BackOffice/Properties/launchSettings.json new file mode 100644 index 0000000000..b145249bb5 --- /dev/null +++ b/src/Umbraco.Web.UI.BackOffice/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:36804", + "sslPort": 44354 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Umbraco.Web.UI.BackOffice": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/Umbraco.Web.UI.BackOffice/Startup.cs b/src/Umbraco.Web.UI.BackOffice/Startup.cs new file mode 100644 index 0000000000..a80f0d0752 --- /dev/null +++ b/src/Umbraco.Web.UI.BackOffice/Startup.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Umbraco.Web.BackOffice.AspNetCore; + + +namespace Umbraco.Web.UI.BackOffice +{ + public class Startup + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + services.AddUmbracoBackOffice(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseUmbracoBackOffice(); + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); + }); + } + } +} diff --git a/src/Umbraco.Web.UI.BackOffice/Umbraco.Web.UI.BackOffice.csproj b/src/Umbraco.Web.UI.BackOffice/Umbraco.Web.UI.BackOffice.csproj new file mode 100644 index 0000000000..b68d2e582e --- /dev/null +++ b/src/Umbraco.Web.UI.BackOffice/Umbraco.Web.UI.BackOffice.csproj @@ -0,0 +1,11 @@ + + + + netcoreapp3.1 + + + + + + + diff --git a/src/Umbraco.Web.UI.BackOffice/appsettings.Development.json b/src/Umbraco.Web.UI.BackOffice/appsettings.Development.json new file mode 100644 index 0000000000..8983e0fc1c --- /dev/null +++ b/src/Umbraco.Web.UI.BackOffice/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/Umbraco.Web.UI.BackOffice/appsettings.json b/src/Umbraco.Web.UI.BackOffice/appsettings.json new file mode 100644 index 0000000000..d9d9a9bff6 --- /dev/null +++ b/src/Umbraco.Web.UI.BackOffice/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 63212b2fd4..276eed8344 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -128,10 +128,6 @@ {f6de8da0-07cc-4ef2-8a59-2bc81dbb3830} Umbraco.PublishedCache.NuCache - - {9b95eef7-63fe-4432-8c63-166be9c1a929} - Umbraco.Web.BackOffice - {651e1350-91b6-44b7-bd60-7207006d7003} Umbraco.Web diff --git a/src/umbraco.sln b/src/umbraco.sln index 2b9f9d004b..0a5a2b3ae5 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -119,6 +119,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Examine.Lucene", "U EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Web.BackOffice", "Umbraco.Web.BackOffice\Umbraco.Web.BackOffice.csproj", "{9B95EEF7-63FE-4432-8C63-166BE9C1A929}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Web.UI.BackOffice", "Umbraco.Web.UI.BackOffice\Umbraco.Web.UI.BackOffice.csproj", "{DCDFE97C-5630-4F6F-855D-8AEEB96556A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -183,6 +185,10 @@ Global {9B95EEF7-63FE-4432-8C63-166BE9C1A929}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B95EEF7-63FE-4432-8C63-166BE9C1A929}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B95EEF7-63FE-4432-8C63-166BE9C1A929}.Release|Any CPU.Build.0 = Release|Any CPU + {DCDFE97C-5630-4F6F-855D-8AEEB96556A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DCDFE97C-5630-4F6F-855D-8AEEB96556A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DCDFE97C-5630-4F6F-855D-8AEEB96556A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DCDFE97C-5630-4F6F-855D-8AEEB96556A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE