AB#6233 - Cleanup

This commit is contained in:
Bjarke Berg
2020-04-29 16:11:56 +02:00
parent fa740f36b5
commit 59501eba86
12 changed files with 77 additions and 134 deletions

View File

@@ -70,10 +70,9 @@ namespace Umbraco.Core.Composing
}
}
var assemblyNameToAssembly = assemblies.ToDictionary(x => x.GetName());
foreach (var item in assemblies)
{
var classification = Resolve(item, assemblyNameToAssembly);
var classification = Resolve(item);
if (classification == Classification.ReferencesUmbraco || classification == Classification.IsUmbraco)
{
applicationParts.Add(item);
@@ -101,7 +100,7 @@ namespace Umbraco.Core.Composing
return assembly.Location;
}
private Classification Resolve(Assembly assembly, IDictionary<AssemblyName, Assembly> assemblyNameToAssembly)
private Classification Resolve(Assembly assembly)
{
if (_classifications.TryGetValue(assembly, out var classification))
{
@@ -124,10 +123,10 @@ namespace Umbraco.Core.Composing
else
{
classification = Classification.DoesNotReferenceUmbraco;
foreach (var reference in GetReferences(assembly, assemblyNameToAssembly))
foreach (var reference in GetReferences(assembly))
{
// recurse
var referenceClassification = Resolve(reference, assemblyNameToAssembly);
var referenceClassification = Resolve(reference);
if (referenceClassification == Classification.IsUmbraco || referenceClassification == Classification.ReferencesUmbraco)
{
@@ -142,7 +141,7 @@ namespace Umbraco.Core.Composing
return classification;
}
protected virtual IEnumerable<Assembly> GetReferences(Assembly assembly, IDictionary<AssemblyName, Assembly> assemblyNameToAssembly)
protected virtual IEnumerable<Assembly> GetReferences(Assembly assembly)
{
var referencedAssemblies = assembly.GetReferencedAssemblies();
@@ -152,20 +151,7 @@ namespace Umbraco.Core.Composing
if (TypeFinder.KnownAssemblyExclusionFilter.Any(f => referenceName.FullName.StartsWith(f, StringComparison.InvariantCultureIgnoreCase)))
continue;
Assembly reference ;
try
{
reference = Assembly.Load(referenceName);
}
catch (Exception)
{
if (!assemblyNameToAssembly.TryGetValue(referenceName, out var item))
{
continue;
}
reference = Assembly.LoadFrom(item.Location);
}
var reference = Assembly.Load(referenceName);
if (!_lookup.Contains(reference))
{

View File

@@ -142,8 +142,10 @@ namespace Umbraco.Core.Composing
"ServiceStack.",
"SqlCE4Umbraco,",
"Superpower,", // used by Serilog
// "System.",
"System.Data.SqlClient,",
"System.Data.Odbc,",
"System.Data.OleDb,",
"System.Data.Entity,",
"System.Runtime,",
"System.Runtime.",
"TidyNet,",

View File

@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Semver;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Web.Install.Models;
@@ -28,9 +29,6 @@ namespace Umbraco.Web.Install.InstallSteps
{
get
{
//TODO this will always compare the same version now
var newVersion = _umbracoVersion.SemanticVersion.ToString();
string FormatGuidState(string value)
{
if (string.IsNullOrWhiteSpace(value)) value = "unknown";
@@ -39,14 +37,14 @@ namespace Umbraco.Web.Install.InstallSteps
return value;
}
var currentState = FormatGuidState(_runtimeState.CurrentMigrationState);
var newState = FormatGuidState(_runtimeState.FinalMigrationState);
var currentVersion = _umbracoVersion.Current;
var newVersion = _umbracoVersion.SemanticVersion.ToString();
var oldVersion = new SemVersion(_umbracoVersion.SemanticVersion.Major, 0, 0).ToString(); //TODO can we find the old version somehow? e.g. from current state
var reportUrl = $"https://our.umbraco.com/contribute/releases/compare?from={currentVersion}&to={newVersion}&notes=1";
var reportUrl = $"https://our.umbraco.com/contribute/releases/compare?from={oldVersion}&to={newVersion}&notes=1";
return new { currentVersion, newVersion, currentState, newState, reportUrl };
return new { oldVersion, newVersion, currentState, newState, reportUrl };
}
}
}

View File

@@ -97,35 +97,6 @@ namespace Umbraco.Core
/// </summary>
public void DetermineRuntimeLevel(IUmbracoDatabaseFactory databaseFactory, ILogger logger)
{
// var localVersion = _umbracoVersion.LocalVersion; // the local, files, version
// var codeVersion = SemanticVersion; // the executing code version
var connect = false;
//
// if (localVersion == null)
// {
// // there is no local version, we are not installed
// logger.Debug<RuntimeState>("No local version, need to install Umbraco.");
// Level = RuntimeLevel.Install;
// Reason = RuntimeLevelReason.InstallNoVersion;
// return;
// }
//
// if (localVersion < codeVersion)
// {
// // there *is* a local version, but it does not match the code version
// // need to upgrade
// logger.Debug<RuntimeState>("Local version '{LocalVersion}' < code version '{CodeVersion}', need to upgrade Umbraco.", localVersion, codeVersion);
// Level = RuntimeLevel.Upgrade;
// Reason = RuntimeLevelReason.UpgradeOldVersion;
// }
// else if (localVersion > codeVersion)
// {
// logger.Warn<RuntimeState>("Local version '{LocalVersion}' > code version '{CodeVersion}', downgrading is not supported.", localVersion, codeVersion);
//
// // in fact, this is bad enough that we want to throw
// Reason = RuntimeLevelReason.BootFailedCannotDowngrade;
// throw new BootFailedException($"Local version \"{localVersion}\" > code version \"{codeVersion}\", downgrading is not supported.");
// }
if (databaseFactory.Configured == false)
{
// local version *does* match code version, but the database is not configured
@@ -139,6 +110,7 @@ namespace Umbraco.Core
// else, keep going,
// anything other than install wants a database - see if we can connect
// (since this is an already existing database, assume localdb is ready)
var connect = false;
var tries = _globalSettings.InstallMissingDatabase ? 2 : 5;
for (var i = 0;;)
{

View File

@@ -10,6 +10,7 @@ using Umbraco.Core;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Migrations.Install;
using Umbraco.Net;
using Umbraco.Web.Common.Attributes;
using Umbraco.Web.Install;
using Umbraco.Web.Install.Models;
@@ -23,17 +24,20 @@ namespace Umbraco.Web.Common.Install
{
private readonly DatabaseBuilder _databaseBuilder;
private readonly InstallStatusTracker _installStatusTracker;
private readonly IRuntimeState _runtimeState;
private readonly InstallStepCollection _installSteps;
private readonly ILogger _logger;
private readonly IProfilingLogger _proflog;
public InstallApiController(DatabaseBuilder databaseBuilder, IProfilingLogger proflog,
InstallHelper installHelper, InstallStepCollection installSteps, InstallStatusTracker installStatusTracker)
InstallHelper installHelper, InstallStepCollection installSteps, InstallStatusTracker installStatusTracker,
IRuntimeState runtimeState)
{
_databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder));
_proflog = proflog ?? throw new ArgumentNullException(nameof(proflog));
_installSteps = installSteps;
_installStatusTracker = installStatusTracker;
_runtimeState = runtimeState;
InstallHelper = installHelper;
_logger = _proflog;
}

View File

@@ -1,58 +0,0 @@
using System;
using System.Security;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Core.Models.Membership;
using Microsoft.AspNetCore.Http;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.Models;
using Umbraco.Web.Common.Extensions;
using Umbraco.Web.Security;
namespace Umbraco.Web.Common.Security
{
/// <summary>
/// A utility class used for dealing with USER security in Umbraco
/// </summary>
public class WebSecurity : IWebSecurity
{
private IUser _currentUser;
public IUser CurrentUser
{
get => _currentUser;
set => _currentUser = value;
}
public double PerformLogin(int userId)
{
return 15;
}
public void ClearCurrentLogin()
{
}
public Attempt<int> GetUserId()
{
return new Attempt<int>();
}
public bool ValidateCurrentUser()
{
return false;
}
public ValidateRequestAttempt ValidateCurrentUser(bool throwExceptions, bool requiresApproval = true) => throw new NotImplementedException();
public ValidateRequestAttempt AuthorizeRequest(bool throwExceptions = false) => throw new NotImplementedException();
public bool UserHasSectionAccess(string section, IUser user) => false;
public bool IsAuthenticated() => false;
}
}

View File

@@ -6,7 +6,6 @@ using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.Common.Security;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Security;
@@ -74,7 +73,7 @@ namespace Umbraco.Web
_variationContextAccessor.VariationContext = new VariationContext(_defaultCultureAccessor.DefaultCulture);
}
var webSecurity = new WebSecurity();
IWebSecurity webSecurity = null; // TODO, we need to when users are migrated
return new UmbracoContext(
_publishedSnapshotService,

View File

@@ -1,7 +1,5 @@
{
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|\\Umbraco.sdf;Flush Interval=1;"
},
"ConnectionStrings": {},
"Logging": {
"LogLevel": {
"Default": "Information",
@@ -119,4 +117,4 @@
}
}
}
}
}

View File

@@ -1,6 +1,5 @@
@using Umbraco.Core.Configuration
@using Umbraco.Web
@using Umbraco.Web.Install.Controllers
@{
Layout = null;
}

View File

@@ -0,0 +1,42 @@
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using System.Linq;
using Umbraco.Core.Composing;
using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.Web.Macros
{
/// <summary>
/// Controller to render macro content for Partial View Macros
/// </summary>
[MergeParentContextViewData]
[HideFromTypeFinder] // explicitly used: do *not* find and register it!
internal class PartialViewMacroController : Controller
{
private readonly MacroModel _macro;
private readonly IPublishedContent _content;
public PartialViewMacroController(MacroModel macro, IPublishedContent content)
{
_macro = macro;
_content = content;
}
/// <summary>
/// Child action to render a macro
/// </summary>
/// <returns></returns>
[ChildActionOnly]
public PartialViewResult Index()
{
var model = new PartialViewMacroModel(
_content,
_macro.Id,
_macro.Alias,
_macro.Name,
_macro.Properties.ToDictionary(x => x.Key, x => (object)x.Value));
return PartialView(_macro.MacroSource, model);
}
}
}

View File

@@ -76,17 +76,17 @@ namespace Umbraco.Web.Macros
var request = new RequestContext(httpContext, routeVals);
string output = String.Empty;
//TODO Render!!
// using (var controller = new PartialViewMacroController(macro, content))
// {
// controller.ViewData = viewContext.ViewData;
//
// controller.ControllerContext = new ControllerContext(request, controller);
//
// //call the action to render
// var result = controller.Index();
// output = controller.RenderViewResultAsString(result);
// }
using (var controller = new PartialViewMacroController(macro, content))
{
controller.ViewData = viewContext.ViewData;
controller.ControllerContext = new ControllerContext(request, controller);
//call the action to render
var result = controller.Index();
output = controller.RenderViewResultAsString(result);
}
return new MacroContent { Text = output };
}

View File

@@ -145,6 +145,7 @@
<Compile Include="Composing\LightInject\LightInjectContainer.cs" />
<Compile Include="Macros\MacroRenderer.cs" />
<Compile Include="Macros\MemberUserKeyProvider.cs" />
<Compile Include="Macros\PartialViewMacroController.cs" />
<Compile Include="Macros\PartialViewMacroEngine.cs" />
<Compile Include="Mvc\UmbracoViewPageOfTModel.cs" />
<Compile Include="WebAssets\CDF\ClientDependencyRuntimeMinifier.cs" />