/// <summary> /// Process the input template /// </summary> /// <param name="templateFileName"></param> /// <param name="outputFileName"></param> /// <returns></returns> public CompilerErrorCollection ProcessTemplate(string templateFileName, out string data) { if (!File.Exists(templateFileName)) { throw new FileNotFoundException("The file cannot be found"); } DynamicTemplateHost host = this; Engine engine = new Engine(); host.TemplateFile = templateFileName; //Read the text template. string input = File.ReadAllText(templateFileName); //Transform the text template. if (EnablePreProcess) { input = Preprocess(input); } string output = engine.ProcessTemplate(input, host); data = output; return(host.Errors); }
/// <summary> /// Render the model and returns the results /// </summary> /// <param name="modelPath"></param> /// <param name="modelType"></param> /// <param name="ttPath"></param> public string RenderModel(string modelPath, string modelType, string ttPath, bool preProcess) { if (!string.IsNullOrEmpty(_basePath)) { modelPath = modelPath.Replace("~", _basePath); ttPath = ttPath.Replace("~", _basePath); } if (!File.Exists(modelPath) || !File.Exists(ttPath)) { throw new Exception("Model file ('" + modelPath + "') or Template file ('" + ttPath + "') doesn't exist."); } string templateData = Properties.Resources.Header + File.ReadAllText(ttPath) + Properties.Resources.Footer.Replace("~~", Path.GetFullPath(modelPath)); File.WriteAllText(ttPath + ".tmp", templateData); DynamicTemplateHost thost = new DynamicTemplateHost(); string data = string.Empty; _errors.Clear(); var results = thost.ProcessTemplate(ttPath + ".tmp", out data); foreach (var res in results) { _errors.Add(res as CompilerError); } try { File.Delete(ttPath + ".tmp"); } catch { } return(data); }
/// <summary> /// Process the input template /// </summary> /// <param name="templateFileName"></param> /// <param name="outputFileName"></param> /// <returns></returns> public CompilerErrorCollection ProcessTemplate(string templateFileName, string outputFileName) { if (!File.Exists(templateFileName)) { throw new FileNotFoundException("The file cannot be found"); } DynamicTemplateHost host = this; Engine engine = new Engine(); host.TemplateFile = templateFileName; //Read the text template. string input = File.ReadAllText(templateFileName); //Transform the text template. string output = engine.ProcessTemplate(Preprocess(input), host); File.WriteAllText(outputFileName, output, host.FileEncoding); return(host.Errors); }
/// <summary> /// Render the model and returns the results /// </summary> /// <param name="modelPath"></param> /// <param name="modelType"></param> /// <param name="ttPath"></param> public string RenderModel(string modelPath,string modelType, string ttPath,bool preProcess) { if (!string.IsNullOrEmpty(_basePath)) { modelPath = modelPath.Replace("~", _basePath); ttPath = ttPath.Replace("~", _basePath); } if (!File.Exists(modelPath) || !File.Exists(ttPath)) { throw new Exception("Model file ('" + modelPath + "') or Template file ('" + ttPath + "') doesn't exist."); } string templateData = Properties.Resources.Header + File.ReadAllText(ttPath) + Properties.Resources.Footer.Replace("~~", Path.GetFullPath(modelPath)); File.WriteAllText(ttPath + ".tmp", templateData); DynamicTemplateHost thost = new DynamicTemplateHost(); string data = string.Empty; _errors.Clear(); var results = thost.ProcessTemplate(ttPath + ".tmp", out data); foreach (var res in results) _errors.Add(res as CompilerError); try { File.Delete(ttPath + ".tmp"); } catch { } return data; }