Ejemplo n.º 1
0
        public static TemplatesSettings Load()
        {
            TemplatesSettings templates = new TemplatesSettings();

            if (File.Exists(pathFile))
            {
                using (var fileStream = new FileStream(pathFile, FileMode.Open))
                {
                    templates = (TemplatesSettings) new BinaryFormatter().Deserialize(fileStream);
                }
            }

            return(templates);
        }
        /// <exception cref="FileGenerationException">
        /// An error has occured while generating the source file.
        /// </exception>
        public List<string> GenerateFiles(string directory, bool perEntity)
        {
            List<string> files = new List<string>();

            var tmpltsSettings = TemplatesSettings.Load();

            if (!Directory.Exists(directory))
                Directory.CreateDirectory(directory);

            foreach (var group in tmpltsSettings.Groups.Where(x => x.Enabled))
            {
                foreach (var tmpltSettings in group.Templates.Where(x => x.Enabled && x.PerEntity == perEntity))
                {
                    try
                    {
                        string fileName = null;

                        if (tmpltSettings.PerEntity)
                        {
                            var entityMeta = GenerateEntityMeta();
                            fileName = TemplateRender("entity", entityMeta, tmpltSettings.FileExt);
                        }
                        else
                        {
                            var modelMeta = GenerateModelMeta();                            
                            fileName = TemplateRender("model", modelMeta, tmpltSettings.FileExt);
                        }

                        fileName = Regex.Replace(fileName, @"\<(?<type>.+)\>", @"[${type}]");
                        string path = Path.Combine(directory, fileName);

                        if (WriteFileContent(tmpltSettings))
                        {
                            using (StreamWriter writer = new StreamWriter(path, false, Encoding.Unicode))
                            {
                                writer.Write(CodeBuilder.ToString());
                            }

                            files.Add(fileName);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new FileGenerationException(directory, ex);
                    }
                }
            }

            return files;
        }
Ejemplo n.º 3
0
        public static TemplatesSettings Load()
        {
            TemplatesSettings templates = new TemplatesSettings();

            var xmlSerializer = new XmlSerializer(typeof(TemplatesSettings));
            var fi            = new FileInfo(Application.StartupPath + @"\Templates\templates.xml");

            if (fi.Exists)
            {
                using (FileStream fileStream = fi.OpenRead())
                {
                    templates = (TemplatesSettings)xmlSerializer.Deserialize(fileStream);
                }
            }

            return(templates);
        }