├── .gitattributes ├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── Packaging └── Umbraco.CodeGen.Package.xml ├── Umbraco.CodeGen.Integration ├── Api │ ├── ConfigurationController.cs │ ├── FactoriesDto.cs │ └── PreviewController.cs ├── ApplicationEvents.cs ├── AssemblyInfo.cs ├── Configuration.cs ├── USyncConfigurationProvider.cs ├── USyncDataTypeProvider.cs ├── Umbraco.CodeGen.Integration.csproj ├── app.config ├── config │ ├── CodeGen.config │ └── uSyncSettings.config └── packages.config ├── Umbraco.CodeGen.Packager ├── App.config ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Umbraco.CodeGen.Packager.csproj └── packages.config ├── Umbraco.CodeGen.Tests ├── AnnotatedCodeGeneratorAcceptanceTests.cs ├── BaseSupportedAnnotatedCodeGeneratorAcceptanceTests.cs ├── CodeGeneratorAcceptanceTestBase.cs ├── CodeGeneratorAcceptanceTests.cs ├── CodeParserAcceptanceTests.cs ├── CodeParserToXmlAcceptanceTests.cs ├── Configuration │ ├── CodeGeneratorConfigurationTests.cs │ ├── FileCodeGeneratorConfigurationProviderTests.cs │ └── USyncDataTypeProviderTests.cs ├── ContentTypeSerializerTests.cs ├── GenerateOnlyCodeGeneratorAcceptanceTests.cs ├── GenerateOnlyInterfaceAcceptanceTests.cs ├── Generators │ ├── Annotated │ │ ├── AnnotationCodeGeneratorTestBase.cs │ │ ├── CommonInfoGeneratorTests.cs │ │ ├── DocumentTypeInfoGeneratorTests.cs │ │ ├── EntityDescriptionGeneratorTests.cs │ │ ├── ImportsGeneratorTests.cs │ │ ├── PropertyInfoCodeGeneratorTests.cs │ │ └── StructureGeneratorTests.cs │ ├── AttributeGeneratorTests.cs │ ├── BaseSupportedAnnotated │ │ ├── CtorGeneratorTests.cs │ │ ├── ImportsGeneratorTests.cs │ │ └── PropertyBodyGeneratorTests.cs │ ├── Bcl │ │ ├── CommonInfoGeneratorTests.cs │ │ ├── DocumentTypeInfoGeneratorTests.cs │ │ ├── EntityDescriptionGeneratorTests.cs │ │ ├── ImportsGeneratorTests.cs │ │ ├── PropertyInfoCodeGeneratorTests.cs │ │ └── StructureGeneratorTests.cs │ ├── ClassGeneratorTests.cs │ ├── CodeGenerationHelper.cs │ ├── CodeGeneratorTestBase.cs │ ├── CtorGeneratorTests.cs │ ├── GenerateOnly │ │ ├── ImportsGeneratorTests.cs │ │ ├── InterfaceGeneratorTests.cs │ │ ├── InterfaceNameGeneratorTests.cs │ │ ├── InterfacePropertyBodyGeneratorTests.cs │ │ └── InterfacePropertyDeclarationGeneratorTests.cs │ ├── NamespaceGeneratorTests.cs │ ├── PropertiesGeneratorTests.cs │ ├── PropertyBodyGeneratorTest.cs │ ├── PropertyBodyGeneratorTestBase.cs │ ├── SpyGenerator.cs │ └── TypeCodeGeneratorTestBase.cs ├── Parsers │ ├── Annotated │ │ ├── CommonInfoParserTests.cs │ │ ├── DocumentTypeInfoParserTests.cs │ │ ├── PropertyParserTests.cs │ │ └── StructureParserTests.cs │ ├── Bcl │ │ ├── CommonInfoParserTests.cs │ │ ├── DocumentTypeInfoParserTests.cs │ │ ├── PropertyParserTests.cs │ │ └── StructureParserTests.cs │ ├── ContentTypeCodeParserTestBase.cs │ ├── DefaultParserFactoryTests.cs │ ├── MediaPropertyParserTests.cs │ ├── PropertiesParserTests.cs │ ├── PropertyParserTestBase.cs │ └── TabsParserTests.cs ├── Properties │ └── AssemblyInfo.cs ├── TestFiles │ ├── GenerateOnlyDocumentType.cs │ ├── GenerateOnlyDocumentTypeWithComposition.cs │ ├── GenerateOnlyInterface.cs │ ├── SomeAnnotatedDocumentType.cs │ ├── SomeAnnotatedMediaType.cs │ ├── SomeBaseSupportedAnnotatedDocumentType.cs │ ├── SomeBaseSupportedAnnotatedMediaType.cs │ ├── SomeDocumentType.cs │ ├── SomeDocumentType.xml │ ├── SomeMediaType.cs │ └── SomeMediaType.xml ├── TestHelpers │ ├── SerializationHelper.cs │ ├── TestDataTypeProvider.cs │ └── TestFactory.cs ├── Umbraco.CodeGen.Tests.csproj ├── app.config ├── config │ └── CodeGen.config ├── packages.config └── uSync │ ├── DataTypeDefinition │ ├── Approved Color.config │ ├── Checkbox list.config │ ├── Content Picker.config │ ├── Date Picker with time.config │ ├── Date Picker.config │ ├── Dropdown multiple.config │ ├── Dropdown.config │ ├── Folder Browser.config │ ├── Label.config │ ├── Media Picker.config │ ├── Member Picker.config │ ├── Multiple Media Picker.config │ ├── Numeric.config │ ├── Radiobox.config │ ├── Related Links.config │ ├── Richtext editor.config │ ├── Tags.config │ ├── Textbox multiple.config │ ├── Textstring.config │ ├── Truefalse.config │ └── Upload.config │ ├── DocumentType │ ├── SamePropertyName │ │ └── def.config │ └── pfxRoot │ │ ├── def.config │ │ ├── pfxChild │ │ ├── GrandChildNoPfx │ │ │ └── def.config │ │ └── def.config │ │ └── pfxSibling │ │ └── def.config │ └── MediaType │ ├── File │ └── def.config │ ├── Folder │ └── def.config │ └── Image │ └── def.config ├── Umbraco.CodeGen.Umbraco.Tests ├── Mapping_IContentType_To_ContentType.cs ├── Properties │ └── AssemblyInfo.cs ├── Umbraco.CodeGen.Umbraco.Tests.csproj ├── app.config └── packages.config ├── Umbraco.CodeGen.Umbraco ├── Bootstrap.cs ├── ContentTypeMapping.cs ├── ModelGenerator.cs ├── Properties │ └── AssemblyInfo.cs ├── Umbraco.CodeGen.Umbraco.csproj ├── UmbracoDataTypesProvider.cs ├── app.config └── packages.config ├── Umbraco.CodeGen.WaitForSixTwo ├── Properties │ └── AssemblyInfo.cs ├── PublishedContentFactoryHook.cs ├── Umbraco.CodeGen.WaitForSixTwo.csproj ├── Umbraco.CodeGen.WaitForSixTwo.nuspec ├── app.config └── packages.config ├── Umbraco.CodeGen.Web ├── App_Plugins │ └── CodeGen │ │ ├── backoffice │ │ └── codegen │ │ │ ├── codegen.configuration.html │ │ │ └── codegen.preview.html │ │ ├── codegen.configuration.contentType.html │ │ ├── codegen.configuration.controller.js │ │ ├── codegen.preview.controller.js │ │ └── package.manifest ├── App_Start │ └── RouteConfig.cs ├── Content │ ├── bootstrap-responsive.css │ ├── bootstrap-responsive.min.css │ ├── bootstrap.css │ └── bootstrap.min.css ├── Controllers │ └── HomeController.cs ├── Global.asax ├── Global.asax.cs ├── Properties │ └── AssemblyInfo.cs ├── Scripts │ ├── angular-cookies.js │ ├── angular-cookies.min.js │ ├── angular-loader.js │ ├── angular-loader.min.js │ ├── angular-mobile.js │ ├── angular-mobile.min.js │ ├── angular-mocks.js │ ├── angular-resource.js │ ├── angular-resource.min.js │ ├── angular-sanitize.js │ ├── angular-sanitize.min.js │ ├── angular-scenario.js │ ├── angular.js │ ├── angular.min.js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── jquery-2.1.0.intellisense.js │ ├── jquery-2.1.0.js │ ├── jquery-2.1.0.min.js │ └── jquery-2.1.0.min.map ├── Umbraco.CodeGen.Web.csproj ├── Umbraco │ └── Plugins │ │ └── uSync │ │ └── uSyncUi.ascx ├── Views │ ├── Home │ │ └── Index.cshtml │ └── Web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── config │ ├── CodeGen.config │ ├── dashboard.config.uninstall.xdt │ ├── trees.config.uninstall.xdt │ └── uSyncSettings.config ├── img │ ├── glyphicons-halflings-white.png │ └── glyphicons-halflings.png └── packages.config ├── Umbraco.CodeGen.sln ├── Umbraco.CodeGen ├── Annotations │ ├── ContentTypeAttribute.cs │ ├── DocumentTypeAttribute.cs │ ├── EntityDescriptionAttribute.cs │ ├── GenericPropertyAttribute.cs │ └── MediaTypeAttribute.cs ├── CodeGenerator.cs ├── CodeParser.cs ├── Configuration │ ├── CodeGeneratorConfiguration.cs │ ├── CodeGeneratorConfigurationFileProvider.cs │ ├── CodeGeneratorConfigurationProvider.cs │ ├── DataTypeDefinition.cs │ ├── IConfigurationProvider.cs │ ├── IDataTypeProvider.cs │ └── ParserAttribute.cs ├── ContentTypeSerializer.cs ├── Definitions │ ├── ClassDiagram.cd │ ├── ContentType.cs │ ├── DocumentType.cs │ ├── DocumentTypeInfo.cs │ ├── Entity.cs │ ├── EntityDescription.cs │ ├── EnumerableExtensions.cs │ ├── GenericProperty.cs │ ├── IEntityDescription.cs │ ├── Info.cs │ ├── MediaType.cs │ └── Tab.cs ├── EnumerableExtensions.cs ├── Generators │ ├── Annotated │ │ ├── CommonInfoGenerator.cs │ │ ├── DocumentTypeInfoGenerator.cs │ │ ├── EntityDescriptionGenerator.cs │ │ ├── ImportsGenerator.cs │ │ ├── PropertyInfoGenerator.cs │ │ └── StructureGenerator.cs │ ├── AnnotatedCodeGeneratorFactory.cs │ ├── AttributeCodeGenerator.cs │ ├── BaseSupportedAnnotated │ │ ├── CtorGenerator.cs │ │ ├── ImportsGenerator.cs │ │ └── PropertyBodyGenerator.cs │ ├── BaseSupportedAnnotatedCodeGeneratorFactory.cs │ ├── Bcl │ │ ├── CommonInfoGenerator.cs │ │ ├── DocumentTypeInfoGenerator.cs │ │ ├── EntityDescriptionGenerator.cs │ │ ├── ImportsGenerator.cs │ │ ├── PropertyInfoGenerator.cs │ │ └── StructureGenerator.cs │ ├── BclCodeGeneratorFactory.cs │ ├── ClassDiagram.cd │ ├── ClassGenerator.cs │ ├── CodeGeneratorBase.cs │ ├── CodeGeneratorFactory.cs │ ├── CompositeCodeGenerator.cs │ ├── CtorGenerator.cs │ ├── DefaultCodeGeneratorFactory.cs │ ├── EntityNameGenerator.cs │ ├── GenerateOnly │ │ ├── ImportsGenerator.cs │ │ ├── InterfaceGenerator.cs │ │ ├── InterfaceNameGenerator.cs │ │ ├── InterfacePropertyBodyGenerator.cs │ │ └── InterfacePropertyDeclarationGenerator.cs │ ├── GenerateOnlyGeneratorFactory.cs │ ├── InterfaceGeneratorFactory.cs │ ├── NameGenerator.cs │ ├── NamespaceGenerator.cs │ ├── PropertiesGenerator.cs │ ├── PropertyBodyGenerator.cs │ ├── PropertyDeclarationGenerator.cs │ └── PublicPropertyDeclarationGenerator.cs ├── Parsers │ ├── Annotated │ │ ├── CommonInfoParser.cs │ │ ├── DocumentTypeInfoParser.cs │ │ ├── PropertyParser.cs │ │ └── StructureParser.cs │ ├── AnnotatedParserFactory.cs │ ├── Bcl │ │ ├── CommonInfoParser.cs │ │ ├── DocumentTypeInfoParser.cs │ │ ├── PropertyParser.cs │ │ └── StructureParser.cs │ ├── BclParserFactory.cs │ ├── ClassDiagram.cd │ ├── CodeParserBase.cs │ ├── ContentTypeCodeParser.cs │ ├── ContentTypeCodeParserBase.cs │ ├── DefaultParserFactory.cs │ ├── DocumentTypeCodeParser.cs │ ├── InfoParserBase.cs │ ├── MediaPropertyParser.cs │ ├── MediaTypeCodeParser.cs │ ├── ParserFactory.cs │ ├── PropertiesParser.cs │ └── TabsParser.cs ├── Properties │ └── AssemblyInfo.cs ├── StringExtensions.cs ├── Umbraco.CodeGen.csproj ├── XExtensions.cs └── packages.config ├── license.txt ├── packaging └── Umbraco.CodeGen.nuspec └── readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lars-erik/Umbraco.CodeGen/1bc32b2a5cc921434341e4afb6b9307a6c2fa80c/.nuget/NuGet.exe -------------------------------------------------------------------------------- /Packaging/Umbraco.CodeGen.Package.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Umbraco.CodeGen.dll 6 | /bin 7 | Umbraco.CodeGen.dll 8 | 9 | 10 | Umbraco.CodeGen.Integration.dll 11 | /bin 12 | Umbraco.CodeGen.Integration.dll 13 | 14 | 15 | ICSharpCode.NRefactory.CSharp.dll 16 | /bin 17 | ICSharpCode.NRefactory.CSharp.dll 18 | 19 | 20 | ICSharpCode.NRefactory.dll 21 | /bin 22 | ICSharpCode.NRefactory.dll 23 | 24 | 25 | Mono.Cecil.dll 26 | /bin 27 | Mono.Cecil.dll 28 | 29 | 30 | CodeGen.config 31 | /config 32 | CodeGen.config 33 | 34 | 35 | 36 | 37 | Umbraco CodeGen 38 | 1.0.4937.26953 39 | MIT license 40 | http://lars-erik.github.io/Umbraco.CodeGen/ 41 | 42 | 6 43 | 1 44 | 0 45 | 46 | 47 | 48 | Lars-Erik Aabech 49 | http://aabech.no 50 | 51 | 52 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Integration/Api/FactoriesDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Umbraco.CodeGen.Integration.Api 8 | { 9 | public class FactoryDto 10 | { 11 | public string GeneratorFactory { get; set; } 12 | public string ParserFactory { get; set; } 13 | public string Description { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Integration/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco USync Code Generator")] 9 | [assembly: AssemblyDescription("Generates XML and code on uSync events")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Omnicom AS")] 12 | [assembly: AssemblyProduct("Umbraco USync Code Generator")] 13 | [assembly: AssemblyCopyright("Copyright © Omnicom AS 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("3ae9f628-f2c8-4424-88c0-97e829b19be6")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.*")] 33 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Integration/USyncConfigurationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Xml.Linq; 5 | using System.Xml.XPath; 6 | 7 | namespace Umbraco.CodeGen.Integration 8 | { 9 | public class USyncConfigurationProvider 10 | { 11 | private readonly string uSyncConfigPath; 12 | private readonly IRelativePathResolver pathResolver; 13 | 14 | public USyncConfigurationProvider(string uSyncConfigPath, IRelativePathResolver pathResolver) 15 | { 16 | this.uSyncConfigPath = uSyncConfigPath; 17 | this.pathResolver = pathResolver; 18 | } 19 | 20 | public USyncConfiguration GetConfiguration() 21 | { 22 | var configuration = new USyncConfiguration(); 23 | if (!File.Exists(uSyncConfigPath)) 24 | return configuration; 25 | var doc = XDocument.Load(uSyncConfigPath); 26 | var relativePath = doc.XPathSelectElements("configuration/usync").Select(e => e.AttributeValue("folder")).SingleOrDefault(); 27 | if (!String.IsNullOrEmpty(relativePath)) 28 | configuration.USyncFolder = pathResolver.Resolve(relativePath); 29 | return configuration; 30 | } 31 | } 32 | 33 | public class USyncConfiguration 34 | { 35 | public string USyncFolder { get; set; } 36 | } 37 | 38 | public interface IRelativePathResolver 39 | { 40 | string Resolve(string relativePath); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Integration/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Integration/config/CodeGen.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Integration/config/uSyncSettings.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 31 | 32 | 33 | 37 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Packager/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Packager/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco.CodeGen.Packager")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Umbraco.CodeGen.Packager")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("75539c5b-f9ad-48a9-b11e-c54f0e4036fd")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Packager/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/AnnotatedCodeGeneratorAcceptanceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Generators; 6 | using Umbraco.CodeGen.Generators.Annotated; 7 | 8 | namespace Umbraco.CodeGen.Tests 9 | { 10 | [TestFixture] 11 | public class AnnotatedCodeGeneratorAcceptanceTests : CodeGeneratorAcceptanceTestBase 12 | { 13 | [Test] 14 | public void BuildCode_GeneratesCodeForDocumentType() 15 | { 16 | TestBuildCode("SomeAnnotatedDocumentType", "SomeDocumentType", "DocumentType"); 17 | } 18 | 19 | [Test] 20 | public void BuildCode_GeneratesCodeForMediaType() 21 | { 22 | TestBuildCode("SomeAnnotatedMediaType", "SomeMediaType", "MediaType"); 23 | } 24 | 25 | protected override CodeGeneratorFactory CreateGeneratorFactory() 26 | { 27 | return new AnnotatedCodeGeneratorFactory(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/BaseSupportedAnnotatedCodeGeneratorAcceptanceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using NUnit.Framework; 7 | using Umbraco.CodeGen.Configuration; 8 | using Umbraco.CodeGen.Definitions; 9 | using Umbraco.CodeGen.Generators; 10 | using Umbraco.CodeGen.Generators.Annotated; 11 | using Umbraco.CodeGen.Tests.TestHelpers; 12 | 13 | namespace Umbraco.CodeGen.Tests 14 | { 15 | [TestFixture] 16 | public class BaseSupportedAnnotatedCodeGeneratorAcceptanceTests : CodeGeneratorAcceptanceTestBase 17 | { 18 | [Test] 19 | public void BuildCode_GeneratesCodeForDocumentType() 20 | { 21 | TestBuildCode("SomeBaseSupportedAnnotatedDocumentType", "SomeDocumentType", "DocumentType"); 22 | } 23 | 24 | [Test] 25 | public void BuildCode_GeneratesCodeForMediaType() 26 | { 27 | TestBuildCode("SomeBaseSupportedAnnotatedMediaType", "SomeMediaType", "MediaType"); 28 | } 29 | 30 | protected override void OnConfiguring(CodeGeneratorConfiguration configuration, string contentTypeName) 31 | { 32 | var typeConfig = configuration.Get(contentTypeName); 33 | typeConfig.BaseClass = "BaseClassWithSupport"; 34 | } 35 | 36 | protected override CodeGeneratorFactory CreateGeneratorFactory() 37 | { 38 | return new BaseSupportedAnnotatedCodeGeneratorFactory(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/CodeGeneratorAcceptanceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using NUnit.Framework; 5 | using Umbraco.CodeGen.Configuration; 6 | using Umbraco.CodeGen.Definitions; 7 | using Umbraco.CodeGen.Generators; 8 | using Umbraco.CodeGen.Parsers; 9 | using Umbraco.CodeGen.Tests.TestHelpers; 10 | 11 | namespace Umbraco.CodeGen.Tests 12 | { 13 | [TestFixture] 14 | public class CodeGeneratorAcceptanceTests : CodeGeneratorAcceptanceTestBase 15 | { 16 | [Test] 17 | public void BuildCode_GeneratesCodeForDocumentType() 18 | { 19 | TestBuildCode("SomeDocumentType", "DocumentType"); 20 | } 21 | 22 | [Test] 23 | public void BuildCode_GeneratesCodeForMediaType() 24 | { 25 | TestBuildCode("SomeMediaType", "MediaType"); 26 | } 27 | 28 | protected override CodeGeneratorFactory CreateGeneratorFactory() 29 | { 30 | return new BclCodeGeneratorFactory(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Configuration/USyncDataTypeProviderTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using NUnit.Framework; 5 | using Umbraco.CodeGen.Integration; 6 | 7 | namespace Umbraco.CodeGen.Tests.Configuration 8 | { 9 | [TestFixture] 10 | public class USyncDataTypeProviderTests 11 | { 12 | [Test] 13 | public void GetDataTypes_ReturnsTypesFromDiskConfig() 14 | { 15 | var provider = new USyncDataTypeProvider(@"..\..\uSync"); 16 | var dataTypes = provider.GetDataTypes().ToList(); 17 | Assert.AreNotEqual(0, dataTypes.Count()); 18 | Assert.IsNotNullOrEmpty(dataTypes.First().DataTypeName); 19 | Assert.AreNotEqual(String.Empty, dataTypes.First().DataTypeId); 20 | Assert.AreNotEqual(Guid.Empty, dataTypes.First().DefinitionId); 21 | foreach (var type in provider.GetDataTypes()) 22 | { 23 | Console.WriteLine("{0,-25}{1,-30}{2,-20}", type.DataTypeName, type.DataTypeId, type.DefinitionId); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/GenerateOnlyInterfaceAcceptanceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | using Umbraco.CodeGen.Generators; 6 | 7 | namespace Umbraco.CodeGen.Tests 8 | { 9 | [TestFixture] 10 | public class GenerateOnlyInterfaceAcceptanceTests : CodeGeneratorAcceptanceTestBase 11 | { 12 | [Test] 13 | public void BuildCode_Generates_Interface() 14 | { 15 | TestBuildCode("GenerateOnlyInterface", CreateInterfaceType(), "DocumentType"); 16 | } 17 | 18 | protected override CodeGeneratorFactory CreateGeneratorFactory() 19 | { 20 | return new InterfaceGeneratorFactory(); 21 | } 22 | 23 | protected override void OnConfiguring(CodeGeneratorConfiguration configuration, string contentTypeName) 24 | { 25 | var config = configuration.Get(contentTypeName); 26 | config.BaseClass = "IPublishedContent"; 27 | } 28 | 29 | private static DocumentType CreateInterfaceType() 30 | { 31 | var expected = new DocumentType 32 | { 33 | Info = new DocumentTypeInfo() 34 | { 35 | Alias = "Mixin" 36 | }, 37 | Tabs = new List { new Tab { Caption = "Mixin tab" } }, 38 | GenericProperties = new List 39 | { 40 | new GenericProperty 41 | { 42 | Alias = "mixinProp", 43 | Name = "Mixin prop", 44 | Type = "Umbraco.Integer", 45 | Tab = "Mixin tab" 46 | } 47 | } 48 | }; 49 | return expected; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/Annotated/AnnotationCodeGeneratorTestBase.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | 4 | namespace Umbraco.CodeGen.Tests.Generators.Annotated 5 | { 6 | public class AnnotationCodeGeneratorTestBase : CodeGeneratorTestBase 7 | { 8 | protected static object FindAttributeArgumentValue(CodeAttributeDeclaration attributeDeclaration, string attributeName) 9 | { 10 | var argument = FindAttributeArgument(attributeDeclaration, attributeName); 11 | var argValue = ((CodePrimitiveExpression)argument.Value).Value; 12 | return argValue; 13 | } 14 | 15 | protected static CodeAttributeArgument FindAttributeArgument(CodeAttributeDeclaration attributeDeclaration, 16 | string attributeName) 17 | { 18 | var argument = attributeDeclaration.Arguments 19 | .Cast() 20 | .SingleOrDefault(arg => arg.Name == attributeName); 21 | return argument; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/Annotated/ImportsGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using NUnit.Framework; 7 | using Umbraco.CodeGen.Generators.Annotated; 8 | 9 | namespace Umbraco.CodeGen.Tests.Generators.Annotated 10 | { 11 | [TestFixture] 12 | public class ImportsGeneratorTests 13 | { 14 | [Test] 15 | public void Generate_AddsImports() 16 | { 17 | var ns = new CodeNamespace("ANamespace"); 18 | var generator = new ImportsGenerator(null); 19 | generator.Generate(ns, null); 20 | Assert.That( 21 | new[] 22 | { 23 | "global::System", 24 | "global::Umbraco.CodeGen.Annotations", 25 | "global::Umbraco.Core.Models", 26 | "global::Umbraco.Web" 27 | }.SequenceEqual( 28 | ns.Imports.Cast() 29 | .Select(import => import.Namespace) 30 | )); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/BaseSupportedAnnotated/CtorGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using NUnit.Framework; 3 | using Umbraco.CodeGen.Definitions; 4 | using Umbraco.CodeGen.Generators.BaseSupportedAnnotated; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators.BaseSupportedAnnotated 7 | { 8 | [TestFixture] 9 | public class CtorGeneratorTests 10 | { 11 | [Test] 12 | public void Generate_AddsConstructorWithBaseCall_PassingQualifiedIPublishedContentParameter() 13 | { 14 | var type = new CodeTypeDeclaration{Name="AName"}; 15 | type.BaseTypes.Add("ABaseType"); 16 | var generator = new CtorGenerator(null); 17 | generator.Generate(type, new MediaType()); 18 | 19 | var ns = CodeGenerationHelper.CreateNamespaceWithType(type); 20 | var code = CodeGenerationHelper.GenerateCode(ns); 21 | 22 | Assert.AreEqual( 23 | @"namespace ANamespace { 24 | 25 | 26 | public class AName : ABaseType { 27 | 28 | public AName(Umbraco.Core.Models.IPublishedContent content) : 29 | base(content) { 30 | } 31 | } 32 | } 33 | ", code.ToString()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/BaseSupportedAnnotated/ImportsGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Generators.BaseSupportedAnnotated; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators.BaseSupportedAnnotated 7 | { 8 | [TestFixture] 9 | class ImportsGeneratorTests 10 | { 11 | [Test] 12 | public void Generate_AddsImports() 13 | { 14 | var ns = new CodeNamespace("ANamespace"); 15 | var generator = new ImportsGenerator(null); 16 | generator.Generate(ns, null); 17 | Assert.That( 18 | new[] 19 | { 20 | "global::System", 21 | "global::Umbraco.CodeGen.Annotations" 22 | }.SequenceEqual( 23 | ns.Imports.Cast() 24 | .Select(import => import.Namespace) 25 | )); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/BaseSupportedAnnotated/PropertyBodyGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Generators; 4 | using PropertyBodyGenerator = Umbraco.CodeGen.Generators.BaseSupportedAnnotated.PropertyBodyGenerator; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators.BaseSupportedAnnotated 7 | { 8 | [TestFixture] 9 | public class PropertyBodyGeneratorTests : PropertyBodyGeneratorTestBase 10 | { 11 | [Test] 12 | public void Generate_Body_GetsValueFromBaseMethodGetValue() 13 | { 14 | var body = GeneratePropertyAndGetBodyText(); 15 | 16 | Assert.AreEqual( 17 | "return GetValue(\"aProperty\");", 18 | body 19 | ); 20 | } 21 | 22 | protected override CodeGeneratorBase CreateGenerator() 23 | { 24 | return new PropertyBodyGenerator(CodeGeneratorConfiguration.Create().MediaTypes); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/Bcl/ImportsGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Generators.Bcl; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators.Bcl 7 | { 8 | [TestFixture] 9 | public class ImportsGeneratorTests 10 | { 11 | [Test] 12 | public void Generate_AddsImports() 13 | { 14 | var ns = new CodeNamespace("ANamespace"); 15 | var generator = new ImportsGenerator(null); 16 | generator.Generate(ns, null); 17 | Assert.That( 18 | new[] 19 | { 20 | "global::System", 21 | "global::System.ComponentModel", 22 | "global::System.ComponentModel.DataAnnotations", 23 | "global::Umbraco.Core.Models", 24 | "global::Umbraco.Web" 25 | }.SequenceEqual( 26 | ns.Imports.Cast() 27 | .Select(import => import.Namespace) 28 | )); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/CodeGenerationHelper.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.CodeDom.Compiler; 3 | using System.IO; 4 | using System.Text; 5 | using Microsoft.CSharp; 6 | 7 | static internal class CodeGenerationHelper 8 | { 9 | public static CodeNamespace CreateNamespaceWithTypeAndProperty(CodeMemberProperty propNode) 10 | { 11 | var type = new CodeTypeDeclaration("AClass"); 12 | type.Members.Add(propNode); 13 | return CreateNamespaceWithType(type); 14 | } 15 | 16 | public static CodeNamespace CreateNamespaceWithType(CodeTypeDeclaration type) 17 | { 18 | var ns = new CodeNamespace("ANamespace"); 19 | ns.Types.Add(type); 20 | return ns; 21 | } 22 | 23 | public static StringBuilder GenerateCode(CodeNamespace ns) 24 | { 25 | var codeProvider = new CSharpCodeProvider(); 26 | var builder = new StringBuilder(); 27 | var writer = new StringWriter(builder); 28 | 29 | codeProvider.GenerateCodeFromNamespace(ns, writer, new CodeGeneratorOptions()); 30 | writer.Flush(); 31 | return builder; 32 | } 33 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/CodeGeneratorTestBase.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Generators; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators 7 | { 8 | public abstract class CodeGeneratorTestBase 9 | { 10 | protected CodeGeneratorBase Generator; 11 | protected CodeTypeMember Candidate; 12 | protected ContentTypeConfiguration Configuration; 13 | 14 | protected object FindAttributeValue(string attributeName) 15 | { 16 | var attribute = FindAttribute(attributeName); 17 | var value = ((CodePrimitiveExpression) attribute.Arguments[0].Value).Value; 18 | return value; 19 | } 20 | 21 | protected CodeAttributeDeclaration FindAttribute(string attributeName) 22 | { 23 | var attribute = Candidate.CustomAttributes.Cast().SingleOrDefault(att => att.Name == attributeName); 24 | return attribute; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/CtorGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using NUnit.Framework; 3 | using Umbraco.CodeGen.Definitions; 4 | using Umbraco.CodeGen.Generators; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators 7 | { 8 | [TestFixture] 9 | public class CtorGeneratorTests 10 | { 11 | [Test] 12 | public void Generate_AddsConstructorWithBaseCall_PassingIPublishedContentParameter() 13 | { 14 | var type = new CodeTypeDeclaration{Name="AName"}; 15 | type.BaseTypes.Add("ABaseType"); 16 | var generator = new CtorGenerator(null); 17 | generator.Generate(type, new MediaType()); 18 | 19 | var ns = CodeGenerationHelper.CreateNamespaceWithType(type); 20 | var code = CodeGenerationHelper.GenerateCode(ns); 21 | 22 | Assert.AreEqual( 23 | @"namespace ANamespace { 24 | 25 | 26 | public class AName : ABaseType { 27 | 28 | public AName(IPublishedContent content) : 29 | base(content) { 30 | } 31 | } 32 | } 33 | ", code.ToString()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/GenerateOnly/ImportsGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Generators.GenerateOnly; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators.GenerateOnly 7 | { 8 | [TestFixture] 9 | public class ImportsGeneratorTests 10 | { 11 | [Test] 12 | public void Generate_AddsImports() 13 | { 14 | var ns = new CodeNamespace("ANamespace"); 15 | var generator = new ImportsGenerator(null); 16 | generator.Generate(ns, null); 17 | Assert.That( 18 | new[] 19 | { 20 | "global::System", 21 | "global::Umbraco.Core.Models", 22 | "global::Umbraco.Web" 23 | }.SequenceEqual( 24 | ns.Imports.Cast() 25 | .Select(import => import.Namespace) 26 | )); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/GenerateOnly/InterfaceGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | using Umbraco.CodeGen.Generators; 7 | using Umbraco.CodeGen.Generators.GenerateOnly; 8 | 9 | namespace Umbraco.CodeGen.Tests.Generators.GenerateOnly 10 | { 11 | [TestFixture] 12 | public class InterfaceGeneratorTests : TypeCodeGeneratorTestBase 13 | { 14 | private CodeNamespace ns; 15 | 16 | [SetUp] 17 | public void SetUp() 18 | { 19 | Configuration = CodeGeneratorConfiguration.Create().DocumentTypes; 20 | Generator = new InterfaceGenerator( 21 | Configuration 22 | ); 23 | ContentType = new DocumentType { Info = { Alias = "Mixin" } }; 24 | ns = new CodeNamespace("ANamespace"); 25 | } 26 | 27 | [Test] 28 | public void Generate_AddsTypeToNamespace() 29 | { 30 | Generate(); 31 | Assert.IsNotNull(Type); 32 | } 33 | 34 | [Test] 35 | public void Derives_From_IPublishedContent() 36 | { 37 | Generate(); 38 | Assert.AreEqual("IPublishedContent", Type.BaseTypes[0].BaseType); 39 | } 40 | 41 | [Test] 42 | public void Is_Interface() 43 | { 44 | Generate(); 45 | Assert.IsTrue(Type.IsInterface); 46 | } 47 | 48 | [Test] 49 | public void Is_Partial() 50 | { 51 | Generate(); 52 | Assert.IsTrue(Type.IsPartial); 53 | } 54 | 55 | [Test] 56 | public void CallsMemberGenerators() 57 | { 58 | var spies = new[] { new SpyGenerator(), new SpyGenerator() }; 59 | var memberGenerators = spies.Cast().ToArray(); 60 | Generator = new ClassGenerator(Configuration, memberGenerators); 61 | Generate(); 62 | Assert.That(spies.All(s => s.Called)); 63 | } 64 | 65 | protected void Generate() 66 | { 67 | Generator.Generate(ns, ContentType); 68 | Candidate = Type = ns.Types.Cast().Single(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/GenerateOnly/InterfaceNameGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using NUnit.Framework; 8 | using Umbraco.CodeGen.Configuration; 9 | using Umbraco.CodeGen.Definitions; 10 | using Umbraco.CodeGen.Generators.GenerateOnly; 11 | 12 | namespace Umbraco.CodeGen.Tests.Generators.GenerateOnly 13 | { 14 | [TestFixture] 15 | public class InterfaceNameGeneratorTests : TypeCodeGeneratorTestBase 16 | { 17 | protected EntityDescription EntityDescription; 18 | private DocumentType documentType; 19 | 20 | [SetUp] 21 | public void SetUp() 22 | { 23 | Configuration = CodeGeneratorConfiguration.Create().DocumentTypes; 24 | Candidate = Type = new CodeTypeDeclaration(); 25 | Generator = new InterfaceNameGenerator(Configuration); 26 | documentType = new DocumentType { Info = { Alias = "aMixin" } }; 27 | EntityDescription = documentType.Info; 28 | } 29 | 30 | [Test] 31 | public void Generate_Alias_Pascal_Cases_Name_And_Prefixes_With_I() 32 | { 33 | Generate(); 34 | Assert.AreEqual("I" + EntityDescription.Alias.PascalCase(), Candidate.Name); 35 | } 36 | 37 | protected virtual void Generate() 38 | { 39 | Generator.Generate(Candidate, EntityDescription); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/GenerateOnly/InterfacePropertyBodyGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using NUnit.Framework; 8 | using Umbraco.CodeGen.Configuration; 9 | using Umbraco.CodeGen.Definitions; 10 | using Umbraco.CodeGen.Generators.GenerateOnly; 11 | 12 | namespace Umbraco.CodeGen.Tests.Generators.GenerateOnly 13 | { 14 | [TestFixture] 15 | public class InterfacePropertyBodyGeneratorTests : TypeCodeGeneratorTestBase 16 | { 17 | [Test] 18 | public void Generate_Adds_Getter() 19 | { 20 | var property = new GenericProperty { Alias = "aProperty" }; 21 | var propNode = new CodeMemberProperty { Type = new CodeTypeReference("String") }; 22 | 23 | var generator = new InterfacePropertyBodyGenerator(CodeGeneratorConfiguration.Create().DocumentTypes); 24 | generator.Generate(propNode, property); 25 | 26 | Assert.IsTrue(propNode.HasGet); 27 | Assert.AreEqual(0, propNode.GetStatements.Count); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/NamespaceGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Linq; 4 | using NUnit.Framework; 5 | using Umbraco.CodeGen.Configuration; 6 | using Umbraco.CodeGen.Definitions; 7 | using Umbraco.CodeGen.Generators; 8 | 9 | namespace Umbraco.CodeGen.Tests.Generators 10 | { 11 | [TestFixture] 12 | public class NamespaceGeneratorTests : TypeCodeGeneratorTestBase 13 | { 14 | private CodeCompileUnit compileUnit; 15 | 16 | [SetUp] 17 | public void SetUp() 18 | { 19 | Configuration = CodeGeneratorConfiguration.Create().MediaTypes; 20 | Configuration.Namespace = "MyWeb.Models"; 21 | ContentType = new MediaType(); 22 | Generator = new NamespaceGenerator(Configuration); 23 | compileUnit = new CodeCompileUnit(); 24 | } 25 | 26 | [Test] 27 | public void Generate_AddsNamespace() 28 | { 29 | Generator.Generate(compileUnit, ContentType); 30 | Assert.AreEqual("MyWeb.Models", GetNamespace().Name); 31 | } 32 | 33 | [Test] 34 | [ExpectedException(typeof(Exception), ExpectedMessage = "ContentType namespace not configured.")] 35 | [TestCase(null)] 36 | [TestCase("")] 37 | [TestCase(" ")] 38 | public void Generate_NoConfiguredNamespace_Throws(string value) 39 | { 40 | Configuration.Namespace = value; 41 | Generator.Generate(compileUnit, ContentType); 42 | } 43 | 44 | [Test] 45 | public void CallsMemberGenerators() 46 | { 47 | var spies = new[]{new SpyGenerator(), new SpyGenerator()}; 48 | var memberGenerators = spies.Cast().ToArray(); 49 | Generator = new NamespaceGenerator(Configuration, memberGenerators); 50 | Generator.Generate(compileUnit, ContentType); 51 | Assert.That(spies.All(s => s.Called)); 52 | } 53 | 54 | private CodeNamespace GetNamespace() 55 | { 56 | return compileUnit.Namespaces.Cast().Single(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/PropertyBodyGeneratorTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Generators; 4 | 5 | namespace Umbraco.CodeGen.Tests.Generators 6 | { 7 | [TestFixture] 8 | public class PropertyBodyGeneratorTest : PropertyBodyGeneratorTestBase 9 | { 10 | [Test] 11 | public void Generate_Body_GetsContentPropertyValueOfType() 12 | { 13 | var body = GeneratePropertyAndGetBodyText(); 14 | 15 | Assert.AreEqual( 16 | "return Content.GetPropertyValue(\"aProperty\");", 17 | body 18 | ); 19 | } 20 | 21 | protected override CodeGeneratorBase CreateGenerator() 22 | { 23 | return new PropertyBodyGenerator(CodeGeneratorConfiguration.Create().MediaTypes); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/PropertyBodyGeneratorTestBase.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | using Umbraco.CodeGen.Generators; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators 7 | { 8 | public abstract class PropertyBodyGeneratorTestBase 9 | { 10 | protected string GeneratePropertyAndGetBodyText() 11 | { 12 | var property = new GenericProperty {Alias = "aProperty"}; 13 | var propNode = new CodeMemberProperty {Type = new CodeTypeReference("String")}; 14 | var generator = CreateGenerator(); 15 | 16 | generator.Generate(propNode, property); 17 | 18 | var ns = CodeGenerationHelper.CreateNamespaceWithTypeAndProperty(propNode); 19 | var builder = CodeGenerationHelper.GenerateCode(ns); 20 | 21 | var code = builder.ToString(); 22 | var returnIndex = code.IndexOf("return"); 23 | var endIndex = code.IndexOf(";", returnIndex); 24 | var body = code.Substring(returnIndex, endIndex - returnIndex + 1); 25 | return body; 26 | } 27 | 28 | protected abstract CodeGeneratorBase CreateGenerator(); 29 | } 30 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/SpyGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Collections.Generic; 3 | using Umbraco.CodeGen.Definitions; 4 | using Umbraco.CodeGen.Generators; 5 | 6 | namespace Umbraco.CodeGen.Tests.Generators 7 | { 8 | public class SpyGenerator : CodeGeneratorBase 9 | { 10 | public bool Called; 11 | public List CodeObjects = new List(); 12 | 13 | public SpyGenerator() : base(null) 14 | { 15 | } 16 | 17 | public override void Generate(object codeObject, Entity entity) 18 | { 19 | CodeObjects.Add(codeObject); 20 | Called = true; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Generators/TypeCodeGeneratorTestBase.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Tests.Generators 6 | { 7 | public abstract class TypeCodeGeneratorTestBase : CodeGeneratorTestBase 8 | { 9 | protected ContentType ContentType; 10 | protected CodeTypeDeclaration Type; 11 | 12 | protected object PrimitiveFieldValue(string fieldName) 13 | { 14 | var field = FindField(fieldName); 15 | if (field == null) return null; 16 | return ((CodePrimitiveExpression)field.InitExpression).Value; 17 | } 18 | 19 | protected CodeMemberField FindField(string fieldName) 20 | { 21 | return Type.Members.Cast() 22 | .SingleOrDefault(f => f.Name == fieldName); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/Annotated/StructureParserTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | using Umbraco.CodeGen.Parsers.Annotated; 7 | 8 | namespace Umbraco.CodeGen.Tests.Parsers.Annotated 9 | { 10 | [TestFixture] 11 | public class StructureParserTests : ContentTypeCodeParserTestBase 12 | { 13 | [SetUp] 14 | public void SetUp() 15 | { 16 | Configuration = CodeGeneratorConfiguration.Create().MediaTypes; 17 | Parser = new StructureParser(Configuration); 18 | ContentType = new MediaType(); 19 | } 20 | 21 | [Test] 22 | public void Parse_Structure_WhenStructureMember_HasMemberValue() 23 | { 24 | const string code = @" 25 | [MediaType(Structure = new[]{ 26 | typeof(AnotherClass), 27 | typeof(DifferentClass) 28 | })] 29 | public class AClass { 30 | }"; 31 | 32 | Parse(code); 33 | Console.WriteLine(String.Join(", ", ContentType.Structure)); 34 | Assert.That( 35 | new[] { "AnotherClass", "DifferentClass" } 36 | .SequenceEqual(ContentType.Structure) 37 | ); 38 | } 39 | 40 | [Test] 41 | public void Parse_Structure_WhenStructureMemberMissing_IsEmpty() 42 | { 43 | Parse(EmptyClass); 44 | Assert.AreEqual(0, ContentType.Structure.Count); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/Bcl/DocumentTypeInfoParserTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NUnit.Framework; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | using Umbraco.CodeGen.Parsers.Bcl; 6 | 7 | namespace Umbraco.CodeGen.Tests.Parsers.Bcl 8 | { 9 | [TestFixture] 10 | public class DocumentTypeInfoParserTests : ContentTypeCodeParserTestBase 11 | { 12 | private DocumentTypeInfo typedInfo; 13 | 14 | [SetUp] 15 | public void SetUp() 16 | { 17 | Configuration = CodeGeneratorConfiguration.Create().MediaTypes; 18 | Parser = new DocumentTypeInfoParser(Configuration); 19 | ContentType = new DocumentType(); 20 | Info = ContentType.Info; 21 | typedInfo = (DocumentTypeInfo) Info; 22 | } 23 | 24 | [Test] 25 | public void DefaultTemplate_WhenMember_HasMemberValue() 26 | { 27 | const string code = @" 28 | public class AClass { 29 | string defaultTemplate = ""defaultTemplate""; 30 | }"; 31 | Parse(code); 32 | Assert.AreEqual("defaultTemplate", typedInfo.DefaultTemplate); 33 | } 34 | 35 | [Test] 36 | public void DefaultTemplate_WhenMissingMember_IsNull() 37 | { 38 | Parse(EmptyClass); 39 | Assert.IsNull(typedInfo.DefaultTemplate); 40 | } 41 | 42 | [Test] 43 | public void AllowedTemplates_WhenMember_HasMemberValue() 44 | { 45 | const string code = @" 46 | public class AClass { 47 | string[] allowedTemplates = new[]{ 48 | ""template"", 49 | ""another"" 50 | }; 51 | }"; 52 | Parse(code); 53 | Assert.That( 54 | new[]{"template", "another"} 55 | .SequenceEqual(typedInfo.AllowedTemplates) 56 | ); 57 | } 58 | 59 | [Test] 60 | public void AllowedTemplates_WhenMissingMember_IsEmpty() 61 | { 62 | Parse(EmptyClass); 63 | Assert.AreEqual(0, typedInfo.AllowedTemplates.Count); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/Bcl/StructureParserTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NUnit.Framework; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | using Umbraco.CodeGen.Parsers.Bcl; 6 | 7 | namespace Umbraco.CodeGen.Tests.Parsers.Bcl 8 | { 9 | [TestFixture] 10 | public class StructureParserTests : ContentTypeCodeParserTestBase 11 | { 12 | [SetUp] 13 | public void SetUp() 14 | { 15 | Configuration = CodeGeneratorConfiguration.Create().MediaTypes; 16 | Parser = new StructureParser(Configuration); 17 | ContentType = new MediaType(); 18 | } 19 | 20 | [Test] 21 | public void Parse_Structure_WhenStructureMember_HasMemberValue() 22 | { 23 | const string code = @" 24 | public class AClass { 25 | Type[] structure = new[]{ 26 | typeof(AnotherClass), 27 | typeof(DifferentClass) 28 | }; 29 | }"; 30 | 31 | Parse(code); 32 | Assert.That( 33 | new[]{"AnotherClass", "DifferentClass"} 34 | .SequenceEqual(ContentType.Structure) 35 | ); 36 | } 37 | 38 | [Test] 39 | public void Parse_Structure_WhenStructureMemberMissing_IsEmpty() 40 | { 41 | Parse(EmptyClass); 42 | Assert.AreEqual(0, ContentType.Structure.Count); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/ContentTypeCodeParserTestBase.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using ICSharpCode.NRefactory.CSharp; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | using Umbraco.CodeGen.Parsers; 7 | 8 | namespace Umbraco.CodeGen.Tests.Parsers 9 | { 10 | public class ContentTypeCodeParserTestBase 11 | { 12 | protected const string EmptyClass = @"public class AClass {}"; 13 | protected ContentTypeConfiguration Configuration; 14 | protected ContentTypeCodeParserBase Parser; 15 | protected ContentType ContentType; 16 | protected Info Info; 17 | 18 | protected void Parse(string code) 19 | { 20 | var type = ParseType(code); 21 | Parser.Parse(type, ContentType); 22 | } 23 | 24 | protected static TypeDeclaration ParseType(string code) 25 | { 26 | var cSharpParser = new CSharpParser(); 27 | var tree = cSharpParser.Parse(code); 28 | Assert.AreEqual(0, tree.Errors.Count, tree.Errors.Aggregate("", (s, e) => s + e.Message + "\r\n")); 29 | var type = tree.GetTypes().Single(); 30 | return (TypeDeclaration)type; 31 | } 32 | 33 | protected object PropertyValue(string memberName) 34 | { 35 | return Info.GetType().GetProperty(memberName).GetValue(Info, null); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/DefaultParserFactoryTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using NUnit.Framework; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Parsers; 5 | 6 | namespace Umbraco.CodeGen.Tests.Parsers 7 | { 8 | [TestFixture] 9 | public class DefaultParserFactoryTests 10 | { 11 | [Test] 12 | public void Create_DelegatesConfiguration() 13 | { 14 | var factory = new DefaultParserFactory(); 15 | var configuration = new ContentTypeConfiguration(CodeGeneratorConfiguration.Create(), "DocumentType"); 16 | var dataTypeDefinitions = new List(); 17 | var parser = factory.Create(configuration, dataTypeDefinitions); 18 | Assert.IsInstanceOf(parser); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/MediaPropertyParserTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using Umbraco.CodeGen.Parsers; 3 | using Umbraco.CodeGen.Tests.TestHelpers; 4 | 5 | namespace Umbraco.CodeGen.Tests.Parsers 6 | { 7 | [TestFixture] 8 | public class MediaPropertyParserTests : PropertyParserTestBase 9 | { 10 | protected override ContentTypeCodeParserBase CreateParser() 11 | { 12 | return new MediaPropertyParser( 13 | new CodeGen.Parsers.Annotated.PropertyParser(Configuration, DataTypeConfiguration), 14 | Configuration, DataTypeConfiguration 15 | ); 16 | } 17 | 18 | [Test] 19 | public void Parse_Type_IsDataTypeGuid() 20 | { 21 | const string code = @" 22 | public class AClass { 23 | [GenericProperty(Definition=""Richtext editor"")] 24 | public string AProperty {get;set;} 25 | }"; 26 | ParseProperty(code); 27 | Assert.AreEqual(TestDataTypeProvider.Richtexteditor.DataTypeGuid, Property.Type); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/PropertiesParserTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using ICSharpCode.NRefactory.CSharp; 4 | using NUnit.Framework; 5 | using Umbraco.CodeGen.Configuration; 6 | using Umbraco.CodeGen.Definitions; 7 | using Umbraco.CodeGen.Parsers; 8 | 9 | namespace Umbraco.CodeGen.Tests.Parsers 10 | { 11 | [TestFixture] 12 | public class PropertiesParserTests : ContentTypeCodeParserTestBase 13 | { 14 | [Test] 15 | public void RunsPropertyParserForEachProperty() 16 | { 17 | const string code = @" 18 | public class AClass { 19 | public string One {get;set;} 20 | public string Two {get;set;} 21 | }"; 22 | 23 | var tree = ParseType(code); 24 | var contentType = new MediaType(); 25 | var propertyParser = new SpyPropertyParser(null); 26 | var parser = new PropertiesParser( 27 | new ContentTypeConfiguration(), 28 | propertyParser 29 | ); 30 | 31 | parser.Parse(tree, contentType); 32 | Assert.IsTrue( 33 | new[]{"One", "Two"} 34 | .SequenceEqual(propertyParser.PropertyNames) 35 | ); 36 | } 37 | 38 | private class SpyPropertyParser : ContentTypeCodeParserBase 39 | { 40 | public readonly List PropertyNames = new List(); 41 | 42 | public SpyPropertyParser(ContentTypeConfiguration configuration) : base(configuration) 43 | { 44 | } 45 | 46 | public override void Parse(AstNode node, ContentType contentType) 47 | { 48 | var propNode = (PropertyDeclaration) node; 49 | PropertyNames.Add(propNode.Name); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/PropertyParserTestBase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using NUnit.Framework; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | using Umbraco.CodeGen.Parsers; 7 | using Umbraco.CodeGen.Tests.TestHelpers; 8 | 9 | namespace Umbraco.CodeGen.Tests.Parsers 10 | { 11 | public abstract class PropertyParserTestBase : ContentTypeCodeParserTestBase 12 | { 13 | protected GenericProperty Property; 14 | protected List DataTypeConfiguration; 15 | protected CodeGeneratorConfiguration CodeGenConfig; 16 | protected const string PureProperty = @" 17 | public class AClass { 18 | public string AProperty {get;set;} 19 | }"; 20 | 21 | [SetUp] 22 | public void SetUp() 23 | { 24 | Configuration = CodeGeneratorConfiguration.Create().MediaTypes; 25 | DataTypeConfiguration = TestDataTypeProvider.All; 26 | 27 | Parser = CreateParser(); 28 | } 29 | 30 | protected abstract ContentTypeCodeParserBase CreateParser(); 31 | 32 | protected void ParseProperty(string code) 33 | { 34 | const string propertyName = "AProperty"; 35 | ContentType = new MediaType(); 36 | var type = ParseType(code); 37 | var prop = type.Members.SingleOrDefault(m => m.Name == propertyName); 38 | Parser.Parse(prop, ContentType); 39 | Property = ContentType.GenericProperties.SingleOrDefault(p => p.Alias == propertyName.CamelCase()); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Parsers/TabsParserTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Text; 4 | using NUnit.Framework; 5 | using Umbraco.CodeGen.Definitions; 6 | using Umbraco.CodeGen.Parsers; 7 | 8 | namespace Umbraco.CodeGen.Tests.Parsers 9 | { 10 | [TestFixture] 11 | public class TabsParserTests 12 | { 13 | [Test] 14 | public void Parse_AddsTabForEachDistinctNonEmptyPropertyTab() 15 | { 16 | var contentType = new MediaType 17 | { 18 | GenericProperties = new List 19 | { 20 | new GenericProperty {Tab = "A"}, 21 | new GenericProperty {Tab = "A"}, 22 | new GenericProperty {Tab = "B"}, 23 | new GenericProperty {Tab = ""}, 24 | new GenericProperty() 25 | } 26 | }; 27 | var parser = new TabsParser(null); 28 | parser.Parse(null, contentType); 29 | Assert.That( 30 | new[]{"A","B"} 31 | .SequenceEqual(contentType.Tabs.Select(t => t.Caption)) 32 | ); 33 | Assert.AreEqual(0, contentType.Tabs.Sum(t => t.Id)); 34 | // TODO: Tab sortorder 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco.CodeGen.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Umbraco.CodeGen.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c3caf629-d6f2-44c9-b594-f159f505e547")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/GenerateOnlyDocumentType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::Umbraco.Core.Models; 5 | using global::Umbraco.Web; 6 | 7 | public partial class SomeDocumentType : global::Umbraco.Core.Models.PublishedContent.PublishedContentModel 8 | { 9 | public SomeDocumentType(IPublishedContent content) : 10 | base(content) 11 | { 12 | } 13 | public virtual String SomeProperty 14 | { 15 | get 16 | { 17 | return Content.GetPropertyValue("someProperty"); 18 | } 19 | } 20 | public virtual String AnotherProperty 21 | { 22 | get 23 | { 24 | return Content.GetPropertyValue("anotherProperty"); 25 | } 26 | } 27 | public virtual Int32 TablessProperty 28 | { 29 | get 30 | { 31 | return Content.GetPropertyValue("tablessProperty"); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/GenerateOnlyDocumentTypeWithComposition.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::Umbraco.Core.Models; 5 | using global::Umbraco.Web; 6 | 7 | public partial class SomeDocumentType : global::Umbraco.Core.Models.PublishedContent.PublishedContentModel, IMixin 8 | { 9 | public SomeDocumentType(IPublishedContent content) : 10 | base(content) 11 | { 12 | } 13 | public virtual String SomeProperty 14 | { 15 | get 16 | { 17 | return Content.GetPropertyValue("someProperty"); 18 | } 19 | } 20 | public virtual String AnotherProperty 21 | { 22 | get 23 | { 24 | return Content.GetPropertyValue("anotherProperty"); 25 | } 26 | } 27 | public virtual Int32 TablessProperty 28 | { 29 | get 30 | { 31 | return Content.GetPropertyValue("tablessProperty"); 32 | } 33 | } 34 | public virtual Int32 MixinProp 35 | { 36 | get 37 | { 38 | return Content.GetPropertyValue("mixinProp"); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/GenerateOnlyInterface.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::Umbraco.Core.Models; 5 | using global::Umbraco.Web; 6 | 7 | public partial interface IMixin : IPublishedContent 8 | { 9 | Int32 MixinProp 10 | { 11 | get; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeAnnotatedDocumentType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::Umbraco.CodeGen.Annotations; 5 | using global::Umbraco.Core.Models; 6 | using global::Umbraco.Web; 7 | 8 | [DocumentType(Description="A description of some document type", Icon="privateMemberIcon.gif", Thumbnail="privateMemberThumb.png", AllowAtRoot=true, DefaultTemplate="ATemplate", AllowedTemplates=new String[] { 9 | "ATemplate", 10 | "AnotherTemplate"}, Structure=new System.Type[] { 11 | typeof(SomeOtherDocType)})] 12 | public partial class SomeDocumentType : Umbraco.Core.Models.TypedModelBase 13 | { 14 | public SomeDocumentType(IPublishedContent content) : 15 | base(content) 16 | { 17 | } 18 | [GenericProperty(Description="A description", Definition="Richtext editor", Tab="A tab", Mandatory=true, Validation="[a-z]")] 19 | public virtual String SomeProperty 20 | { 21 | get 22 | { 23 | return Content.GetPropertyValue("someProperty"); 24 | } 25 | } 26 | [GenericProperty(Description="Another description", Definition="Richtext editor", Tab="A tab")] 27 | public virtual String AnotherProperty 28 | { 29 | get 30 | { 31 | return Content.GetPropertyValue("anotherProperty"); 32 | } 33 | } 34 | [GenericProperty(Definition="Numeric")] 35 | public virtual Int32 TablessProperty 36 | { 37 | get 38 | { 39 | return Content.GetPropertyValue("tablessProperty"); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeAnnotatedMediaType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::Umbraco.CodeGen.Annotations; 5 | using global::Umbraco.Core.Models; 6 | using global::Umbraco.Web; 7 | 8 | [MediaType(Icon="folder.gif", Thumbnail="folder.png", AllowAtRoot=true, Structure=new System.Type[] { 9 | typeof(Folder), 10 | typeof(Image), 11 | typeof(File), 12 | typeof(InheritedMediaFolder)})] 13 | public partial class InheritedMediaFolder : Folder 14 | { 15 | public InheritedMediaFolder(IPublishedContent content) : 16 | base(content) 17 | { 18 | } 19 | [GenericProperty(Definition="Textstring", Tab="A tab")] 20 | public virtual String LetsHaveAProperty 21 | { 22 | get 23 | { 24 | return Content.GetPropertyValue("letsHaveAProperty"); 25 | } 26 | } 27 | [GenericProperty(Definition="Textstring")] 28 | public virtual String AndATablessProperty 29 | { 30 | get 31 | { 32 | return Content.GetPropertyValue("andATablessProperty"); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeBaseSupportedAnnotatedDocumentType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::Umbraco.CodeGen.Annotations; 5 | 6 | [DocumentType(Description="A description of some document type", Icon="privateMemberIcon.gif", Thumbnail="privateMemberThumb.png", AllowAtRoot=true, DefaultTemplate="ATemplate", AllowedTemplates=new String[] { 7 | "ATemplate", 8 | "AnotherTemplate"}, Structure=new System.Type[] { 9 | typeof(SomeOtherDocType)})] 10 | public partial class SomeDocumentType : BaseClassWithSupport 11 | { 12 | public SomeDocumentType(Umbraco.Core.Models.IPublishedContent content) : 13 | base(content) 14 | { 15 | } 16 | [GenericProperty(Description="A description", Definition="Richtext editor", Tab="A tab", Mandatory=true, Validation="[a-z]")] 17 | public virtual String SomeProperty 18 | { 19 | get 20 | { 21 | return GetValue("someProperty"); 22 | } 23 | } 24 | [GenericProperty(Description="Another description", Definition="Richtext editor", Tab="A tab")] 25 | public virtual String AnotherProperty 26 | { 27 | get 28 | { 29 | return GetValue("anotherProperty"); 30 | } 31 | } 32 | [GenericProperty(Definition="Numeric")] 33 | public virtual Int32 TablessProperty 34 | { 35 | get 36 | { 37 | return GetValue("tablessProperty"); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeBaseSupportedAnnotatedMediaType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::Umbraco.CodeGen.Annotations; 5 | 6 | [MediaType(Icon="folder.gif", Thumbnail="folder.png", AllowAtRoot=true, Structure=new System.Type[] { 7 | typeof(Folder), 8 | typeof(Image), 9 | typeof(File), 10 | typeof(InheritedMediaFolder)})] 11 | public partial class InheritedMediaFolder : Folder 12 | { 13 | public InheritedMediaFolder(Umbraco.Core.Models.IPublishedContent content) : 14 | base(content) 15 | { 16 | } 17 | [GenericProperty(Definition="Textstring", Tab="A tab")] 18 | public virtual String LetsHaveAProperty 19 | { 20 | get 21 | { 22 | return GetValue("letsHaveAProperty"); 23 | } 24 | } 25 | [GenericProperty(Definition="Textstring")] 26 | public virtual String AndATablessProperty 27 | { 28 | get 29 | { 30 | return GetValue("andATablessProperty"); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeDocumentType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::System.ComponentModel; 5 | using global::System.ComponentModel.DataAnnotations; 6 | using global::Umbraco.Core.Models; 7 | using global::Umbraco.Web; 8 | 9 | [Description("A description of some document type")] 10 | public partial class SomeDocumentType : Umbraco.Core.Models.TypedModelBase 11 | { 12 | private string icon = "privateMemberIcon.gif"; 13 | private string thumbnail = "privateMemberThumb.png"; 14 | private bool allowAtRoot = true; 15 | private string defaultTemplate = "ATemplate"; 16 | private string[] allowedTemplates = new string[] { 17 | "ATemplate", 18 | "AnotherTemplate"}; 19 | private System.Type[] structure = new System.Type[] { 20 | typeof(SomeOtherDocType)}; 21 | public SomeDocumentType(IPublishedContent content) : 22 | base(content) 23 | { 24 | } 25 | [Description("A description")] 26 | [DataType("Richtext editor")] 27 | [Category("A tab")] 28 | [Required()] 29 | [RegularExpression("[a-z]")] 30 | public virtual String SomeProperty 31 | { 32 | get 33 | { 34 | return Content.GetPropertyValue("someProperty"); 35 | } 36 | } 37 | [Description("Another description")] 38 | [DataType("Richtext editor")] 39 | [Category("A tab")] 40 | public virtual String AnotherProperty 41 | { 42 | get 43 | { 44 | return Content.GetPropertyValue("anotherProperty"); 45 | } 46 | } 47 | [DataType("Numeric")] 48 | public virtual Int32 TablessProperty 49 | { 50 | get 51 | { 52 | return Content.GetPropertyValue("tablessProperty"); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeDocumentType.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lars-erik/Umbraco.CodeGen/1bc32b2a5cc921434341e4afb6b9307a6c2fa80c/Umbraco.CodeGen.Tests/TestFiles/SomeDocumentType.xml -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeMediaType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Models 2 | { 3 | using global::System; 4 | using global::System.ComponentModel; 5 | using global::System.ComponentModel.DataAnnotations; 6 | using global::Umbraco.Core.Models; 7 | using global::Umbraco.Web; 8 | 9 | public partial class InheritedMediaFolder : Folder 10 | { 11 | private string icon = "folder.gif"; 12 | private string thumbnail = "folder.png"; 13 | private bool allowAtRoot = true; 14 | private System.Type[] structure = new System.Type[] { 15 | typeof(Folder), 16 | typeof(Image), 17 | typeof(File), 18 | typeof(InheritedMediaFolder)}; 19 | public InheritedMediaFolder(IPublishedContent content) : 20 | base(content) 21 | { 22 | } 23 | [DataType("Textstring")] 24 | [Category("A tab")] 25 | public virtual String LetsHaveAProperty 26 | { 27 | get 28 | { 29 | return Content.GetPropertyValue("letsHaveAProperty"); 30 | } 31 | } 32 | [DataType("Textstring")] 33 | public virtual String AndATablessProperty 34 | { 35 | get 36 | { 37 | return Content.GetPropertyValue("andATablessProperty"); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestFiles/SomeMediaType.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lars-erik/Umbraco.CodeGen/1bc32b2a5cc921434341e4afb6b9307a6c2fa80c/Umbraco.CodeGen.Tests/TestFiles/SomeMediaType.xml -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/TestHelpers/SerializationHelper.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Text; 3 | using System.Xml; 4 | using System.Xml.Serialization; 5 | using Umbraco.CodeGen.Definitions; 6 | 7 | namespace Umbraco.CodeGen.Tests.TestHelpers 8 | { 9 | static internal class SerializationHelper 10 | { 11 | public static void BclSerialize(StringBuilder builder, T contentType) 12 | { 13 | var writer = new StringWriter(builder); 14 | var xmlSerializer = new XmlSerializer(typeof (T), new[] {typeof(DocumentTypeInfo)}); 15 | xmlSerializer.Serialize(writer, contentType); 16 | } 17 | 18 | public static string BclSerialize(T contentType) 19 | { 20 | var builder = new StringBuilder(); 21 | BclSerialize(builder, contentType); 22 | return builder.ToString(); 23 | } 24 | 25 | public static string CleanSerialize(T obj, string rootName) 26 | { 27 | var settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true }; 28 | var serializer = new XmlSerializer(typeof(T), new XmlRootAttribute(rootName) { Namespace = "" }); 29 | var builder = new StringBuilder(); 30 | var writer = XmlWriter.Create(builder, settings); 31 | 32 | serializer.Serialize(writer, obj, new XmlSerializerNamespaces(new[] { new XmlQualifiedName("") })); 33 | return builder.ToString(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/config/CodeGen.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Approved Color.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | bb07bfcac84f6f2d99e8c98b2bdf0b49 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Checkbox list.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | e9367b36fb06a4fbf38c856ac0b6eb0e 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Content Picker.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ef8cccf969caae53328aa820fe6bb7f8 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Date Picker with time.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 93a56a0a259952c0bb448fc8917e74b0 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Date Picker.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | e7fbcad0f8d189b11909a7ee1393808b 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Dropdown multiple.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 05c3672034c87cc254c9a630533991d5 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Dropdown.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 4a7233b5e9cdcda20669c31f573afee2 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Folder Browser.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | d94c43f6cd15d188ef3cc00817e474e1 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Label.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | b710ea810e1c9a0fd33a126218bccbd3 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Media Picker.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5d5ba49ac31f012965eab0662b9efb4d 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Member Picker.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | b8dc24eda0f6b5e03606e3a04ea80f55 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Multiple Media Picker.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 0000075fb58c74c98b6de6d6c7be3b06 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Numeric.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | d875c72ee3411d8b03a190e3a4b1cb6e 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Radiobox.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6bd8c4f9f159a429dd7a2ed5a890a3a5 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Related Links.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 74d5ff64aa9c92b1783f971dfa35cf3a 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Richtext editor.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 2dcb8aca3ac7d8f0cca7920e6dc7e707 7 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Tags.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | bc82e384143f864182f1aa796ff3b112 7 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Textbox multiple.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | d0de289f551284b1a5ae98637bfe408e 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Textstring.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 26c5e4130d49fbfbea0628ef1c5796c9 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Truefalse.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 06b2670873202ec49085ce53b3f0ada0 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DataTypeDefinition/Upload.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 69f918949fb1dc8ecbe08962fac00167 5 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DocumentType/SamePropertyName/def.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #SamePropertyName 5 | samePropertyName 6 | folder.gif 7 | folder.png 8 | 9 | 10 | False 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | #SamePropertyName 20 | samePropertyName 21 | ec15c1e5-9d90-422a-aa52-4f7622c63bea 22 | 0cc0eba1-9960-42c9-bf9b-60e150b429ae 23 | Properties 24 | False 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DocumentType/pfxRoot/def.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #Prefixed Root 5 | pfxRoot 6 | folder.gif 7 | folder.png 8 | 9 | 10 | True 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | #SomePropertyName 20 | pfxSomeProperty 21 | ec15c1e5-9d90-422a-aa52-4f7622c63bea 22 | 0cc0eba1-9960-42c9-bf9b-60e150b429ae 23 | #ContentTab 24 | False 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 0 33 | #ContentTab 34 | 35 | 36 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DocumentType/pfxRoot/pfxChild/GrandChildNoPfx/def.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #Grand child without prefix 5 | grandChildNoPfx 6 | folder.gif 7 | folder.png 8 | 9 | 10 | False 11 | pfxChild 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DocumentType/pfxRoot/pfxChild/def.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #Prefixed Child 5 | pfxChild 6 | folder.gif 7 | folder.png 8 | 9 | 10 | False 11 | pfxRoot 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | #MainImage 20 | pfxMainImage 21 | ead69342-f06d-4253-83ac-28000225583b 22 | e2651a57-597d-4186-9110-956182b90b80 23 | #ContentTab 24 | False 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/DocumentType/pfxRoot/pfxSibling/def.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #Prefixed Sibling 5 | pfxSibling 6 | folder.gif 7 | folder.png 8 | 9 | 10 | False 11 | pfxRoot 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | #AnotherImage 20 | anotherImage 21 | ead69342-f06d-4253-83ac-28000225583b 22 | e2651a57-597d-4186-9110-956182b90b80 23 | #ContentTab 24 | False 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/MediaType/File/def.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | File 5 | File 6 | icon-document 7 | mediaFile.png 8 | 9 | 10 | False 11 | 12 | 13 | 14 | 15 | Upload file 16 | umbracoFile 17 | 5032a6e6-69e3-491d-bb28-cd31cd11086c 18 | 84c6b441-31df-4ffe-b67e-67d5bc3ae65a 19 | File 20 | False 21 | 22 | 23 | 24 | 25 | 26 | Type 27 | umbracoExtension 28 | 7a2d436c-34c2-410f-898f-4a23b3d79f54 29 | f0bc4bfb-b499-40d6-ba86-058885a5178c 30 | File 31 | False 32 | 33 | 34 | 35 | 36 | 37 | Size 38 | umbracoBytes 39 | 7a2d436c-34c2-410f-898f-4a23b3d79f54 40 | f0bc4bfb-b499-40d6-ba86-058885a5178c 41 | File 42 | False 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 4 51 | File 52 | 1 53 | 54 | 55 | 65fe672caa4bbc32bd8156182aa8a2e0 56 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Tests/uSync/MediaType/Folder/def.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Folder 5 | Folder 6 | icon-folder 7 | folder.png 8 | 9 | 10 | True 11 | 12 | 13 | Folder 14 | Image 15 | File 16 | 17 | 18 | 19 | Contents: 20 | contents 21 | cccd4ae9-f399-4ed2-8038-2e88d19e810c 22 | fd9f1447-6c61-4a7c-9595-5aa39147d318 23 | Contents 24 | False 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 5 33 | Contents 34 | 1 35 | 36 | 37 | 7070a45997d783d8aae5876dab533d3d 38 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Umbraco.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco.CodeGen.Umbraco.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Umbraco.CodeGen.Umbraco.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1afff98d-33c4-43fe-a972-abc58bca0a37")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Umbraco.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Umbraco.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Umbraco/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco.CodeGen.Umbraco")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Umbraco.CodeGen.Umbraco")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f14ff7b5-e91c-42e1-b147-99d062731d70")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Umbraco/UmbracoDataTypesProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.Web; 5 | 6 | namespace Umbraco.CodeGen.Umbraco 7 | { 8 | public class UmbracoDataTypesProvider : IDataTypeProvider 9 | { 10 | private readonly object lockObj = new object(); 11 | private IEnumerable dataTypes; 12 | 13 | public IEnumerable GetDataTypes() 14 | { 15 | lock(lockObj) 16 | { 17 | if (dataTypes == null) 18 | { 19 | var umbracoDefinitions = UmbracoContext.Current.Application.Services.DataTypeService.GetAllDataTypeDefinitions(); 20 | dataTypes = umbracoDefinitions.Select(d => new DataTypeDefinition(d.Name, "", d.PropertyEditorAlias, "")); 21 | } 22 | } 23 | return dataTypes; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Umbraco/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Umbraco/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.WaitForSixTwo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco.CodeGen.U7")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Umbraco.CodeGen.U7")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("41d3e760-88d1-45a6-8e64-51ed3266d7b2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.*")] 36 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.WaitForSixTwo/Umbraco.CodeGen.WaitForSixTwo.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Umbraco.CodeGen.U7 5 | $version$ 6 | Umbraco CodeGen for Umbraco 7 7 | Lars-Erik Aabech 8 | Lars-Erik Aabech 9 | http://opensource.org/licenses/MIT 10 | https://github.com/lars-erik/Umbraco.CodeGen 11 | false 12 | Generates and parses typed models in Umbraco. 13 | 14 | Copyright 2014 Lars-Erik Aabech 15 | Umbraco typed models 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.WaitForSixTwo/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/App_Plugins/CodeGen/backoffice/codegen/codegen.preview.html: -------------------------------------------------------------------------------- 1 | 
2 |
3 |

