private void WriteDocuments(
			ContentTypeConfiguration contentTypeConfiguration,
			IEnumerable<XDocument> documents, 
			string path, 
			string baseClass
			)
		{
			var contentTypeName = contentTypeConfiguration.ContentTypeName;
			var docsAtLevel = documents.Where(doc => doc.Element(contentTypeName).Element("Info").Element("Master").Value == baseClass);
			foreach (var doc in docsAtLevel)
			{
				var alias = doc.Element(contentTypeName).Element("Info").Element("Alias").Value;
				var directoryPath = Path.Combine(path, alias);
				if (!Directory.Exists(directoryPath))
					Directory.CreateDirectory(directoryPath);
				var defPath = Path.Combine(directoryPath, "def.config");

				if (configuration.OverwriteReadOnly && File.Exists(defPath))
					File.SetAttributes(defPath, File.GetAttributes(defPath) & ~FileAttributes.ReadOnly);

				doc.Save(defPath);

				WriteDocuments(contentTypeConfiguration, documents, directoryPath, alias);
			}
		}
예제 #2
0
 public PropertyInfoGenerator(
     ContentTypeConfiguration config,
     IList <DataTypeDefinition> dataTypes
     ) : base(config)
 {
     this.dataTypes = dataTypes;
 }
예제 #3
0
 private static CodeGeneratorBase CreateGenerators(
     ContentTypeConfiguration configuration,
     IEnumerable <DataTypeDefinition> dataTypes
     )
 {
     return(new NamespaceGenerator(
                configuration,
                new ImportsGenerator(configuration),
                new ClassGenerator(configuration,
                                   new CompositeCodeGenerator(
                                       configuration,
                                       new EntityNameGenerator(configuration)
                                       ),
                                   new CtorGenerator(configuration),
                                   new PropertiesGenerator(
                                       configuration,
                                       new PublicPropertyDeclarationGenerator(
                                           configuration,
                                           dataTypes.ToList(),
                                           new EntityNameGenerator(configuration),
                                           new PropertyBodyGenerator(configuration)
                                           )
                                       )
                                   )
                ));
 }
예제 #4
0
 public CompositeCodeGenerator(
     ContentTypeConfiguration config,
     params CodeGeneratorBase[] generators
     ) : base(config)
 {
     this.generators = generators;
 }
예제 #5
0
        private void WriteDocuments(
            ContentTypeConfiguration contentTypeConfiguration,
            IEnumerable <XDocument> documents,
            string path,
            string baseClass
            )
        {
            var contentTypeName = contentTypeConfiguration.ContentTypeName;
            var docsAtLevel     = documents.Where(doc => doc.Element(contentTypeName).Element("Info").Element("Master").Value == baseClass);

            foreach (var doc in docsAtLevel)
            {
                var alias         = doc.Element(contentTypeName).Element("Info").Element("Alias").Value;
                var directoryPath = Path.Combine(path, alias);
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                var defPath = Path.Combine(directoryPath, "def.config");

                if (configuration.OverwriteReadOnly && File.Exists(defPath))
                {
                    File.SetAttributes(defPath, File.GetAttributes(defPath) & ~FileAttributes.ReadOnly);
                }

                doc.Save(defPath);

                WriteDocuments(contentTypeConfiguration, documents, directoryPath, alias);
            }
        }
 public PropertyInfoGenerator(
     ContentTypeConfiguration config,
     IList <DataTypeDefinition> dataTypes,
     params CodeGeneratorBase[] memberGenerators
     ) : base(config, dataTypes, memberGenerators)
 {
 }
 public NamespaceGenerator(
     ContentTypeConfiguration config,
     params CodeGeneratorBase[] memberGenerators
     ) : base(config)
 {
     this.memberGenerators = memberGenerators;
 }
 public ClassGenerator(
     ContentTypeConfiguration config,
     params CodeGeneratorBase[] memberGenerators
     )
     : base(config, memberGenerators)
 {
 }
