示例#1
0
        protected override string CloseSection(SectionOutput section, XmlNode node)
        {
            XmlSectionOutput sectionXml = (XmlSectionOutput)section;

            if (sectionXml.XmlTagType == XmlTagType.Complex)
            {
                return(string.Format("</{0}>", sectionXml.Name));
            }
            return(string.Empty);
        }
示例#2
0
        protected override string CloseSection(SectionOutput section, XmlNode node)
        {
            JsonSectionOutput sectionJson = (JsonSectionOutput)section;

            if ((section.Repetitions > 1 || !section.Itera.IsNullOrWhiteSpace() || sectionJson.JsonArray) && section.Consecutive == section.Repetitions)
            {
                return("}]");
            }
            else
            {
                return("}");
            }
        }
示例#3
0
        public override void GetElementValue(ElementOutput element, XmlNode node, SectionOutput section)
        {
            XmlElementOutput elementXml = (XmlElementOutput)element;

            if (!elementXml.ReleaseChars.HasValue)
            {
                elementXml.ReleaseChars = _structureXml.XmlReleaseChars;
            }

            base.GetElementValue(element, node, section);
            if (elementXml.ReleaseChars.Value)
            {
                element.Value = SecurityElement.Escape(element.Value);
            }
        }
示例#4
0
        protected override string GenerateSection(SectionOutput section, XmlNode node)
        {
            StringBuilder         sb          = new StringBuilder();
            FlatFileSectionOutput sectionFlat = (FlatFileSectionOutput)section;
            bool hasElements = false;

            #region Obtener informacion de la seccion

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

                if (!element.Hidden)
                {
                    sb.Append(string.Concat(element.Value, sectionFlat.Separator)); hasElements = true;
                }
            }

            string resultValue = string.Empty;
            if (sectionFlat.RemoveFinalSeparators)
            {
                resultValue = sb.ToString().TrimEnd(sectionFlat.Separator.ToCharArray());
            }
            else
            {
                resultValue = sb.ToString();
                if (resultValue.Length > 0)
                {
                    resultValue = resultValue.GetSafeSubstring(0, resultValue.Length - sectionFlat.Separator.Length);
                }
            }

            #endregion

            if (hasElements)
            {
                _segmentCount++;
                return(resultValue);
            }
            return(null); // If all elements are (Oculto="Si")
        }
示例#5
0
        protected override string GenerateSection(SectionOutput section, XmlNode node)
        {
            StringBuilder    sb         = new StringBuilder();
            XmlSectionOutput sectionXml = (XmlSectionOutput)section;

            #region Get the XmlValue

            if (_validateStructure)
            {
                _structureXml      = (XmlStructureOutput)_currentEstructuraOutput;
                _validateStructure = false;
            }

            #endregion

            #region Obtener informacion de la seccion

            string internalValue = string.Empty;

            // Se valida ya que lo comentarios y CData se construyen de otra forma
            if (sectionXml.XmlTagType != XmlTagType.Comment && sectionXml.XmlTagType != XmlTagType.CData)
            {
                sb.Append("<" + sectionXml.Name);
            }

            #region Recorre elementos

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

                if (element.XmlValue)
                {
                    if (element.XmlElementType == XmlElementType.NotApply)
                    {
                        internalValue += element.Value;
                    }
                    else if (element.XmlElementType == XmlElementType.Comment)
                    {
                        internalValue += string.Format("<!--{0}-->", element.Value);
                    }
                    else if (element.XmlElementType == XmlElementType.CData)
                    {
                        internalValue += string.Format("<![CDATA[{0}]]>", element.Value);
                    }
                }
                else
                {
                    if (!element.Hidden)
                    {
                        if (!element.MandatoryValue || (element.MandatoryValue && !string.IsNullOrEmpty(element.Value)))
                        {
                            sb.Append(string.Format(" {0}=\"{1}\"", element.Name, element.Value));
                        }
                    }
                }
            }

            #endregion

            #region Finalizar seccion

            if (sectionXml.XmlTagType == XmlTagType.Complex)
            {
                sb.Append(string.Format(">{0}", internalValue));
            }
            else if (sectionXml.XmlTagType == XmlTagType.Simple)
            {
                sb.Append("/>");
            }
            else if (sectionXml.XmlTagType == XmlTagType.Comment)
            {
                sb.Append(string.Format("<!--{0}-->", internalValue));
            }
            else if (sectionXml.XmlTagType == XmlTagType.CData)
            {
                sb.Append(string.Format("<![CDATA[{0}]]>", internalValue));
            }

            _segmentCount++;

            #endregion

            #endregion

            return(sb.ToString());
        }
