Zetbox.Generator.ResourceBasedGenerationHost.CallTemplateToFile C# (CSharp) Method

CallTemplateToFile() public method

public CallTemplateToFile ( string templateClass, string outputfile ) : void
templateClass string
outputfile string
return void
        public void CallTemplateToFile(string templateClass, string outputfile, params object[] parameters)
        {
            try
            {
                // Push new writer as contexts writer:
                this.contextWriter.Push(new StringWriter());

                this.CallTemplateToContext(templateClass, parameters);
            }
            finally
            {
                // Restore previous writer context:
                TextWriter writer = this.contextWriter.Pop();

                // Write the file:
                if (outputfile != null)
                    this.WriteFile(Path.Combine(this.outputDirectory, outputfile), writer.ToString());
            }
        }

Usage Example

Beispiel #1
0
        public virtual int ExecuteTemplate(ResourceBasedGenerationHost genHost, string templateFilename, string outputFilename, object[] templateParameters)
        {
            if (genHost == null)
            {
                throw new ArgumentNullException("genHost");
            }

            using (log4net.NDC.Push(templateFilename))
            {
                try
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.DebugFormat("Executing template");
                    }
                    genHost.Initialize(this.Settings);
                    genHost.CallTemplateToFile(templateFilename, outputFilename, templateParameters);
                    return(0);
                }
                catch (CompilationFailedException ex)
                {
                    Log.Error("Template compilation failed", ex);
                    foreach (CompilerError err in ex.Errors)
                    {
                        Log.WarnFormat("{0} {1}: {2}\r\n  \"{3}\", line #{4}",
                                       err.IsWarning ? "Warning" : "Error",
                                       err.ErrorNumber,
                                       err.ErrorText,
                                       err.FileName,
                                       err.Line);
                    }
                    throw;
                }
            }
        }
All Usage Examples Of Zetbox.Generator.ResourceBasedGenerationHost::CallTemplateToFile