Exemplo n.º 1
0
 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));
        }
Exemplo n.º 3
0
        private static ContentType MapContentTypeBase(IContentTypeBase contentTypeBase)
        {
            var type = new ContentType();

            MapContentTypeBase(contentTypeBase, type);
            return(type);
        }
Exemplo n.º 4
0
 private static void MapContentTypeBase(IContentTypeBase contentTypeBase, ContentType type)
 {
     MapInfo(contentTypeBase, type.Info);
     MapStructure(contentTypeBase, type);
     MapGenericProperties(contentTypeBase, type);
     MapTabs(contentTypeBase, type);
 }
Exemplo n.º 5
0
 protected bool Equals(ContentType other)
 {
     return Equals(Info, other.Info) && 
            GenericProperties.NullableSequenceEqual(other.GenericProperties) && 
            Tabs.NullableSequenceEqual(other.Tabs) && 
            Structure.NullableSequenceEqual(other.Structure);
 }
Exemplo n.º 6
0
 private static void MapComposition(IContentType umbracoContentType, ContentType type)
 {
     type.Composition = umbracoContentType.ContentTypeComposition
         .Where(cmp => cmp.Id != umbracoContentType.ParentId)
         .Select(MapContentTypeBase)
         .ToList();
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 private static void MapComposition(IContentType umbracoContentType, ContentType type)
 {
     type.Composition = umbracoContentType.ContentTypeComposition
                        .Where(cmp => cmp.Id != umbracoContentType.ParentId)
                        .Select(MapContentTypeBase)
                        .ToList();
 }
Exemplo n.º 9
0
        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())));
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
        public override void Parse(AstNode node, ContentType contentType)
        {
            var type = (TypeDeclaration) node;

            contentType.Structure = TypeArrayValue(type, "Structure")
                .Select(val => val.CamelCase())
                .ToList();
        }
Exemplo n.º 12
0
        public void Generate(ContentType contentType, TextWriter writer)
        {
            EnsureGenerator();

            var compileUnit = new CodeCompileUnit();
            generator.Generate(compileUnit, contentType);
            CodeProvider.GenerateCodeFromCompileUnit(compileUnit, writer, options);
            writer.Flush();
        }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
0
 // 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;
 }
Exemplo n.º 18
0
 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
                    })
         );
 }
Exemplo n.º 19
0
 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();
 }
Exemplo n.º 20
0
 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();
 }
Exemplo n.º 22
0
 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);
 }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
 private void GenerateInterface(ContentType contentType)
 {
     GenerateModel(contentType, interfaceGeneratorFactory, c => "I" + c.Alias.PascalCase());
 }
 public abstract void Parse(AstNode node, ContentType contentType);
Exemplo n.º 27
0
        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));
        }
Exemplo n.º 28
0
 private void GenerateClass(ContentType contentType)
 {
     GenerateModel(contentType, generatorFactory, c => c.Alias.PascalCase());
 }
Exemplo n.º 29
0
 private static void MapTabs(IContentTypeBase contentTypeBase, ContentType type)
 {
     type.Tabs = contentTypeBase.PropertyGroups.Select(pg => new Tab {
         Caption = pg.Name
     }).ToList();
 }
Exemplo n.º 30
0
 private void GenerateInterface(ContentType contentType)
 {
     GenerateModel(contentType, interfaceGeneratorFactory, c => "I" + c.Alias.PascalCase());
 }
Exemplo n.º 31
0
 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;
 }
Exemplo n.º 33
0
 public override void Parse(AstNode node, ContentType definition)
 {
     var type = (TypeDeclaration) node;
     OnParseInfo(type, definition);
 }
Exemplo n.º 34
0
 private static void MapStructure(IContentTypeBase contentTypeBase, ContentType type)
 {
     type.Structure = contentTypeBase.AllowedContentTypes.Select(ct => ct.Alias).ToList();
 }
Exemplo n.º 35
0
 protected abstract void OnParseInfo(TypeDeclaration type, ContentType definition);
Exemplo n.º 36
0
 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));
 }
Exemplo n.º 38
0
 private void GenerateClass(ContentType contentType)
 {
     GenerateModel(contentType, generatorFactory, c => c.Alias.PascalCase());
 }
Exemplo n.º 39
0
 private static void MapStructure(IContentTypeBase contentTypeBase, ContentType type)
 {
     type.Structure = contentTypeBase.AllowedContentTypes.Select(ct => ct.Alias).ToList();
 }