Merge branch 'netcore/feature/move-more-install-stuff' into netcore/feature/executable-backoffice

This commit is contained in:
Bjarke Berg
2020-02-27 10:58:48 +01:00
10 changed files with 43 additions and 56 deletions

View File

@@ -2,6 +2,7 @@ namespace Umbraco.Net
{
public interface IUmbracoApplicationLifetime
{
bool IsRestarting { get; }
void Restart();
}
}

View File

@@ -1,11 +1,12 @@
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Composing
@using Umbraco.Web.Controllers
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var profileModel = Members.GetCurrentMemberProfileModel();
var profileModel = Current.MembershipHelper.GetCurrentMemberProfileModel();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
@@ -19,7 +20,7 @@
@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
@Html.RenderJsHere()
@if (Members.IsLoggedIn() && profileModel != null)
@if (Current.MembershipHelper.IsLoggedIn() && profileModel != null)
{
if (success)
{

View File

@@ -1,11 +1,12 @@
@using System.Web.Mvc.Html
@using Umbraco.Web
@using Umbraco.Web.Composing
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var loginStatusModel = Members.GetCurrentLoginStatus();
var loginStatusModel = Current.MembershipHelper.GetCurrentLoginStatus();
var logoutModel = new PostRedirectModel();
@*

View File

@@ -1,6 +1,7 @@
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Composing
@using Umbraco.Web.Controllers
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@@ -12,7 +13,7 @@
var registerModel = Members.CreateRegistrationModel("Custom Member");
*@
var registerModel = Members.CreateRegistrationModel();
var registerModel = Current.MembershipHelper.CreateRegistrationModel();
@*
Configurable here:

View File

@@ -1,3 +1,5 @@
using System.Threading;
using System.Web;
using Umbraco.Net;
namespace Umbraco.Web.AspNet
@@ -11,9 +13,22 @@ namespace Umbraco.Web.AspNet
_httpContextAccessor = httpContextAccessor;
}
public bool IsRestarting { get; set; }
public void Restart()
{
UmbracoApplication.Restart(_httpContextAccessor.HttpContext);
IsRestarting = true;
var httpContext = _httpContextAccessor.HttpContext;
if (httpContext != null)
{
// unload app domain - we must null out all identities otherwise we get serialization errors
// http://www.zpqrtbnk.net/posts/custom-iidentity-serialization-issue
httpContext.User = null;
}
Thread.CurrentPrincipal = null;
HttpRuntime.UnloadAppDomain();
}
}
}

View File

@@ -26,6 +26,7 @@ using Umbraco.Web.HealthCheck;
using Umbraco.Web.Mvc;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using Umbraco.Web.Services;
using Umbraco.Web.Trees;
using Umbraco.Web.WebApi;
@@ -262,6 +263,8 @@ namespace Umbraco.Web.Composing
public static IUmbracoVersion UmbracoVersion => Factory.GetInstance<IUmbracoVersion>();
public static IPublishedUrlProvider PublishedUrlProvider => Factory.GetInstance<IPublishedUrlProvider>();
public static IMenuItemCollectionFactory MenuItemCollectionFactory => Factory.GetInstance<IMenuItemCollectionFactory>();
public static MembershipHelper MembershipHelper => Factory.GetInstance<MembershipHelper>();
public static IUmbracoApplicationLifetime UmbracoApplicationLifetime => Factory.GetInstance<IUmbracoApplicationLifetime>();
#endregion
}

View File