예제 #9
0
 public PropertiesParser(
     ContentTypeConfiguration configuration,
     ContentTypeCodeParserBase propertyParser
     ) : base(configuration)
 {
     this.propertyParser = propertyParser;
 }
예제 #10
0
 public CodeGeneratorBase CreateMediaTypeGenerator(ContentTypeConfiguration configuration, IEnumerable <DataTypeDefinition> dataTypes)
 {
     return(CreateGenerators(
                configuration,
                dataTypes
                ));
 }
예제 #11
0
 public PropertiesGenerator(
     ContentTypeConfiguration config,
     params CodeGeneratorBase[] propertyGenerators
     ) : base(config)
 {
     this.propertyGenerators = propertyGenerators;
 }
예제 #12
0
 public override CodeGeneratorBase Create(ContentTypeConfiguration configuration, IEnumerable <DataTypeDefinition> dataTypes)
 {
     if (configuration.ContentTypeName == "DocumentType")
     {
         return(CreateDocTypeGenerator(configuration, dataTypes));
     }
     return(CreateMediaTypeGenerator(configuration, dataTypes));
 }
예제 #13
0
 protected ContentTypeCodeParser(
     ContentTypeConfiguration configuration,
     params ContentTypeCodeParserBase[] memberParsers
     )
     : base(configuration)
 {
     this.memberParsers = memberParsers;
 }
 public CodeGeneratorBase CreateDocTypeGenerator(ContentTypeConfiguration configuration, IEnumerable <DataTypeDefinition> dataTypes)
 {
     return(CreateGenerators(
                configuration,
                dataTypes,
                "DocumentType",
                new DocumentTypeInfoGenerator(configuration)
                ));
 }
예제 #15
0
 protected PropertyDeclarationGenerator(
     ContentTypeConfiguration config,
     IList <DataTypeDefinition> dataTypes,
     params CodeGeneratorBase[] memberGenerators
     ) : base(config)
 {
     this.DataTypes        = dataTypes;
     this.MemberGenerators = memberGenerators;
 }
 public AttributeCodeGenerator(
     string attributeName,
     ContentTypeConfiguration config,
     params CodeGeneratorBase[] memberGenerators
     ) : base(config)
 {
     this.attributeName    = attributeName;
     this.memberGenerators = memberGenerators;
 }
예제 #17
0
 public CodeGenerator(
     ContentTypeConfiguration contentTypeConfiguration,
     IDataTypeProvider dataTypeProvider,
     CodeGeneratorFactory factory)
 {
     this.contentTypeConfiguration = contentTypeConfiguration;
     this.dataTypeProvider         = dataTypeProvider;
     this.factory = factory;
 }
예제 #18
0
 public CodeGenerator(
     ContentTypeConfiguration contentTypeConfiguration, 
     IDataTypeProvider dataTypeProvider, 
     CodeGeneratorFactory factory)
 {
     this.contentTypeConfiguration = contentTypeConfiguration;
     this.dataTypeProvider = dataTypeProvider;
     this.factory = factory;
 }
        public void Create_DelegatesConfiguration()
        {
            var factory             = new DefaultParserFactory();
            var configuration       = new ContentTypeConfiguration(CodeGeneratorConfiguration.Create(), "DocumentType");
            var dataTypeDefinitions = new List <DataTypeDefinition>();
            var parser = factory.Create(configuration, dataTypeDefinitions);

            Assert.IsInstanceOf <DocumentTypeCodeParser>(parser);
        }
 public DocumentTypeCodeParser(
     ContentTypeConfiguration configuration,
     params ContentTypeCodeParserBase[] memberParsers
     ) : base(
         configuration,
         memberParsers
         )
 {
 }
예제 #21
0
        private string EnsureModelPath(ContentTypeConfiguration typeConfig)
        {
            var modelPath = paths[typeConfig.ContentTypeName];

            if (!Directory.Exists(modelPath))
            {
                Directory.CreateDirectory(modelPath);
            }
            return(modelPath);
        }
