///-------------------------------------------------------------------------------- /// <summary>This method generates the associated output path for the template.</summary> /// /// <param name="parentModelContext">The parent model context from which to generate code.</param> /// /// <returns>A string representing the generated code for the template.</returns> ///-------------------------------------------------------------------------------- public string GenerateOutput(IDomainEnterpriseObject parentModelContext) { try { MessageBuilder.Clear(); OutputCodeBuilder.Clear(); Parameters.Clear(); Variables.Clear(); if (OutputAST == null) { ParseOutput(Solution.IsSampleMode); } IDomainEnterpriseObject context = GetTemplateModelContext(parentModelContext); if (OutputAST != null && OutputAST.ChildNodes.Count > 0) { OutputAST.InterpretNode(InterpreterTypeCode.Output, Solution, this, context, null); OutputCode = OutputCodeBuilder.ToString() + MessageBuilder.ToString(); } return(OutputCode); } catch (ApplicationAbortException) { throw; } catch (System.Exception ex) { HasErrors = true; Solution.ShowIssue(ex.Message + ex.StackTrace, DisplayValues.Exception_CodeGenerationTitle, Solution.IsSampleMode); } return(null); }
///-------------------------------------------------------------------------------- /// <summary>Interpret this node to produce code, output, or model data..</summary> /// /// <param name="solutionContext">The associated solution.</param> /// <param name="templateContext">The associated template.</param> /// <param name="modelContext">The associated model context.</param> /// <param name="appendToTemplateContext">Flag to append content.</param> /// <param name="parameters">Template parameters.</param> ///-------------------------------------------------------------------------------- public void GenerateOutput(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext, bool appendToTemplateContext, NameObjectCollection parameters) { ModelContextStack = null; PopCount = 0; if (modelContext is Project) { BusinessConfiguration.CurrentProject = modelContext as Project; } PushModelContext(modelContext); OutputCodeBuilder.Clear(); CurrentTabIndent = templateContext.CurrentTabIndent; if (OutputAST == null) { ParseOutput(Solution.IsSampleMode); } if (OutputAST != null) { OutputAST.InterpretNode(InterpreterTypeCode.Output, solutionContext, this, modelContext, parameters); } else { OutputCodeBuilder.Append("<" + TemplateName + ">"); } if (appendToTemplateContext == true) { templateContext.OutputCodeBuilder.Append(ContentCodeBuilder.ToString()); } ModelContextStack = null; PopCount = 0; }
///-------------------------------------------------------------------------------- /// <summary>This method parses the template output into a parse tree.</summary> /// /// <returns>A ParseTree with the parsing results.</returns> ///-------------------------------------------------------------------------------- public bool ParseOutput(bool showDialog = true) { try { OutputAST = null; if (String.IsNullOrEmpty(TemplateOutput)) { HasErrors = true; Solution.ShowIssue(String.Format(DisplayValues.Exception_NoOutput, TemplateName), DisplayValues.Exception_ParsingTitle, showDialog); return(false); } ParseTree tree = Solution.SpecTemplateOutputParser.Parse(TemplateOutput); if (tree.ParserMessages.Count == 0 && tree.Root.AstNode is TemplateNode) { OutputAST = tree.Root.AstNode as TemplateNode; if (OutputAST.LineNumber == 0 || TemplateOutput.TrimStart().StartsWith("//") == true) { // TODO: this is a hack, investigate why parsing result line numbers are sometimes zero based and // sometimes one based. Need line numbers to be one based in line with text editors. OutputAST.ExecuteVisitor(new IncrementLineNumberVisitor()); } Solution.SpecTemplates[TemplateKey] = this; } else if (tree.ParserMessages.Count > 0) { HasErrors = true; StringBuilder messages = new StringBuilder(); messages.Append(DisplayValues.Exception_Parsing); messages.Append("\r\n"); messages.Append(DisplayValues.Exception_SolutionIntro); messages.Append(" "); messages.Append(Solution.SolutionName); messages.Append("\r\n"); messages.Append(DisplayValues.Exception_NodeIntro); messages.Append(" "); messages.Append(NodeName); messages.Append("\r\n"); messages.Append(DisplayValues.Exception_TemplateIntro); messages.Append(" "); messages.Append(TemplateName); messages.Append("\r\n"); messages.Append(DisplayValues.Exception_InnerMessageIntro); messages.Append("\r\n"); foreach (ParserMessage message in tree.ParserMessages) { messages.Append(String.Format(DisplayValues.Message_TemplateOutputParseError, (message.Location.Line + 1).ToString(), (message.Location.Column + 1).ToString(), message.Message)); } Solution.ShowIssue(messages.ToString(), DisplayValues.Exception_ParsingTitle, showDialog); return(false); } return(true); } catch (ApplicationAbortException) { throw; } catch (System.Exception ex) { HasErrors = true; Solution.ShowIssue(ex.Message + ex.StackTrace, DisplayValues.Exception_ParsingTitle, showDialog); } return(false); }