Example #1
0
        OwlEDIConfig GetConfig(string filename)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(filename);
            OwlEDIConfig owlConfig = XmlExtension.Deserialize <OwlEDIConfig>(xml);

            return(owlConfig);
        }
Example #2
0
        public void ValidateContent_1()
        {
            OwlEDIConfig owlConfig = GetConfig(@"examples\edi\1\owl-config-edi.xml");

            EDIDocument document = new EDIDocument();
            string      original = GetContent(@"examples\edi\1\test.txt");

            document.LoadContent(owlConfig, original);

            string content = document.ToString();

            Assert.AreEqual(original, content);
        }
Example #3
0
        public void LoadContent(OwlEDIConfig config, string content)
        {
            #region Validate params

            if (config == null)
            {
                throw new ArgumentNullException("config", "El parametro 'config' no puede ser nulo");
            }
            if (config.Sections.Count == 0)
            {
                throw new OwlAdapterException("El Owl Input Config no tiene Secciones configuradas");
            }
            if (content.IsNullOrWhiteSpace())
            {
                throw new OwlContentException("El documento EDI no contiene información");
            }

            #endregion

            InitializeProperties();

            #region Previous Validation

            // This validation is for process correctly the segment terminator
            content = Regex.Replace(content,
                                    string.Format(@"\{0}\{1}", Properties.ReleaseChar, Properties.SegmentSeparator), (match) => { return("```"); });

            #endregion

            var sb = new StringBuilder(content);
            this.Segments.AddRange(Load(config.Sections, sb));

            if (sb.Length != 0)
            {
                string message = string.Format("Se encontró un contenido no válido en la posición '{0}'.", _currentPos);
                if (_lastValidSegment != null)
                {
                    message += string.Format(" El último segmento válido fue '{0}'", _lastValidSegment.Name);
                }

                throw new OwlContentException(message);
            }
        }