Example #1
0
        string GetSegmentContent(StringBuilder content, OwlEDISection section)
        {
            if (!content.StartsWith(section.Name))
            {
                return(string.Empty);
            }                                                               // If the content doesn't start with the section name break the process

            int intEndSegment = content.IndexOf(Properties.SegmentSeparator);

            if (intEndSegment == -1)
            {
                return(string.Empty);
            }                                                 // if the index is 0 the segment terminator wasn't found

            string segment             = content.Substring(0, intEndSegment);
            int    intElementSeparator = segment.IndexOf(Properties.ElementGroupSeparator);

            if (intElementSeparator == -1)
            {
                intElementSeparator = intEndSegment;
            }                                                                       // Some segments doesn't have elements

            if (segment.GetSafeSubstring(0, intElementSeparator) == section.Name)
            {
                return(string.Concat(segment, Properties.SegmentSeparator));
            }

            return(string.Empty);
        }
Example #2
0
 void InitializeProperties()
 {
     Segments = new List <EDISegmentBase>();
     if (Properties == null)
     {
         Properties = new EDISegmentProperties();
     }
     _currentPos       = 1;
     _lastValidSegment = null;
 }
Example #3
0
        List <EDISegmentBase> Load(List <OwlEDISection> sections, StringBuilder content)
        {
            List <EDISegmentBase> listSegments = new List <EDISegmentBase>();

            foreach (OwlEDISection section in sections)
            {
                if (content.Length == 0)
                {
                    break;
                }
                string segmentContent = string.Empty;

                do
                {
                    segmentContent = GetSegmentContent(content, section);

                    if (!string.IsNullOrEmpty(segmentContent))
                    {
                        // Create segment
                        EDISegmentBase iSegment = GetSegmentInstance(segmentContent, section.Name);
                        listSegments.Add(iSegment);

                        content.Remove(0, segmentContent.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.Segments = new List <EDISegmentBase>();
                                iSegment.Segments.AddRange(internalSegments);
                            }
                        }
                    }
                } while (!string.IsNullOrEmpty(segmentContent)); // The while is for the segments that have repetitions
            }

            return(listSegments);
        }