private static void MapContentTypeBase(IContentTypeBase contentTypeBase, ContentType type) { MapInfo(contentTypeBase, type.Info); MapStructure(contentTypeBase, type); MapGenericProperties(contentTypeBase, type); MapTabs(contentTypeBase, type); }
private void GenerateModel(ContentType contentType, CodeGeneratorFactory specificGeneratorFactory, Func <ContentType, string> fileNameGetter) { var typeConfig = contentType is DocumentType ? configuration.DocumentTypes : configuration.MediaTypes; if (!typeConfig.GenerateClasses) { return; } var itemStart = DateTime.Now; LogHelper.Debug <CodeGenerator>( () => String.Format("Content type {0} saved, generating typed model", contentType.Name)); LogHelper.Info <CodeGenerator>(() => String.Format("Generating typed model for {0}", contentType.Alias)); var modelPath = EnsureModelPath(typeConfig); var path = GetPath(modelPath, fileNameGetter(contentType)); RemoveReadonly(path); var classGenerator = new CodeGenerator(typeConfig, dataTypeProvider, specificGeneratorFactory); using (var stream = System.IO.File.CreateText(path)) classGenerator.Generate(contentType, stream); LogHelper.Debug <CodeGenerator>( () => String.Format("Typed model for {0} generated. Took {1}", contentType.Alias, DateTime.Now - itemStart)); }
private static ContentType MapContentTypeBase(IContentTypeBase contentTypeBase) { var type = new ContentType(); MapContentTypeBase(contentTypeBase, type); return(type); }
protected bool Equals(ContentType other) { return Equals(Info, other.Info) && GenericProperties.NullableSequenceEqual(other.GenericProperties) && Tabs.NullableSequenceEqual(other.Tabs) && Structure.NullableSequenceEqual(other.Structure); }
private static void MapComposition(IContentType umbracoContentType, ContentType type) { type.Composition = umbracoContentType.ContentTypeComposition .Where(cmp => cmp.Id != umbracoContentType.ParentId) .Select(MapContentTypeBase) .ToList(); }
public override void Parse(AstNode node, ContentType contentType) { var type = (TypeDeclaration) node; var props = FindProperties(type); foreach(var prop in props) propertyParser.Parse(prop, contentType); }
private void AddInterfaces(CodeTypeDeclaration type, ContentType contentType) { if (contentType.IsMixin) type.BaseTypes.Add((new CodeTypeReference("I" + contentType.Alias.PascalCase()))); foreach (var composition in contentType.Composition) type.BaseTypes.Add((new CodeTypeReference("I" + composition.Alias.PascalCase()))); }
public override void Parse(AstNode node, ContentType contentType) { propertyParser.Parse(node, contentType); var property = contentType.GenericProperties.Last(); var dataTypeDefinition = dataTypes.Single(dt => String.Equals(dt.DataTypeId, property.Type, StringComparison.InvariantCultureIgnoreCase)); property.Type = dataTypeDefinition.DataTypeGuid; }
public override void Parse(AstNode node, ContentType contentType) { var type = (TypeDeclaration) node; contentType.Structure = TypeArrayValue(type, "Structure") .Select(val => val.CamelCase()) .ToList(); }
public void Generate(ContentType contentType, TextWriter writer) { EnsureGenerator(); var compileUnit = new CodeCompileUnit(); generator.Generate(compileUnit, contentType); CodeProvider.GenerateCodeFromCompileUnit(compileUnit, writer, options); writer.Flush(); }
public override void Parse(AstNode node, ContentType contentType) { var type = (TypeDeclaration) node; var attribute = FindContentTypeAttribute(type, contentType); contentType.Structure = TypeArrayValue(attribute, "Structure") .Select(val => val.PascalCase()) .ToList(); }
// TODO: Dry up protected static Attribute FindContentTypeAttribute(TypeDeclaration type, ContentType definition) { string attributeName; if (definition is MediaType) attributeName = "MediaType"; else attributeName = "DocumentType"; var attribute = FindAttribute(type.Attributes, attributeName); return attribute; }
protected override void OnParseInfo(TypeDeclaration type, ContentType definition) { base.OnParseInfo(type, definition); var docType = (DocumentType)definition; var info = (DocumentTypeInfo)docType.Info; info.DefaultTemplate = StringFieldValue(type, "DefaultTemplate"); info.AllowedTemplates = StringArrayValue(type, "AllowedTemplates").ToList(); }
protected override void OnParseInfo(TypeDeclaration type, ContentType definition) { base.OnParseInfo(type, definition); var docType = (DocumentType)definition; var info = (DocumentTypeInfo)docType.Info; var attribute = FindAttribute(type.Attributes, "DocumentType"); info.DefaultTemplate = AttributeArgumentValue<string>(attribute, "DefaultTemplate", null); info.AllowedTemplates = StringArrayValue(attribute, "AllowedTemplates").ToList(); }
public ContentType Deserialize(StreamReader reader) { var doc = XDocument.Load(reader); root = doc.Root; if (root == null) throw new Exception("There's no root"); typedSerializer = CreateTypedSerializer(root); type = typedSerializer.Create(root); typedSerializer.DeserializeInfo(root.Element("Info"), type); DeserializeStructure(); DeserializeProperties(); DeserializeTabs(); return type; }
public override void Parse(AstNode node, ContentType contentType) { contentType.Tabs.AddRange( contentType.GenericProperties .Select(p => p.Tab) .Where(name => !String.IsNullOrWhiteSpace(name)) .Distinct() .Select(name => new Tab { Caption = name }) ); }
private static void MapGenericProperties(IContentTypeBase contentTypeBase, ContentType type) { type.GenericProperties = contentTypeBase.PropertyGroups.SelectMany(pg => pg.PropertyTypes.Select(p => new GenericProperty { Alias = p.Alias, Description = p.Description, Mandatory = p.Mandatory, Name = p.Name, Tab = pg.Name, Type = p.PropertyEditorAlias, Validation = p.ValidationRegExp } ) ).ToList(); }
public string Serialize(ContentType contentType) { var doc = new XDocument(); var infoElement = new XElement("Info"); type = contentType; typedSerializer = CreateTypedSerializer(); root = typedSerializer.CreateRoot(); doc.Add(root); root.Add(infoElement); typedSerializer.SerializeInfo(infoElement, contentType); SerializeStructure(); SerializeProperties(); SerializeTabs(); var sb = new StringBuilder(); var writer = new StringWriter(sb); doc.Save(writer); writer.Flush(); return sb.ToString(); }
private static void AddStructure(CodeTypeDeclaration type, ContentType contentType) { if (contentType.Structure.All(String.IsNullOrWhiteSpace)) return; var field = new CodeMemberField( typeof (Type[]), "structure" ); var typeofExpressions = contentType.Structure .Where(allowedType => !String.IsNullOrWhiteSpace(allowedType)) .Select(allowedType => new CodeTypeOfExpression(allowedType.PascalCase())) .Cast<CodeExpression>() .ToArray(); field.InitExpression = new CodeArrayCreateExpression( typeof(Type[]), typeofExpressions ); type.Members.Add(field); }
public override void Parse(AstNode node, ContentType contentType) { var propNode = (PropertyDeclaration) node; var definitionId = AttributeValue(propNode, "DataType"); var dataType = FindDataTypeDefinition(definitionId) ?? defaultDataType; if (dataType == null) throw new Exception("Default datatype could not be found. Set a known datatype in TypeMappings.DefaultDefinitionId."); var property = new GenericProperty { Alias = propNode.Name.CamelCase(), Name = AttributeValue(propNode, "DisplayName", propNode.Name.SplitPascalCase()), Description = AttributeValue(propNode, "Description"), Definition = dataType.DefinitionId, Type = dataType.DataTypeId, Tab = AttributeValue(propNode, "Category"), Mandatory = FindAttribute(propNode.Attributes, "Required") != null, Validation = AttributeValue(propNode, "RegularExpression") }; contentType.GenericProperties.Add(property); }
public override void Parse(AstNode node, ContentType contentType) { var propNode = (PropertyDeclaration)node; var attribute = FindAttribute(propNode.Attributes, "GenericProperty"); var definitionId = AttributeArgumentValue<string>(attribute, "Definition", null); var dataType = FindDataTypeDefinition(definitionId) ?? DefaultDataType; if (dataType == null) throw new Exception("Default datatype could not be found. Set a known datatype in TypeMappings.DefaultDefinitionId."); var property = new GenericProperty { Alias = propNode.Name.CamelCase(), Name = AttributeArgumentValue(attribute, "DisplayName", propNode.Name.SplitPascalCase()), Description = AttributeArgumentValue<string>(attribute, "Description", null), Definition = dataType.DefinitionId, Type = dataType.DataTypeId, Tab = AttributeArgumentValue<string>(attribute, "Tab", null), Mandatory = AttributeArgumentValue(attribute, "Mandatory", false), Validation = AttributeArgumentValue<string>(attribute, "Validation", null) }; contentType.GenericProperties.Add(property); }
private void GenerateInterface(ContentType contentType) { GenerateModel(contentType, interfaceGeneratorFactory, c => "I" + c.Alias.PascalCase()); }
public abstract void Parse(AstNode node, ContentType contentType);
private void GenerateModel(ContentType contentType, CodeGeneratorFactory specificGeneratorFactory, Func<ContentType, string> fileNameGetter) { var typeConfig = contentType is DocumentType ? configuration.DocumentTypes : configuration.MediaTypes; if (!typeConfig.GenerateClasses) return; var itemStart = DateTime.Now; LogHelper.Debug<CodeGenerator>( () => String.Format("Content type {0} saved, generating typed model", contentType.Name)); LogHelper.Info<CodeGenerator>(() => String.Format("Generating typed model for {0}", contentType.Alias)); var modelPath = EnsureModelPath(typeConfig); var path = GetPath(modelPath, fileNameGetter(contentType)); RemoveReadonly(path); var classGenerator = new CodeGenerator(typeConfig, dataTypeProvider, specificGeneratorFactory); using (var stream = System.IO.File.CreateText(path)) classGenerator.Generate(contentType, stream); LogHelper.Debug<CodeGenerator>( () => String.Format("Typed model for {0} generated. Took {1}", contentType.Alias, DateTime.Now - itemStart)); }
private void GenerateClass(ContentType contentType) { GenerateModel(contentType, generatorFactory, c => c.Alias.PascalCase()); }
private static void MapTabs(IContentTypeBase contentTypeBase, ContentType type) { type.Tabs = contentTypeBase.PropertyGroups.Select(pg => new Tab { Caption = pg.Name }).ToList(); }
private static ContentType MapContentTypeBase(IContentTypeBase contentTypeBase) { var type = new ContentType(); MapContentTypeBase(contentTypeBase, type); return type; }
protected override Info GetInfo(ContentType type) { return ((MediaType) type).Info; }
public override void Parse(AstNode node, ContentType definition) { var type = (TypeDeclaration) node; OnParseInfo(type, definition); }
private static void MapStructure(IContentTypeBase contentTypeBase, ContentType type) { type.Structure = contentTypeBase.AllowedContentTypes.Select(ct => ct.Alias).ToList(); }
protected abstract void OnParseInfo(TypeDeclaration type, ContentType definition);
private static void MapTabs(IContentTypeBase contentTypeBase, ContentType type) { type.Tabs = contentTypeBase.PropertyGroups.Select(pg => new Tab {Caption = pg.Name}).ToList(); }
public override IEnumerable<XElement> CreateStructureElements(ContentType contentType) { return contentType.Structure .Where(s => !String.IsNullOrEmpty(s)) .Select(s => new XElement("MediaType", s)); }