Exemplo n.º 1
0
 ///--------------------------------------------------------------------------------
 /// <summary>Interpret this node to produce code, output, or model data..</summary>
 ///
 /// <param name="interpreterType">The type of interpretation to perform.</param>
 /// <param name="solutionContext">The associated solution.</param>
 /// <param name="templateContext">The associated template.</param>
 /// <param name="modelContext">The associated model context.</param>
 ///--------------------------------------------------------------------------------
 public void InterpretNode(InterpreterTypeCode interpreterType, Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext)
 {
     try
     {
         solutionContext.PutStringLoggedValue(Parameter1.GetStringValue(solutionContext, templateContext, modelContext, interpreterType), Parameter2.GetStringValue(solutionContext, templateContext, modelContext, interpreterType), Parameter3.GetStringValue(solutionContext, templateContext, modelContext, interpreterType));
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (System.Exception ex)
     {
         LogException(solutionContext, templateContext, modelContext, ex, interpreterType);
     }
 }
Exemplo n.º 2
0
        ///--------------------------------------------------------------------------------
        /// <summary>Get the string value for this parameter.</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="interpreterType">The type of interpretation to perform.</param>
        ///--------------------------------------------------------------------------------
        public object GetObjectValue(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext, InterpreterTypeCode interpreterType)
        {
            if (ModelProperty != null)
            {
                return(ModelProperty.GetPropertyObjectValue(solutionContext, templateContext, modelContext, modelContext, interpreterType));
            }
            else if (Literal != null)
            {
                return(Literal.GetObjectValue(solutionContext, templateContext, modelContext));
            }
            else if (Parameter1 != null && Parameter2 != null)
            {
                string parameter1Value = Parameter1.GetStringValue(solutionContext, templateContext, modelContext, interpreterType);
                string parameter2Value = Parameter2.GetStringValue(solutionContext, templateContext, modelContext, interpreterType);
                long   parameter1Long;
                long   parameter2Long;
                double parameter1Double;
                double parameter2Double;
                switch (MathOperator.Operator)
                {
                case "+":
                    if (long.TryParse(parameter1Value, out parameter1Long) == true && long.TryParse(parameter2Value, out parameter2Long) == true)
                    {
                        return(parameter1Long + parameter2Long);
                    }
                    else if (double.TryParse(parameter1Value, out parameter1Double) == true && double.TryParse(parameter2Value, out parameter2Double) == true)
                    {
                        return(parameter1Double + parameter2Double);
                    }
                    else
                    {
                        return(parameter1Value + parameter2Value);
                    }

                case "-":
                    if (long.TryParse(parameter1Value, out parameter1Long) == true && long.TryParse(parameter2Value, out parameter2Long) == true)
                    {
                        return(parameter1Long - parameter2Long);
                    }
                    else if (double.TryParse(parameter1Value, out parameter1Double) == true && double.TryParse(parameter2Value, out parameter2Double) == true)
                    {
                        return(parameter1Double - parameter2Double);
                    }
                    else
                    {
                        return(parameter1Value.Replace(parameter2Value, ""));
                    }

                case "*":
                    if (long.TryParse(parameter1Value, out parameter1Long) == true && long.TryParse(parameter2Value, out parameter2Long) == true)
                    {
                        return(parameter1Long * parameter2Long);
                    }
                    else if (double.TryParse(parameter1Value, out parameter1Double) == true && double.TryParse(parameter2Value, out parameter2Double) == true)
                    {
                        return(parameter1Double * parameter2Double);
                    }
                    break;

                case "/":
                    if (long.TryParse(parameter1Value, out parameter1Long) == true && long.TryParse(parameter2Value, out parameter2Long) == true && parameter2Long != 0)
                    {
                        return(parameter1Long / parameter2Long);
                    }
                    else if (double.TryParse(parameter1Value, out parameter1Double) == true && double.TryParse(parameter2Value, out parameter2Double) == true && parameter2Double != 0.00)
                    {
                        return(parameter1Double / parameter2Double);
                    }
                    break;

                default:
                    break;
                }
            }
            return(null);
        }
 ///--------------------------------------------------------------------------------
 /// <summary>Interpret this node to produce code, output, or model data..</summary>
 ///
 /// <param name="interpreterType">The type of interpretation to perform.</param>
 /// <param name="solutionContext">The associated solution.</param>
 /// <param name="templateContext">The associated template.</param>
 /// <param name="modelContext">The associated model context.</param>
 ///--------------------------------------------------------------------------------
 public void InterpretNode(InterpreterTypeCode interpreterType, Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext)
 {
     try
     {
         string path = Parameter1.GetStringValue(solutionContext, templateContext, modelContext, interpreterType);
         if (!String.IsNullOrEmpty(path))
         {
             if (solutionContext.IsSampleMode == true)
             {
                 // don't perform removal of output file data, just indicate it would be output
                 templateContext.MessageBuilder.Append("\r\n- ");
                 templateContext.MessageBuilder.Append(path);
                 templateContext.MessageBuilder.Append(": \"");
                 templateContext.MessageBuilder.Append(Parameter2.GetStringValue(solutionContext, templateContext, modelContext, interpreterType));
                 if (Parameter4 != null)
                 {
                     templateContext.MessageBuilder.Append("\", \"");
                     templateContext.MessageBuilder.Append(Parameter3.GetStringValue(solutionContext, templateContext, modelContext, interpreterType));
                     templateContext.MessageBuilder.Append("\", \"");
                     templateContext.MessageBuilder.Append(Parameter4.GetStringValue(solutionContext, templateContext, modelContext, interpreterType));
                 }
                 templateContext.MessageBuilder.Append("\"");
             }
             else if (solutionContext.LoggedErrors.Count == 0)
             {
                 if (File.Exists(path) == true)
                 {
                     string text = FileHelper.GetText(path);
                     if (Parameter4 != null)
                     {
                         // remove text bounded by begin and end tags
                         string beginTag     = Parameter2.GetStringValue(solutionContext, templateContext, modelContext, interpreterType);
                         string endTag       = Parameter3.GetStringValue(solutionContext, templateContext, modelContext, interpreterType);
                         string matchingText = Parameter4.GetStringValue(solutionContext, templateContext, modelContext, interpreterType);
                         int    beginIndex   = text.IndexOf(beginTag);
                         while (beginIndex >= 0)
                         {
                             int endIndex = text.IndexOf(endTag, beginIndex);
                             if (endIndex < 0)
                             {
                                 break;
                             }
                             int matchingIndex = text.IndexOf(matchingText, beginIndex);
                             if (matchingIndex >= 0 && matchingIndex < endIndex && matchingIndex + matchingText.Length <= endIndex)
                             {
                                 if (endIndex + endTag.Length >= text.Length)
                                 {
                                     text = text.Substring(0, beginIndex);
                                 }
                                 else
                                 {
                                     text = text.Substring(0, beginIndex) + text.Substring(endIndex + endTag.Length);
                                 }
                                 FileHelper.ReplaceFile(path, text);
                                 break;
                             }
                             beginIndex += beginTag.Length;
                             beginIndex  = text.IndexOf(beginTag, beginIndex);
                         }
                     }
                     else
                     {
                         // remove text matching input match text
                         string matchingText = Parameter2.GetStringValue(solutionContext, templateContext, modelContext, interpreterType);
                         int    index        = text.IndexOf(matchingText);
                         if (index >= 0)
                         {
                             if (index + matchingText.Length >= text.Length)
                             {
                                 text = text.Substring(0, index);
                             }
                             else
                             {
                                 text = text.Substring(0, index) + text.Substring(index + matchingText.Length);
                             }
                             FileHelper.ReplaceFile(path, text);
                         }
                     }
                 }
             }
         }
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (System.Exception ex)
     {
         LogException(solutionContext, templateContext, modelContext, ex, interpreterType);
     }
 }