public BlockListPropertyValueConverter(IProfilingLogger proflog, BlockEditorConverter blockConverter, IOptions <ModelsBuilderSettings> modelsBuilderOptions) { _proflog = proflog; _blockConverter = blockConverter; _blockListEditorDataConverter = new BlockListEditorDataConverter(); _modelsBuilderSettings = modelsBuilderOptions?.Value; }
public DashboardReport(IOptions <ModelsBuilderSettings> config, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { _config = config.Value; _outOfDateModels = outOfDateModels; _mbErrors = mbErrors; }
public ModelsGenerator(UmbracoServices umbracoService, IOptions <ModelsBuilderSettings> config, OutOfDateModelsStatus outOfDateModels, IHostingEnvironment hostingEnvironment) { _umbracoService = umbracoService; _config = config.Value; _outOfDateModels = outOfDateModels; _hostingEnvironment = hostingEnvironment; }
public ModelsGenerator(UmbracoServices umbracoService, IOptionsMonitor <ModelsBuilderSettings> config, OutOfDateModelsStatus outOfDateModels, IHostingEnvironment hostingEnvironment) { _umbracoService = umbracoService; _config = config.CurrentValue; _outOfDateModels = outOfDateModels; _hostingEnvironment = hostingEnvironment; config.OnChange(x => _config = x); }
public ModelsBuilderDashboardController(IOptions <ModelsBuilderSettings> config, ModelsGenerator modelsGenerator, OutOfDateModelsStatus outOfDateModels, ModelsGenerationError mbErrors) { _config = config.Value; _modelGenerator = modelsGenerator; _outOfDateModels = outOfDateModels; _mbErrors = mbErrors; _dashboardReport = new DashboardReport(config, outOfDateModels, mbErrors); }
public ModelsBuilderNotificationHandler( IOptions <ModelsBuilderSettings> config, IShortStringHelper shortStringHelper, IModelsBuilderDashboardProvider modelsBuilderDashboardProvider) { _config = config.Value; _shortStringHelper = shortStringHelper; _modelsBuilderDashboardProvider = modelsBuilderDashboardProvider; }
/// <summary> /// Adds umbraco's embedded model builder support /// </summary> public static IUmbracoBuilder AddModelsBuilder(this IUmbracoBuilder builder) { var umbServices = new UniqueServiceDescriptor(typeof(UmbracoServices), typeof(UmbracoServices), ServiceLifetime.Singleton); if (builder.Services.Contains(umbServices)) { // if this ext method is called more than once just exit return(builder); } builder.Services.Add(umbServices); builder.AddInMemoryModelsRazorEngine(); // TODO: I feel like we could just do builder.AddNotificationHandler<ModelsBuilderNotificationHandler>() and it // would automatically just register for all implemented INotificationHandler{T}? builder.AddNotificationHandler <TemplateSavingNotification, ModelsBuilderNotificationHandler>(); builder.AddNotificationHandler <ServerVariablesParsingNotification, ModelsBuilderNotificationHandler>(); builder.AddNotificationHandler <ModelBindingErrorNotification, ModelsBuilderNotificationHandler>(); builder.AddNotificationHandler <UmbracoApplicationStartingNotification, AutoModelsNotificationHandler>(); builder.AddNotificationHandler <UmbracoRequestEndNotification, AutoModelsNotificationHandler>(); builder.AddNotificationHandler <ContentTypeCacheRefresherNotification, AutoModelsNotificationHandler>(); builder.AddNotificationHandler <DataTypeCacheRefresherNotification, AutoModelsNotificationHandler>(); builder.Services.AddSingleton <ModelsGenerator>(); builder.Services.AddSingleton <OutOfDateModelsStatus>(); builder.AddNotificationHandler <ContentTypeCacheRefresherNotification, OutOfDateModelsStatus>(); builder.AddNotificationHandler <DataTypeCacheRefresherNotification, OutOfDateModelsStatus>(); builder.Services.AddSingleton <ModelsGenerationError>(); builder.Services.AddSingleton <InMemoryModelFactory>(); // This is what the community MB would replace, all of the above services are fine to be registered // even if the community MB is in place. builder.Services.AddSingleton <IPublishedModelFactory>(factory => { ModelsBuilderSettings config = factory.GetRequiredService <IOptions <ModelsBuilderSettings> >().Value; if (config.ModelsMode == ModelsMode.InMemoryAuto) { return(factory.GetRequiredService <InMemoryModelFactory>()); } else { return(factory.CreateDefaultPublishedModelFactory()); } }); if (!builder.Services.Any(x => x.ServiceType == typeof(IModelsBuilderDashboardProvider))) { builder.Services.AddUnique <IModelsBuilderDashboardProvider, NoopModelsBuilderDashboardProvider>(); } return(builder); }
public void GenerateAmbiguous() { var type1 = new TypeModel { Id = 1, Alias = "type1", ClrName = "Type1", ParentId = 0, BaseType = null, ItemType = TypeModel.ItemTypes.Content, IsMixin = true, }; type1.Properties.Add(new PropertyModel { Alias = "prop1", ClrName = "Prop1", ModelClrType = typeof(IPublishedContent), }); type1.Properties.Add(new PropertyModel { Alias = "prop2", ClrName = "Prop2", ModelClrType = typeof(StringBuilder), }); type1.Properties.Add(new PropertyModel { Alias = "prop3", ClrName = "Prop3", ModelClrType = typeof(global::Umbraco.Cms.Core.Exceptions.BootFailedException), }); TypeModel[] types = new[] { type1 }; var modelsBuilderConfig = new ModelsBuilderSettings(); var builder = new TextBuilder(modelsBuilderConfig, types) { ModelsNamespace = "Umbraco.ModelsBuilder.Models" // forces conflict with Umbraco.ModelsBuilder.Umbraco }; var sb = new StringBuilder(); foreach (TypeModel model in builder.GetModelsToGenerate()) { builder.Generate(sb, model); } var gen = sb.ToString(); Console.WriteLine(gen); Assert.IsTrue(gen.Contains(" global::Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent Prop1")); Assert.IsTrue(gen.Contains(" global::System.Text.StringBuilder Prop2")); Assert.IsTrue(gen.Contains(" global::Umbraco.Cms.Core.Exceptions.BootFailedException Prop3")); }
/// <summary> /// Initializes a new instance of the <see cref="Builder"/> class with a list of models to generate, /// the result of code parsing, and a models namespace. /// </summary> /// <param name="typeModels">The list of models to generate.</param> /// <param name="modelsNamespace">The models namespace.</param> protected Builder(ModelsBuilderSettings config, IList <TypeModel> typeModels) { TypeModels = typeModels ?? throw new ArgumentNullException(nameof(typeModels)); Config = config ?? throw new ArgumentNullException(nameof(config)); // can be null or empty, we'll manage ModelsNamespace = Config.ModelsNamespace; // but we want it to prepare Prepare(); }
/// <summary> /// Initializes a new instance of the <see cref="AutoModelsNotificationHandler"/> class. /// </summary> public AutoModelsNotificationHandler( ILogger <AutoModelsNotificationHandler> logger, IOptions <ModelsBuilderSettings> config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IMainDom mainDom) { _logger = logger; _config = config.Value ?? throw new ArgumentNullException(nameof(config)); _modelGenerator = modelGenerator; _mbErrors = mbErrors; _mainDom = mainDom; }
public static string ModelsDirectoryAbsolute(this ModelsBuilderSettings modelsBuilderConfig, IHostingEnvironment hostingEnvironment) { if (_modelsDirectoryAbsolute is null) { var modelsDirectory = modelsBuilderConfig.ModelsDirectory; var root = hostingEnvironment.MapPathContentRoot("~/"); _modelsDirectoryAbsolute = GetModelsDirectory(root, modelsDirectory, modelsBuilderConfig.AcceptUnsafeModelsDirectory); } return(_modelsDirectoryAbsolute); }
/// <summary> /// Initializes a new instance of the <see cref="AutoModelsNotificationHandler"/> class. /// </summary> public AutoModelsNotificationHandler( ILogger <AutoModelsNotificationHandler> logger, IOptionsMonitor <ModelsBuilderSettings> config, ModelsGenerator modelGenerator, ModelsGenerationError mbErrors, IMainDom mainDom) { _logger = logger; //We cant use IOptionsSnapshot here, cause this is used in the Core runtime, and that cannot use a scoped service as it has no scope _config = config.CurrentValue ?? throw new ArgumentNullException(nameof(config)); _modelGenerator = modelGenerator; _mbErrors = mbErrors; _mainDom = mainDom; }
public InMemoryModelFactory( Lazy <UmbracoServices> umbracoServices, IProfilingLogger profilingLogger, ILogger <InMemoryModelFactory> logger, IOptionsMonitor <ModelsBuilderSettings> config, IHostingEnvironment hostingEnvironment, IApplicationShutdownRegistry hostingLifetime, IPublishedValueFallback publishedValueFallback, ApplicationPartManager applicationPartManager) { _umbracoServices = umbracoServices; _profilingLogger = profilingLogger; _logger = logger; _config = config.CurrentValue; _hostingEnvironment = hostingEnvironment; _hostingLifetime = hostingLifetime; _publishedValueFallback = publishedValueFallback; _applicationPartManager = applicationPartManager; _errors = new ModelsGenerationError(config, _hostingEnvironment); _ver = 1; // zero is for when we had no version _skipver = -1; // nothing to skip if (!hostingEnvironment.IsHosted) { return; } config.OnChange(x => _config = x); _pureLiveDirectory = new Lazy <string>(PureLiveDirectoryAbsolute); if (!Directory.Exists(_pureLiveDirectory.Value)) { Directory.CreateDirectory(_pureLiveDirectory.Value); } // BEWARE! if the watcher is not properly released then for some reason the // BuildManager will start confusing types - using a 'registered object' here // though we should probably plug into Umbraco's MainDom - which is internal _hostingLifetime.RegisterObject(this); _watcher = new FileSystemWatcher(_pureLiveDirectory.Value); _watcher.Changed += WatcherOnChanged; _watcher.EnableRaisingEvents = true; // get it here, this need to be fast _debugLevel = _config.DebugLevel; AssemblyLoadContext.Default.Resolving += OnResolvingDefaultAssemblyLoadContext; }
public SystemInformationTelemetryProvider( IUmbracoVersion version, ILocalizationService localizationService, IOptions <ModelsBuilderSettings> modelsBuilderSettings, IOptions <HostingSettings> hostingSettings, IOptions <GlobalSettings> globalSettings, IHostEnvironment hostEnvironment, Lazy <IUmbracoDatabase> database) { _version = version; _localizationService = localizationService; _hostEnvironment = hostEnvironment; _database = database; _globalSettings = globalSettings.Value; _hostingSettings = hostingSettings.Value; _modelsBuilderSettings = modelsBuilderSettings.Value; }
public SystemInformationTelemetryProvider( IUmbracoVersion version, ILocalizationService localizationService, IOptionsMonitor <ModelsBuilderSettings> modelsBuilderSettings, IOptionsMonitor <HostingSettings> hostingSettings, IOptionsMonitor <GlobalSettings> globalSettings, IHostEnvironment hostEnvironment, IUmbracoDatabaseFactory umbracoDatabaseFactory) { _version = version; _localizationService = localizationService; _hostEnvironment = hostEnvironment; _umbracoDatabaseFactory = umbracoDatabaseFactory; _globalSettings = globalSettings.CurrentValue; _hostingSettings = hostingSettings.CurrentValue; _modelsBuilderSettings = modelsBuilderSettings.CurrentValue; }
private static IUmbracoBuilder AddInMemoryModelsRazorEngine(this IUmbracoBuilder builder) { // See notes in RefreshingRazorViewEngine for information on what this is doing. // copy the current collection, we need to use this later to rebuild a container // to re-create the razor compiler provider var initialCollection = new ServiceCollection { builder.Services }; // Replace the default with our custom engine builder.Services.AddSingleton <IRazorViewEngine>( s => new RefreshingRazorViewEngine( () => { // re-create the original container so that a brand new IRazorPageActivator // is produced, if we don't re-create the container then it will just return the same instance. ServiceProvider recreatedServices = initialCollection.BuildServiceProvider(); return(recreatedServices.GetRequiredService <IRazorViewEngine>()); }, s.GetRequiredService <InMemoryModelFactory>())); builder.Services.AddSingleton <InMemoryModelFactory>(); // This is what the community MB would replace, all of the above services are fine to be registered // even if the community MB is in place. builder.Services.AddSingleton <IPublishedModelFactory>(factory => { ModelsBuilderSettings modelsBuilderSettings = factory.GetRequiredService <IOptions <ModelsBuilderSettings> >().Value; if (modelsBuilderSettings.ModelsMode == ModelsMode.InMemoryAuto) { return(factory.GetRequiredService <InMemoryModelFactory>()); } else { return(factory.CreateDefaultPublishedModelFactory()); } }); return(builder); }
/// <summary> /// Initializes a new instance of the <see cref="OutOfDateModelsStatus"/> class. /// </summary> public OutOfDateModelsStatus(IOptions <ModelsBuilderSettings> config, IHostingEnvironment hostingEnvironment) { _config = config.Value; _hostingEnvironment = hostingEnvironment; }
/// <summary> /// Initializes a new instance of the <see cref="TextBuilder"/> class with a list of models to generate /// and the result of code parsing. /// </summary> /// <param name="typeModels">The list of models to generate.</param> public TextBuilder(ModelsBuilderSettings config, IList <TypeModel> typeModels) : base(config, typeModels) { }
public void GenerateComposedType() { // Umbraco returns nice, pascal-cased names. var composition1 = new TypeModel { Id = 2, Alias = "composition1", ClrName = "Composition1", Name = "composition1Name", ParentId = 0, BaseType = null, ItemType = TypeModel.ItemTypes.Content, IsMixin = true, }; composition1.Properties.Add(new PropertyModel { Alias = "compositionProp", ClrName = "CompositionProp", Name = "compositionPropName", ModelClrType = typeof(string), ClrTypeName = typeof(string).FullName }); var type1 = new TypeModel { Id = 1, Alias = "type1", ClrName = "Type1", Name = "type1Name", ParentId = 0, BaseType = null, ItemType = TypeModel.ItemTypes.Content, }; type1.Properties.Add(new PropertyModel { Alias = "prop1", ClrName = "Prop1", Name = "prop1Name", ModelClrType = typeof(string), }); type1.MixinTypes.Add(composition1); TypeModel[] types = new[] { type1, composition1 }; var modelsBuilderConfig = new ModelsBuilderSettings(); var builder = new TextBuilder(modelsBuilderConfig, types); SemVersion version = ApiVersion.Current.Version; var sb = new StringBuilder(); builder.Generate(sb, builder.GetModelsToGenerate().First()); var genComposed = sb.ToString(); var expectedComposed = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Umbraco.ModelsBuilder.Embedded v" + version + @" // // Changes to this file will be lost if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ using System; using System.Linq.Expressions; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Infrastructure.ModelsBuilder; using Umbraco.Cms.Core; using Umbraco.Extensions; namespace Umbraco.Cms.Web.Common.PublishedModels { /// <summary>type1Name</summary> [PublishedModel(""type1"")] public partial class Type1 : PublishedContentModel, IComposition1 { // helpers #pragma warning disable 0109 // new is redundant [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const string ModelTypeAlias = ""type1""; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const PublishedItemType ModelItemType = PublishedItemType.Content; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor) => PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias); [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<Type1, TValue>> selector) => PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector); #pragma warning restore 0109 private IPublishedValueFallback _publishedValueFallback; // ctor public Type1(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback) { _publishedValueFallback = publishedValueFallback; } // properties ///<summary> /// prop1Name ///</summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [global::System.Diagnostics.CodeAnalysis.MaybeNull] [ImplementPropertyType(""prop1"")] public virtual string Prop1 => this.Value<string>(_publishedValueFallback, ""prop1""); ///<summary> /// compositionPropName ///</summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [global::System.Diagnostics.CodeAnalysis.MaybeNull] [ImplementPropertyType(""compositionProp"")] public virtual string CompositionProp => global::Umbraco.Cms.Web.Common.PublishedModels.Composition1.GetCompositionProp(this, _publishedValueFallback); } } "; Console.WriteLine(genComposed); Assert.AreEqual(expectedComposed.ClearLf(), genComposed); var sb2 = new StringBuilder(); builder.Generate(sb2, builder.GetModelsToGenerate().Skip(1).First()); var genComposition = sb2.ToString(); var expectedComposition = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Umbraco.ModelsBuilder.Embedded v" + version + @" // // Changes to this file will be lost if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ using System; using System.Linq.Expressions; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Infrastructure.ModelsBuilder; using Umbraco.Cms.Core; using Umbraco.Extensions; namespace Umbraco.Cms.Web.Common.PublishedModels { // Mixin Content Type with alias ""composition1"" /// <summary>composition1Name</summary> public partial interface IComposition1 : IPublishedContent { /// <summary>compositionPropName</summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [global::System.Diagnostics.CodeAnalysis.MaybeNull] string CompositionProp { get; } } /// <summary>composition1Name</summary> [PublishedModel(""composition1"")] public partial class Composition1 : PublishedContentModel, IComposition1 { // helpers #pragma warning disable 0109 // new is redundant [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const string ModelTypeAlias = ""composition1""; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const PublishedItemType ModelItemType = PublishedItemType.Content; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor) => PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias); [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<Composition1, TValue>> selector) => PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector); #pragma warning restore 0109 private IPublishedValueFallback _publishedValueFallback; // ctor public Composition1(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback) { _publishedValueFallback = publishedValueFallback; } // properties ///<summary> /// compositionPropName ///</summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [global::System.Diagnostics.CodeAnalysis.MaybeNull] [ImplementPropertyType(""compositionProp"")] public virtual string CompositionProp => GetCompositionProp(this, _publishedValueFallback); /// <summary>Static getter for compositionPropName</summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public static string GetCompositionProp(IComposition1 that, IPublishedValueFallback publishedValueFallback) => that.Value<string>(publishedValueFallback, ""compositionProp""); } } "; Console.WriteLine(genComposition); Assert.AreEqual(expectedComposition.ClearLf(), genComposition); }
public void GenerateInheritedType() { var parentType = new TypeModel { Id = 1, Alias = "parentType", ClrName = "ParentType", Name = "parentTypeName", ParentId = 0, IsParent = true, BaseType = null, ItemType = TypeModel.ItemTypes.Content, }; parentType.Properties.Add(new PropertyModel { Alias = "prop1", ClrName = "Prop1", Name = "prop1Name", ModelClrType = typeof(string), }); var childType = new TypeModel { Id = 2, Alias = "childType", ClrName = "ChildType", Name = "childTypeName", ParentId = 1, BaseType = parentType, ItemType = TypeModel.ItemTypes.Content, }; TypeModel[] docTypes = new[] { parentType, childType }; var modelsBuilderConfig = new ModelsBuilderSettings(); var builder = new TextBuilder(modelsBuilderConfig, docTypes); var sb = new StringBuilder(); builder.Generate(sb, builder.GetModelsToGenerate().First()); var genParent = sb.ToString(); SemVersion version = ApiVersion.Current.Version; var expectedParent = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Umbraco.ModelsBuilder.Embedded v" + version + @" // // Changes to this file will be lost if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ using System; using System.Linq.Expressions; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Infrastructure.ModelsBuilder; using Umbraco.Cms.Core; using Umbraco.Extensions; namespace Umbraco.Cms.Web.Common.PublishedModels { /// <summary>parentTypeName</summary> [PublishedModel(""parentType"")] public partial class ParentType : PublishedContentModel { // helpers #pragma warning disable 0109 // new is redundant [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const string ModelTypeAlias = ""parentType""; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const PublishedItemType ModelItemType = PublishedItemType.Content; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor) => PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias); [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<ParentType, TValue>> selector) => PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector); #pragma warning restore 0109 private IPublishedValueFallback _publishedValueFallback; // ctor public ParentType(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback) { _publishedValueFallback = publishedValueFallback; } // properties ///<summary> /// prop1Name ///</summary> [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [global::System.Diagnostics.CodeAnalysis.MaybeNull] [ImplementPropertyType(""prop1"")] public virtual string Prop1 => this.Value<string>(_publishedValueFallback, ""prop1""); } } "; Console.WriteLine(genParent); Assert.AreEqual(expectedParent.ClearLf(), genParent); var sb2 = new StringBuilder(); builder.Generate(sb2, builder.GetModelsToGenerate().Skip(1).First()); var genChild = sb2.ToString(); var expectedChild = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Umbraco.ModelsBuilder.Embedded v" + version + @" // // Changes to this file will be lost if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ using System; using System.Linq.Expressions; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Infrastructure.ModelsBuilder; using Umbraco.Cms.Core; using Umbraco.Extensions; namespace Umbraco.Cms.Web.Common.PublishedModels { /// <summary>childTypeName</summary> [PublishedModel(""childType"")] public partial class ChildType : ParentType { // helpers #pragma warning disable 0109 // new is redundant [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const string ModelTypeAlias = ""childType""; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const PublishedItemType ModelItemType = PublishedItemType.Content; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor) => PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias); [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<ChildType, TValue>> selector) => PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector); #pragma warning restore 0109 private IPublishedValueFallback _publishedValueFallback; // ctor public ChildType(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback) { _publishedValueFallback = publishedValueFallback; } // properties } } "; Console.WriteLine(genChild); Assert.AreEqual(expectedChild.ClearLf(), genChild); }
/// <summary> /// Initializes a new instance of the <see cref="ModelsGenerationError"/> class. /// </summary> public ModelsGenerationError(IOptions <ModelsBuilderSettings> config, IHostingEnvironment hostingEnvironment) { _config = config.Value; _hostingEnvironment = hostingEnvironment; }
public void GenerateSimpleType_Ambiguous_Issue() { // Umbraco returns nice, pascal-cased names. var type1 = new TypeModel { Id = 1, Alias = "type1", ClrName = "Type1", ParentId = 0, BaseType = null, ItemType = TypeModel.ItemTypes.Content, }; type1.Properties.Add(new PropertyModel { Alias = "foo", ClrName = "Foo", ModelClrType = typeof(IEnumerable <>).MakeGenericType(ModelType.For("foo")), }); var type2 = new TypeModel { Id = 2, Alias = "foo", ClrName = "Foo", ParentId = 0, BaseType = null, ItemType = TypeModel.ItemTypes.Element, }; TypeModel[] types = new[] { type1, type2 }; var modelsBuilderConfig = new ModelsBuilderSettings(); var builder = new TextBuilder(modelsBuilderConfig, types) { ModelsNamespace = "Umbraco.Cms.Web.Common.PublishedModels" }; var sb1 = new StringBuilder(); builder.Generate(sb1, builder.GetModelsToGenerate().Skip(1).First()); var gen1 = sb1.ToString(); Console.WriteLine(gen1); var sb = new StringBuilder(); builder.Generate(sb, builder.GetModelsToGenerate().First()); var gen = sb.ToString(); SemVersion version = ApiVersion.Current.Version; var expected = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Umbraco.ModelsBuilder.Embedded v" + version + @" // // Changes to this file will be lost if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ using System; using System.Linq.Expressions; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.PublishedCache; using Umbraco.Cms.Infrastructure.ModelsBuilder; using Umbraco.Cms.Core; using Umbraco.Extensions; namespace Umbraco.Cms.Web.Common.PublishedModels { [PublishedModel(""type1"")] public partial class Type1 : PublishedContentModel { // helpers #pragma warning disable 0109 // new is redundant [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const string ModelTypeAlias = ""type1""; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] public new const PublishedItemType ModelItemType = PublishedItemType.Content; [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor) => PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias); [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [return: global::System.Diagnostics.CodeAnalysis.MaybeNull] public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<Type1, TValue>> selector) => PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector); #pragma warning restore 0109 private IPublishedValueFallback _publishedValueFallback; // ctor public Type1(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback) { _publishedValueFallback = publishedValueFallback; } // properties [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """ + version + @""")] [global::System.Diagnostics.CodeAnalysis.MaybeNull] [ImplementPropertyType(""foo"")] public virtual global::System.Collections.Generic.IEnumerable<global::" + modelsBuilderConfig.ModelsNamespace + @".Foo> Foo => this.Value<global::System.Collections.Generic.IEnumerable<global::" + modelsBuilderConfig.ModelsNamespace + @".Foo>>(_publishedValueFallback, ""foo""); } } "; Console.WriteLine(gen); Assert.AreEqual(expected.ClearLf(), gen); }
/// <summary> /// Initializes a new instance of the <see cref="OutOfDateModelsStatus"/> class. /// </summary> public OutOfDateModelsStatus(IOptionsMonitor <ModelsBuilderSettings> config, IHostingEnvironment hostingEnvironment) { _config = config.CurrentValue; _hostingEnvironment = hostingEnvironment; config.OnChange(x => _config = x); }
/// <summary> /// Initializes a new instance of the <see cref="ModelsGenerationError"/> class. /// </summary> public ModelsGenerationError(IOptionsMonitor <ModelsBuilderSettings> config, IHostingEnvironment hostingEnvironment) { _config = config.CurrentValue; _hostingEnvironment = hostingEnvironment; config.OnChange(x => _config = x); }