示例#6
0
 public override void GetElementValue(ElementOutput element, XmlNode node, SectionOutput section)
 {
     base.GetElementValue(element, node, section);
     element.Value = element.Value.Replace("\"", "\\\"").Replace("\\", "\\\\");
 }
示例#7
0
        protected override string GenerateSection(SectionOutput section, XmlNode node)
        {
            StringBuilder     sb          = new StringBuilder();
            JsonSectionOutput sectionJson = (JsonSectionOutput)section;

            #region Obtener informacion de la seccion

            bool addSeparator = false;
            foreach (XmlNode nElement in _handler.ConfigMap.GetOutputElements(node))
            {
                ElementOutput element = (ElementOutput)_handler.XOMLValidator.GetXOMLObject(new ElementOutput(), nElement, _handler);
                GetElementValue(element, nElement, section);
                if (!element.Hidden)
                {
                    if (addSeparator)
                    {
                        sb.Append(",");
                    }
                    if (element.DataType == ElementDataType.Numeric)
                    {
                        sb.Append($"\"{element.Name}\":{element.Value}");
                    }
                    else
                    {
                        sb.Append($"\"{element.Name}\":\"{element.Value}\"");
                    }
                    addSeparator = true;
                }
            }

            #endregion

            if (section.Repetitions > 1 || !section.Itera.IsNullOrWhiteSpace() || sectionJson.JsonArray)
            {
                if (section.Consecutive > 1)
                {
                    sb.Insert(0, ",{");
                }
                else
                {
                    sb.Insert(0, "{");
                }
                if (section.Consecutive == 1)
                {
                    sb.Insert(0, $"\"{section.Name}\":[");
                    if (node.PreviousSibling != null && (node.PreviousSibling.Name == "element" || node.PreviousSibling.Name == "section"))
                    {
                        sb.Insert(0, ",");
                    }
                }
            }
            else
            {
                sb.Insert(0, $"\"{section.Name}\":{{");
                if (node.PreviousSibling != null && (node.PreviousSibling.Name == "element" || node.PreviousSibling.Name == "section"))
                {
                    sb.Insert(0, ",");
                }
            }

            _segmentCount++;
            return(sb.ToString());
        }
示例#8
0
        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);
        }
