2020-03-18 11:29:29 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2020-03-19 19:06:05 +01:00
|
|
|
|
using Umbraco.Core;
|
2020-03-16 14:02:08 +01:00
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Configuration.Models
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Represents the models builder configuration.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
internal class ModelsBuilderConfig : IModelsBuilderConfig
|
|
|
|
|
|
{
|
2020-03-19 19:06:05 +01:00
|
|
|
|
private const string Prefix = Constants.Configuration.ConfigModelsBuilderPrefix;
|
2020-03-16 14:02:08 +01:00
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Initializes a new instance of the <see cref="ModelsBuilderConfig" /> class.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ModelsBuilderConfig(IConfiguration configuration)
|
|
|
|
|
|
{
|
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-18 11:29:29 +01:00
|
|
|
|
public string DefaultModelsDirectory => "~/App_Data/Models";
|
|
|
|
|
|
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets a value indicating whether the whole models experience is enabled.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>If this is false then absolutely nothing happens.</para>
|
|
|
|
|
|
/// <para>Default value is <c>false</c> which means that unless we have this setting, nothing happens.</para>
|
|
|
|
|
|
/// </remarks>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
public bool Enable => _configuration.GetValue(Prefix+"Enable", false);
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets the models mode.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
public ModelsMode ModelsMode =>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
_configuration.GetValue(Prefix+"ModelsMode", ModelsMode.Nothing);
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets the models namespace.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>That value could be overriden by other (attribute in user's code...). Return default if no value was supplied.</remarks>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
public string ModelsNamespace => _configuration.GetValue<string>(Prefix+"ModelsNamespace");
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets a value indicating whether we should enable the models factory.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>Default value is <c>true</c> because no factory is enabled by default in Umbraco.</remarks>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
public bool EnableFactory => _configuration.GetValue(Prefix+"EnableFactory", true);
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets a value indicating whether we should flag out-of-date models.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Models become out-of-date when data types or content types are updated. When this
|
|
|
|
|
|
/// setting is activated the ~/App_Data/Models/ood.txt file is then created. When models are
|
|
|
|
|
|
/// generated through the dashboard, the files is cleared. Default value is <c>false</c>.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public bool FlagOutOfDateModels =>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
_configuration.GetValue(Prefix+"FlagOutOfDateModels", false) && !ModelsMode.IsLive();
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets the models directory.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>Default is ~/App_Data/Models but that can be changed.</remarks>
|
2020-03-16 18:51:35 +01:00
|
|
|
|
public string ModelsDirectory =>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
_configuration.GetValue(Prefix+"ModelsDirectory", "~/App_Data/Models");
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets a value indicating whether to accept an unsafe value for ModelsDirectory.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// An unsafe value is an absolute path, or a relative path pointing outside
|
|
|
|
|
|
/// of the website root.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public bool AcceptUnsafeModelsDirectory =>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
_configuration.GetValue(Prefix+"AcceptUnsafeModelsDirectory", false);
|
2020-03-16 14:02:08 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-03-18 11:29:29 +01:00
|
|
|
|
/// Gets a value indicating the debug log level.
|
2020-03-16 14:02:08 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>0 means minimal (safe on live site), anything else means more and more details (maybe not safe).</remarks>
|
2020-03-19 19:06:05 +01:00
|
|
|
|
public int DebugLevel => _configuration.GetValue(Prefix+"DebugLevel", 0);
|
2020-03-16 14:02:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|