Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="templateFullPath"></param>
        /// <param name="solutionRootFolder"></param>
        /// <param name="tables"></param>
        /// <returns> Error message or generated file name</returns>
        public string GenerateIt(String tableName, string templateFullPath, string solutionRootFolder, List <Table> tables)
        {
            string templateString = ReadTemplate(templateFullPath);

            if (templateString.Contains("::"))
            {
                return(templateString);//Error!
            }
            Table table = (from Table t in tables
                           where t.Name == tableName
                           select t).First();
            string tempOutput;

            try
            {
                tempOutput = GetExecuted(templateString, table);
            }
            catch (Exception ex)
            {
                return("::Error ! " + ex.Message.Replace(@"\r\n", System.Environment.NewLine));
            }
            string          templatename    = Path.GetFileNameWithoutExtension(templateFullPath);
            TemplateOutputs templateOutputs = ReadOutputFile(tempOutput, templatename);
            string          outputFile      = templateOutputs.GetFinalFileNameForceFully(solutionRootFolder);

            File.WriteAllText(outputFile, templateOutputs.FinalOutputString);

            return(outputFile);
        }
Exemple #2
0
        private TemplateOutputs ReadOutputFile(string outptString, string templateName)
        {
            TemplateOutputs templateOutputs = new TemplateOutputs();

            templateOutputs.FileNameFromTemplate = templateName;
            using (StringReader reader = new StringReader(outptString))
            {
                string line = string.Empty;
                do
                {
                    line = reader.ReadLine();
                    if (line != null)
                    {
                        if (line.Trim().StartsWith("##filename"))
                        {
                            templateOutputs.FileNameFromTemplate = line.Trim().Replace("##filename", "").Replace("##", "").Replace("=", "").Trim();
                        }
                        else
                        {
                            templateOutputs.FinalOutputString = templateOutputs.FinalOutputString + line + System.Environment.NewLine;
                        }
                    }
                } while (line != null);
            }
            return(templateOutputs);
        }