示例#9
0
        protected override string GenerateSection(SectionOutput section, XmlNode node)
        {
            StringBuilder    sb = new StringBuilder(), sbComplement = new StringBuilder();;
            SqlSectionOutput sectionSQL  = (SqlSectionOutput)section;
            bool             hasElements = false;

            #region Obtener informacion de la seccion

            #region Recorre elementos

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

                if (!element.Hidden)
                {
                    if (sectionSQL.SqlType == SqlType.Delete)
                    {
                        element.SqlElementType = SqlElementType.Where;
                    }

                    if (sectionSQL.SqlType != SqlType.Insert && element.SqlElementType == SqlElementType.Where)
                    {
                        // Where

                        if (element.WhereType == WhereType.Equal)
                        {
                            sbComplement.Append(element.Name);
                            if (string.IsNullOrEmpty(element.Value))
                            {
                                if (element.MandatoryValue)
                                {
                                    sbComplement.Append(" = '' AND ");
                                }
                                else
                                {
                                    sbComplement.Append(" IS NULL AND ");
                                }
                            }
                            else
                            {
                                sbComplement.Append(string.Concat(" = '", element.Value, "' AND "));
                            }
                        }
                        else if (element.WhereType == WhereType.Different)
                        {
                            sbComplement.Append(element.Name);
                            if (string.IsNullOrEmpty(element.Value))
                            {
                                if (element.MandatoryValue)
                                {
                                    sbComplement.Append(" <> '' AND ");
                                }
                                else
                                {
                                    sbComplement.Append(" IS NOT NULL AND ");
                                }
                            }
                            else
                            {
                                sbComplement.Append(string.Concat(" <> '", element.Value, "' AND "));
                            }
                        }
                        else if (element.WhereType == WhereType.Like)
                        {
                            sbComplement.Append(string.Concat(element.Name, " LIKE "));
                            sbComplement.Append(string.Concat("'%", element.Value, "%' AND "));
                        }
                        else if (element.WhereType == WhereType.In)
                        {
                            sbComplement.Append(string.Concat(element.Name, " IN "));
                            sbComplement.Append(string.Concat("(", element.Value, ") AND "));
                        }
                        else if (element.WhereType == WhereType.Between)
                        {
                            sbComplement.Append(string.Concat(element.Name, " BETWEEN "));
                            sbComplement.Append(string.Concat("", element.Value, " AND "));
                        }
                        else if (element.WhereType == WhereType.NotBetween)
                        {
                            sbComplement.Append(string.Concat(element.Name, " NOT BETWEEN "));
                            sbComplement.Append(string.Concat("", element.Value, " AND "));
                        }
                    }
                    else
                    {
                        if (sectionSQL.SqlType == SqlType.Select)
                        {
                            sb.Append(string.Concat(element.Name, ", "));
                        }
                        else if (sectionSQL.SqlType == SqlType.Insert)
                        {
                            sbComplement.Append(string.Concat(element.Name, ", "));

                            if (string.IsNullOrEmpty(element.Value))
                            {
                                if (element.MandatoryValue)
                                {
                                    sb.Append("'', ");
                                }
                                else
                                {
                                    sb.Append("NULL, ");
                                }
                            }
                            else
                            {
                                sb.Append(string.Concat("'", element.Value, "', "));
                            }
                        }
                        else if (sectionSQL.SqlType == SqlType.Update)
                        {
                            sb.Append(string.Concat(element.Name, " = "));
                            if (string.IsNullOrEmpty(element.Value))
                            {
                                if (element.MandatoryValue)
                                {
                                    sb.Append("'', ");
                                }
                                else
                                {
                                    sb.Append("NULL, ");
                                }
                            }
                            else
                            {
                                sb.Append(string.Concat("'", element.Value, "', "));
                            }
                        }
                    }

                    hasElements = true;
                }
            }

            #endregion

            #region Finalizar seccion

            if (hasElements)
            {
                if (sectionSQL.SqlType == SqlType.Select)
                {
                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 2, 2);
                    }

                    sb.Insert(0, "SELECT ");
                    sb.Append(string.Concat(" FROM ", section.Name));

                    if (sbComplement.Length > 0)
                    {
                        sbComplement.Remove(sbComplement.Length - 5, 5);
                        sb.Append(" WHERE ");
                        sb.Append(sbComplement.ToString());
                    }
                }
                else if (sectionSQL.SqlType == SqlType.Insert)
                {
                    if (sbComplement.Length > 0)
                    {
                        sbComplement.Remove(sbComplement.Length - 2, 2);
                    }
                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 2, 2);
                    }

                    sb.Insert(0, string.Concat("INSERT INTO ", section.Name, " (", sbComplement.ToString(), ") VALUES ("));
                    sb.Append(")");
                }
                else if (sectionSQL.SqlType == SqlType.Update)
                {
                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 2, 2);
                    }
                    sb.Insert(0, string.Concat("UPDATE ", section.Name, " SET "));

                    if (sbComplement.Length > 0)
                    {
                        sbComplement.Remove(sbComplement.Length - 5, 5);
                        sb.Append(" WHERE ");
                        sb.Append(sbComplement.ToString());
                    }
                }
                else if (sectionSQL.SqlType == SqlType.Delete)
                {
                    if (sbComplement.Length > 0)
                    {
                        sbComplement.Remove(sbComplement.Length - 5, 5);
                    }
                    sbComplement.Insert(0, string.Concat("DELETE FROM ", section.Name, " WHERE "));
                    sb = sbComplement;
                }

                _segmentCount++;
                return(sb.ToString());
            }

            #endregion

            #endregion

            return(null); // If all elements are (Oculto="Si")
        }