Merge remote-tracking branch 'origin/netcore/netcore' into feature/8651-config-options-patten

# Conflicts:
#	src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs
#	src/Umbraco.ModelsBuilder.Embedded/BackOffice/ContentTypeModelValidatorBase.cs
#	src/Umbraco.ModelsBuilder.Embedded/BackOffice/ModelsBuilderDashboardController.cs
#	src/Umbraco.ModelsBuilder.Embedded/Building/ModelsGenerator.cs
#	src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs
#	src/Umbraco.ModelsBuilder.Embedded/ModelsGenerationError.cs
#	src/Umbraco.ModelsBuilder.Embedded/OutOfDateModelsStatus.cs
#	src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs
#	src/Umbraco.Web.BackOffice/Controllers/RedirectUrlManagementController.cs
This commit is contained in:
Bjarke Berg
2020-09-10 14:01:38 +02:00
249 changed files with 6053 additions and 4380 deletions

View File

@@ -17,11 +17,8 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
/// <summary>
/// Provides a base class for all builders.
/// </summary>
internal abstract class Builder
public abstract class Builder
{
private readonly IList<TypeModel> _typeModels;
protected Dictionary<string, string> ModelsMap { get; } = new Dictionary<string, string>();
@@ -30,13 +27,11 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
protected readonly IList<string> TypesUsing = new List<string>
{
"System",
"System.Collections.Generic",
"System.Linq.Expressions",
"System.Web",
"Umbraco.Core.Models",
"Umbraco.Core.Models.PublishedContent",
"Umbraco.Web",
"Umbraco.ModelsBuilder.Embedded"
"Umbraco.Web.PublishedCache",
"Umbraco.ModelsBuilder.Embedded",
"Umbraco.Core"
};
/// <summary>
@@ -63,7 +58,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
/// Gets the list of all models.
/// </summary>
/// <remarks>Includes those that are ignored.</remarks>
internal IList<TypeModel> TypeModels => _typeModels;
public IList<TypeModel> TypeModels => _typeModels;
/// <summary>
/// Initializes a new instance of the <see cref="Builder"/> class with a list of models to generate,
@@ -200,7 +195,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
return true;
}
internal string ModelsNamespaceForTests;
public string ModelsNamespaceForTests;
public string GetModelsNamespace()
{

View File

@@ -4,6 +4,7 @@ using Microsoft.Extensions.Options;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.IO;
using Umbraco.Core.Hosting;
namespace Umbraco.ModelsBuilder.Embedded.Building
{
@@ -12,19 +13,19 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
private readonly UmbracoServices _umbracoService;
private readonly ModelsBuilderConfig _config;
private readonly OutOfDateModelsStatus _outOfDateModels;
private readonly IIOHelper _ioHelper;
private readonly IHostingEnvironment _hostingEnvironment;
public ModelsGenerator(UmbracoServices umbracoService, IOptions<ModelsBuilderConfig> config, OutOfDateModelsStatus outOfDateModels, IIOHelper ioHelper)
public ModelsGenerator(UmbracoServices umbracoService, IOptions<ModelsBuilderConfig> config, OutOfDateModelsStatus outOfDateModels, IHostingEnvironment hostingEnvironment)
{
_umbracoService = umbracoService;
_config = config.Value;
_outOfDateModels = outOfDateModels;
_ioHelper = ioHelper;
_hostingEnvironment = hostingEnvironment;
}
internal void GenerateModels()
{
var modelsDirectory = _config.ModelsDirectoryAbsolute(_ioHelper);
var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostingEnvironment);
if (!Directory.Exists(modelsDirectory))
Directory.CreateDirectory(modelsDirectory);

View File

@@ -23,7 +23,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
{ }
// internal for unit tests only
internal TextBuilder()
public TextBuilder()
{ }
/// <summary>
@@ -185,16 +185,17 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
sb.AppendFormat("\t\tpublic new const PublishedItemType ModelItemType = PublishedItemType.{0};\n",
itemType);
WriteGeneratedCodeAttribute(sb, "\t\t");
sb.Append("\t\tpublic new static IPublishedContentType GetModelContentType()\n");
sb.Append("\t\t\t=> PublishedModelUtility.GetModelContentType(ModelItemType, ModelTypeAlias);\n");
sb.Append("\t\tpublic new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor)\n");
sb.Append("\t\t\t=> PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias);\n");
WriteGeneratedCodeAttribute(sb, "\t\t");
sb.AppendFormat("\t\tpublic static IPublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<{0}, TValue>> selector)\n",
sb.AppendFormat("\t\tpublic static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<{0}, TValue>> selector)\n",
type.ClrName);
sb.Append("\t\t\t=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(), selector);\n");
sb.Append("\t\t\t=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);\n");
sb.Append("#pragma warning restore 0109\n\n");
sb.Append("\t\tprivate IPublishedValueFallback _publishedValueFallback;");
// write the ctor
sb.AppendFormat("\t\t// ctor\n\t\tpublic {0}(IPublished{1} content)\n\t\t\t: base(content)\n\t\t{{ }}\n\n",
sb.AppendFormat("\n\n\t\t// ctor\n\t\tpublic {0}(IPublished{1} content, IPublishedValueFallback publishedValueFallback)\n\t\t\t: base(content)\n\t\t{{\n\t\t\t_publishedValueFallback = publishedValueFallback; \n\t\t}}\n\n",
type.ClrName, type.IsElement ? "Element" : "Content");
// write the properties
@@ -325,7 +326,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
WriteClrType(sb, property.ClrTypeName);
sb.Append(">");
}
sb.AppendFormat("(\"{0}\");\n",
sb.AppendFormat("(_publishedValueFallback, \"{0}\");\n",
property.Alias);
}
@@ -417,7 +418,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
}
// internal for unit tests
internal void WriteClrType(StringBuilder sb, Type type)
public void WriteClrType(StringBuilder sb, Type type)
{
var s = type.ToString();

View File

@@ -1,5 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Umbraco.Core;
namespace Umbraco.ModelsBuilder.Embedded.Building
{
@@ -7,38 +11,38 @@ namespace Umbraco.ModelsBuilder.Embedded.Building
{
public static string Hash(IEnumerable<TypeModel> typeModels)
{
var hash = new HashCombiner();
var builder = new StringBuilder();
// see Umbraco.ModelsBuilder.Umbraco.Application for what's important to hash
// ie what comes from Umbraco (not computed by ModelsBuilder) and makes a difference
foreach (var typeModel in typeModels.OrderBy(x => x.Alias))
{
hash.Add("--- CONTENT TYPE MODEL ---");
hash.Add(typeModel.Id);
hash.Add(typeModel.Alias);
hash.Add(typeModel.ClrName);
hash.Add(typeModel.ParentId);
hash.Add(typeModel.Name);
hash.Add(typeModel.Description);
hash.Add(typeModel.ItemType.ToString());
hash.Add("MIXINS:" + string.Join(",", typeModel.MixinTypes.OrderBy(x => x.Id).Select(x => x.Id)));
builder.AppendLine("--- CONTENT TYPE MODEL ---");
builder.AppendLine(typeModel.Id.ToString());
builder.AppendLine(typeModel.Alias);
builder.AppendLine(typeModel.ClrName);
builder.AppendLine(typeModel.ParentId.ToString());
builder.AppendLine(typeModel.Name);
builder.AppendLine(typeModel.Description);
builder.AppendLine(typeModel.ItemType.ToString());
builder.AppendLine("MIXINS:" + string.Join(",", typeModel.MixinTypes.OrderBy(x => x.Id).Select(x => x.Id)));
foreach (var prop in typeModel.Properties.OrderBy(x => x.Alias))
{
hash.Add("--- PROPERTY ---");
hash.Add(prop.Alias);
hash.Add(prop.ClrName);
hash.Add(prop.Name);
hash.Add(prop.Description);
hash.Add(prop.ModelClrType.ToString()); // see ModelType tests, want ToString() not FullName
builder.AppendLine("--- PROPERTY ---");
builder.AppendLine(prop.Alias);
builder.AppendLine(prop.ClrName);
builder.AppendLine(prop.Name);
builder.AppendLine(prop.Description);
builder.AppendLine(prop.ModelClrType.ToString()); // see ModelType tests, want ToString() not FullName
}
}
// Include the MB version in the hash so that if the MB version changes, models are rebuilt
hash.Add(ApiVersion.Current.Version.ToString());
builder.AppendLine(ApiVersion.Current.Version.ToString());
return hash.GetCombinedHashCode();
return builder.ToString().GenerateHash();
}
}
}