static void ProcessTemplate(string[] args) { string templateFileName = null; if (args.Length == 0) { throw new System.Exception("you must provide a text template file path"); } templateFileName = args[0]; if (templateFileName == null) { throw new ArgumentNullException("the file name cannot be null"); } if (!File.Exists(templateFileName)) { throw new FileNotFoundException("the file cannot be found"); } Templating host = new Templating(); Engine engine = new Engine(); host.TemplateFileValue = templateFileName; //Read the text template. string input = File.ReadAllText(templateFileName); //Transform the text template. string output = engine.ProcessTemplate(input, host); string outputFileName = Path.GetFileNameWithoutExtension(templateFileName); outputFileName = Path.Combine(Path.GetDirectoryName(templateFileName), outputFileName); outputFileName = outputFileName + "1" + host.FileExtension; File.WriteAllText(outputFileName, output, host.FileEncoding); foreach (CompilerError error in host.Errors) { Console.WriteLine(error.ToString()); } }
public void CreateTemplate() { TempContent = File.ReadAllText(TemplateFilePath); Parameter param; if (CodeItem != null) { param = new Parameter() { CodeItem = CodeItem }; } else { param = new Parameter() { TableName = TableName, Table = DataTable, NameSpace = NameSpace }; } //Templating host = new Templating(); //host.Session = host.CreateSession(); //host.Session.Add("Param", param); //Engine engine = new Engine(); //OutContent = engine.ProcessTemplate(TempContent, host); Templating host = new Templating(); Engine engine = new Engine(); host.TemplateFileValue = TemplateFilePath; string output = engine.ProcessTemplate(TempContent, host); StringBuilder sbLog = new StringBuilder(); bool error = false; foreach (var e in host.Errors) { sbLog.AppendLine(e.ToString()); error = true; } if (error) { OutContent = sbLog.ToString(); } //StringBuilder sbLog = new StringBuilder(); //bool error = false; //foreach (var item in host.Errors) //{ // sbLog.AppendLine(item.ToString()); // error = true; //}; //if (error) //{ // OutContent = sbLog.ToString(); //} }