Пример #1
0
        /// <summary>
        /// Release de field value
        /// </summary>
        /// <param name="value"></param>
        /// <param name="properties"></param>
        /// <returns>New value</returns>
        public static string ReleaseValue(string content, ANSISegmentProperties properties)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(content);
            }
            string result = string.Empty;

            try
            {
                result = Regex.Replace(content,
                                       string.Format(@"\{0}|\{1}|\{2}"
                                                     , properties.ElementSeparator, properties.ReleaseChar, properties.SegmentSeparator)
                                       , (match) => { return(properties.ReleaseChar + match.Value); });
            }
            catch (ArgumentException)
            {
                result = Regex.Replace(content,
                                       string.Format(@"\{0}|\{1}|{2}"
                                                     , properties.ElementSeparator, properties.ReleaseChar, properties.SegmentSeparator)
                                       , (match) => { return(properties.ReleaseChar + match.Value); });
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Trim the segment
        /// </summary>
        /// <param name="name">Segment Name</param>
        /// <param name="content">Segment Content</param>
        /// <param name="properties">Properties</param>
        /// <returns>New value</returns>
        public static string TrimSegment(string name, string content, ANSISegmentProperties properties)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(content);
            }

            #region Previous Validation

            // This validation is for donn't remove release values
            content = Regex.Replace(content,
                                    string.Format(@"\{0}\{0}|\{0}\{1}", properties.ReleaseChar, properties.ElementSeparator),
                                    (match) =>
            {
                if (match.Value == string.Format("{0}{1}", properties.ReleaseChar, properties.ElementSeparator))
                {
                    return("¨¨¨");
                }
                else if (match.Value == string.Format("{0}{0}", properties.ReleaseChar))
                {
                    return("^^^");
                }
                return(match.Value);
            });

            #endregion

            // Se quita el separador de Elementos
            content = content.TrimEnd(properties.SegmentSeparator).TrimEnd(properties.ElementSeparator);

            // Si solo esta el nombre se retorna con el terminador
            if (content == name)
            {
                return(string.Concat(content, properties.SegmentSeparator));
            }

            #region Final Validation

            // This validation is for put the orinal release value
            content = Regex.Replace(content, @"¨¨¨|\^\^\^",
                                    (match) =>
            {
                if (match.Value == "¨¨¨")
                {
                    return(string.Format("{0}{1}", properties.ReleaseChar, properties.ElementSeparator));
                }
                else if (match.Value == "^^^")
                {
                    return(string.Format("{0}{0}", properties.ReleaseChar));
                }
                return(match.Value);
            });

            #endregion

            return(string.Concat(content, properties.SegmentSeparator));
        }
Пример #3
0
 void InitializeProperties()
 {
     Segments = new List <ANSISegmentBase>();
     if (Properties == null)
     {
         Properties = new ANSISegmentProperties();
     }
     _currentPos       = 1;
     _lastValidSegment = null;
 }
Пример #4
0
        /// <summary>
        /// Método encargado de realizar el parseo de una cadena correspondiente a un segmento EDI.
        /// El parseo se realiza de la siguiente manera:
        /// Se realiza un split de la cadena sobre el caracter '+', de modo que se obtiene un array de los elementos
        /// que componen el segmento, en donde el primer elemento [indice 0] es el nombre del segmento, por lo que los
        /// datos usables del segmento se encuentran a partir del segundo elemento [índice 1].
        /// Luego, se recorre cada uno de los elementos, haciendo un split en cada indice por el caracter ':' para obtener
        /// los subelementos, de tal manera que finalmente se obtiene un array de 2 dimensiones de la siguiente manera:
        /// array[posicion1] = elemento 1 del segmento
        /// array[posicion1][posicion2] = subelemento 1 del elemento 1 del segmento
        /// </summary>
        /// <param name="content">La cadena que se debe parsear.</param>
        /// <returns>El array bidimensional con la información</returns>
        public static List <string> ProcessSegment(string content, ANSISegmentProperties properties)
        {
            // Array bidimensional
            List <string> strElementos = new List <string>();

            #region Previous Validation

            // This validation is for don't remove release values
            content = Regex.Replace(content, string.Format(@"\{0}\{1}", properties.ReleaseChar, properties.ElementSeparator), (match) => { return("¨¨¨"); });

            #endregion

            // Dividir la cadena por el caracter 'ElementSeparator' para sacar los elementos que componen el segmento.
            string[] strLineas = content.TrimEnd(properties.SegmentSeparator).Split(properties.ElementSeparator);
            foreach (string strLinea in strLineas)
            {
                #region Final Validation

                // This validation is for put the original value without release
                string finalValue = Regex.Replace(strLinea, @"¨¨¨|```",
                                                  (match) =>
                {
                    if (match.Value == "¨¨¨")
                    {
                        return(string.Format("{0}", properties.ElementSeparator));
                    }
                    else if (match.Value == "```")
                    {
                        return(string.Format("{0}", properties.SegmentSeparator));
                    }
                    return(match.Value);
                });

                #endregion

                strElementos.Add(strLinea);
            }

            return(strElementos);
        }
Пример #5
0
        protected override string GenerateSection(SectionOutput section, XmlNode node)
        {
            #region Separators

            if (validateSeparator)
            {
                _structureANSI     = (ANSIStructureOutput)_currentEstructuraOutput;
                _segmentProperties = new ANSISegmentProperties();

                if (_structureANSI.SegmentSeparator == char.MinValue)
                {
                    _structureANSI.SegmentSeparator = _segmentProperties.SegmentSeparator;
                }
                else if (_structureANSI.SegmentSeparator != _segmentProperties.SegmentSeparator)
                {
                    _segmentProperties.SegmentSeparator = _structureANSI.SegmentSeparator;
                }

                if (_structureANSI.ElementSeparator == char.MinValue)
                {
                    _structureANSI.ElementSeparator = _segmentProperties.ElementSeparator;
                }
                else if (_structureANSI.ElementSeparator != _segmentProperties.ElementSeparator)
                {
                    _segmentProperties.ElementSeparator = _structureANSI.ElementSeparator;
                }

                if (_structureANSI.ReleaseChar == char.MinValue)
                {
                    _structureANSI.ReleaseChar = _segmentProperties.ReleaseChar;
                }
                else if (_structureANSI.ReleaseChar != _segmentProperties.ReleaseChar)
                {
                    _segmentProperties.ReleaseChar = _structureANSI.ReleaseChar;
                }

                validateSeparator = false;
            }

            #endregion

            #region Hidden Elements

            foreach (XmlNode nElement in _handler.ConfigMap.GetHiddenOutputElements(node))
            {
                ElementOutput element = (ElementOutput)_handler.XOMLValidator.GetXOMLObject(new ElementOutput(), nElement, _handler);
                GetElementValue(element, nElement, section);
            }

            #endregion

            #region Segments

            string name = section.Name;
            if (name == "CON")
            {
                name = "CON_";
            }
            Type type = Type.GetType(string.Format(OwlAdapterSettings.Settings.MapperANSILibrary, name));
            if (type == null)
            {
                throw new OwlSectionException(string.Format(ETexts.GT(ErrorType.InvalidSegment), section.Name), node.OuterXml, node.Name, section.Name);
            }

            IANSISegment segment = (IANSISegment)Activator.CreateInstance(type);
            segment.Properties = _segmentProperties;

            #endregion

            if (segment != null)
            {
                string value = XOMLOutputValidator.GetANSISegment(segment, node, _handler, section, this).ToString();
                if (!value.IsNullOrWhiteSpace())
                {
                    _segmentCount++;
                    return(value);
                }
            }
            return(null);
        }