Esempio n. 1
0
 ///--------------------------------------------------------------------------------
 /// <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;
 }
Esempio n. 2
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method gets the updated content 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 GetContent(IDomainEnterpriseObject parentModelContext)
 {
     try
     {
         ContentCodeBuilder.Clear();
         if (IsWatchTemplate == false)
         {
             // clear parameters and variables if not passed in for temporary watch templates
             Parameters.Clear();
             Variables.Clear();
         }
         if (ContentAST == null && TemplateContent != String.Empty)
         {
             ParseContent(Solution.IsSampleMode);
         }
         if (ContentAST != null && ContentAST.ChildNodes.Count > 0)
         {
             ContentAST.InterpretNode(InterpreterTypeCode.Content, Solution, this, GetTemplateModelContext(parentModelContext), null);
         }
         ContentCode = ContentCodeBuilder.ToString() + MessageBuilder.ToString();
         return(ContentCode);
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (System.Exception ex)
     {
         HasErrors = true;
         Solution.ShowIssue(ex.Message + ex.StackTrace, DisplayValues.Exception_CodeGenerationTitle, Solution.IsSampleMode);
     }
     return(null);
 }
Esempio n. 3
0
        ///--------------------------------------------------------------------------------
        /// <summary>Interpret this node to produce content.</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 GenerateContent(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);
            MessageBuilder.Clear();
            ContentCodeBuilder.Clear();
            Parameters.Clear();
            Variables.Clear();
            CurrentTabIndent = templateContext.CurrentTabIndent;
            if (ContentAST == null && TemplateContent != String.Empty)
            {
                ParseContent(Solution.IsSampleMode);
            }
            if (Solution.UseTemplateCache == true && Solution.IsSampleMode == false && String.IsNullOrEmpty(TemplateOutput) && !String.IsNullOrEmpty(TemplateContent) && modelContext != null && CachedContent[modelContext.ID.ToString()] != null)
            {
                // use cached content
                solutionContext.TemplatesExecuted++;
                solutionContext.CachedTemplatesExecuted++;
                ContentCodeBuilder.Append(CachedContent[modelContext.ID.ToString()] as String);
            }
            else
            {
                if (ContentAST != null)
                {
                    ContentAST.InterpretNode(InterpreterTypeCode.Content, solutionContext, this, modelContext, parameters);
                }
                else
                {
                    ContentCodeBuilder.Append("<" + TemplateName + ">");
                }
            }
            if (Solution.UseTemplateCache == true && Solution.IsSampleMode == false && String.IsNullOrEmpty(TemplateOutput))
            {
                CachedContent[modelContext.ID.ToString()] = null;

                // only cache smaller content that has no parameters or config settings
                if (Parameters.Count == 0 && HasRelativeSettings == false && ContentCodeBuilder.Length <= Solution.TemplateCacheMaxContentSize)
                {
                    CachedContent[modelContext.ID.ToString()] = ContentCodeBuilder.ToString();
                }
            }
            if (appendToTemplateContext == true)
            {
                templateContext.ContentCodeBuilder.Append(ContentCodeBuilder.ToString());
            }
            ModelContextStack = null;
            PopCount          = 0;
        }
Esempio n. 4
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method gets the updated content for the template.  By not
 /// supplying a model context, the generated code is generally suitable as a
 /// sample only.</summary>
 ///
 /// <returns>A string representing the generated code for the template.</returns>
 ///--------------------------------------------------------------------------------
 public string GetContent()
 {
     try
     {
         return(GetContent(BusinessConfiguration.CurrentSpecificationSource));
     }
     catch (ApplicationAbortException)
     {
         // abort with whatever content is available
         ContentCode = ContentCodeBuilder.ToString() + MessageBuilder.ToString();
         return(ContentCode);
     }
 }
 ///--------------------------------------------------------------------------------
 /// <summary>This method gets the updated content for the template.  By not
 /// supplying a model context, the generated code is generally suitable as a
 /// sample only.</summary>
 ///
 /// <returns>A string representing the generated code for the template.</returns>
 ///--------------------------------------------------------------------------------
 public string GetContent()
 {
     try
     {
         return(GetContent(Solution));
     }
     catch (ApplicationAbortException)
     {
         // abort with whatever content is available
         ContentCode = ContentCodeBuilder.ToString() + MessageBuilder.ToString();
         return(ContentCode);
     }
 }
Esempio n. 6
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method generates the associated output path for the code 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 GenerateContentAndOutput(IDomainEnterpriseObject parentModelContext)
 {
     try
     {
         MessageBuilder.Clear();
         ContentCodeBuilder.Clear();
         Parameters.Clear();
         Variables.Clear();
         if (ContentAST == null && TemplateContent != String.Empty)
         {
             ParseContent(Solution.IsSampleMode);
         }
         OutputCodeBuilder.Clear();
         Parameters.Clear();
         Variables.Clear();
         if (OutputAST == null && TemplateOutput != String.Empty)
         {
             ParseOutput(Solution.IsSampleMode);
         }
         IDomainEnterpriseObject context = GetTemplateModelContext(parentModelContext);
         if (ContentAST != null && ContentAST.ChildNodes.Count > 0)
         {
             ContentAST.InterpretNode(InterpreterTypeCode.Content, Solution, this, context, null);
         }
         if (OutputAST != null && OutputAST.ChildNodes.Count > 0)
         {
             OutputAST.InterpretNode(InterpreterTypeCode.Output, Solution, this, context, null);
         }
         ContentCode = ContentCodeBuilder.ToString();
         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);
 }