{{title}}

4 |
5 |
6 | 7 |
8 |
9 | 10 |
11 |
12 |
13 |
14 |
-------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/App_Plugins/CodeGen/codegen.configuration.contentType.html: -------------------------------------------------------------------------------- 1 | 
2 |
3 | 6 |
7 |
8 | 12 |
13 |
14 | 18 |
19 |
20 |
21 |
22 | 23 |
24 |
25 | 26 |
27 |
28 |
29 |
30 | 31 |
32 |
33 | 34 |
35 |
36 |
37 |
38 | 39 |
40 |
41 | 42 |
43 |
44 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/App_Plugins/CodeGen/package.manifest: -------------------------------------------------------------------------------- 1 | { 2 | javascript: [ 3 | "~/App_Plugins/CodeGen/codegen.configuration.controller.js", 4 | "~/App_Plugins/CodeGen/codegen.preview.controller.js" 5 | ] 6 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using System.Web.Mvc; 3 | using System.Web.Routing; 4 | 5 | namespace Umbraco.CodeGen.Web.App_Start 6 | { 7 | public class RouteConfig 8 | { 9 | public static void ApplyRoutes(RouteCollection routes) 10 | { 11 | routes.MapHttpRoute( 12 | "codegen", 13 | "CodeGen/{controller}/{action}/{id}", 14 | new { id = UrlParameter.Optional } 15 | ); 16 | 17 | routes.MapRoute( 18 | "default", 19 | "{controller}/{action}/{id}", 20 | new {controller = "Home", action = "Index", id = UrlParameter.Optional} 21 | ); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace Umbraco.CodeGen.Web.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | public ActionResult Index() 12 | { 13 | return View(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.CodeGen.Web.Global" Language="C#" %> 2 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco.CodeGen.Web")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Umbraco.CodeGen.Web")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("26aff645-1775-4ca0-9097-bd83a745033d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Scripts/angular-cookies.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | AngularJS v1.1.5 3 | (c) 2010-2012 Google, Inc. http://angularjs.org 4 | License: MIT 5 | */ 6 | (function(m,f,l){'use strict';f.module("ngCookies",["ng"]).factory("$cookies",["$rootScope","$browser",function(d,b){var c={},g={},h,i=!1,j=f.copy,k=f.isUndefined;b.addPollFn(function(){var a=b.cookies();h!=a&&(h=a,j(a,g),j(a,c),i&&d.$apply())})();i=!0;d.$watch(function(){var a,e,d;for(a in g)k(c[a])&&b.cookies(a,l);for(a in c)e=c[a],f.isString(e)?e!==g[a]&&(b.cookies(a,e),d=!0):f.isDefined(g[a])?c[a]=g[a]:delete c[a];if(d)for(a in e=b.cookies(),c)c[a]!==e[a]&&(k(e[a])?delete c[a]:c[a]=e[a])});return c}]).factory("$cookieStore", 7 | ["$cookies",function(d){return{get:function(b){return(b=d[b])?f.fromJson(b):b},put:function(b,c){d[b]=f.toJson(c)},remove:function(b){delete d[b]}}}])})(window,window.angular); 8 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Scripts/angular-loader.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | AngularJS v1.1.5 3 | (c) 2010-2012 Google, Inc. http://angularjs.org 4 | License: MIT 5 | */ 6 | (function(i){'use strict';function d(c,b,e){return c[b]||(c[b]=e())}return d(d(i,"angular",Object),"module",function(){var c={};return function(b,e,f){e&&c.hasOwnProperty(b)&&(c[b]=null);return d(c,b,function(){function a(a,b,d){return function(){c[d||"push"]([a,b,arguments]);return g}}if(!e)throw Error("No module: "+b);var c=[],d=[],h=a("$injector","invoke"),g={_invokeQueue:c,_runBlocks:d,requires:e,name:b,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide","service"), 7 | value:a("$provide","value"),constant:a("$provide","constant","unshift"),animation:a("$animationProvider","register"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:h,run:function(a){d.push(a);return this}};f&&h(f);return g})}})})(window); 8 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model dynamic 2 | 3 | @{ 4 | Layout = null; 5 | } 6 | 7 | 8 | 9 | 10 | 11 | CodeGen Admin UI Test 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
42 |
43 | 44 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/config/CodeGen.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/config/dashboard.config.uninstall.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 |
4 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/config/trees.config.uninstall.xdt: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/config/uSyncSettings.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 31 | 32 | 33 | 37 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lars-erik/Umbraco.CodeGen/1bc32b2a5cc921434341e4afb6b9307a6c2fa80c/Umbraco.CodeGen.Web/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /Umbraco.CodeGen.Web/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lars-erik/Umbraco.CodeGen/1bc32b2a5cc921434341e4afb6b9307a6c2fa80c/Umbraco.CodeGen.Web/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /Umbraco.CodeGen/Annotations/ContentTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Umbraco.CodeGen.Annotations 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 6 | public abstract class ContentTypeAttribute : EntityDescriptionAttribute 7 | { 8 | public string Icon { get; set; } 9 | public string Thumbnail { get; set; } 10 | public bool AllowAtRoot { get; set; } 11 | public Type[] Structure { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Annotations/DocumentTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Umbraco.CodeGen.Annotations 7 | { 8 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 9 | public class DocumentTypeAttribute : ContentTypeAttribute 10 | { 11 | public string DefaultTemplate { get; set; } 12 | public string[] AllowedTemplates { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Annotations/EntityDescriptionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Umbraco.CodeGen.Annotations 4 | { 5 | public abstract class EntityDescriptionAttribute : Attribute 6 | { 7 | public string DisplayName { get; set; } 8 | public string Description { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Annotations/GenericPropertyAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Annotations 2 | { 3 | public class GenericPropertyAttribute : EntityDescriptionAttribute 4 | { 5 | public string Definition { get; set; } 6 | public string Tab { get; set; } 7 | public bool Mandatory { get; set; } 8 | public string Validation { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Annotations/MediaTypeAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Umbraco.CodeGen.Annotations 7 | { 8 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 9 | public class MediaTypeAttribute : ContentTypeAttribute 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Configuration/CodeGeneratorConfigurationFileProvider.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Text; 3 | using System.Xml; 4 | 5 | namespace Umbraco.CodeGen.Configuration 6 | { 7 | public class CodeGeneratorConfigurationFileProvider : IConfigurationProvider, IConfigurationPersister 8 | { 9 | private readonly string path; 10 | private readonly IConfigurationProvider provider; 11 | 12 | public CodeGeneratorConfigurationFileProvider(string path) 13 | { 14 | this.path = path; 15 | using (var reader = File.OpenText(path)) 16 | { 17 | provider = new CodeGeneratorConfigurationProvider(reader.ReadToEnd()); 18 | } 19 | } 20 | 21 | public CodeGeneratorConfiguration GetConfiguration() 22 | { 23 | return provider.GetConfiguration(); 24 | } 25 | 26 | public void SaveConfiguration(CodeGeneratorConfiguration configuration) 27 | { 28 | using (var writer = File.CreateText(path)) 29 | { 30 | var xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings { OmitXmlDeclaration = true, Encoding = Encoding.UTF8, Indent = true }); 31 | CodeGeneratorConfigurationProvider.SerializeConfiguration(configuration, xmlWriter); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Configuration/CodeGeneratorConfigurationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Xml; 4 | using System.Xml.Serialization; 5 | 6 | namespace Umbraco.CodeGen.Configuration 7 | { 8 | public class CodeGeneratorConfigurationProvider : IConfigurationProvider 9 | { 10 | private readonly string inputFileContent; 11 | private CodeGeneratorConfiguration configuration; 12 | 13 | public CodeGeneratorConfigurationProvider(string inputFileContent) 14 | { 15 | this.inputFileContent = inputFileContent; 16 | } 17 | 18 | public CodeGeneratorConfiguration GetConfiguration() 19 | { 20 | return configuration ?? (configuration = LoadConfiguration()); 21 | } 22 | 23 | private CodeGeneratorConfiguration LoadConfiguration() 24 | { 25 | var serializer = new XmlSerializer(typeof (CodeGeneratorConfiguration)); 26 | return (CodeGeneratorConfiguration) serializer.Deserialize(new StringReader(inputFileContent)); 27 | } 28 | 29 | public static void SerializeConfiguration(CodeGeneratorConfiguration newConfiguration, XmlWriter writer) 30 | { 31 | var serializer = new XmlSerializer(typeof(CodeGeneratorConfiguration), new XmlRootAttribute("CodeGenerator") {Namespace=""}); 32 | serializer.Serialize(writer, newConfiguration, new XmlSerializerNamespaces(new[] { new XmlQualifiedName("", "") })); 33 | writer.Flush(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Configuration/DataTypeDefinition.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Configuration 2 | { 3 | public class DataTypeDefinition 4 | { 5 | public string DefinitionId { get; set; } 6 | public string DataTypeId { get; set; } 7 | public string DataTypeName { get; set; } 8 | public string DataTypeGuid { get; set; } 9 | 10 | public DataTypeDefinition() 11 | { 12 | } 13 | 14 | public DataTypeDefinition(string name, string dataTypeId, string definitionId, string dataTypeGuid) 15 | { 16 | DataTypeName = name; 17 | DataTypeId = dataTypeId; 18 | DefinitionId = definitionId; 19 | DataTypeGuid = dataTypeGuid; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Configuration/IConfigurationProvider.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Umbraco.CodeGen.Configuration 4 | { 5 | public interface IConfigurationProvider 6 | { 7 | CodeGeneratorConfiguration GetConfiguration(); 8 | } 9 | 10 | public interface IConfigurationPersister 11 | { 12 | void SaveConfiguration(CodeGeneratorConfiguration newConfiguration); 13 | } 14 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Configuration/IDataTypeProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Umbraco.CodeGen.Configuration 4 | { 5 | public interface IDataTypeProvider 6 | { 7 | IEnumerable GetDataTypes(); 8 | } 9 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Configuration/ParserAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Umbraco.CodeGen.Configuration 8 | { 9 | [AttributeUsage(AttributeTargets.Class)] 10 | public class ParserAttribute : Attribute 11 | { 12 | public Type Type { get; set; } 13 | 14 | public ParserAttribute(Type type) 15 | { 16 | Type = type; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/ContentType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Umbraco.CodeGen.Definitions 4 | { 5 | public class ContentType : Entity, IEntityDescription 6 | { 7 | public string Name { get { return Info.Name; } } 8 | public string Alias { get { return Info.Alias; } } 9 | public string Description { get { return Info.Description; } } 10 | 11 | public Info Info { get; set; } 12 | public List GenericProperties { get; set; } 13 | public List Tabs { get; set; } 14 | public List Structure { get; set; } 15 | public List Composition { get; set; } 16 | public bool IsMixin { get; set; } 17 | 18 | public ContentType() 19 | { 20 | GenericProperties = new List(); 21 | Tabs = new List(); 22 | Structure = new List(); 23 | Info = new Info(); 24 | Composition = new List(); 25 | } 26 | 27 | protected bool Equals(ContentType other) 28 | { 29 | return Equals(Info, other.Info) && 30 | GenericProperties.NullableSequenceEqual(other.GenericProperties) && 31 | Tabs.NullableSequenceEqual(other.Tabs) && 32 | Structure.NullableSequenceEqual(other.Structure); 33 | } 34 | 35 | public override bool Equals(object obj) 36 | { 37 | if (ReferenceEquals(null, obj)) return false; 38 | if (ReferenceEquals(this, obj)) return true; 39 | if (obj.GetType() != this.GetType()) return false; 40 | return Equals((ContentType) obj); 41 | } 42 | 43 | public override int GetHashCode() 44 | { 45 | unchecked 46 | { 47 | var hashCode = (Info != null ? Info.GetHashCode() : 0); 48 | hashCode = (hashCode*397) ^ (GenericProperties != null ? GenericProperties.GetHashCode() : 0); 49 | hashCode = (hashCode*397) ^ (Tabs != null ? Tabs.GetHashCode() : 0); 50 | hashCode = (hashCode*397) ^ (Structure != null ? Structure.GetHashCode() : 0); 51 | return hashCode; 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/DocumentType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Umbraco.CodeGen.Definitions 4 | { 5 | public class DocumentType : ContentType 6 | { 7 | public DocumentType() 8 | { 9 | Info = new DocumentTypeInfo(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/DocumentTypeInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Umbraco.CodeGen.Definitions 4 | { 5 | public class DocumentTypeInfo : Info 6 | { 7 | public List AllowedTemplates { get; set; } 8 | public string DefaultTemplate { get; set; } 9 | 10 | public DocumentTypeInfo() 11 | { 12 | AllowedTemplates = new List(); 13 | } 14 | 15 | protected bool Equals(DocumentTypeInfo other) 16 | { 17 | return AllowedTemplates.NullableSequenceEqual(AllowedTemplates) && string.Equals(DefaultTemplate, other.DefaultTemplate); 18 | } 19 | 20 | public override bool Equals(object obj) 21 | { 22 | if (ReferenceEquals(null, obj)) return false; 23 | if (ReferenceEquals(this, obj)) return true; 24 | if (obj.GetType() != this.GetType()) return false; 25 | return Equals((DocumentTypeInfo) obj); 26 | } 27 | 28 | public override int GetHashCode() 29 | { 30 | unchecked 31 | { 32 | return ((AllowedTemplates != null ? AllowedTemplates.GetHashCode() : 0)*397) ^ (DefaultTemplate != null ? DefaultTemplate.GetHashCode() : 0); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/Entity.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Definitions 2 | { 3 | public abstract class Entity 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/EntityDescription.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Definitions 2 | { 3 | public abstract class EntityDescription : Entity, IEntityDescription 4 | { 5 | public string Name { get; set; } 6 | public string Alias { get; set; } 7 | public string Description { get; set; } 8 | 9 | protected bool Equals(EntityDescription other) 10 | { 11 | return string.Equals(Name, other.Name) && string.Equals(Alias, other.Alias) && string.Equals(Description, other.Description); 12 | } 13 | 14 | public override bool Equals(object obj) 15 | { 16 | if (ReferenceEquals(null, obj)) return false; 17 | if (ReferenceEquals(this, obj)) return true; 18 | if (obj.GetType() != this.GetType()) return false; 19 | return Equals((EntityDescription) obj); 20 | } 21 | 22 | public override int GetHashCode() 23 | { 24 | unchecked 25 | { 26 | var hashCode = (Name != null ? Name.GetHashCode() : 0); 27 | hashCode = (hashCode*397) ^ (Alias != null ? Alias.GetHashCode() : 0); 28 | hashCode = (hashCode*397) ^ (Description != null ? Description.GetHashCode() : 0); 29 | return hashCode; 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Umbraco.CodeGen.Definitions 8 | { 9 | internal static class EnumerableExtensions 10 | { 11 | public static bool NullableSequenceEqual(this IEnumerable a, IEnumerable b) 12 | { 13 | return (a == null && b == null) || 14 | (a != null && b != null && a.SequenceEqual(b)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/GenericProperty.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Definitions 2 | { 3 | public class GenericProperty : EntityDescription 4 | { 5 | public string Type { get; set; } 6 | public string Definition { get; set; } 7 | public string Tab { get; set; } 8 | public bool Mandatory { get; set; } 9 | public string Validation { get; set; } 10 | 11 | protected bool Equals(GenericProperty other) 12 | { 13 | return base.Equals(other) && string.Equals(Type, other.Type) && string.Equals(Definition, other.Definition) && string.Equals(Tab, other.Tab) && Mandatory.Equals(other.Mandatory) && string.Equals(Validation, other.Validation); 14 | } 15 | 16 | public override bool Equals(object obj) 17 | { 18 | if (ReferenceEquals(null, obj)) return false; 19 | if (ReferenceEquals(this, obj)) return true; 20 | if (obj.GetType() != this.GetType()) return false; 21 | return Equals((GenericProperty) obj); 22 | } 23 | 24 | public override int GetHashCode() 25 | { 26 | unchecked 27 | { 28 | var hashCode = base.GetHashCode(); 29 | hashCode = (hashCode*397) ^ (Type != null ? Type.GetHashCode() : 0); 30 | hashCode = (hashCode*397) ^ (Definition != null ? Definition.GetHashCode() : 0); 31 | hashCode = (hashCode*397) ^ (Tab != null ? Tab.GetHashCode() : 0); 32 | hashCode = (hashCode*397) ^ Mandatory.GetHashCode(); 33 | hashCode = (hashCode*397) ^ (Validation != null ? Validation.GetHashCode() : 0); 34 | return hashCode; 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/IEntityDescription.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Definitions 2 | { 3 | public interface IEntityDescription 4 | { 5 | string Name { get; } 6 | string Alias { get; } 7 | string Description { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/Info.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Definitions 2 | { 3 | public class Info : EntityDescription 4 | { 5 | public string Icon { get; set; } 6 | public string Thumbnail { get; set; } 7 | public bool AllowAtRoot { get; set; } 8 | public string Master { get; set; } 9 | 10 | protected bool Equals(Info other) 11 | { 12 | return base.Equals(other) && string.Equals(Icon, other.Icon) && string.Equals(Thumbnail, other.Thumbnail) && AllowAtRoot.Equals(other.AllowAtRoot) && string.Equals(Master, other.Master); 13 | } 14 | 15 | public override bool Equals(object obj) 16 | { 17 | if (ReferenceEquals(null, obj)) return false; 18 | if (ReferenceEquals(this, obj)) return true; 19 | if (obj.GetType() != this.GetType()) return false; 20 | return Equals((Info) obj); 21 | } 22 | 23 | public override int GetHashCode() 24 | { 25 | unchecked 26 | { 27 | var hashCode = base.GetHashCode(); 28 | hashCode = (hashCode*397) ^ (Icon != null ? Icon.GetHashCode() : 0); 29 | hashCode = (hashCode*397) ^ (Thumbnail != null ? Thumbnail.GetHashCode() : 0); 30 | hashCode = (hashCode*397) ^ AllowAtRoot.GetHashCode(); 31 | hashCode = (hashCode*397) ^ (Master != null ? Master.GetHashCode() : 0); 32 | return hashCode; 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/MediaType.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Definitions 2 | { 3 | public class MediaType : ContentType 4 | { 5 | public MediaType() 6 | { 7 | Info = new Info(); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Definitions/Tab.cs: -------------------------------------------------------------------------------- 1 | namespace Umbraco.CodeGen.Definitions 2 | { 3 | public class Tab 4 | { 5 | public int Id { get; set; } 6 | public string Caption { get; set; } 7 | public int? Order { get; set; } 8 | 9 | protected bool Equals(Tab other) 10 | { 11 | return Id == other.Id && string.Equals(Caption, other.Caption) && Order == other.Order; 12 | } 13 | 14 | public override bool Equals(object obj) 15 | { 16 | if (ReferenceEquals(null, obj)) return false; 17 | if (ReferenceEquals(this, obj)) return true; 18 | if (obj.GetType() != this.GetType()) return false; 19 | return Equals((Tab) obj); 20 | } 21 | 22 | public override int GetHashCode() 23 | { 24 | unchecked 25 | { 26 | var hashCode = Id; 27 | hashCode = (hashCode*397) ^ (Caption != null ? Caption.GetHashCode() : 0); 28 | hashCode = (hashCode*397) ^ Order.GetHashCode(); 29 | return hashCode; 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace Umbraco.CodeGen 8 | { 9 | public static class EnumerableExtensions 10 | { 11 | public static IEnumerable NonNullOrWhiteSpace(this IEnumerable strings) 12 | { 13 | return strings.Where(s => !String.IsNullOrWhiteSpace(s)); 14 | } 15 | 16 | public static CodeExpression[] AsPrimitiveExpressions(this IEnumerable values) 17 | { 18 | return values 19 | .Select(v => new CodePrimitiveExpression(v)) 20 | .Cast() 21 | .ToArray(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Annotated/CommonInfoGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Generators.Annotated 7 | { 8 | public class CommonInfoGenerator : EntityDescriptionGenerator 9 | { 10 | public CommonInfoGenerator(ContentTypeConfiguration configuration) 11 | : base(configuration) 12 | { 13 | 14 | } 15 | 16 | public override void Generate(object codeObject, Entity entity) 17 | { 18 | base.Generate(codeObject, entity); 19 | 20 | var attribute = codeObject as CodeAttributeDeclaration; 21 | if (attribute == null) 22 | throw new Exception("Common info generator must be used on an attribute declaration"); 23 | 24 | var info = ((ContentType)entity).Info; 25 | 26 | AddAttributeArgumentIfValue(attribute, "Icon", info.Icon); 27 | AddAttributeArgumentIfValue(attribute, "Thumbnail", info.Thumbnail); 28 | if (info.AllowAtRoot) 29 | AddAttributePrimitiveArgument(attribute, "AllowAtRoot", true); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Annotated/DocumentTypeInfoGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Generators.Annotated 7 | { 8 | public class DocumentTypeInfoGenerator : CommonInfoGenerator 9 | { 10 | public DocumentTypeInfoGenerator(ContentTypeConfiguration config) : base(config) 11 | { 12 | } 13 | 14 | public override void Generate(object codeObject, Entity entity) 15 | { 16 | base.Generate(codeObject, entity); 17 | 18 | var attribute = (CodeAttributeDeclaration)codeObject; 19 | var docType = (DocumentType)entity; 20 | var info = (DocumentTypeInfo)docType.Info; 21 | 22 | AddAttributeArgumentIfValue(attribute, "DefaultTemplate", info.DefaultTemplate); 23 | 24 | var allowedTemplates = 25 | info.AllowedTemplates 26 | .NonNullOrWhiteSpace() 27 | .AsPrimitiveExpressions(); 28 | var arrayCreateExpression = new CodeArrayCreateExpression("String", allowedTemplates); 29 | if (allowedTemplates.Any()) 30 | AddAttributeArgument(attribute, "AllowedTemplates", arrayCreateExpression); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Annotated/EntityDescriptionGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Generators.Annotated 7 | { 8 | public class EntityDescriptionGenerator : CodeGeneratorBase 9 | { 10 | public EntityDescriptionGenerator(ContentTypeConfiguration config) : base(config) 11 | { 12 | } 13 | 14 | public override void Generate(object codeObject, Entity entity) 15 | { 16 | var description = (IEntityDescription)entity; 17 | var attribute = (CodeAttributeDeclaration)codeObject; 18 | 19 | AddDisplayNameIfDifferent(attribute, description); 20 | AddAttributeArgumentIfValue(attribute, "Description", description.Description); 21 | } 22 | 23 | protected static void AddDisplayNameIfDifferent(CodeAttributeDeclaration attribute, IEntityDescription description) 24 | { 25 | var name = description.Name; 26 | if (String.Compare(name, description.Alias, IgnoreCase) == 0 || 27 | String.Compare(name, description.Alias.SplitPascalCase(), IgnoreCase) == 0) 28 | return; 29 | AddAttributePrimitiveArgument(attribute, "DisplayName", name); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Annotated/ImportsGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators.Annotated 6 | { 7 | public class ImportsGenerator : CodeGeneratorBase 8 | { 9 | public ImportsGenerator(ContentTypeConfiguration config) 10 | : base(config) 11 | { 12 | } 13 | 14 | public override void Generate(object codeObject, Entity entity) 15 | { 16 | var ns = (CodeNamespace)codeObject; 17 | AddImports(ns); 18 | } 19 | 20 | private static void AddImports(CodeNamespace ns) 21 | { 22 | ns.Imports.Add(new CodeNamespaceImport("global::System")); 23 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.CodeGen.Annotations")); 24 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.Core.Models")); 25 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.Web")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Annotated/PropertyInfoGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using Umbraco.CodeGen.Configuration; 6 | using Umbraco.CodeGen.Definitions; 7 | 8 | namespace Umbraco.CodeGen.Generators.Annotated 9 | { 10 | public class PropertyInfoGenerator : EntityDescriptionGenerator 11 | { 12 | private readonly IList dataTypes; 13 | 14 | public PropertyInfoGenerator( 15 | ContentTypeConfiguration config, 16 | IList dataTypes 17 | ) : base(config) 18 | { 19 | this.dataTypes = dataTypes; 20 | } 21 | 22 | public override void Generate(object codeObject, Entity entity) 23 | { 24 | base.Generate(codeObject, entity); 25 | 26 | var property = (GenericProperty) entity; 27 | var attribute = (CodeAttributeDeclaration) codeObject; 28 | 29 | AddDataType(attribute, property); 30 | AddAttributeArgumentIfValue(attribute, "Tab", property.Tab); 31 | if (property.Mandatory) 32 | AddAttributePrimitiveArgument(attribute, "Mandatory", true); 33 | AddAttributeArgumentIfValue(attribute, "Validation", property.Validation); 34 | } 35 | 36 | private void AddDataType(CodeAttributeDeclaration attribute, GenericProperty property) 37 | { 38 | var dataType = dataTypes.SingleOrDefault(dt => 39 | String.Compare(dt.DefinitionId, property.Definition, IgnoreCase) == 0 || 40 | String.Compare(dt.DataTypeName, property.Definition, IgnoreCase) == 0); 41 | var dataTypeValue = dataType != null 42 | ? dataType.DataTypeName 43 | : Config.TypeMappings.DefaultDefinitionId; 44 | if (dataTypeValue == null) 45 | throw new Exception("TypeMappings/DefaultDefinitionId not set. Cannot guess default definition."); 46 | 47 | AddAttributePrimitiveArgument(attribute, "Definition", dataTypeValue); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Annotated/StructureGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Definitions; 8 | 9 | namespace Umbraco.CodeGen.Generators.Annotated 10 | { 11 | public class StructureGenerator : CodeGeneratorBase 12 | { 13 | public StructureGenerator(ContentTypeConfiguration config) : base(config) 14 | { 15 | } 16 | 17 | public override void Generate(object codeObject, Entity entity) 18 | { 19 | var contentType = (ContentType) entity; 20 | var attribute = (CodeAttributeDeclaration) codeObject; 21 | 22 | var structure = contentType.Structure; 23 | if (structure.All(String.IsNullOrWhiteSpace)) 24 | return; 25 | 26 | var typeofExpressions = 27 | structure 28 | .Where(allowedType => !String.IsNullOrWhiteSpace(allowedType)) 29 | .Select(allowedType => new CodeTypeOfExpression(allowedType.PascalCase())) 30 | .Cast() 31 | .ToArray(); 32 | var expression = new CodeArrayCreateExpression( 33 | typeof(Type[]), 34 | typeofExpressions 35 | ); 36 | 37 | AddAttributeArgument(attribute, "Structure", expression); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/AttributeCodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators 6 | { 7 | public class AttributeCodeGenerator : CodeGeneratorBase 8 | { 9 | private readonly string attributeName; 10 | private readonly CodeGeneratorBase[] memberGenerators; 11 | 12 | public AttributeCodeGenerator( 13 | string attributeName, 14 | ContentTypeConfiguration config, 15 | params CodeGeneratorBase[] memberGenerators 16 | ) : base(config) 17 | { 18 | this.attributeName = attributeName; 19 | this.memberGenerators = memberGenerators; 20 | } 21 | 22 | public override void Generate(object codeObject, Entity entity) 23 | { 24 | var type = (CodeTypeMember)codeObject; 25 | 26 | var attribute = AddAttribute(type, attributeName); 27 | 28 | if (memberGenerators != null) 29 | foreach(var generator in memberGenerators) 30 | generator.Generate(attribute, entity); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/BaseSupportedAnnotated/CtorGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators.BaseSupportedAnnotated 6 | { 7 | public class CtorGenerator : CodeGeneratorBase 8 | { 9 | public CtorGenerator(ContentTypeConfiguration config) : base(config) 10 | { 11 | } 12 | 13 | public override void Generate(object codeObject, Entity entity) 14 | { 15 | var type = (CodeTypeDeclaration) codeObject; 16 | var ctor = new CodeConstructor 17 | { 18 | Attributes = MemberAttributes.Public 19 | }; 20 | ctor.Parameters.Add( 21 | new CodeParameterDeclarationExpression( 22 | "Umbraco.Core.Models.IPublishedContent", 23 | "content" 24 | ) 25 | ); 26 | ctor.BaseConstructorArgs.Add( 27 | new CodeVariableReferenceExpression("content") 28 | ); 29 | type.Members.Add(ctor); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/BaseSupportedAnnotated/ImportsGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators.BaseSupportedAnnotated 6 | { 7 | public class ImportsGenerator : CodeGeneratorBase 8 | { 9 | public ImportsGenerator(ContentTypeConfiguration config) 10 | : base(config) 11 | { 12 | } 13 | 14 | public override void Generate(object codeObject, Entity entity) 15 | { 16 | var ns = (CodeNamespace)codeObject; 17 | AddImports(ns); 18 | } 19 | 20 | private static void AddImports(CodeNamespace ns) 21 | { 22 | ns.Imports.Add(new CodeNamespaceImport("global::System")); 23 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.CodeGen.Annotations")); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/BaseSupportedAnnotated/PropertyBodyGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators.BaseSupportedAnnotated 6 | { 7 | public class PropertyBodyGenerator : CodeGeneratorBase 8 | { 9 | public PropertyBodyGenerator(ContentTypeConfiguration config) 10 | : base(config) 11 | { 12 | } 13 | 14 | public override void Generate(object codeObject, Entity entity) 15 | { 16 | var propNode = (CodeMemberProperty) codeObject; 17 | var property = (GenericProperty) entity; 18 | 19 | var getPropertyValueMethod = new CodeMethodReferenceExpression(null, "GetValue", propNode.Type); 20 | var getPropertyValueCall = new CodeMethodInvokeExpression(getPropertyValueMethod, new CodePrimitiveExpression(property.Alias)); 21 | propNode.GetStatements.Add(new CodeMethodReturnStatement(getPropertyValueCall)); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Bcl/CommonInfoGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators.Bcl 6 | { 7 | public class CommonInfoGenerator : CodeGeneratorBase 8 | { 9 | public CommonInfoGenerator(ContentTypeConfiguration config) : base(config) 10 | { 11 | } 12 | 13 | public override void Generate(object codeObject, Entity entity) 14 | { 15 | var type = (CodeTypeDeclaration)codeObject; 16 | var contentType = (ContentType) entity; 17 | var info = contentType.Info; 18 | 19 | AddFieldIfNotEmpty(type, "icon", info.Icon); 20 | AddFieldIfNotEmpty(type, "thumbnail", info.Thumbnail); 21 | AddFieldIfTrue(type, "allowAtRoot", info.AllowAtRoot); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Bcl/DocumentTypeInfoGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Linq; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | 7 | namespace Umbraco.CodeGen.Generators.Bcl 8 | { 9 | public class DocumentTypeInfoGenerator : CommonInfoGenerator 10 | { 11 | public DocumentTypeInfoGenerator(ContentTypeConfiguration config) : base(config) 12 | { 13 | } 14 | 15 | public override void Generate(object codeObject, Entity entity) 16 | { 17 | var contentType = (ContentType) entity; 18 | var info = (DocumentTypeInfo) contentType.Info; 19 | var type = (CodeTypeDeclaration) codeObject; 20 | 21 | base.Generate(type, contentType); 22 | 23 | AddFieldIfNotEmpty(type, "defaultTemplate", info.DefaultTemplate); 24 | AddAllowedTemplates(type, info); 25 | } 26 | 27 | private static void AddAllowedTemplates(CodeTypeDeclaration type, DocumentTypeInfo info) 28 | { 29 | if (info.AllowedTemplates.All(String.IsNullOrWhiteSpace)) 30 | return; 31 | var field = new CodeMemberField( 32 | typeof (string[]), 33 | "allowedTemplates" 34 | ); 35 | var expressions = 36 | info.AllowedTemplates 37 | .NonNullOrWhiteSpace() 38 | .AsPrimitiveExpressions(); 39 | field.InitExpression = new CodeArrayCreateExpression( 40 | typeof(string[]), 41 | expressions 42 | ); 43 | type.Members.Add(field); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Bcl/EntityDescriptionGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Generators.Bcl 7 | { 8 | public class EntityDescriptionGenerator : EntityNameGenerator 9 | { 10 | public EntityDescriptionGenerator(ContentTypeConfiguration config) : base(config) 11 | { 12 | } 13 | 14 | public override void Generate(object codeObject, Entity entity) 15 | { 16 | base.Generate(codeObject, entity); 17 | 18 | var description = (IEntityDescription) entity; 19 | var type = (CodeTypeMember)codeObject; 20 | 21 | AddDisplayNameIfDifferent(type, description); 22 | AddDescription(type, description); 23 | } 24 | 25 | protected static void AddDisplayNameIfDifferent(CodeTypeMember type, IEntityDescription description) 26 | { 27 | var name = description.Name; 28 | if (String.Compare(name, description.Alias, IgnoreCase) == 0 || 29 | String.Compare(name, description.Alias.SplitPascalCase(), IgnoreCase) == 0) 30 | return; 31 | AddAttribute(type, "DisplayName", name); 32 | } 33 | 34 | protected void AddDescription(CodeTypeMember type, IEntityDescription description) 35 | { 36 | if (String.IsNullOrWhiteSpace(description.Description)) 37 | return; 38 | 39 | AddAttribute(type, "Description", description.Description); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Bcl/ImportsGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators.Bcl 6 | { 7 | public class ImportsGenerator : CodeGeneratorBase 8 | { 9 | public ImportsGenerator(ContentTypeConfiguration config) : base(config) 10 | { 11 | } 12 | 13 | public override void Generate(object codeObject, Entity entity) 14 | { 15 | var ns = (CodeNamespace) codeObject; 16 | AddImports(ns); 17 | } 18 | 19 | private static void AddImports(CodeNamespace ns) 20 | { 21 | ns.Imports.Add(new CodeNamespaceImport("global::System")); 22 | ns.Imports.Add(new CodeNamespaceImport("global::System.ComponentModel")); 23 | ns.Imports.Add(new CodeNamespaceImport("global::System.ComponentModel.DataAnnotations")); 24 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.Core.Models")); 25 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.Web")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/Bcl/StructureGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Linq; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | 7 | namespace Umbraco.CodeGen.Generators.Bcl 8 | { 9 | public class StructureGenerator : CodeGeneratorBase 10 | { 11 | public StructureGenerator(ContentTypeConfiguration config) : base(config) 12 | { 13 | } 14 | 15 | public override void Generate(object codeObject, Entity entity) 16 | { 17 | var contentType = (ContentType) entity; 18 | var type = (CodeTypeDeclaration) codeObject; 19 | 20 | AddStructure(type, contentType); 21 | } 22 | 23 | private static void AddStructure(CodeTypeDeclaration type, ContentType contentType) 24 | { 25 | if (contentType.Structure.All(String.IsNullOrWhiteSpace)) 26 | return; 27 | var field = new CodeMemberField( 28 | typeof (Type[]), 29 | "structure" 30 | ); 31 | var typeofExpressions = 32 | contentType.Structure 33 | .Where(allowedType => !String.IsNullOrWhiteSpace(allowedType)) 34 | .Select(allowedType => new CodeTypeOfExpression(allowedType.PascalCase())) 35 | .Cast() 36 | .ToArray(); 37 | field.InitExpression = new CodeArrayCreateExpression( 38 | typeof(Type[]), 39 | typeofExpressions 40 | ); 41 | type.Members.Add(field); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/ClassGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Definitions; 8 | 9 | namespace Umbraco.CodeGen.Generators 10 | { 11 | public class ClassGenerator : CompositeCodeGenerator 12 | { 13 | public ClassGenerator( 14 | ContentTypeConfiguration config, 15 | params CodeGeneratorBase[] memberGenerators 16 | ) 17 | : base(config, memberGenerators) 18 | { 19 | } 20 | 21 | public override void Generate(object codeObject, Entity entity) 22 | { 23 | var contentType = (ContentType) entity; 24 | var info = contentType.Info; 25 | 26 | var ns = (CodeNamespace)codeObject; 27 | var type = new CodeTypeDeclaration(); 28 | ns.Types.Add(type); 29 | 30 | SetPartial(type); 31 | SetBaseClass(type, info); 32 | AddInterfaces(type, contentType); 33 | 34 | base.Generate(type, entity); 35 | } 36 | 37 | private void SetPartial(CodeTypeDeclaration type) 38 | { 39 | type.IsPartial = true; 40 | } 41 | 42 | protected void SetBaseClass(CodeTypeDeclaration type, Info info) 43 | { 44 | var baseReference = String.IsNullOrWhiteSpace(info.Master) 45 | ? new CodeTypeReference(Config.BaseClass) 46 | : new CodeTypeReference(info.Master.PascalCase()); 47 | type.BaseTypes.Add(baseReference); 48 | } 49 | 50 | private void AddInterfaces(CodeTypeDeclaration type, ContentType contentType) 51 | { 52 | if (contentType.IsMixin) 53 | type.BaseTypes.Add((new CodeTypeReference("I" + contentType.Alias.PascalCase()))); 54 | 55 | foreach (var composition in contentType.Composition) 56 | type.BaseTypes.Add((new CodeTypeReference("I" + composition.Alias.PascalCase()))); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/CodeGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Mime; 4 | using Umbraco.CodeGen.Configuration; 5 | 6 | namespace Umbraco.CodeGen.Generators 7 | { 8 | public abstract class CodeGeneratorFactory 9 | { 10 | public abstract CodeGeneratorBase Create(ContentTypeConfiguration configuration, IEnumerable dataTypes); 11 | } 12 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/CompositeCodeGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Umbraco.CodeGen.Configuration; 6 | using Umbraco.CodeGen.Definitions; 7 | 8 | namespace Umbraco.CodeGen.Generators 9 | { 10 | public class CompositeCodeGenerator : CodeGeneratorBase 11 | { 12 | private readonly CodeGeneratorBase[] generators; 13 | 14 | public CompositeCodeGenerator( 15 | ContentTypeConfiguration config, 16 | params CodeGeneratorBase[] generators 17 | ) : base(config) 18 | { 19 | this.generators = generators; 20 | } 21 | 22 | public override void Generate(object codeObject, Entity entity) 23 | { 24 | if (generators != null) 25 | foreach(var generator in generators) 26 | generator.Generate(codeObject, entity); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/CtorGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Definitions; 8 | 9 | namespace Umbraco.CodeGen.Generators 10 | { 11 | public class CtorGenerator : CodeGeneratorBase 12 | { 13 | public CtorGenerator(ContentTypeConfiguration config) : base(config) 14 | { 15 | } 16 | 17 | public override void Generate(object codeObject, Entity entity) 18 | { 19 | var type = (CodeTypeDeclaration) codeObject; 20 | var ctor = new CodeConstructor 21 | { 22 | Attributes = MemberAttributes.Public 23 | }; 24 | ctor.Parameters.Add( 25 | new CodeParameterDeclarationExpression( 26 | "IPublishedContent", 27 | "content" 28 | ) 29 | ); 30 | ctor.BaseConstructorArgs.Add( 31 | new CodeVariableReferenceExpression("content") 32 | ); 33 | type.Members.Add(ctor); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/DefaultCodeGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Parsers; 5 | 6 | namespace Umbraco.CodeGen.Generators 7 | { 8 | [Parser(typeof(DefaultParserFactory))] 9 | [Description("Use whichever generator and parser the dev deems appropriate for this version")] 10 | public class DefaultCodeGeneratorFactory : CodeGeneratorFactory 11 | { 12 | private readonly CodeGeneratorFactory inner = new BaseSupportedAnnotatedCodeGeneratorFactory(); 13 | 14 | public override CodeGeneratorBase Create(ContentTypeConfiguration configuration, IEnumerable dataTypes) 15 | { 16 | return inner.Create(configuration, dataTypes); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/EntityNameGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators 6 | { 7 | public class EntityNameGenerator : NameGenerator 8 | { 9 | public EntityNameGenerator(ContentTypeConfiguration config) : base(config) 10 | { 11 | } 12 | 13 | protected override void SetName(CodeTypeMember type, IEntityDescription description) 14 | { 15 | type.Name = description.Alias.PascalCase(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/GenerateOnly/ImportsGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators.GenerateOnly 6 | { 7 | public class ImportsGenerator : CodeGeneratorBase 8 | { 9 | public ImportsGenerator(ContentTypeConfiguration config) : base(config) 10 | { 11 | } 12 | 13 | public override void Generate(object codeObject, Entity entity) 14 | { 15 | var ns = (CodeNamespace) codeObject; 16 | AddImports(ns); 17 | } 18 | 19 | private static void AddImports(CodeNamespace ns) 20 | { 21 | ns.Imports.Add(new CodeNamespaceImport("global::System")); 22 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.Core.Models")); 23 | ns.Imports.Add(new CodeNamespaceImport("global::Umbraco.Web")); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/GenerateOnly/InterfaceGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Generators.GenerateOnly 7 | { 8 | public class InterfaceGenerator : CompositeCodeGenerator 9 | { 10 | public InterfaceGenerator(ContentTypeConfiguration config, params CodeGeneratorBase[] generators) : base(config, generators) 11 | { 12 | } 13 | 14 | public override void Generate(object codeObject, Entity entity) 15 | { 16 | var ns = (CodeNamespace)codeObject; 17 | var type = new CodeTypeDeclaration(); 18 | ns.Types.Add(type); 19 | 20 | type.IsInterface = true; 21 | type.IsPartial = true; 22 | type.BaseTypes.Add(new CodeTypeReference("IPublishedContent")); 23 | 24 | base.Generate(type, entity); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/GenerateOnly/InterfaceNameGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Umbraco.CodeGen.Configuration; 8 | using Umbraco.CodeGen.Definitions; 9 | 10 | namespace Umbraco.CodeGen.Generators.GenerateOnly 11 | { 12 | public class InterfaceNameGenerator : NameGenerator 13 | { 14 | public InterfaceNameGenerator(ContentTypeConfiguration config) : base(config) 15 | { 16 | } 17 | 18 | protected override void SetName(CodeTypeMember type, IEntityDescription description) 19 | { 20 | type.Name = "I" + description.Alias.PascalCase(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/GenerateOnly/InterfacePropertyBodyGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Umbraco.CodeGen.Configuration; 8 | using Umbraco.CodeGen.Definitions; 9 | 10 | namespace Umbraco.CodeGen.Generators.GenerateOnly 11 | { 12 | public class InterfacePropertyBodyGenerator : CodeGeneratorBase 13 | { 14 | public InterfacePropertyBodyGenerator(ContentTypeConfiguration config) : base(config) 15 | { 16 | } 17 | 18 | public override void Generate(object codeObject, Entity entity) 19 | { 20 | var property = (CodeMemberProperty) codeObject; 21 | property.HasGet = true; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/GenerateOnly/InterfacePropertyDeclarationGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Umbraco.CodeGen.Configuration; 8 | using Umbraco.CodeGen.Definitions; 9 | 10 | namespace Umbraco.CodeGen.Generators.GenerateOnly 11 | { 12 | public class InterfacePropertyDeclarationGenerator : PropertyDeclarationGenerator 13 | { 14 | public InterfacePropertyDeclarationGenerator(ContentTypeConfiguration config, IList dataTypes, params CodeGeneratorBase[] generators) : base(config, dataTypes, generators) 15 | { 16 | } 17 | 18 | protected override void SetAttributes(CodeTypeMember propNode) 19 | { 20 | propNode.Attributes = MemberAttributes.Abstract; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/InterfaceGeneratorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Generators.GenerateOnly; 8 | 9 | namespace Umbraco.CodeGen.Generators 10 | { 11 | public class InterfaceGeneratorFactory : CodeGeneratorFactory 12 | { 13 | public override CodeGeneratorBase Create(ContentTypeConfiguration configuration, IEnumerable dataTypes) 14 | { 15 | return CreateInterfaceGenerator(configuration, dataTypes); 16 | } 17 | 18 | public CodeGeneratorBase CreateInterfaceGenerator(ContentTypeConfiguration configuration, IEnumerable dataTypes) 19 | { 20 | return new NamespaceGenerator( 21 | configuration, 22 | new ImportsGenerator(configuration), 23 | new InterfaceGenerator(configuration, 24 | new CompositeCodeGenerator( 25 | configuration, 26 | new InterfaceNameGenerator(configuration) 27 | ), 28 | new PropertiesGenerator( 29 | configuration, 30 | new InterfacePropertyDeclarationGenerator( 31 | configuration, 32 | dataTypes.ToList(), 33 | new EntityNameGenerator(configuration), 34 | new InterfacePropertyBodyGenerator(configuration) 35 | ) 36 | ) 37 | ) 38 | ); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/NameGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Generators 7 | { 8 | public abstract class NameGenerator : CodeGeneratorBase 9 | { 10 | protected NameGenerator(ContentTypeConfiguration config) : base(config) 11 | { 12 | } 13 | 14 | protected static void ValidateAlias(IEntityDescription description) 15 | { 16 | if (String.IsNullOrWhiteSpace(description.Alias)) 17 | throw new Exception("Cannot generate entity with alias null or empty"); 18 | } 19 | 20 | protected abstract void SetName(CodeTypeMember type, IEntityDescription description); 21 | 22 | public override void Generate(object codeObject, Entity entity) 23 | { 24 | var description = (IEntityDescription)entity; 25 | var type = (CodeTypeMember)codeObject; 26 | 27 | ValidateAlias(description); 28 | SetName(type, description); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/NamespaceGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Generators 7 | { 8 | public class NamespaceGenerator : CodeGeneratorBase 9 | { 10 | private readonly CodeGeneratorBase[] memberGenerators; 11 | 12 | public NamespaceGenerator( 13 | ContentTypeConfiguration config, 14 | params CodeGeneratorBase[] memberGenerators 15 | ) : base(config) 16 | { 17 | this.memberGenerators = memberGenerators; 18 | } 19 | 20 | public override void Generate(object codeObject, Entity entity) 21 | { 22 | CodeNamespace ns; 23 | if (codeObject is CodeCompileUnit) 24 | ns = AddToCompileUnit(codeObject); 25 | else 26 | { 27 | ns = (CodeNamespace) codeObject; 28 | ns.Name = Config.Namespace; 29 | } 30 | 31 | foreach(var generator in memberGenerators) 32 | generator.Generate(ns, entity); 33 | } 34 | 35 | private CodeNamespace AddToCompileUnit(object codeObject) 36 | { 37 | var compileUnit = (CodeCompileUnit) codeObject; 38 | 39 | if (String.IsNullOrWhiteSpace(Config.Namespace)) 40 | throw new Exception("ContentType namespace not configured."); 41 | 42 | var ns = new CodeNamespace(Config.Namespace); 43 | compileUnit.Namespaces.Add(ns); 44 | return ns; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/PropertiesGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Definitions; 8 | 9 | namespace Umbraco.CodeGen.Generators 10 | { 11 | public class PropertiesGenerator : CodeGeneratorBase 12 | { 13 | private readonly CodeGeneratorBase[] propertyGenerators; 14 | 15 | public PropertiesGenerator( 16 | ContentTypeConfiguration config, 17 | params CodeGeneratorBase[] propertyGenerators 18 | ) : base(config) 19 | { 20 | this.propertyGenerators = propertyGenerators; 21 | } 22 | 23 | public override void Generate(object codeObject, Entity entity) 24 | { 25 | var type = (CodeTypeDeclaration) codeObject; 26 | var contentType = (ContentType) entity; 27 | 28 | foreach (var property in contentType.GenericProperties.Union(contentType.Composition.SelectMany(c => c.GenericProperties))) 29 | { 30 | var propNode = new CodeMemberProperty(); 31 | foreach(var generator in propertyGenerators) 32 | generator.Generate(propNode, property); 33 | type.Members.Add(propNode); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/PropertyBodyGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Generators 6 | { 7 | public class PropertyBodyGenerator : CodeGeneratorBase 8 | { 9 | public PropertyBodyGenerator(ContentTypeConfiguration config) : base(config) 10 | { 11 | } 12 | 13 | public override void Generate(object codeObject, Entity entity) 14 | { 15 | var propNode = (CodeMemberProperty) codeObject; 16 | var property = (GenericProperty) entity; 17 | 18 | var contentRef = new CodePropertyReferenceExpression(null, "Content"); 19 | var getPropertyValueMethod = new CodeMethodReferenceExpression(contentRef, "GetPropertyValue", propNode.Type); 20 | var getPropertyValueCall = new CodeMethodInvokeExpression(getPropertyValueMethod, new CodePrimitiveExpression(property.Alias)); 21 | propNode.GetStatements.Add(new CodeMethodReturnStatement(getPropertyValueCall)); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/PropertyDeclarationGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.CodeDom; 3 | using System.Collections.Generic; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | 7 | namespace Umbraco.CodeGen.Generators 8 | { 9 | public abstract class PropertyDeclarationGenerator : CodeGeneratorBase 10 | { 11 | protected IList DataTypes; 12 | protected CodeGeneratorBase[] MemberGenerators; 13 | 14 | protected PropertyDeclarationGenerator( 15 | ContentTypeConfiguration config, 16 | IList dataTypes, 17 | params CodeGeneratorBase[] memberGenerators 18 | ) : base(config) 19 | { 20 | this.DataTypes = dataTypes; 21 | this.MemberGenerators = memberGenerators; 22 | } 23 | 24 | public override void Generate(object codeObject, Entity entity) 25 | { 26 | var property = (GenericProperty)entity; 27 | var propNode = (CodeMemberProperty)codeObject; 28 | 29 | SetType(propNode, property); 30 | 31 | foreach (var generator in MemberGenerators) 32 | generator.Generate(codeObject, property); 33 | 34 | SetAttributes(propNode); 35 | } 36 | 37 | protected abstract void SetAttributes(CodeTypeMember propNode); 38 | 39 | protected void SetType(CodeMemberProperty propNode, GenericProperty property) 40 | { 41 | var hasType = property.Type != null && 42 | Config.TypeMappings.ContainsKey(property.Type.ToLower()); 43 | var typeName = hasType 44 | ? Config.TypeMappings[property.Type.ToLower()] 45 | : Config.TypeMappings.DefaultType; 46 | if (typeName == null) 47 | throw new Exception("TypeMappings/Default not set. Cannot guess default property type."); 48 | propNode.Type = new CodeTypeReference(typeName); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Generators/PublicPropertyDeclarationGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Collections.Generic; 3 | using Umbraco.CodeGen.Configuration; 4 | 5 | namespace Umbraco.CodeGen.Generators 6 | { 7 | public class PublicPropertyDeclarationGenerator : PropertyDeclarationGenerator 8 | { 9 | public PublicPropertyDeclarationGenerator(ContentTypeConfiguration config, IList dataTypes, params CodeGeneratorBase[] memberGenerators) : base(config, dataTypes, memberGenerators) 10 | { 11 | } 12 | 13 | protected override void SetAttributes(CodeTypeMember propNode) 14 | { 15 | propNode.Attributes = MemberAttributes.Public; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/Annotated/CommonInfoParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ICSharpCode.NRefactory.CSharp; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Definitions; 8 | using Attribute = ICSharpCode.NRefactory.CSharp.Attribute; 9 | 10 | namespace Umbraco.CodeGen.Parsers.Annotated 11 | { 12 | public class CommonInfoParser : InfoParserBase 13 | { 14 | public CommonInfoParser(ContentTypeConfiguration configuration) : base(configuration) 15 | { 16 | } 17 | 18 | protected override void OnParseInfo(TypeDeclaration type, ContentType definition) 19 | { 20 | // TODO: Dry this 21 | var info = definition.Info; 22 | info.Alias = type.Name.PascalCase(); 23 | info.Master = FindMaster(type, Configuration).PascalCase(); 24 | 25 | var attribute = FindContentTypeAttribute(type, definition); 26 | 27 | info.Name = AttributeArgumentValue(attribute, "DisplayName", type.Name.SplitPascalCase()); 28 | info.Description = AttributeArgumentValue(attribute, "Description", null); 29 | info.AllowAtRoot = AttributeArgumentValue(attribute, "AllowAtRoot", false); 30 | info.Icon = AttributeArgumentValue(attribute, "Icon", "folder.gif"); 31 | info.Thumbnail = AttributeArgumentValue(attribute, "Thumbnail", "folder.png"); 32 | } 33 | 34 | protected static Attribute FindContentTypeAttribute(TypeDeclaration type, ContentType definition) 35 | { 36 | string attributeName; 37 | if (definition is MediaType) 38 | attributeName = "MediaType"; 39 | else 40 | attributeName = "DocumentType"; 41 | var attribute = FindAttribute(type.Attributes, attributeName); 42 | return attribute; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/Annotated/DocumentTypeInfoParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ICSharpCode.NRefactory.CSharp; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Definitions; 8 | 9 | namespace Umbraco.CodeGen.Parsers.Annotated 10 | { 11 | public class DocumentTypeInfoParser : CommonInfoParser 12 | { 13 | public DocumentTypeInfoParser(ContentTypeConfiguration configuration) : base(configuration) 14 | { 15 | } 16 | 17 | protected override void OnParseInfo(TypeDeclaration type, ContentType definition) 18 | { 19 | base.OnParseInfo(type, definition); 20 | 21 | var docType = (DocumentType)definition; 22 | var info = (DocumentTypeInfo)docType.Info; 23 | var attribute = FindAttribute(type.Attributes, "DocumentType"); 24 | 25 | info.DefaultTemplate = AttributeArgumentValue(attribute, "DefaultTemplate", null); 26 | info.AllowedTemplates = StringArrayValue(attribute, "AllowedTemplates").ToList(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/Annotated/StructureParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ICSharpCode.NRefactory.CSharp; 6 | using Umbraco.CodeGen.Configuration; 7 | using Umbraco.CodeGen.Definitions; 8 | using Attribute = ICSharpCode.NRefactory.CSharp.Attribute; 9 | 10 | namespace Umbraco.CodeGen.Parsers.Annotated 11 | { 12 | public class StructureParser : ContentTypeCodeParserBase 13 | { 14 | public StructureParser(ContentTypeConfiguration configuration) : base(configuration) 15 | { 16 | } 17 | 18 | public override void Parse(AstNode node, ContentType contentType) 19 | { 20 | var type = (TypeDeclaration) node; 21 | 22 | var attribute = FindContentTypeAttribute(type, contentType); 23 | 24 | contentType.Structure = TypeArrayValue(attribute, "Structure") 25 | .Select(val => val.PascalCase()) 26 | .ToList(); 27 | } 28 | 29 | // TODO: Dry up 30 | protected static Attribute FindContentTypeAttribute(TypeDeclaration type, ContentType definition) 31 | { 32 | string attributeName; 33 | if (definition is MediaType) 34 | attributeName = "MediaType"; 35 | else 36 | attributeName = "DocumentType"; 37 | var attribute = FindAttribute(type.Attributes, attributeName); 38 | return attribute; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/AnnotatedParserFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Umbraco.CodeGen.Parsers.Annotated; 3 | 4 | namespace Umbraco.CodeGen.Parsers 5 | { 6 | public class AnnotatedParserFactory : ParserFactory 7 | { 8 | public override ContentTypeCodeParser CreateMediaTypeParser() 9 | { 10 | var parsers = CreateParsers( 11 | new CommonInfoParser(Configuration), 12 | new MediaPropertyParser( 13 | new PropertyParser(Configuration, DataTypes), 14 | Configuration, 15 | DataTypes 16 | ) 17 | ); 18 | return new MediaTypeCodeParser(Configuration, parsers.ToArray()); 19 | } 20 | 21 | public override ContentTypeCodeParser CreateDocumentTypeParser() 22 | { 23 | var parsers = CreateParsers( 24 | new DocumentTypeInfoParser(Configuration), 25 | new PropertyParser(Configuration, DataTypes) 26 | ); 27 | return new DocumentTypeCodeParser(Configuration, parsers.ToArray()); 28 | } 29 | 30 | protected List CreateParsers(InfoParserBase infoParser, ContentTypeCodeParserBase propertyParser) 31 | { 32 | var parsers = CreateDocumentParsers(propertyParser); 33 | parsers.Insert(0, infoParser); 34 | return parsers; 35 | } 36 | 37 | protected List CreateDocumentParsers(ContentTypeCodeParserBase propertyParser) 38 | { 39 | return new List 40 | { 41 | new StructureParser(Configuration), 42 | new PropertiesParser(Configuration, 43 | propertyParser 44 | ), 45 | new TabsParser(Configuration) 46 | }; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/Bcl/CommonInfoParser.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.NRefactory.CSharp; 2 | using Umbraco.CodeGen.Configuration; 3 | 4 | namespace Umbraco.CodeGen.Parsers.Bcl 5 | { 6 | public class CommonInfoParser : InfoParserBase 7 | { 8 | public CommonInfoParser(ContentTypeConfiguration configuration) : base(configuration) 9 | { 10 | } 11 | 12 | protected override void OnParseInfo(TypeDeclaration type, Definitions.ContentType definition) 13 | { 14 | var info = definition.Info; 15 | info.Alias = type.Name.PascalCase(); 16 | info.Master = FindMaster(type, Configuration).PascalCase(); 17 | 18 | info.Name = AttributeValue(type, "DisplayName", type.Name.SplitPascalCase()); 19 | info.Description = AttributeValue(type, "Description", null); 20 | info.AllowAtRoot = BoolFieldValue(type, "AllowAtRoot"); 21 | info.Icon = StringFieldValue(type, "icon", "folder.gif"); 22 | info.Thumbnail = StringFieldValue(type, "thumbnail", "folder.png"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/Bcl/DocumentTypeInfoParser.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using ICSharpCode.NRefactory.CSharp; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Parsers.Bcl 7 | { 8 | public class DocumentTypeInfoParser : CommonInfoParser 9 | { 10 | public DocumentTypeInfoParser(ContentTypeConfiguration configuration) : base(configuration) 11 | { 12 | } 13 | 14 | protected override void OnParseInfo(TypeDeclaration type, ContentType definition) 15 | { 16 | base.OnParseInfo(type, definition); 17 | 18 | var docType = (DocumentType)definition; 19 | var info = (DocumentTypeInfo)docType.Info; 20 | 21 | info.DefaultTemplate = StringFieldValue(type, "DefaultTemplate"); 22 | info.AllowedTemplates = StringArrayValue(type, "AllowedTemplates").ToList(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/Bcl/StructureParser.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using ICSharpCode.NRefactory.CSharp; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Parsers.Bcl 7 | { 8 | public class StructureParser : ContentTypeCodeParserBase 9 | { 10 | public StructureParser(ContentTypeConfiguration configuration) : base(configuration) 11 | { 12 | } 13 | 14 | public override void Parse(AstNode node, ContentType contentType) 15 | { 16 | var type = (TypeDeclaration) node; 17 | 18 | contentType.Structure = TypeArrayValue(type, "Structure") 19 | .Select(val => val.PascalCase()) 20 | .ToList(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/BclParserFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Umbraco.CodeGen.Parsers.Bcl; 3 | 4 | namespace Umbraco.CodeGen.Parsers 5 | { 6 | public class BclParserFactory : ParserFactory 7 | { 8 | public override ContentTypeCodeParser CreateMediaTypeParser() 9 | { 10 | var parsers = CreateParsers( 11 | new CommonInfoParser(Configuration), 12 | new MediaPropertyParser( 13 | new PropertyParser(Configuration, DataTypes), 14 | Configuration, 15 | DataTypes 16 | ) 17 | ); 18 | return new MediaTypeCodeParser(Configuration, parsers.ToArray()); 19 | } 20 | 21 | public override ContentTypeCodeParser CreateDocumentTypeParser() 22 | { 23 | var parsers = CreateParsers(new DocumentTypeInfoParser(Configuration), new PropertyParser(Configuration, DataTypes)); 24 | return new DocumentTypeCodeParser(Configuration, parsers.ToArray()); 25 | } 26 | 27 | protected List CreateParsers(InfoParserBase infoParser, ContentTypeCodeParserBase propertyParser) 28 | { 29 | var parsers = CreateDefaultParsers(propertyParser); 30 | parsers.Insert(0, infoParser); 31 | return parsers; 32 | } 33 | 34 | protected List CreateDefaultParsers(ContentTypeCodeParserBase propertyParser) 35 | { 36 | return new List 37 | { 38 | new StructureParser(Configuration), 39 | new PropertiesParser(Configuration, 40 | propertyParser 41 | ), 42 | new TabsParser(Configuration) 43 | }; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/ContentTypeCodeParser.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using ICSharpCode.NRefactory.CSharp; 3 | using Umbraco.CodeGen.Configuration; 4 | using Umbraco.CodeGen.Definitions; 5 | 6 | namespace Umbraco.CodeGen.Parsers 7 | { 8 | public abstract class ContentTypeCodeParser : ContentTypeCodeParserBase 9 | { 10 | private readonly IEnumerable memberParsers; 11 | 12 | protected ContentTypeCodeParser( 13 | ContentTypeConfiguration configuration, 14 | params ContentTypeCodeParserBase[] memberParsers 15 | ) 16 | : base(configuration) 17 | { 18 | this.memberParsers = memberParsers; 19 | } 20 | 21 | public ContentType Parse(AstNode node) 22 | { 23 | var type = CreateDefinition(); 24 | Parse(node, type); 25 | return type; 26 | } 27 | 28 | public override void Parse(AstNode node, ContentType contentType) 29 | { 30 | foreach(var parser in memberParsers) 31 | parser.Parse(node, contentType); 32 | } 33 | 34 | protected abstract ContentType CreateDefinition(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/ContentTypeCodeParserBase.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.NRefactory.CSharp; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Parsers 6 | { 7 | public abstract class ContentTypeCodeParserBase : CodeParserBase 8 | { 9 | protected ContentTypeConfiguration Configuration; 10 | 11 | protected ContentTypeCodeParserBase(ContentTypeConfiguration configuration) 12 | { 13 | Configuration = configuration; 14 | } 15 | 16 | public abstract void Parse(AstNode node, ContentType contentType); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/DefaultParserFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Parsers.Bcl; 4 | 5 | namespace Umbraco.CodeGen.Parsers 6 | { 7 | public class DefaultParserFactory : ParserFactory 8 | { 9 | private readonly ParserFactory inner = new AnnotatedParserFactory(); 10 | 11 | public override ContentTypeCodeParser Create(ContentTypeConfiguration configuration, IEnumerable dataTypes) 12 | { 13 | return inner.Create(configuration, dataTypes); 14 | } 15 | 16 | public override ContentTypeCodeParser CreateDocumentTypeParser() 17 | { 18 | return inner.CreateDocumentTypeParser(); 19 | } 20 | 21 | public override ContentTypeCodeParser CreateMediaTypeParser() 22 | { 23 | return inner.CreateMediaTypeParser(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/DocumentTypeCodeParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Umbraco.CodeGen.Configuration; 6 | using Umbraco.CodeGen.Definitions; 7 | 8 | namespace Umbraco.CodeGen.Parsers 9 | { 10 | public class DocumentTypeCodeParser : ContentTypeCodeParser 11 | { 12 | public DocumentTypeCodeParser( 13 | ContentTypeConfiguration configuration, 14 | params ContentTypeCodeParserBase[] memberParsers 15 | ) : base( 16 | configuration, 17 | memberParsers 18 | ) 19 | { 20 | } 21 | 22 | protected override ContentType CreateDefinition() 23 | { 24 | return new DocumentType(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/InfoParserBase.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.NRefactory.CSharp; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Parsers 6 | { 7 | public abstract class InfoParserBase : ContentTypeCodeParserBase 8 | { 9 | protected InfoParserBase(ContentTypeConfiguration configuration) 10 | : base(configuration) 11 | { 12 | 13 | } 14 | 15 | public override void Parse(AstNode node, ContentType definition) 16 | { 17 | var type = (TypeDeclaration) node; 18 | OnParseInfo(type, definition); 19 | } 20 | 21 | protected abstract void OnParseInfo(TypeDeclaration type, ContentType definition); 22 | } 23 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/MediaPropertyParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using ICSharpCode.NRefactory.CSharp; 7 | using Umbraco.CodeGen.Configuration; 8 | using Umbraco.CodeGen.Definitions; 9 | 10 | namespace Umbraco.CodeGen.Parsers 11 | { 12 | public class MediaPropertyParser : ContentTypeCodeParserBase 13 | { 14 | private readonly ContentTypeCodeParserBase propertyParser; 15 | private readonly IEnumerable dataTypes; 16 | 17 | public MediaPropertyParser(ContentTypeCodeParserBase propertyParser, ContentTypeConfiguration configuration, IEnumerable dataTypes) : 18 | base(configuration) 19 | { 20 | this.propertyParser = propertyParser; 21 | this.dataTypes = dataTypes; 22 | } 23 | 24 | public override void Parse(AstNode node, ContentType contentType) 25 | { 26 | propertyParser.Parse(node, contentType); 27 | 28 | var property = contentType.GenericProperties.Last(); 29 | var dataTypeDefinition = dataTypes.Single(dt => String.Equals(dt.DataTypeId, property.Type, StringComparison.InvariantCultureIgnoreCase)); 30 | property.Type = dataTypeDefinition.DataTypeGuid; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/MediaTypeCodeParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Umbraco.CodeGen.Configuration; 6 | using Umbraco.CodeGen.Definitions; 7 | 8 | namespace Umbraco.CodeGen.Parsers 9 | { 10 | public class MediaTypeCodeParser : ContentTypeCodeParser 11 | { 12 | public MediaTypeCodeParser( 13 | ContentTypeConfiguration configuration, 14 | params ContentTypeCodeParserBase[] memberParsers 15 | ) 16 | : base( 17 | configuration, 18 | memberParsers 19 | ) 20 | { 21 | } 22 | 23 | protected override ContentType CreateDefinition() 24 | { 25 | return new MediaType(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/ParserFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Umbraco.CodeGen.Configuration; 4 | 5 | namespace Umbraco.CodeGen.Parsers 6 | { 7 | public abstract class ParserFactory 8 | { 9 | protected ContentTypeConfiguration Configuration; 10 | protected IList DataTypes; 11 | 12 | public virtual ContentTypeCodeParser Create( 13 | ContentTypeConfiguration configuration, 14 | IEnumerable dataTypes 15 | ) 16 | { 17 | Configuration = configuration; 18 | DataTypes = dataTypes as List ?? dataTypes.ToList(); 19 | var typedParser = configuration.ContentTypeName == "DocumentType" 20 | ? CreateDocumentTypeParser() 21 | : CreateMediaTypeParser(); 22 | return typedParser; 23 | } 24 | 25 | public abstract ContentTypeCodeParser CreateMediaTypeParser(); 26 | public abstract ContentTypeCodeParser CreateDocumentTypeParser(); 27 | } 28 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/PropertiesParser.cs: -------------------------------------------------------------------------------- 1 | using ICSharpCode.NRefactory.CSharp; 2 | using Umbraco.CodeGen.Configuration; 3 | using Umbraco.CodeGen.Definitions; 4 | 5 | namespace Umbraco.CodeGen.Parsers 6 | { 7 | public class PropertiesParser : ContentTypeCodeParserBase 8 | { 9 | private readonly ContentTypeCodeParserBase propertyParser; 10 | 11 | public PropertiesParser( 12 | ContentTypeConfiguration configuration, 13 | ContentTypeCodeParserBase propertyParser 14 | ) : base(configuration) 15 | { 16 | this.propertyParser = propertyParser; 17 | } 18 | 19 | public override void Parse(AstNode node, ContentType contentType) 20 | { 21 | var type = (TypeDeclaration) node; 22 | var props = FindProperties(type); 23 | foreach(var prop in props) 24 | propertyParser.Parse(prop, contentType); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Parsers/TabsParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using ICSharpCode.NRefactory.CSharp; 4 | using Umbraco.CodeGen.Configuration; 5 | using Umbraco.CodeGen.Definitions; 6 | 7 | namespace Umbraco.CodeGen.Parsers 8 | { 9 | public class TabsParser : ContentTypeCodeParserBase 10 | { 11 | public TabsParser(ContentTypeConfiguration configuration) : base(configuration) 12 | { 13 | } 14 | 15 | public override void Parse(AstNode node, ContentType contentType) 16 | { 17 | contentType.Tabs.AddRange( 18 | contentType.GenericProperties 19 | .Select(p => p.Tab) 20 | .Where(name => !String.IsNullOrWhiteSpace(name)) 21 | .Distinct() 22 | .Select(name => new Tab 23 | { 24 | Caption = name 25 | }) 26 | ); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Umbraco USync Code Generator Core")] 9 | [assembly: AssemblyDescription("Core classes for code generation")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Omnicom AS")] 12 | [assembly: AssemblyProduct("Umbraco USync Code Generator")] 13 | [assembly: AssemblyCopyright("Copyright © Omnicom AS 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e7526afb-3991-4e3d-b77c-27e34561c844")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.*")] 36 | -------------------------------------------------------------------------------- /Umbraco.CodeGen/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | 4 | static public class StringExtensions 5 | { 6 | private const StringComparison IgnoreCase = StringComparison.OrdinalIgnoreCase; 7 | 8 | 9 | public static string PascalCase(this string value) 10 | { 11 | if (String.IsNullOrEmpty(value)) return value; 12 | return value.Substring(0, 1).ToUpper() + value.Substring(1); 13 | } 14 | 15 | public static string SplitPascalCase(this string value) 16 | { 17 | if (String.IsNullOrEmpty(value)) return value; 18 | var cc = CultureInfo.CurrentCulture; 19 | var newValue = PascalCase(value); 20 | var splitValue = ""; 21 | for (var i = 0; i < newValue.Length; i++) 22 | { 23 | if (i > 0 && newValue[i].ToString(cc) == newValue[i].ToString(cc).ToUpper()) 24 | splitValue += " "; 25 | splitValue += newValue[i]; 26 | } 27 | return splitValue; 28 | } 29 | 30 | public static string RemovePrefix(this string name, string removePrefix) 31 | { 32 | if (removePrefix != null && name.StartsWith(removePrefix, IgnoreCase)) 33 | name = name.Substring(removePrefix.Length); 34 | return name; 35 | } 36 | 37 | public static string CamelCase(this string value) 38 | { 39 | if (String.IsNullOrEmpty(value)) return value; 40 | return value.Substring(0, 1).ToLower() + value.Substring(1); 41 | } 42 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/XExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | 5 | namespace Umbraco.CodeGen 6 | { 7 | public static class XExtensions 8 | { 9 | public static string ElementValue(this XContainer element, string elementName) 10 | { 11 | var subElement = element.Element(elementName); 12 | if (subElement == null || String.IsNullOrEmpty(subElement.Value)) 13 | return null; 14 | return subElement.Value; 15 | } 16 | 17 | public static string AttributeValue(this XElement element, string attributeName, string defaultValue = "") 18 | { 19 | return element.Attributes(attributeName).Select(a => a.Value).DefaultIfEmpty(defaultValue).SingleOrDefault(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Umbraco.CodeGen/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Omnicom AS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packaging/Umbraco.CodeGen.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Umbraco.CodeGen 5 | 1.0.2 6 | Umbraco USync Code Generator 7 | Omnicom AS 8 | Omnicom AS 9 | false 10 | Generates XML and code on uSync events 11 | Copyright © Omnicom AS 2013 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Umbraco Code Generator 2 | 3 | Generates typed models for document types automatically. 4 | No templates, no buttons, no hassle, they're just there. 5 | 6 | Generated classes are partial and all virtual for painless extension. 7 | --------------------------------------------------------------------------------