コード例 #1
0
ファイル: EDIDocument.cs プロジェクト: jeffaristi92/owl
 void InitializeProperties()
 {
     Segments = new List <EDISegmentBase>();
     if (Properties == null)
     {
         Properties = new EDISegmentProperties();
     }
     _currentPos       = 1;
     _lastValidSegment = null;
 }
コード例 #2
0
ファイル: Helper.cs プロジェクト: jeffaristi92/owl
        /// <summary>
        /// Release de field value
        /// </summary>
        /// <param name="value"></param>
        /// <param name="properties"></param>
        /// <returns>New value</returns>
        public static string ReleaseValue(string content, EDISegmentProperties properties)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(content);
            }

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

            return(result);
        }
コード例 #3
0
ファイル: EDIOutput.cs プロジェクト: jeffaristi92/owl
        protected override string GenerateSection(SectionOutput section, XmlNode node)
        {
            #region Separators

            if (validateSeparator)
            {
                _structureEDI      = (EDIStructureOutput)_currentEstructuraOutput;
                _segmentProperties = new EDISegmentProperties {
                    DecimalSeparator = _structureEDI.OutputDecimalSeparator
                };

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

                if (_structureEDI.ElementGroupSeparator == char.MinValue)
                {
                    _structureEDI.ElementGroupSeparator = _segmentProperties.ElementGroupSeparator;
                }
                else if (_structureEDI.ElementGroupSeparator != _segmentProperties.ElementGroupSeparator)
                {
                    _segmentProperties.ElementGroupSeparator = _structureEDI.ElementGroupSeparator;
                }

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

                if (_structureEDI.ReleaseChar == char.MinValue)
                {
                    _structureEDI.ReleaseChar = _segmentProperties.ReleaseChar;
                }
                else if (_structureEDI.ReleaseChar != _segmentProperties.ReleaseChar)
                {
                    _segmentProperties.ReleaseChar = _structureEDI.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

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

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

            #endregion

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

            return(null);
        }
コード例 #4
0
ファイル: Helper.cs プロジェクト: jeffaristi92/owl
        /// <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, EDISegmentProperties properties)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(content);
            }

            #region Previous Validation

            // This validation is for don't remove release values
            content = Regex.Replace(content,
                                    string.Format(@"\{0}\{0}|\{0}\{1}|\{0}\{2}", properties.ReleaseChar, properties.ElementGroupSeparator, properties.ElementSeparator),
                                    (match) =>
            {
                if (match.Value == string.Format("{0}{1}", properties.ReleaseChar, properties.ElementGroupSeparator))
                {
                    return("¨¨¨");
                }
                else 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

            // NAD+SU+R0591::+::::+:BONETERA  ORBE S,A ,DE, C,V,::::+:::++++'
            string[]      parts       = content.TrimEnd(properties.SegmentSeparator).Split(properties.ElementGroupSeparator);
            StringBuilder returnValue = new StringBuilder();

            // Se quita el separador de SubElementos
            foreach (string part in parts)
            {
                returnValue.Append(part.TrimEnd(properties.ElementSeparator) + properties.ElementGroupSeparator);
            }

            // Se quita el separador de Elementos
            content = returnValue.ToString().TrimEnd(properties.ElementGroupSeparator);

            // 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 original release value
            content = Regex.Replace(content, @"°°°|¨¨¨|\^\^\^",
                                    (match) =>
            {
                if (match.Value == "¨¨¨")
                {
                    return(string.Format("{0}{1}", properties.ReleaseChar, properties.ElementGroupSeparator));
                }
                else 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));
        }
コード例 #5
0
ファイル: Helper.cs プロジェクト: jeffaristi92/owl
        /// <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 <List <string> > ProcessSegment(string content, EDISegmentProperties properties)
        {
            // Array bidimensional
            List <List <string> > strElementos = new List <List <string> >();

            #region Previous Validation

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

            #endregion

            // Dividir la cadena por el caracter 'ElementSeparator' para sacar los elementos que componen el segmento.
            string[] strLineas = content.TrimEnd(properties.SegmentSeparator).Split(properties.ElementGroupSeparator);

            // Recorrer cada elemento y realizar la división del mismo por el caracter 'SubElementSeparator'
            foreach (string strLinea in strLineas)
            {
                List <string> strSubElementosFinal = new List <string>();
                string[]      strSubElementos      = strLinea.Split(properties.ElementSeparator);

                // Recorrer cada subelemento y agregarlo a la lista.
                foreach (string strSubElemento in strSubElementos)
                {
                    #region Final Validation

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

                    #endregion

                    strSubElementosFinal.Add(finalValue);
                }

                // La lista de subelementos agregarla a la de elementos.
                strElementos.Add(strSubElementosFinal);
            }

            return(strElementos);
        }