예제 #22
0
        protected static string FindMaster(TypeDeclaration type, ContentTypeConfiguration configuration)
        {
            var baseType = type.BaseTypes.FirstOrDefault() as SimpleType;

            if (baseType == null || baseType.Identifier == configuration.BaseClass)
            {
                return(null);
            }
            return(baseType.Identifier);
        }
예제 #23
0
 public CodeParser(
     ContentTypeConfiguration configuration,
     IEnumerable <DataTypeDefinition> dataTypes,
     ParserFactory parserFactory
     )
 {
     this.configuration = configuration;
     this.dataTypes     = dataTypes;
     this.parserFactory = parserFactory;
 }
예제 #24
0
		public CodeParser(
            ContentTypeConfiguration configuration, 
            IEnumerable<DataTypeDefinition> dataTypes,
            ParserFactory parserFactory
        )
		{
			this.configuration = configuration;
			this.dataTypes = dataTypes;
		    this.parserFactory = parserFactory;
		}
예제 #25
0
        public ContentTypeCodeParser Create(
            ContentTypeConfiguration configuration,
            IEnumerable <DataTypeDefinition> dataTypes
            )
        {
            Configuration = configuration;
            DataTypes     = dataTypes as List <DataTypeDefinition> ?? dataTypes.ToList();
            var typedParser = configuration.ContentTypeName == "DocumentType"
                                  ? CreateDocumentTypeParser()
                                  : CreateMediaTypeParser();

            return(typedParser);
        }
 private CodeGeneratorBase CreateGenerators(ContentTypeConfiguration c, CodeGeneratorBase infoGenerator, IEnumerable <DataTypeDefinition> dataTypes)
 {
     return(new NamespaceGenerator(c,
                                   new ImportsGenerator(c),
                                   new ClassGenerator(c,
                                                      new EntityDescriptionGenerator(c),
                                                      new CtorGenerator(c),
                                                      infoGenerator,
                                                      new StructureGenerator(c),
                                                      new PropertiesGenerator(c,
                                                                              new PropertyInfoGenerator(c, dataTypes.ToList(), new EntityDescriptionGenerator(c)),
                                                                              new PropertyBodyGenerator(c)
                                                                              )
                                                      )
                                   ));
 }
예제 #27
0
		private void GenerateXml(ContentTypeConfiguration contentTypeConfiguration)
		{
			var xmlGenerator = new DocumentTypeXmlGenerator(contentTypeConfiguration, dataTypes);
			var modelPath = HttpContext.Current.Server.MapPath(contentTypeConfiguration.ModelPath);
			if (!Directory.Exists(modelPath))
				Directory.CreateDirectory(modelPath);
			var files = Directory.GetFiles(modelPath, "*.cs");
			var documents = new List<XDocument>();
			foreach(var file in files)
			{
				using (var reader = File.OpenText(file))
				{
					documents.AddRange(xmlGenerator.Generate(reader));
				}
			}

			var documentTypeRoot = Path.Combine(uSyncConfiguration.USyncFolder, contentTypeConfiguration.ContentTypeName);
			if (!Directory.Exists(documentTypeRoot))
				Directory.CreateDirectory(documentTypeRoot);
			WriteDocuments(contentTypeConfiguration, documents, documentTypeRoot, "");
		}
 private static CodeGeneratorBase CreateGenerators(
     ContentTypeConfiguration configuration,
     IEnumerable <DataTypeDefinition> dataTypes,
     string attributeName,
     CodeGeneratorBase infoGenerator)
 {
     return(new NamespaceGenerator(
                configuration,
                new ImportsGenerator(configuration),
                new ClassGenerator(configuration,
                                   new CompositeCodeGenerator(
                                       configuration,
                                       new EntityNameGenerator(configuration),
                                       new AttributeCodeGenerator(
                                           attributeName,
                                           configuration,
                                           infoGenerator,
                                           new StructureGenerator(configuration)
                                           )
                                       ),
                                   new BaseSupportedAnnotated.CtorGenerator(configuration),
                                   new PropertiesGenerator(
                                       configuration,
                                       new PublicPropertyDeclarationGenerator(
                                           configuration,
                                           dataTypes.ToList(),
                                           new EntityNameGenerator(configuration),
                                           new AttributeCodeGenerator(
                                               "GenericProperty",
                                               configuration,
                                               new PropertyInfoGenerator(configuration, dataTypes.ToList())
                                               ),
                                           new BaseSupportedAnnotated.PropertyBodyGenerator(configuration)
                                           )
                                       )
                                   )
                ));
 }
