EDISegmentBase GetSegmentInstance(string content, string segmentName) { Type type = Type.GetType(string.Format(OwlAdapterSettings.Settings.MapperEDILibrary, segmentName)); if (type == null) { throw new OwlContentException(string.Format("El segmento '{0}' no es válido para un documento EDI", segmentName)); } EDISegmentBase iSegment = (EDISegmentBase)Activator.CreateInstance(type); iSegment.Properties = (EDISegmentProperties)Properties.Clone(); // TODO: Validate clone iSegment.LoadContent(content); return(iSegment); }
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); }