コード例 #1
0
 private static void MapContentTypeBase(IContentTypeBase contentTypeBase, ContentType type)
 {
     MapInfo(contentTypeBase, type.Info);
     MapStructure(contentTypeBase, type);
     MapGenericProperties(contentTypeBase, type);
     MapTabs(contentTypeBase, type);
 }
コード例 #2
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));
        }
コード例 #3
0
        private static ContentType MapContentTypeBase(IContentTypeBase contentTypeBase)
        {
            var type = new ContentType();

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

            contentType.Structure = TypeArrayValue(type, "Structure")
                .Select(val => val.CamelCase())
                .ToList();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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;
 }
コード例 #15
0
        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();
        }
コード例 #16
0
        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();
        }
コード例 #17
0
 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;
 }
コード例 #18
0
ファイル: TabsParser.cs プロジェクト: scy0846/Umbraco.CodeGen
 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
                    })
         );
 }
コード例 #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();
 }
コード例 #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();
 }
コード例 #21
0
 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();
 }
コード例 #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);
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #25
0
 private void GenerateInterface(ContentType contentType)
 {
     GenerateModel(contentType, interfaceGeneratorFactory, c => "I" + c.Alias.PascalCase());
 }
コード例 #26
0
 public abstract void Parse(AstNode node, ContentType contentType);
コード例 #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));
        }
コード例 #28
0
 private void GenerateClass(ContentType contentType)
 {
     GenerateModel(contentType, generatorFactory, c => c.Alias.PascalCase());
 }
コード例 #29
0
 private static void MapTabs(IContentTypeBase contentTypeBase, ContentType type)
 {
     type.Tabs = contentTypeBase.PropertyGroups.Select(pg => new Tab {
         Caption = pg.Name
     }).ToList();
 }
コード例 #30
0
 private void GenerateInterface(ContentType contentType)
 {
     GenerateModel(contentType, interfaceGeneratorFactory, c => "I" + c.Alias.PascalCase());
 }
コード例 #31
0
 private static ContentType MapContentTypeBase(IContentTypeBase contentTypeBase)
 {
     var type = new ContentType();
     MapContentTypeBase(contentTypeBase, type);
     return type;
 }
コード例 #32
0
 protected override Info GetInfo(ContentType type)
 {
     return ((MediaType) type).Info;
 }
コード例 #33
0
 public override void Parse(AstNode node, ContentType definition)
 {
     var type = (TypeDeclaration) node;
     OnParseInfo(type, definition);
 }
コード例 #34
0
 private static void MapStructure(IContentTypeBase contentTypeBase, ContentType type)
 {
     type.Structure = contentTypeBase.AllowedContentTypes.Select(ct => ct.Alias).ToList();
 }
コード例 #35
0
 protected abstract void OnParseInfo(TypeDeclaration type, ContentType definition);
コード例 #36
0
 private static void MapTabs(IContentTypeBase contentTypeBase, ContentType type)
 {
     type.Tabs = contentTypeBase.PropertyGroups.Select(pg => new Tab {Caption = pg.Name}).ToList();
 }
コード例 #37
0
 public override IEnumerable<XElement> CreateStructureElements(ContentType contentType)
 {
     return contentType.Structure
                       .Where(s => !String.IsNullOrEmpty(s))
                       .Select(s => new XElement("MediaType", s));
 }
コード例 #38
0
 private void GenerateClass(ContentType contentType)
 {
     GenerateModel(contentType, generatorFactory, c => c.Alias.PascalCase());
 }
コード例 #39
0
 private static void MapStructure(IContentTypeBase contentTypeBase, ContentType type)
 {
     type.Structure = contentTypeBase.AllowedContentTypes.Select(ct => ct.Alias).ToList();
 }