Пример #1
0
 /// <summary>CTor.</summary>
 public TemplateSegmentCollection(List<TemplateSegment> segments)
 {
     this.segments = segments;
     this.RootSegment = segments[0];
     this.indexedSegmentNames = new Dictionary<string, int>();
     for (int i = 0; i < this.segments.Count; i++)
         this.indexedSegmentNames[this.segments[i].Id] = i;
 }
Пример #2
0
 private void ParseAndGenerateSegment(StreamWriter output, TemplateSegment segment, ITemplateInputComponent component)
 {
     var orderedSegmentParts = segment.Parse();
     foreach (SegmentPart part in orderedSegmentParts)
     {
         if (part.IsExpression)
         {
             string expressionResult = EvalExpression(component, part.Body);
             output.Write(expressionResult);
         }
         else
         {
             output.Write(part.Body);
         }
     }
 }
Пример #3
0
        /// <summary>Generates code segment for the given input compoments if it matches specified criteria.</summary>
        private void Generate(StreamWriter output, TemplateSegment segment, ITemplateInputComponent component, params Predicate<ITemplateInputComponent>[] componentCriteria)
        {
            if (component == null)
                return;
            if (segment == null)
                throw new ArgumentNullException("segment", "Segment may not be null.");
            bool shouldGenerate = ArrayUtil.IsNullOrEmpty(componentCriteria) || MatchesCriteria(component, componentCriteria);
            if (!shouldGenerate)
                return;

            ParseAndGenerateSegment(output, segment, component);
        }
Пример #4
0
        private string ParseAndGenerateSegment(TemplateSegment segment, ITemplateInputComponent component)
        {
            StringBuilder output = new StringBuilder();
            var orderedSegmentParts = segment.Parse();
            foreach (SegmentPart part in orderedSegmentParts)
            {
                if (part.IsExpression)
                {
                    string expressionResult = EvalExpression(component, part.Body);
                    output.Append(expressionResult);
                }
                else
                {
                    output.Append(part.Body);
                }
            }

            return output.ToString();
        }
Пример #5
0
        private void ReadTemplateSegments(DataSet ds)
        {
            List<TemplateSegment> segments = new List<TemplateSegment>();
            foreach (DataRow rowSegment in ds.Tables["TemplateSegment"].Rows)
            {
                TemplateSegment segment = new TemplateSegment()
                {
                    Id = Convert.ToString(rowSegment["Id"], CultureInfo.InvariantCulture),
                    Body = Convert.ToString(rowSegment["TemplateSegment_Text"], CultureInfo.CurrentCulture)
                };

                segments.Add(segment);
            }

            this.segments = new TemplateSegmentCollection(segments);
        }