List <ANSISegmentBase> Load(List <OwlANSISection> sections, StringBuilder content) { List <ANSISegmentBase> listSegments = new List <ANSISegmentBase>(); foreach (OwlANSISection section in sections) { if (content.Length == 0) { break; } string segmentContent = string.Empty; do { segmentContent = GetSegmentContent(content, section); if (!string.IsNullOrEmpty(segmentContent)) { // Create segment ANSISegmentBase 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 <ANSISegmentBase>(); iSegment.Segments.AddRange(internalSegments); } } } } while (!string.IsNullOrEmpty(segmentContent)); // The while is for the segments that have repetitions } return(listSegments); }
ANSISegmentBase GetSegmentInstance(string content, string segmentName) { if (segmentName == "CON") { segmentName = "CON_"; } Type type = Type.GetType(string.Format(OwlAdapterSettings.Settings.MapperANSILibrary, segmentName)); if (type == null) { throw new OwlContentException(string.Format("El segmento '{0}' no es vĂ¡lido para un documento ANSI", segmentName)); } ANSISegmentBase iSegment = (ANSISegmentBase)Activator.CreateInstance(type); iSegment.Properties = (ANSISegmentProperties)Properties.Clone(); iSegment.LoadContent(content); return(iSegment); }