@@ -18,6 +18,7 @@ using Umbraco.Core.Packaging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Net;
using Umbraco.Web.JavaScript;
using Umbraco.Web.Models;
using Umbraco.Web.Models.ContentEditing;
@@ -39,6 +40,7 @@ namespace Umbraco.Web.Editors
private readonly IUmbracoVersion _umbracoVersion;
private readonly IIOHelper _ioHelper;
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
public PackageInstallController(
IGlobalSettings globalSettings,
@@ -53,11 +55,13 @@ namespace Umbraco.Web.Editors
IUmbracoVersion umbracoVersion,
UmbracoMapper umbracoMapper,
IIOHelper ioHelper,
IPublishedUrlProvider publishedUrlProvider)
IPublishedUrlProvider publishedUrlProvider,
IUmbracoApplicationLifetime umbracoApplicationLifetime)
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper, publishedUrlProvider)
{
_umbracoVersion = umbracoVersion;
_ioHelper = ioHelper;
_umbracoApplicationLifetime = umbracoApplicationLifetime;
}
/// <summary>
@@ -325,7 +329,7 @@ namespace Umbraco.Web.Editors
var installedFiles = Services.PackagingService.InstallCompiledPackageFiles(definition, zipFile, Security.GetUserId().ResultOr(0));
//set a restarting marker and reset the app pool
UmbracoApplication.Restart(Request.TryGetHttpContext().Result);
_umbracoApplicationLifetime.Restart();
model.IsRestarting = true;
@@ -337,12 +341,8 @@ namespace Umbraco.Web.Editors
{
if (model.IsRestarting == false) return model;
//check for the key, if it's not there we're are restarted
if (Request.TryGetHttpContext().Result.Application.AllKeys.Contains("AppPoolRestarting") == false)
{
//reset it
model.IsRestarting = false;
}
model.IsRestarting = _umbracoApplicationLifetime.IsRestarting;
return model;
}

View File

@@ -151,9 +151,15 @@ namespace Umbraco.Web.Mvc
var context = HttpContext.Current;
if (context == null)
{
AppDomain.Unload(AppDomain.CurrentDomain);
}
else
UmbracoApplication.Restart(new HttpContextWrapper(context));
{
Current.UmbracoApplicationLifetime.Restart();
}
}
throw new ModelBindingException(msg.ToString());

View File

@@ -69,7 +69,7 @@ namespace Umbraco.Web.Runtime
composition.Register<ISessionIdResolver, AspNetSessionIdResolver>();
composition.Register<IHostingEnvironment, AspNetHostingEnvironment>();
composition.Register<IBackOfficeInfo, AspNetBackOfficeInfo>();
composition.Register<IUmbracoApplicationLifetime, AspNetUmbracoApplicationLifetime>();
composition.Register<IUmbracoApplicationLifetime, AspNetUmbracoApplicationLifetime>(Lifetime.Singleton);
composition.Register<IPasswordHasher, AspNetPasswordHasher>();
composition.Register<IFilePermissionHelper, FilePermissionHelper>(Lifetime.Singleton);

View File

@@ -36,46 +36,5 @@ namespace Umbraco.Web
return new WebRuntime(configs, umbracoVersion, ioHelper, logger, profiler, hostingEnvironment, backOfficeInfo, dbProviderFactoryCreator, mainDom);
}
/// <summary>
/// Restarts the Umbraco application.
/// </summary>
public static void Restart()
{
// see notes in overload
var httpContext = HttpContext.Current;
if (httpContext != null)
{
httpContext.Application.Add("AppPoolRestarting", true);
httpContext.User = null;
}
Thread.CurrentPrincipal = null;
HttpRuntime.UnloadAppDomain();
}
/// <summary>
/// Restarts the Umbraco application.
/// </summary>
public static void Restart(HttpContextBase httpContext)
{
if (httpContext != null)
{
// we're going to put an application wide flag to show that the application is about to restart.
// we're doing this because if there is a script checking if the app pool is fully restarted, then
// it can check if this flag exists... if it does it means the app pool isn't restarted yet.
httpContext.Application.Add("AppPoolRestarting", true);
// unload app domain - we must null out all identities otherwise we get serialization errors
// http://www.zpqrtbnk.net/posts/custom-iidentity-serialization-issue
httpContext.User = null;
}
if (HttpContext.Current != null)
HttpContext.Current.User = null;
Thread.CurrentPrincipal = null;
HttpRuntime.UnloadAppDomain();
}
}
}