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

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

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

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

            document.LoadContent(owlConfig, original);

            string content = document.ToString();

            Assert.AreEqual(original, content);
        }
Example #3
0
        public void LoadContent(OwlANSIConfig 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 ANSI no contiene información");
            }

            #endregion

            InitializeProperties();

            #region Previous Validation

            // This validation is for process correctly the segment terminator
            try
            {
                content = Regex.Replace(content,
                                        string.Format(@"\{0}\{1}", Properties.ReleaseChar, Properties.SegmentSeparator), (match) => { return("```"); });
            }
            catch (ArgumentException)
            {
                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);
            }
        }