예제 #29
0
        private void GenerateXml(ContentTypeConfiguration contentTypeConfiguration)
        {
            var parser    = new CodeParser(contentTypeConfiguration, dataTypes, parserFactory);
            var modelPath = HttpContext.Current.Server.MapPath(contentTypeConfiguration.ModelPath);

            if (!Directory.Exists(modelPath))
            {
                Directory.CreateDirectory(modelPath);
            }
            var files     = Directory.GetFiles(modelPath, "*.cs");
            var documents = new List <XDocument>();

            foreach (var file in files)
            {
                itemStart = DateTime.Now;
                LogHelper.Debug <CodeGenerator>(() => String.Format("Parsing file {0}", file));
                using (var reader = File.OpenText(file))
                {
                    var contentType = parser.Parse(reader).FirstOrDefault();
                    if (contentType != null)
                    {
                        documents.Add(XDocument.Parse(serializer.Serialize(contentType)));
                    }
                }
                LogHelper.Debug <CodeGenerator>(() => String.Format("Parsing file {0} done. Took {1:MM\\:ss}", file, DateTime.Now - itemStart));
            }

            var documentTypeRoot = Path.Combine(uSyncConfiguration.USyncFolder, contentTypeConfiguration.ContentTypeName);

            if (!Directory.Exists(documentTypeRoot))
            {
                Directory.CreateDirectory(documentTypeRoot);
            }
            itemStart = DateTime.Now;
            LogHelper.Info <CodeGenerator>(() => "Writing uSync definitions");
            WriteDocuments(contentTypeConfiguration, documents, documentTypeRoot, "");
            LogHelper.Info <CodeGenerator>(() => String.Format("Writing uSync definitions done. Took {0:MM\\:ss}", DateTime.Now - itemStart));
        }
		private static void TestBuildCode(string fileName, string contentTypeName)
		{
			var xml = "";
			var expectedOutput = "";
			using (var inputReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".xml"))
			{
				xml = inputReader.ReadToEnd();
			}
            using (var goldReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".cs"))
			{
				expectedOutput = goldReader.ReadToEnd();
			}

			var configuration = new CodeGeneratorConfiguration
			{
				TypeMappings = new Dictionary<string, string>
				{
					{"1413afcb-d19a-4173-8e9a-68288d2a73b8", "Int32"}
				},
				DefaultTypeMapping = "String",
			};
			var typeConfig = new ContentTypeConfiguration(configuration)
			{
				ContentTypeName = contentTypeName,
				BaseClass = "DocumentTypeBase",
				Namespace = "Umbraco.CodeGen.Models"
			};

			var sb = new StringBuilder();
			var writer = new StringWriter(sb);
			var generator = new ContentTypeCodeGenerator(typeConfig, XDocument.Parse(xml), new CSharpCodeProvider());
			generator.BuildCode(writer);
			writer.Flush();
			Console.WriteLine(sb.ToString());

			Assert.AreEqual(expectedOutput, sb.ToString());
		}
예제 #31
0
 public ImportsGenerator(ContentTypeConfiguration config)
     : base(config)
 {
 }
 public EntityDescriptionGenerator(ContentTypeConfiguration config) : base(config)
 {
 }
 public StructureGenerator(ContentTypeConfiguration config) : base(config)
 {
 }
예제 #34
0
 public EntityNameGenerator(ContentTypeConfiguration config) : base(config)
 {
 }
 public PropertyBodyGenerator(ContentTypeConfiguration config) : base(config)
 {
 }