- Moved dashboards to Core
- Introduced IUserAgentProvider, instead of using HttpContext directly - Introduced IUmbracoApplicationLifetime, instead of using UmbracoApplication directly - Introduced IMachineKeyConfig instead of using WebConfigurationManager directly - Move information about dbProvider to the SqlSyntax - Moved install steps
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Configuration;
|
||||
using Umbraco.Configuration;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -10,6 +11,7 @@ namespace Umbraco.Core.Configuration
|
||||
public IHostingSettings HostingSettings { get; } = new HostingSettings();
|
||||
|
||||
public ICoreDebug CoreDebug { get; } = new CoreDebug();
|
||||
public IMachineKeyConfig MachineKeyConfig { get; } = new MachineKeyConfig();
|
||||
|
||||
public IUmbracoSettingsSection UmbracoSettings { get; }
|
||||
|
||||
@@ -27,6 +29,7 @@ namespace Umbraco.Core.Configuration
|
||||
configs.AddPasswordConfigurations();
|
||||
|
||||
configs.Add(() => CoreDebug);
|
||||
configs.Add(() => MachineKeyConfig);
|
||||
configs.Add<IConnectionStrings>(() => new ConnectionStrings(ioHelper));
|
||||
configs.AddCoreConfigs(ioHelper);
|
||||
return configs;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Configuration;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Configuration
|
||||
{
|
||||
public class MachineKeyConfig : IMachineKeyConfig
|
||||
{
|
||||
//TODO all the machineKey stuff should be replaced: https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/replacing-machinekey?view=aspnetcore-3.1
|
||||
|
||||
public bool HasMachineKey
|
||||
{
|
||||
get
|
||||
{
|
||||
var machineKeySection =
|
||||
ConfigurationManager.GetSection("system.web/machineKey") as ConfigurationSection;
|
||||
return !(machineKeySection?.ElementInformation?.Source is null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public interface IMachineKeyConfig
|
||||
{
|
||||
bool HasMachineKey { get;}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Net
|
||||
{
|
||||
public interface IUmbracoApplicationLifetime
|
||||
{
|
||||
void Restart();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Net
|
||||
{
|
||||
public interface IUserAgentProvider
|
||||
{
|
||||
string GetUserAgent();
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace Umbraco.Core.Models.Packaging
|
||||
/// <remarks>
|
||||
/// This is used only for conversions and will not 'get' a PackageDefinition from the repository with a valid ID
|
||||
/// </remarks>
|
||||
internal static PackageDefinition FromCompiledPackage(CompiledPackage compiled)
|
||||
public static PackageDefinition FromCompiledPackage(CompiledPackage compiled)
|
||||
{
|
||||
return new PackageDefinition
|
||||
{
|
||||
|
||||
+20
-25
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Cookie;
|
||||
@@ -12,8 +11,9 @@ using Umbraco.Core.Migrations.Install;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Net;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install
|
||||
@@ -22,25 +22,28 @@ namespace Umbraco.Web.Install
|
||||
{
|
||||
private static HttpClient _httpClient;
|
||||
private readonly DatabaseBuilder _databaseBuilder;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IConnectionStrings _connectionStrings;
|
||||
private readonly IInstallationService _installationService;
|
||||
private readonly ICookieManager _cookieManager;
|
||||
private readonly IUserAgentProvider _userAgentProvider;
|
||||
private readonly Lazy<ISqlContext> _sqlContext;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private InstallationType? _installationType;
|
||||
|
||||
public InstallHelper(IHttpContextAccessor httpContextAccessor,
|
||||
DatabaseBuilder databaseBuilder,
|
||||
public InstallHelper(DatabaseBuilder databaseBuilder,
|
||||
ILogger logger,
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoVersion umbracoVersion,
|
||||
IConnectionStrings connectionStrings,
|
||||
IInstallationService installationService,
|
||||
ICookieManager cookieManager)
|
||||
ICookieManager cookieManager,
|
||||
IUserAgentProvider userAgentProvider,
|
||||
Lazy<ISqlContext> sqlContext,
|
||||
IJsonSerializer jsonSerializer)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
@@ -48,6 +51,9 @@ namespace Umbraco.Web.Install
|
||||
_connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings));
|
||||
_installationService = installationService;
|
||||
_cookieManager = cookieManager;
|
||||
_userAgentProvider = userAgentProvider;
|
||||
_sqlContext = sqlContext;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
}
|
||||
|
||||
public InstallationType GetInstallationType()
|
||||
@@ -57,11 +63,9 @@ namespace Umbraco.Web.Install
|
||||
|
||||
public async Task InstallStatus(bool isCompleted, string errorMsg)
|
||||
{
|
||||
|
||||
var httpContext = _httpContextAccessor.GetRequiredHttpContext();
|
||||
try
|
||||
{
|
||||
var userAgent = httpContext.Request.UserAgent;
|
||||
var userAgent = _userAgentProvider.GetUserAgent();
|
||||
|
||||
// Check for current install Id
|
||||
var installId = Guid.NewGuid();
|
||||
@@ -88,7 +92,7 @@ namespace Umbraco.Web.Install
|
||||
{
|
||||
// we don't have DatabaseProvider anymore... doing it differently
|
||||
//dbProvider = ApplicationContext.Current.DatabaseContext.DatabaseProvider.ToString();
|
||||
dbProvider = GetDbProviderString(Current.SqlContext);
|
||||
dbProvider = GetDbProviderString(_sqlContext.Value);
|
||||
}
|
||||
|
||||
var installLog = new InstallLog(installId: installId, isUpgrade: IsBrandNewInstall == false,
|
||||
@@ -107,19 +111,7 @@ namespace Umbraco.Web.Install
|
||||
|
||||
internal static string GetDbProviderString(ISqlContext sqlContext)
|
||||
{
|
||||
var dbProvider = string.Empty;
|
||||
|
||||
// we don't have DatabaseProvider anymore...
|
||||
//dbProvider = ApplicationContext.Current.DatabaseContext.DatabaseProvider.ToString();
|
||||
//
|
||||
// doing it differently
|
||||
var syntax = sqlContext.SqlSyntax;
|
||||
if (syntax is SqlCeSyntaxProvider)
|
||||
dbProvider = "SqlServerCE";
|
||||
else if (syntax is SqlServerSyntaxProvider)
|
||||
dbProvider = (syntax as SqlServerSyntaxProvider).ServerVersion.IsAzure ? "SqlAzure" : "SqlServer";
|
||||
|
||||
return dbProvider;
|
||||
return sqlContext.SqlSyntax.DbProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -162,7 +154,10 @@ namespace Umbraco.Web.Install
|
||||
using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri))
|
||||
{
|
||||
var response = _httpClient.SendAsync(request).Result;
|
||||
packages = response.Content.ReadAsAsync<IEnumerable<Package>>().Result.ToList();
|
||||
|
||||
|
||||
var json = response.Content.ReadAsStringAsync().Result;
|
||||
packages = _jsonSerializer.Deserialize<IEnumerable<Package>>(json).ToList();
|
||||
}
|
||||
}
|
||||
catch (AggregateException ex)
|
||||
+9
-6
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Configuration;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Web.Install.Models;
|
||||
@@ -12,13 +12,15 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
"ConfigureMachineKey", "machinekey", 2,
|
||||
"Updating some security settings...",
|
||||
PerformsAppRestart = true)]
|
||||
internal class ConfigureMachineKey : InstallSetupStep<bool?>
|
||||
public class ConfigureMachineKey : InstallSetupStep<bool?>
|
||||
{
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IMachineKeyConfig _machineKeyConfig;
|
||||
|
||||
public ConfigureMachineKey(IIOHelper ioHelper)
|
||||
public ConfigureMachineKey(IIOHelper ioHelper, IMachineKeyConfig machineKeyConfig)
|
||||
{
|
||||
_ioHelper = ioHelper;
|
||||
_machineKeyConfig = machineKeyConfig;
|
||||
}
|
||||
|
||||
public override string View => HasMachineKey() == false ? base.View : "";
|
||||
@@ -27,10 +29,11 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
/// Don't display the view or execute if a machine key already exists
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static bool HasMachineKey()
|
||||
private bool HasMachineKey()
|
||||
{
|
||||
var section = (MachineKeySection) WebConfigurationManager.GetSection("system.web/machineKey");
|
||||
return section.ElementInformation.Source != null;
|
||||
return _machineKeyConfig.HasMachineKey;
|
||||
// var section = (MachineKeySection) WebConfigurationManager.GetSection("system.web/machineKey");
|
||||
// return section.ElementInformation.Source != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
+5
-18
@@ -1,44 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Install.Models;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
{
|
||||
[InstallSetupStep(InstallationType.NewInstall | InstallationType.Upgrade,
|
||||
"UmbracoVersion", 50, "Installation is complete!, get ready to be redirected to your new CMS.",
|
||||
PerformsAppRestart = true)]
|
||||
internal class SetUmbracoVersionStep : InstallSetupStep<object>
|
||||
public class SetUmbracoVersionStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly InstallHelper _installHelper;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
|
||||
public SetUmbracoVersionStep(IHttpContextAccessor httpContextAccessor, InstallHelper installHelper, IGlobalSettings globalSettings, IUserService userService, IUmbracoVersion umbracoVersion, IIOHelper ioHelper)
|
||||
public SetUmbracoVersionStep(IUmbracoContextAccessor umbracoContextAccessor, InstallHelper installHelper, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_installHelper = installHelper;
|
||||
_globalSettings = globalSettings;
|
||||
_userService = userService;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_ioHelper = ioHelper;
|
||||
}
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
var security = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper);
|
||||
|
||||
var security = _umbracoContextAccessor.UmbracoContext.Security;
|
||||
if (security.IsAuthenticated() == false && _globalSettings.ConfigurationStatus.IsNullOrWhiteSpace())
|
||||
{
|
||||
security.PerformLogin(-1);
|
||||
+5
-5
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models.Packaging;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Net;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
@@ -20,14 +18,16 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
private readonly InstallHelper _installHelper;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IUmbracoVersion _umbracoVersion;
|
||||
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
|
||||
private readonly IContentService _contentService;
|
||||
private readonly IPackagingService _packageService;
|
||||
|
||||
public StarterKitDownloadStep(IContentService contentService, IPackagingService packageService, InstallHelper installHelper, IUmbracoContextAccessor umbracoContextAccessor, IUmbracoVersion umbracoVersion)
|
||||
public StarterKitDownloadStep(IContentService contentService, IPackagingService packageService, InstallHelper installHelper, IUmbracoContextAccessor umbracoContextAccessor, IUmbracoVersion umbracoVersion, IUmbracoApplicationLifetime umbracoApplicationLifetime)
|
||||
{
|
||||
_installHelper = installHelper;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_umbracoVersion = umbracoVersion;
|
||||
_umbracoApplicationLifetime = umbracoApplicationLifetime;
|
||||
_contentService = contentService;
|
||||
_packageService = packageService;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
|
||||
var (packageFile, packageId) = await DownloadPackageFilesAsync(starterKitId.Value);
|
||||
|
||||
UmbracoApplication.Restart();
|
||||
_umbracoApplicationLifetime.Restart();
|
||||
|
||||
return new InstallSetupResult(new Dictionary<string, object>
|
||||
{
|
||||
+7
-6
@@ -2,9 +2,8 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Net;
|
||||
using Umbraco.Web.Install.Models;
|
||||
|
||||
namespace Umbraco.Web.Install.InstallSteps
|
||||
@@ -14,13 +13,13 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
PerformsAppRestart = true)]
|
||||
internal class StarterKitInstallStep : InstallSetupStep<object>
|
||||
{
|
||||
private readonly IHttpContextAccessor _httContextAccessor;
|
||||
private readonly IUmbracoApplicationLifetime _umbracoApplicationLifetime;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IPackagingService _packagingService;
|
||||
|
||||
public StarterKitInstallStep(IHttpContextAccessor httContextAccessor, IUmbracoContextAccessor umbracoContextAccessor, IPackagingService packagingService)
|
||||
public StarterKitInstallStep(IUmbracoApplicationLifetime umbracoApplicationLifetime, IUmbracoContextAccessor umbracoContextAccessor, IPackagingService packagingService)
|
||||
{
|
||||
_httContextAccessor = httContextAccessor;
|
||||
_umbracoApplicationLifetime = umbracoApplicationLifetime;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_packagingService = packagingService;
|
||||
}
|
||||
@@ -34,7 +33,9 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
|
||||
InstallBusinessLogic(packageId);
|
||||
|
||||
UmbracoApplication.Restart(_httContextAccessor.GetRequiredHttpContext());
|
||||
_umbracoApplicationLifetime.Restart();
|
||||
|
||||
|
||||
|
||||
return Task.FromResult<InstallSetupResult>(null);
|
||||
}
|
||||
@@ -77,12 +77,13 @@ namespace Umbraco.Core.Persistence.SqlSyntax
|
||||
string ConvertIntegerToOrderableString { get; }
|
||||
string ConvertDateToOrderableString { get; }
|
||||
string ConvertDecimalToOrderableString { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the default isolation level for the database
|
||||
/// </summary>
|
||||
IsolationLevel DefaultIsolationLevel { get; }
|
||||
|
||||
string DbProvider { get; }
|
||||
IEnumerable<string> GetTablesInSchema(IDatabase db);
|
||||
IEnumerable<ColumnInfo> GetColumnsInSchema(IDatabase db);
|
||||
|
||||
|
||||
@@ -175,6 +175,8 @@ namespace Umbraco.Core.Persistence.SqlSyntax
|
||||
return items.Select(x => new Tuple<string, string, string, string>(x.TableName, x.ColumnName, x.Name, x.Definition));
|
||||
}
|
||||
|
||||
public override string DbProvider => ServerVersion.IsAzure ? "SqlAzure" : "SqlServer";
|
||||
|
||||
public override IEnumerable<string> GetTablesInSchema(IDatabase db)
|
||||
{
|
||||
var items = db.Fetch<dynamic>("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = (SELECT SCHEMA_NAME())");
|
||||
|
||||
@@ -202,6 +202,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax
|
||||
}
|
||||
|
||||
public abstract IsolationLevel DefaultIsolationLevel { get; }
|
||||
public abstract string DbProvider { get; }
|
||||
|
||||
public virtual IEnumerable<string> GetTablesInSchema(IDatabase db)
|
||||
{
|
||||
|
||||
@@ -55,6 +55,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax
|
||||
}
|
||||
|
||||
public override System.Data.IsolationLevel DefaultIsolationLevel => System.Data.IsolationLevel.RepeatableRead;
|
||||
public override string DbProvider => "SqlServerCE";
|
||||
|
||||
public override string FormatColumnRename(string tableName, string oldName, string newName)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Umbraco.Net;
|
||||
|
||||
namespace Umbraco.Web.AspNet
|
||||
{
|
||||
public class AspNetUmbracoApplicationLifetime : IUmbracoApplicationLifetime
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public AspNetUmbracoApplicationLifetime(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
UmbracoApplication.Restart(_httpContextAccessor.HttpContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Umbraco.Net;
|
||||
|
||||
namespace Umbraco.Web.AspNet
|
||||
{
|
||||
public class AspNetUserAgentProvider : IUserAgentProvider
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public AspNetUserAgentProvider(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public string GetUserAgent()
|
||||
{
|
||||
return _httpContextAccessor.GetRequiredHttpContext().Request.UserAgent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,7 +331,7 @@ namespace Umbraco.Web.Macros
|
||||
/// <returns>The text output of the macro execution.</returns>
|
||||
private MacroContent ExecutePartialView(MacroModel macro, IPublishedContent content)
|
||||
{
|
||||
var engine = new PartialViewMacroEngine();
|
||||
var engine = new PartialViewMacroEngine(_umbracoContextAccessor, _httpContextAccessor, _ioHelper);
|
||||
return engine.Execute(macro, content);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Web.Routing;
|
||||
using System.Web.WebPages;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
@@ -15,37 +16,24 @@ namespace Umbraco.Web.Macros
|
||||
/// </summary>
|
||||
public class PartialViewMacroEngine
|
||||
{
|
||||
private readonly Func<HttpContextBase> _getHttpContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly Func<IUmbracoContext> _getUmbracoContext;
|
||||
|
||||
public PartialViewMacroEngine()
|
||||
public PartialViewMacroEngine(IUmbracoContextAccessor umbracoContextAccessor, IHttpContextAccessor httpContextAccessor, IIOHelper ioHelper)
|
||||
{
|
||||
_getHttpContext = () =>
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
throw new InvalidOperationException($"The {GetType()} cannot execute with a null HttpContext.Current reference.");
|
||||
return new HttpContextWrapper(HttpContext.Current);
|
||||
};
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_ioHelper = ioHelper;
|
||||
|
||||
_getUmbracoContext = () =>
|
||||
{
|
||||
if (Current.UmbracoContext == null)
|
||||
var context = umbracoContextAccessor.UmbracoContext;
|
||||
if (context == null)
|
||||
throw new InvalidOperationException($"The {GetType()} cannot execute with a null UmbracoContext.Current reference.");
|
||||
return Current.UmbracoContext;
|
||||
return context;
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor generally used for unit testing
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <param name="umbracoContext"> </param>
|
||||
internal PartialViewMacroEngine(HttpContextBase httpContext, IUmbracoContext umbracoContext)
|
||||
{
|
||||
_getHttpContext = () => httpContext;
|
||||
_getUmbracoContext = () => umbracoContext;
|
||||
}
|
||||
|
||||
public bool Validate(string code, string tempFileName, IPublishedContent currentPage, out string errorMessage)
|
||||
{
|
||||
var temp = GetVirtualPathFromPhysicalPath(tempFileName);
|
||||
@@ -68,7 +56,7 @@ namespace Umbraco.Web.Macros
|
||||
if (content == null) throw new ArgumentNullException(nameof(content));
|
||||
if (macro.MacroSource.IsNullOrWhiteSpace()) throw new ArgumentException("The MacroSource property of the macro object cannot be null or empty");
|
||||
|
||||
var http = _getHttpContext();
|
||||
var httpContext = _httpContextAccessor.GetRequiredHttpContext();
|
||||
var umbCtx = _getUmbracoContext();
|
||||
var routeVals = new RouteData();
|
||||
routeVals.Values.Add("controller", "PartialViewMacro");
|
||||
@@ -79,13 +67,14 @@ namespace Umbraco.Web.Macros
|
||||
var viewContext = new ViewContext { ViewData = new ViewDataDictionary() };
|
||||
//try and extract the current view context from the route values, this would be set in the UmbracoViewPage or in
|
||||
// the UmbracoPageResult if POSTing to an MVC controller but rendering in Webforms
|
||||
if (http.Request.RequestContext.RouteData.DataTokens.ContainsKey(Mvc.Constants.DataTokenCurrentViewContext))
|
||||
if (httpContext.Request.RequestContext.RouteData.DataTokens.ContainsKey(Mvc.Constants.DataTokenCurrentViewContext))
|
||||
{
|
||||
viewContext = (ViewContext)http.Request.RequestContext.RouteData.DataTokens[Mvc.Constants.DataTokenCurrentViewContext];
|
||||
viewContext = (ViewContext)httpContext.Request.RequestContext.RouteData.DataTokens[Mvc.Constants.DataTokenCurrentViewContext];
|
||||
}
|
||||
routeVals.DataTokens.Add("ParentActionViewContext", viewContext);
|
||||
|
||||
var request = new RequestContext(http, routeVals);
|
||||
var request = new RequestContext(httpContext, routeVals);
|
||||
|
||||
string output;
|
||||
using (var controller = new PartialViewMacroController(macro, content))
|
||||
{
|
||||
@@ -103,7 +92,7 @@ namespace Umbraco.Web.Macros
|
||||
|
||||
private string GetVirtualPathFromPhysicalPath(string physicalPath)
|
||||
{
|
||||
var rootpath = _getHttpContext().Server.MapPath("~/");
|
||||
var rootpath = _ioHelper.MapPath("~/");
|
||||
physicalPath = physicalPath.Replace(rootpath, "");
|
||||
physicalPath = physicalPath.Replace("\\", "/");
|
||||
return "~/" + physicalPath;
|
||||
|
||||
@@ -49,6 +49,7 @@ using Current = Umbraco.Web.Composing.Current;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.AspNet;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
namespace Umbraco.Web.Runtime
|
||||
@@ -64,9 +65,11 @@ namespace Umbraco.Web.Runtime
|
||||
|
||||
composition.Register<UmbracoInjectedModule>();
|
||||
composition.Register<IIpResolver, AspNetIpResolver>();
|
||||
composition.Register<IUserAgentProvider, AspNetUserAgentProvider>();
|
||||
composition.Register<ISessionIdResolver, AspNetSessionIdResolver>();
|
||||
composition.Register<IHostingEnvironment, AspNetHostingEnvironment>();
|
||||
composition.Register<IBackOfficeInfo, AspNetBackOfficeInfo>();
|
||||
composition.Register<IUmbracoApplicationLifetime, AspNetUmbracoApplicationLifetime>();
|
||||
composition.Register<IPasswordHasher, AspNetPasswordHasher>();
|
||||
composition.Register<IFilePermissionHelper, FilePermissionHelper>(Lifetime.Singleton);
|
||||
|
||||
|
||||
@@ -134,7 +134,9 @@
|
||||
<Compile Include="AppBuilderExtensions.cs" />
|
||||
<Compile Include="AreaRegistrationContextExtensions.cs" />
|
||||
<Compile Include="AspNet\AspNetHostingEnvironment.cs" />
|
||||
<Compile Include="AspNet\AspNetUserAgentProvider.cs" />
|
||||
<Compile Include="AspNet\FrameworkMarchal.cs" />
|
||||
<Compile Include="AspNet\AspNetUmbracoApplicationLifetime.cs" />
|
||||
<Compile Include="Cache\WebCachingAppCache.cs" />
|
||||
<Compile Include="Compose\AuditEventsComponent.cs" />
|
||||
<Compile Include="Compose\AuditEventsComposer.cs" />
|
||||
@@ -158,8 +160,6 @@
|
||||
<Compile Include="HttpContextExtensions.cs" />
|
||||
<Compile Include="ImageCropperTemplateCoreExtensions.cs" />
|
||||
<Compile Include="Install\ChangesMonitor.cs" />
|
||||
<Compile Include="Install\InstallSteps\StarterKitDownloadStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\StarterKitInstallStep.cs" />
|
||||
<Compile Include="Logging\OwinLogger.cs" />
|
||||
<Compile Include="Logging\OwinLoggerFactory.cs" />
|
||||
<Compile Include="Logging\WebProfiler.cs" />
|
||||
@@ -270,7 +270,6 @@
|
||||
<Compile Include="Composing\CompositionExtensions\WebMappingProfiles.cs" />
|
||||
<Compile Include="Editors\BackOfficeNotificationsController.cs" />
|
||||
<Compile Include="Install\InstallStepCollection.cs" />
|
||||
<Compile Include="Install\InstallSteps\ConfigureMachineKey.cs" />
|
||||
<Compile Include="Editors\MemberGroupController.cs" />
|
||||
<Compile Include="Composing\CompositionExtensions\Controllers.cs" />
|
||||
<Compile Include="HealthCheck\HealthCheckController.cs" />
|
||||
@@ -359,7 +358,6 @@
|
||||
<Compile Include="Editors\RelationController.cs" />
|
||||
<Compile Include="GridTemplateExtensions.cs" />
|
||||
<Compile Include="Editors\TemplateQueryController.cs" />
|
||||
<Compile Include="Install\InstallSteps\SetUmbracoVersionStep.cs" />
|
||||
<Compile Include="Install\InstallSteps\NewInstallStep.cs" />
|
||||
<Compile Include="Install\UmbracoInstallArea.cs" />
|
||||
<Compile Include="Install\Controllers\InstallApiController.cs" />
|
||||
@@ -455,7 +453,6 @@
|
||||
<Compile Include="HttpRequestExtensions.cs" />
|
||||
<Compile Include="HttpUrlHelperExtensions.cs" />
|
||||
<Compile Include="Install\FilePermissionHelper.cs" />
|
||||
<Compile Include="Install\InstallHelper.cs" />
|
||||
<Compile Include="Install\HttpInstallAuthorizeAttribute.cs" />
|
||||
<Compile Include="Macros\PartialViewMacroController.cs" />
|
||||
<Compile Include="Macros\PartialViewMacroEngine.cs" />
|
||||
|
||||
@@ -70,7 +70,6 @@ namespace Umbraco.Web
|
||||
_variationContextAccessor.VariationContext = new VariationContext(_defaultCultureAccessor.DefaultCulture);
|
||||
}
|
||||
|
||||
|
||||
var webSecurity = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper);
|
||||
|
||||
return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility, _cookieManager);
|
||||
|
||||
@@ -3,13 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Xml;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user