using Microsoft.Extensions.Configuration;
using Umbraco.Core;
using Umbraco.Core.Configuration;
namespace Umbraco.Configuration.Models
{
///
/// Represents the models builder configuration.
///
internal class ModelsBuilderConfig : IModelsBuilderConfig
{
private const string Prefix = Constants.Configuration.ConfigModelsBuilderPrefix;
private readonly IConfiguration _configuration;
///
/// Initializes a new instance of the class.
///
public ModelsBuilderConfig(IConfiguration configuration)
{
_configuration = configuration;
}
public string DefaultModelsDirectory => "~/App_Data/Models";
///
/// Gets a value indicating whether the whole models experience is enabled.
///
///
/// If this is false then absolutely nothing happens.
/// Default value is false which means that unless we have this setting, nothing happens.
///
public bool Enable => _configuration.GetValue(Prefix+"Enable", false);
///
/// Gets the models mode.
///
public ModelsMode ModelsMode =>
_configuration.GetValue(Prefix+"ModelsMode", ModelsMode.Nothing);
///
/// Gets the models namespace.
///
/// That value could be overriden by other (attribute in user's code...). Return default if no value was supplied.
public string ModelsNamespace => _configuration.GetValue(Prefix+"ModelsNamespace");
///
/// Gets a value indicating whether we should enable the models factory.
///
/// Default value is true because no factory is enabled by default in Umbraco.
public bool EnableFactory => _configuration.GetValue(Prefix+"EnableFactory", true);
///
/// Gets a value indicating whether we should flag out-of-date models.
///
///
/// 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 false.
///
public bool FlagOutOfDateModels =>
_configuration.GetValue(Prefix+"FlagOutOfDateModels", false) && !ModelsMode.IsLive();
///
/// Gets the models directory.
///
/// Default is ~/App_Data/Models but that can be changed.
public string ModelsDirectory =>
_configuration.GetValue(Prefix+"ModelsDirectory", "~/App_Data/Models");
///
/// Gets a value indicating whether to accept an unsafe value for ModelsDirectory.
///
///
/// An unsafe value is an absolute path, or a relative path pointing outside
/// of the website root.
///
public bool AcceptUnsafeModelsDirectory =>
_configuration.GetValue(Prefix+"AcceptUnsafeModelsDirectory", false);
///
/// Gets a value indicating the debug log level.
///
/// 0 means minimal (safe on live site), anything else means more and more details (maybe not safe).
public int DebugLevel => _configuration.GetValue(Prefix+"DebugLevel", 0);
}
}