AmazedSaint.Elastic.Templating.DynamicTemplateHost.ProcessTemplate C# (CSharp) Method

ProcessTemplate() public method

Process the input template
public ProcessTemplate ( string templateFileName, string outputFileName ) : CompilerErrorCollection
templateFileName string
outputFileName string
return System.CodeDom.Compiler.CompilerErrorCollection
        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;
        }

Usage Example

Ejemplo n.º 1
0
        /// <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);
        }
All Usage Examples Of AmazedSaint.Elastic.Templating.DynamicTemplateHost::ProcessTemplate