static CompilerErrorCollection ProcessTemplate(string args, string schema, string table) { string templateFileName = null; if (args == null) { throw new Exception("you must provide a text template file path"); } templateFileName = args; if (templateFileName == null) { throw new ArgumentNullException("the file name cannot be null"); } if (!File.Exists(templateFileName)) { throw new FileNotFoundException("the file cannot be found"); } SQLViewsHost host = new SQLViewsHost(); Engine engine = new Engine(); host.TemplateFileValue = templateFileName; //Read the text template. TextTemplatingSession session = new TextTemplatingSession(); session["SchemaName"] = schema; session["TableName"] = table; session["ViewName"] = String.Format("v{0}", table); session["Username"] = "******"; var sessionHost = (ITextTemplatingSessionHost)host; sessionHost.Session = session; string input = File.ReadAllText(templateFileName); //Transform the text template. string output = engine.ProcessTemplate(input, host); string outputFileName = Path.GetFileNameWithoutExtension(String.Format("v{0}", table)); outputFileName = Path.Combine(Path.GetDirectoryName(String.Format("v{0}", table)), outputFileName); outputFileName = outputFileName + host.FileExtension; File.WriteAllText(outputFileName, output, host.FileEncoding); return(host.Errors); }
static CompilerErrorCollection ProcessTemplate(string args, string schema, string table) { string templateFileName = null; if (args == null) { throw new Exception("you must provide a text template file path"); } templateFileName = args; if (templateFileName == null) { throw new ArgumentNullException("the file name cannot be null"); } if (!File.Exists(templateFileName)) { throw new FileNotFoundException("the file cannot be found"); } SQLViewsHost host = new SQLViewsHost(); Engine engine = new Engine(); host.TemplateFileValue = templateFileName; //Read the text template. TextTemplatingSession session = new TextTemplatingSession(); session["SchemaName"] = schema; session["TableName"] = table; session["ViewName"] = String.Format("v{0}", table); session["Username"] = "******"; var sessionHost = (ITextTemplatingSessionHost)host; sessionHost.Session = session; string input = File.ReadAllText(templateFileName); //Transform the text template. string output = engine.ProcessTemplate(input, host); string outputFileName = Path.GetFileNameWithoutExtension(String.Format("v{0}", table)); outputFileName = Path.Combine(Path.GetDirectoryName(String.Format("v{0}", table)), outputFileName); outputFileName = outputFileName + host.FileExtension; File.WriteAllText(outputFileName, output, host.FileEncoding); return host.Errors; }