/// <summary> /// Inspect the template to process and construct the input and output file /// names from it. Together with the info from the datatype to process. /// </summary> private void ConstructInputOutputFilenames() { string templatefilename = GetXmlValue(m_templateDefinition.SelectSingleNode("templatefilename"), ""); if (templatefilename == "") { throw new ApplicationException("templatefilename is mandatory in template definitions file"); } string directory_expression = ""; // We maken een LineProcessor voor het interpreteren van de tekst van de directory en filenaam. LineProcessor lp = new LineProcessor(m_current, new Hashtable(), new Hashtable(), new StringCollection(), new StringCollection(), m_log, m_KeepInfo, m_FunctionInfo, GetCurrentTemplatename(), null); lp.AddObserver(this); try { directory_expression = m_templateDefinition.SelectSingleNode("directory").InnerText; if (directory_expression.Contains("@")) { m_outputfilename = lp.ProcessLine(directory_expression); } else { m_outputfilename = directory_expression; } } catch (Exception ex) { throw new ApplicationException("Directory expression '" + directory_expression + "' results in error: " + ex.Message); } if (m_outputfilename == "") { throw new ApplicationException("Directory expression '" + directory_expression + "' results in empty directoryname for template: " + m_templateDefinition.SelectSingleNode("name").InnerText); } if (!m_outputfilename.EndsWith(@"\")) { m_outputfilename += @"\"; } string filename_expression = m_templateDefinition.SelectSingleNode("filename").InnerText; string filename = ""; try { filename = lp.ProcessLine(filename_expression); } catch (Exception ex) { throw new ApplicationException("Filename expression '" + filename_expression + "' results in error: " + ex.Message); } if (filename == "") { throw new ApplicationException("Filename expression '" + filename_expression + "' results in empty filename for template: " + m_templateDefinition.SelectSingleNode("name").InnerText); } m_outputfilename += filename; m_inputfilename = TemplateCache.Instance().SolutionLocation + @"\TemplateFile\" + m_templateDefinition.SelectSingleNode("templatefilename").InnerText; }
public void Generate() { m_VariableInfo = new Hashtable(); m_Stack = new Stack(); m_errors = 0; try { //m_evaluator = new ExpressionEvaluator(this); m_log = new Log("startup " + DateTime.Now.ToString("MM-dd hhmmss ") + Math.Round((new Random().NextDouble() * 9000) + 1000, 0).ToString() + ".log"); ConstructInputOutputFilenames(); MakeSureDirectoryExistsFor(m_outputfilename); m_log = new Log(Path.GetFileName(m_outputfilename) + ".log"); // Check to see if only a filecopy has to be done. XmlNode copyonly = m_templateDefinition.SelectSingleNode("copyonly"); if (copyonly != null && copyonly.InnerText == "1") { // Ok copy only. No template interpretation. File.Copy(m_inputfilename, m_outputfilename, true); return; } // Check to see if generate-once is set, and output already available. XmlNode generateonce = m_templateDefinition.SelectSingleNode("generateonce"); if (generateonce != null && generateonce.InnerText == "1") { if (File.Exists(m_outputfilename)) { return; } } InitializeKeepInfo(); m_source = LoadTemplateSource(); m_target = new StringCollection(); m_log.Write(0, InterpretationStatus.Active, "Templatefile: " + m_inputfilename); m_log.Write(0, InterpretationStatus.Active, "Outputfile: " + m_outputfilename); LineProcessor lp = new LineProcessor(m_current, new Hashtable(), new Hashtable(), m_source, m_target, m_log, m_KeepInfo, m_FunctionInfo, GetCurrentTemplatename(), null); lp.AddObserver(this); m_errors = lp.Generate(); } catch (SyntaxErrorException ex) { WriteError(ex); //GenerateOutput.OutputToInstance(CurrentContext() + ex.Message); m_errors++; WriteOutputfile(m_target); return; } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException is SyntaxErrorException) { WriteError(ex.InnerException as SyntaxErrorException); } else { WriteError(ex.Message); } m_errors++; WriteOutputfile(m_target); return; } WriteOutputfile(m_target); if (m_log != null) { m_log.Close(); } return; }