Rename models builder modes (#10272)

* Renaming AppData Models Builder mode

* Renaming PureLive Models Builder mode to Runtime

* ModelsBuilderAssembly attribute flags if models are "Live" or not

* Updated ModelsMode names

* Only add tag if it is not a pull request. Apparently this is not allowed when it is from a fork.

* Revert "Only add tag if it is not a pull request. Apparently this is not allowed when it is from a fork."

This reverts commit 92b33f3c

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Callum Whyte
2021-05-26 07:36:21 +01:00
committed by GitHub
parent 0358e2aff7
commit b07f6519e7
21 changed files with 554 additions and 546 deletions

View File

@@ -2,34 +2,39 @@ using System;
using System.Threading;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Runtime;
using Umbraco.Cms.Infrastructure.ModelsBuilder.Building;
using Umbraco.Extensions;
using Umbraco.Cms.Core.Configuration;
namespace Umbraco.Cms.Infrastructure.ModelsBuilder
{
// supports LiveAppData - but not PureLive
public sealed class LiveModelsProvider : INotificationHandler<UmbracoApplicationStartingNotification>,
/// <summary>
/// Notification handlers used by <see cref="ModelsMode.SourceCodeAuto"/>.
/// </summary>
/// <remarks>
/// supports <see cref="ModelsMode.SourceCodeAuto"/> mode but not <see cref="ModelsMode.InMemoryAuto"/> mode.
/// </remarks>
public sealed class AutoModelsNotificationHandler : INotificationHandler<UmbracoApplicationStartingNotification>,
INotificationHandler<UmbracoRequestEndNotification>,
INotificationHandler<ContentTypeCacheRefresherNotification>,
INotificationHandler<DataTypeCacheRefresherNotification>
{
private static int s_req;
private readonly ILogger<LiveModelsProvider> _logger;
private readonly ILogger<AutoModelsNotificationHandler> _logger;
private readonly ModelsBuilderSettings _config;
private readonly ModelsGenerator _modelGenerator;
private readonly ModelsGenerationError _mbErrors;
private readonly IMainDom _mainDom;
/// <summary>
/// Initializes a new instance of the <see cref="LiveModelsProvider"/> class.
/// Initializes a new instance of the <see cref="AutoModelsNotificationHandler"/> class.
/// </summary>
public LiveModelsProvider(
ILogger<LiveModelsProvider> logger,
public AutoModelsNotificationHandler(
ILogger<AutoModelsNotificationHandler> logger,
IOptions<ModelsBuilderSettings> config,
ModelsGenerator modelGenerator,
ModelsGenerationError mbErrors,
@@ -42,8 +47,8 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder
_mainDom = mainDom;
}
// we do not manage pure live here
internal bool IsEnabled => _config.ModelsMode.IsLiveNotPure();
// we do not manage InMemory models here
internal bool IsEnabled => _config.ModelsMode.IsAutoNotInMemory();
/// <summary>
/// Handles the <see cref="UmbracoApplicationStartingNotification"/> notification
@@ -74,6 +79,7 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder
}
_logger.LogDebug("Requested to generate models.");
Interlocked.Exchange(ref s_req, 1);
}

View File

@@ -93,12 +93,12 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder.Building
{
TypeModel.MapModelTypes(_typeModels, ModelsNamespace);
var pureLive = Config.ModelsMode == ModelsMode.PureLive;
var isInMemoryMode = Config.ModelsMode == ModelsMode.InMemoryAuto;
// for the first two of these two tests,
// always throw, even in purelive: cannot happen unless ppl start fidling with attributes to rename
// always throw, even in InMemory mode: cannot happen unless ppl start fidling with attributes to rename
// things, and then they should pay attention to the generation error log - there's no magic here
// for the last one, don't throw in purelive, see comment
// for the last one, don't throw in InMemory mode, see comment
// ensure we have no duplicates type names
foreach (var xx in _typeModels.GroupBy(x => x.ClrName).Where(x => x.Count() > 1))
@@ -118,12 +118,12 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder.Building
{
foreach (var xx in typeModel.Properties.Where(x => x.ClrName == typeModel.ClrName))
{
if (!pureLive)
if (!isInMemoryMode)
throw new InvalidOperationException($"The model class for content type with alias \"{typeModel.Alias}\" is named \"{xx.ClrName}\"."
+ $" CSharp does not support using the same name for the property with alias \"{xx.Alias}\"."
+ " Consider using an attribute to assign a different name to the property.");
// for purelive, will we generate a commented out properties with an error message,
// in InMemory mode we generate commented out properties with an error message,
// instead of throwing, because then it kills the sites and ppl don't understand why
xx.AddError($"The class {typeModel.ClrName} cannot implement this property, because"
+ $" CSharp does not support naming the property with alias \"{xx.Alias}\" with the same name as content type with alias \"{typeModel.Alias}\"."

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Configuration;
namespace Umbraco.Cms.Infrastructure.ModelsBuilder.Building
{
@@ -46,7 +47,7 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder.Building
/// </summary>
/// <remarks>This should be null, unless something prevents the property from being
/// generated, and then the value should explain what. This can be used to generate
/// commented out code eg in PureLive.</remarks>
/// commented out code eg in <see cref="ModelsMode.InMemoryAuto"/> mode.</remarks>
public List<string> Errors;
/// <summary>

View File

@@ -9,10 +9,10 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder
public sealed class ModelsBuilderAssemblyAttribute : Attribute
{
/// <summary>
/// Gets or sets a value indicating whether the assembly is a PureLive assembly.
/// Gets or sets a value indicating whether the assembly is a InMemory assembly.
/// </summary>
/// <remarks>A Models Builder assembly can be either PureLive or normal Dll.</remarks>
public bool PureLive { get; set; }
/// <remarks>A Models Builder assembly can be either InMemory or a normal Dll.</remarks>
public bool IsInMemory { get; set; }
/// <summary>
/// Gets or sets a hash value representing the state of the custom source code files

View File

@@ -43,7 +43,7 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder
{
var types = new List<TypeModel>();
// TODO: this will require 3 rather large SQL queries on startup in PureLive. I know that these will be cached after lookup but it will slow
// TODO: this will require 3 rather large SQL queries on startup in ModelsMode.InMemoryAuto mode. I know that these will be cached after lookup but it will slow
// down startup time ... BUT these queries are also used in NuCache on startup so we can't really avoid them. Maybe one day we can
// load all of these in in one query and still have them cached per service, and/or somehow improve the perf of these since they are used on startup
// in more than one place.