void InitializeProperties() { Sections = new List <Section>(); if (Properties == null) { Properties = new OwlProperties(); } _currentPos = 1; _lastValidSegment = null; }
Section GetSegmentInstance(string content, OwlFlatFileSection section) { Section iSegment = new Section(); iSegment.Properties = (OwlProperties)Properties.Clone(); // TODO: Validate clone iSegment.Configuration = section; iSegment.Name = section.Name; iSegment.LoadContent(content); return(iSegment); }
List <Section> Load(List <OwlFlatFileSection> sections, StringBuilder content) { List <Section> listSegments = new List <Section>(); foreach (OwlFlatFileSection section in sections) { if (content.Length == 0) { break; } string segmentContent = string.Empty; do { segmentContent = GetSegmentContent(content, section); if (!string.IsNullOrEmpty(segmentContent)) { // Create segment Section iSegment = GetSegmentInstance(segmentContent, section); listSegments.Add(iSegment); content.Remove(0, segmentContent.Length + iSegment.Properties.SegmentTerminator.Length); // Log validators _currentPos += segmentContent.Length; _lastValidSegment = section; if (section.Sections != null && section.Sections.Count != 0) { var internalSegments = Load(section.Sections, content); if (internalSegments.Count != 0) { iSegment.Sections = new List <Section>(); iSegment.Sections.AddRange(internalSegments); } } } } while (!string.IsNullOrEmpty(segmentContent)); // The while is for the segments that have repetitions } return(listSegments); }
string GetSegmentContent(StringBuilder content, OwlFlatFileSection section) { // Two options // Content start with the section id // Id is empty and the process get always the line if (!content.StartsWith(string.Concat(section.Id, section.Separator)) && !string.IsNullOrEmpty(section.Id)) { return(string.Empty); } int intEndSegment = content.IndexOf(Properties.SegmentTerminator); if (intEndSegment == -1) { return(string.Empty); } // if the index is 0 the segment terminator wasn't found string segment = content.Substring(0, intEndSegment); return(segment); }