Example #1
0
        /// <summary>
        /// Carga los archivos de configuracion, se debe llamar de primero
        /// </summary>
        /// <exception cref="OwlException">Error al cargar el archivo de Configuracion Xml</exception>
        public void LoadConfigMap()
        {
            if (_settings.XmlConfig == null)
            {
                try
                {
                    _xmlConfig = new XmlDocument();
                    _xmlConfig.Load(_settings.PathConfig);
                }
                catch (Exception e) { throw new OwlException(ETexts.GT(ErrorType.ErrorLoadConfigMap), e); }
            }
            else
            {
                _xmlConfig = _settings.XmlConfig;
            }

            if (_settings.XmlConfigBase != null)
            {
                _xmlConfigBase = _settings.XmlConfigBase;
            }
            else if (!_settings.PathConfigBase.IsNullOrWhiteSpace())
            {
                try
                {
                    _xmlConfigBase = new XmlDocument();
                    _xmlConfigBase.Load(_settings.PathConfigBase);
                }
                catch (Exception e) { throw new OwlException(ETexts.GT(ErrorType.ErrorLoadConfigMapBase), e); }
            }

            if (_xmlConfigBase != null)
            {
                ValidateAndLoadBaseConfiguration();
            }
        }
Example #2
0
        /// <summary>
        /// Otiene un valor
        /// </summary>
        /// <param name="eval">Expresion a evaluar</param>
        /// <returns>Valor</returns>
        public string GetValue(string eval)
        {
            XPathNavigator nav = _xml.CreateNavigator();

            #region Ejecutar XPath

            try
            {
                XPathExpression exp = nav.Compile(eval);

                if (exp.ReturnType == XPathResultType.String || exp.ReturnType == XPathResultType.Number)
                {
                    return(nav.Evaluate(eval, _nsmgr).ToString());
                }
                else if (exp.ReturnType == XPathResultType.NodeSet)
                {
                    XPathNodeIterator nodes = nav.Select(eval, _nsmgr);
                    while (nodes.MoveNext())
                    {
                        return(nodes.Current.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                throw new OwlSectionException(string.Format(ETexts.GT(ErrorType.ErrorExecuteExpression), eval), "", _xml.Name, "owl", e);
            }

            #endregion

            return(string.Empty);
        }
Example #3
0
        /// <summary>
        /// Metodo recursivo para obtener los campos requeridos
        /// </summary>
        /// <param name="nodo">Nodo actual</param>
        private void ProcessNode(XmlNode nodo)
        {
            foreach (XmlNode nodoHijo in nodo.ChildNodes)
            {
                if (nodoHijo.Name != "item")
                {
                    throw new OwlException(string.Format(ETexts.GT(ErrorType.TagInvalid), nodoHijo.Name, "required"));
                }

                if (nodoHijo.FirstChild != null && nodoHijo.FirstChild.NodeType == XmlNodeType.Element)
                {
                    if (nodoHijo.FirstChild.Name == "required")
                    {
                        ProcessNode(nodoHijo.FirstChild);
                    }
                    else
                    {
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.TagInvalid), nodoHijo.FirstChild.Name, "required"));
                    }
                }
                else
                {
                    if (!_fieldsRequireds.ContainsKey(nodoHijo.InnerText))
                    {
                        _fieldsRequireds.Add(nodoHijo.InnerText, string.Empty);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Carga los datos de la entrada
        /// </summary>
        /// <param name="configMap">Objeto de configuracion XML</param>
        /// <param name="configSettings">Objeto de configuracion de mapeo</param>
        public void LoadData(OwlConfigMap configMap, OwlSettings configSettings)
        {
            if (_xml == null)
            {
                _xml = new XmlDocument();
                try { _xml.Load(_pathFile); }
                catch (Exception e) { throw new OwlException(string.Format(ETexts.GT(ErrorType.ErrorLoadInputFile), _pathFile), e); }
            }

            if (_nsmgr == null)
            {
                _nsmgr = new XmlNamespaceManager(_xml.NameTable);
                if (!_prefix.IsNullOrWhiteSpace() && !_uri.IsNullOrWhiteSpace())
                {
                    AddNamespace(_prefix, _uri);
                }

                if (configSettings.LoadXmlPrefix)
                {
                    // Get the Namespaces with prefix
                    MatchCollection matches = Regex.Matches(_xml.OuterXml, "xmlns\\:(?<prefix>[A-Za-z][\\w\\d]*)\\=\\\"(?<uri>[\\w\\W][^\"]*)");
                    foreach (Match match in matches)
                    {
                        AddNamespace(match.Groups["prefix"].Value, match.Groups["uri"].Value);
                    }

                    // Get the Namespaces without prefix
                    matches = Regex.Matches(_xml.OuterXml, "xmlns\\=\\\"(?<uri>[\\w\\W][^\"]*)");
                    foreach (Match match in matches)
                    {
                        AddNamespace("def", match.Groups["uri"].Value);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Metodo recursivo para obtener los campos requeridos
        /// </summary>
        /// <param name="nodo">Nodo actual</param>
        private bool ValidateNodes(XmlNode nodo)
        {
            if (nodo == null)
            {
                return(true);
            }

            int  intContador = 1;
            bool booEstado   = true;

            foreach (XmlNode nodoHijo in nodo.ChildNodes)
            {
                bool booValActual = false;

                if (nodoHijo.FirstChild != null && nodoHijo.FirstChild.NodeType == XmlNodeType.Element)
                {
                    booValActual = ValidateNodes(nodoHijo.FirstChild);
                    if (intContador == 1)
                    {
                        booEstado = booValActual;
                    }
                }
                else
                {
                    if (intContador == 1)
                    {
                        if (string.IsNullOrEmpty(_fieldsRequireds[nodoHijo.InnerText]))
                        {
                            booEstado = false;
                        }
                    }
                    else
                    {
                        booValActual = !string.IsNullOrEmpty(_fieldsRequireds[nodoHijo.InnerText]);
                    }
                }

                if (intContador != 1)
                {
                    string operadorLogico = nodoHijo.Attributes["logical-operator"] != null ? nodoHijo.Attributes["logical-operator"].Value : string.Empty;
                    if (operadorLogico == "or")
                    {
                        booEstado = booEstado || booValActual;
                    }
                    else if (operadorLogico == "and")
                    {
                        booEstado = booEstado && booValActual;
                    }
                    else
                    {
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), operadorLogico, "logical-operator"));
                    }
                }

                intContador++;
            }

            return(booEstado);
        }
Example #6
0
 /// <summary>
 /// Obtiene variable global
 /// </summary>
 /// <param name="key">Llave</param>
 /// <exception cref="OwlException">La variable no existe</exception>
 private string GetVariable(string key)
 {
     if (_OwlVars.ContainsKey(key))
     {
         return(_OwlVars[key]);
     }
     throw new OwlException(string.Format(ETexts.GT(ErrorType.OwlVarUndefined), key));
 }
Example #7
0
 /// <summary>
 /// Instancia clase
 /// </summary>
 /// <param name="settings">Objeto con la configuracion de mapeo</param>
 public OwlHandler(OwlSettings settings)
 {
     ETexts.LoadTexts();
     Settings        = settings;
     XOMLValidator   = new XOMLValidator();
     KeywordsManager = new KeywordsManager();
     _OwlVars        = new Dictionary <string, string>();
 }
Example #8
0
        /// <summary>
        /// Procesa la longitud numerica
        /// </summary>
        /// <param name="eval">Expresion a evaluar</param>
        void SetNumbersParts(string eval)
        {
            // 5,2 <-- Expresion a evaluar
            string[] parts = eval.Split(',');

            if (parts.Length > 2)
            {
                throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), eval, "length"));
            }

            #region Parte Decimal

            ValidateDecimalPart = false;
            if (parts.Length == 2)
            {
                if (parts[1] == "*")
                {
                    _decimalPart = -1;
                }
                else
                {
                    if (parts[1].IsInt())
                    {
                        _decimalPart = Convert.ToInt32(parts[1]);
                    }
                    else
                    {
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLNumericValue), parts[1], "length"));
                    }
                }

                ValidateDecimalPart = true;
            }

            #endregion

            #region Parte Entera

            if (parts[0] == "*")
            {
                _integerPart = -1;
            }
            else
            {
                if (parts[0].IsInt())
                {
                    _integerPart = Convert.ToInt32(parts[0]);
                }
                else
                {
                    throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLNumericValue), parts[0], "length"));
                }
            }

            #endregion
        }
Example #9
0
        /// <summary>
        /// Set the property value
        /// </summary>
        /// <param name="property">Property Name</param>
        /// <param name="obj">Object</param>
        /// <param name="value">Value</param>
        protected void SetProperty(string property, object obj, object value)
        {
            PropertyInfo prop = obj.GetType().GetProperty(property);

            if (prop == null)
            {
                throw new OwlException(string.Format(ETexts.GT(ErrorType.PropertyNotExist), property));
            }
            prop.SetValue(obj, value, null);
        }
Example #10
0
 public void SetPropertyValue(string property, string value)
 {
     if (property == "Type")
     {
         Type = (ValidationType)Enum.Parse(typeof(ValidationType), value.XOMLName());
     }
     else
     {
         throw new OwlKeywordException(KeywordsType.If, string.Format(ETexts.GT(ErrorType.XOMLEnumInvalid), property));
     }
 }
Example #11
0
 /// <summary>
 /// Cantidad de resultados que retorna la expresion
 /// </summary>
 /// <param name="eval">Expresion a evaluar</param>
 /// <returns>Cantidad de resultados</returns>
 public int Count(string eval)
 {
     try
     {
         string value = GetValue(string.Format("count({0})", eval));
         return(Convert.ToInt32(value));
     }
     catch (Exception e)
     {
         throw new OwlSectionException(string.Format(ETexts.GT(ErrorType.ErrorExecuteExpression), eval), "", _xml.Name, "owl", e);
     }
 }
Example #12
0
        /// <summary>
        /// Set the value in Int properties
        /// </summary>
        /// <param name="property">Property Name</param>
        /// <param name="obj">Object</param>
        /// <param name="value">Value</param>
        protected void SetIntProperty(string property, object obj, string value)
        {
            int number;

            if (int.TryParse(value, out number))
            {
                SetProperty(property, obj, number);
            }
            else
            {
                throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), value, property));
            }
        }
Example #13
0
        /// <summary>
        /// Devuelve los valores
        /// </summary>
        /// <param name="eval">Expresion a evaluar</param>
        /// <returns>IEnumerable con los resultados</returns>
        public IEnumerable <InputValue> GetValues(string eval)
        {
            XmlNodeList nodes = null;

            try { nodes = _xml.SelectNodes(eval, _nsmgr); }
            catch (Exception e)
            {
                throw new OwlSectionException(string.Format(ETexts.GT(ErrorType.ErrorExecuteExpression), eval), "", _xml.Name, "owl", e);
            }

            foreach (XmlNode node in nodes)
            {
                yield return(new XmlInputValue(node, _nsmgr));
            }
        }
Example #14
0
 public virtual void SetPropertyValue(string property, string value)
 {
     if (property == "DataType")
     {
         DataType = (ElementDataType)Enum.Parse(typeof(ElementDataType), value.XOMLName());
     }
     else if (property == "Length")
     {
         Length = new FieldLength(value);
     }
     else
     {
         throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLEnumInvalid), property));
     }
 }
Example #15
0
        /// <summary>
        /// Valida y carga la informacion de la configuracion del mapeo
        /// </summary>
        /// <exception cref="OwlException">Error al cargar el archivo de Configuracion Xml</exception>
        public void LoadConfigMap()
        {
            if (_owlSettings == null)
            {
                throw new OwlException(ETexts.GT(ErrorType.OwlSettingsIsNull));
            }
            if (_owlSettings.PathConfig.IsNullOrWhiteSpace() && _owlSettings.XmlConfig == null)
            {
                throw new OwlException(ETexts.GT(ErrorType.PathConfigMapIsEmpty));
            }
            if (!_owlSettings.PathConfig.IsNullOrWhiteSpace() && !File.Exists(_owlSettings.PathConfig))
            {
                throw new OwlException(string.Format(ETexts.GT(ErrorType.ConfigMapNotFound), _owlSettings.PathConfig));
            }

            ConfigMap = new OwlConfigMap(Settings);
            ConfigMap.LoadConfigMap();
        }
Example #16
0
        /// <summary>
        /// Set the value in Boolean properties
        /// </summary>
        /// <param name="property">Property Name</param>
        /// <param name="obj">Object</param>
        /// <param name="value">Value</param>
        protected void SetBooleanProperty(string property, object obj, string value)
        {
            bool boolValue;

            if (value == "true")
            {
                boolValue = true;
            }
            else if (value == "false")
            {
                boolValue = false;
            }
            else
            {
                throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), value, property));
            }

            SetProperty(property, obj, boolValue);
        }
Example #17
0
        /// <summary>
        /// Valida las configuraciones para verificar si hereda
        /// </summary>
        private void ValidateAndLoadBaseConfiguration()
        {
            foreach (XmlNode nStructureChild in GetOutputStructures())
            {
                string idConfigBase = GetAttributeValue("base", nStructureChild);

                // Si la estructura tiene configuracion base se carga
                if (!idConfigBase.IsNullOrWhiteSpace())
                {
                    #region Cargar config base

                    // Valida si existe el nodo base
                    XmlNode nStructureBase = _xmlConfigBase.SelectSingleNode(string.Format(_xpathOutputBaseStructure, idConfigBase));
                    if (nStructureBase == null)
                    {
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.ErrorConfigBaseDoesNotExist), idConfigBase));
                    }

                    #endregion

                    #region Procesa estructura

                    // Procesa las configuraciones para unirlas
                    ProcessAttributes(nStructureBase, nStructureChild, "id", "base");
                    ProcessSections(nStructureChild.SelectNodes(_xpathSections), string.Format(_xpathOutputBaseStructure, idConfigBase));
                    ProcessXOMLConfiguration(nStructureChild.SelectNodes(_xpathXOMLStructure), nStructureBase);

                    // Se borran las demas estructuras que estan en el config base para que solo quede la que heredo
                    XmlNodeList nEstructuras = _xmlConfig.SelectNodes(string.Format(_xpathOutputNoBaseStructure, idConfigBase));
                    foreach (XmlNode nEstructura in nEstructuras)
                    {
                        nEstructura.ParentNode.RemoveChild(nEstructura);
                    }

                    #endregion

                    _xmlConfig = _xmlConfigBase;
                }

                break;
            }
        }
Example #18
0
        /// <summary>
        /// Obtiene el valor de la palabra clave
        /// </summary>
        /// <param name="handler">Orquestador</param>
        /// <returns>Valor</returns>
        public string GetValue(object handler)
        {
            string[] partsReturn = Value.Split(new string[] { ":" }, 2, StringSplitOptions.None);
            string   returnValue = partsReturn.GetSafeValue(0);
            string   format      = partsReturn.GetSafeValue(1);

            if (returnValue == "DATETIME")
            {
                if (format.IsNullOrWhiteSpace())
                {
                    return(DateTime.Now.ToString("yyyyMMdd"));
                }
                else
                {
                    return(DateTime.Now.ToString(format));
                }
            }
            else
            {
                OwlHandler config = (OwlHandler)handler;

                // Si es una instancia y no existe la variable se retorna un valor generico
                if (config.Settings.Instance && !config.ExistVariable(returnValue))
                {
                    return(config.KeywordsManager.DefaultAlphanumericInstanceValue);
                }

                if (config.ExistVariable(returnValue))
                {
                    return(config[returnValue]);
                }
                else
                {
                    throw new OwlException(string.Format(ETexts.GT(ErrorType.ReservadaWordDoesNotSupport), returnValue), "Key");
                }
            }
        }
Example #19
0
        /// <summary>
        /// Construye la clase
        /// </summary>
        /// <param name="eval">Expresion a evaluar</param>
        public FieldLength(string eval)
        {
            // "5/left/ " <-- Expresion a evaluar (Texto)
            // "5,2/number-s/ , " <-- Expresion a evaluar (Numero)
            // "5,2/right/ /pad" <-- Expresion a evaluar (Numero)

            string[] parts = eval.Split(new char[] { '/' }, 4);
            PaddingChar = ' ';

            if (parts.Length == 4)
            {
                if (parts[3] == "pad")
                {
                    PaddingWhenIsEmpty = Padding.Pad;
                }
                else if (parts[3] == "not-pad")
                {
                    PaddingWhenIsEmpty = Padding.NotPad;
                }
                else if (parts[3] == "pad-s")
                {
                    PaddingWhenIsEmpty = Padding.PadWithoutSeparator;
                }
                else
                {
                    throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), parts[3], "PaddingWhenIsEmpty"));
                }
            }

            if (parts.Length >= 3)
            {
                if (parts[2].Length > 0)
                {
                    string[] partsPadding = parts[2].Split(',');
                    if (partsPadding.Length > 2)
                    {
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), eval, "length"));
                    }

                    if (partsPadding[0].Length > 0)
                    {
                        PaddingChar = partsPadding[0][0];
                    }
                    if (partsPadding.Length == 2 && partsPadding[1].Length > 0)
                    {
                        PaddingCharDecimalPart = partsPadding[1][0];
                    }
                }
            }

            if (parts.Length >= 2)
            {
                if (parts[1] == "left")
                {
                    Aligment = AligmentType.Left;
                }
                else if (parts[1] == "right")
                {
                    Aligment = AligmentType.Right;
                }
                else if (parts[1] == "number")
                {
                    Aligment = AligmentType.Number;
                }
                else if (parts[1] == "number-s")
                {
                    Aligment = AligmentType.NumberWithoutSeparator;
                }
                else
                {
                    throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), parts[1], "Aligment"));
                }
            }
            else
            {
                Aligment = AligmentType.NotApply;
            }

            SetNumbersParts(parts[0]);
        }
Example #20
0
        /// <summary>
        /// Obtiene el valor de la palabra clave
        /// </summary>
        /// <param name="handler">Orquestador</param>
        /// <returns>Valor</returns>
        public string GetValue(object handler)
        {
            #region Validate that the configuration have at least one item

            if ((FieldsGet == null || FieldsSeek == null || ValuesSeek == null) || (FieldsGet.Count == 0 || FieldsSeek.Count == 0 || ValuesSeek.Count == 0))
            {
                throw new OwlKeywordException(KeywordsType.Reference, string.Format(ETexts.GT(ErrorType.KeywordPropertyUndefined), "FieldsGet, FieldsSeek and ValuesSeek"));
            }

            #endregion

            #region Valida que los valores y columnas a buscar sean igual en cantidad

            if (FieldsSeek.Count != ValuesSeek.Count)
            {
                throw new OwlKeywordException(KeywordsType.Reference, ETexts.GT(ErrorType.ReferenceValuesAndFieldsNotEquals));
            }

            #endregion

            #region Valida que existan los valores configurados

            OwlHandler config = (OwlHandler)handler;

            if (config.Settings.References == null)
            {
                throw new OwlKeywordException(KeywordsType.Reference, ETexts.GT(ErrorType.ReferenceDataSetNull));
            }

            // Valida existencia tabla y columna
            if (!config.Settings.References.Tables.Contains(Table))
            {
                throw new OwlKeywordException(KeywordsType.Reference, string.Format(ETexts.GT(ErrorType.ReferenceTableDontExist), Table));
            }
            else
            {
                // Query for validate if exists all columns
                var columns = config.Settings.References.Tables[Table].Columns.Cast <DataColumn>();
                var result  = (from co in FieldsGet
                               join col in columns on co equals col.ColumnName into gr
                               from subgr in gr.DefaultIfEmpty()
                               where subgr == null
                               select co).ToArray <string>();

                if (result.Length > 0)
                {
                    string fields = string.Join(", ", result);
                    throw new OwlKeywordException(KeywordsType.Reference, string.Format(ETexts.GT(ErrorType.ReferenceColumnDontExist), fields));
                }
            }

            #endregion

            #region Consulta

            StringBuilder sb = new StringBuilder();

            #region Create Query

            // Ciclo para generar el where de la consulta
            for (int i = 0; i < FieldsSeek.Count; i++)
            {
                if (!config.Settings.References.Tables[Table].Columns.Contains(FieldsSeek[i]))
                {
                    throw new OwlKeywordException(KeywordsType.Reference, string.Format(ETexts.GT(ErrorType.ReferenceColumnDontExist), FieldsSeek[i]));
                }

                sb.Append(string.Format("{0} = '{1}'", FieldsSeek[i], ValuesSeek[i].Replace("'", "''")));
                sb.Append(" AND ");
            }

            string select = sb.ToString(0, sb.Length - 5); // Elimina el ultimo " AND "

            #endregion

            #region Execute Query

            DataRow[] drs = config.Settings.References.Tables[Table].Select(select);

            if (drs.Length == 0)
            {
                ValueFound = false;
                if (DefaultValue != null)
                {
                    return(DefaultValue);
                }
                return(string.Empty);
            }
            else
            {
                ValueFound = true;
                if (FieldsGet.Count == 1)
                {
                    string value = drs[0][FieldsGet[0]].ToString();
                    if (Format.IsNullOrWhiteSpace())
                    {
                        return(value);
                    }
                    else
                    {
                        return(string.Format(Format, value));
                    }
                }
                else
                {
                    string[] values = new string[FieldsGet.Count];
                    for (int i = 0; i < FieldsGet.Count; i++)
                    {
                        values[i] = drs[0][FieldsGet[i]].ToString();
                    }
                    if (Format.IsNullOrWhiteSpace())
                    {
                        return(string.Concat(values));
                    }
                    else
                    {
                        return(string.Format(Format, values));
                    }
                }
            }

            #endregion

            #endregion
        }
Example #21
0
 public virtual void SetPropertyValue(string property, string value)
 {
     throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLEnumInvalid), property));
 }
Example #22
0
        /// <summary>
        /// Obtiene el valor de la palabra clave
        /// </summary>
        /// <param name="handler">Orquestador</param>
        /// <returns>Valor</returns>
        public string GetValue(object handler)
        {
            #region Validate values

            if (Values == null || Values.Count == 0)
            {
                throw new OwlKeywordException(KeywordsType.Concatenate, string.Format(ETexts.GT(ErrorType.KeywordPropertyUndefined), "values"));
            }

            #endregion

            if (!string.IsNullOrEmpty(Separator))
            {
                return(string.Join(Separator, Values.ToArray()));
            }
            else
            {
                if (Format.IsNullOrWhiteSpace())
                {
                    return(string.Concat(Values.ToArray()));
                }
                else
                {
                    return(string.Format(Format, Values.ToArray()));
                }
            }
        }
Example #23
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);
        }
Example #24
0
        /// <summary>
        /// Obtiene el valor de la palabra clave
        /// </summary>
        /// <param name="handler">Orquestador</param>
        /// <returns>Valor</returns>
        public string GetValue(object handler)
        {
            if (False == null)
            {
                False = string.Empty;
            }

            switch (Type)
            {
                #region Texto

            case ValidationType.Equal:
                if (Value1 == Value2)
                {
                    return(True);
                }
                else
                {
                    return(False);
                }

            case ValidationType.Different:
                if (Value1 != Value2)
                {
                    return(True);
                }
                else
                {
                    return(False);
                }

                #endregion

                #region Numericos

            case ValidationType.Greater:
            case ValidationType.Less:
            case ValidationType.GreaterEqual:
            case ValidationType.LessEqual:

                decimal vValor1 = 0, vValor2 = 0;

                #region Validaciones

                if (!Value1.IsDecimal())
                {
                    throw new OwlKeywordException(KeywordsType.If, string.Format(ETexts.GT(ErrorType.IfNonNumericValue), Type, "type", Value1, "value-1"));
                }
                else
                {
                    vValor1 = Convert.ToDecimal(Value1);
                }

                if (!Value2.IsDecimal())
                {
                    throw new OwlKeywordException(KeywordsType.If, string.Format(ETexts.GT(ErrorType.IfNonNumericValue), Type, "type", Value2, "value-2"));
                }
                else
                {
                    vValor2 = Convert.ToDecimal(Value2);
                }

                #endregion

                if (Type == ValidationType.Greater)
                {
                    if (vValor1 > vValor2)
                    {
                        return(True);
                    }
                    else
                    {
                        return(False);
                    }
                }
                else if (Type == ValidationType.Less)
                {
                    if (vValor1 < vValor2)
                    {
                        return(True);
                    }
                    else
                    {
                        return(False);
                    }
                }
                else if (Type == ValidationType.GreaterEqual)
                {
                    if (vValor1 >= vValor2)
                    {
                        return(True);
                    }
                    else
                    {
                        return(False);
                    }
                }
                else if (Type == ValidationType.LessEqual)
                {
                    if (vValor1 <= vValor2)
                    {
                        return(True);
                    }
                    else
                    {
                        return(False);
                    }
                }

                break;

                #endregion
            }

            return(string.Empty);
        }
Example #25
0
        /// <summary>
        /// Valida y obtiene el objeto
        /// </summary>
        /// <param name="obj">Objeto a validar y obtener</param>
        /// <param name="node">Nodo con la configuracion</param>
        /// <param name="handler">Orquestador</param>
        /// <returns>Objeto con los datos</returns>
        public IXOMLObject GetXOMLObject(IXOMLObject obj, XmlNode node, OwlHandler handler)
        {
            XOMLSigning    xs                   = obj.GetSigning();
            Type           type                 = obj.GetType();
            List <XmlNode> valuesConf           = new List <XmlNode>();
            bool           hasXOMLConfiguration = ValidateXOMLCount(node);

            #region Valida propiedades

            foreach (XOMLSigning.XOMLRestriction xr in xs.Restrictions)
            {
                bool hasMandatoryValidation = false;

                #region Attribute

                XmlAttribute nAttribute = null;
                if (xr.Attribute)
                {
                    nAttribute = GetXOMLAttribute(node, xr.TagName);
                }                                                                      // Validate if the field can be an attribute

                if (nAttribute != null)
                {
                    string value = nAttribute.Value;
                    hasMandatoryValidation = true;

                    if (xr.PropertyType != XOMLPropertyType.List)
                    {
                        value = ValidateInlineXOML(value, handler);

                        if (xr.PropertyType == XOMLPropertyType.String)
                        {
                            SetProperty(xr.PropertyName, obj, value);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Char && value.Length > 0)
                        {
                            SetProperty(xr.PropertyName, obj, value[0]);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Boolean)
                        {
                            SetBooleanProperty(xr.PropertyName, obj, value);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Int)
                        {
                            SetIntProperty(xr.PropertyName, obj, value);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Enum || xr.PropertyType == XOMLPropertyType.Object)
                        {
                            SetPropertyValue(xr.PropertyName, obj, value);
                        }
                    }
                    else
                    {
                        List <string> values = new List <string>();
                        foreach (string v in value.Split(','))
                        {
                            string val = ValidateInlineXOML(v, handler); values.Add(val);
                        }

                        SetProperty(xr.PropertyName, obj, values);
                    }
                }

                #endregion

                #region Tag

                else if (xr.Tag && hasXOMLConfiguration) // Validate if the field can be an tag
                {
                    XmlNode nProperty = GetXOMLProperty(node, xr.TagName);
                    if (nProperty != null)
                    {
                        string value = string.Empty;
                        hasMandatoryValidation = true;
                        if (xr.PropertyType != XOMLPropertyType.List)
                        {
                            value = GetKeywordValue(nProperty, handler);
                        }

                        if (xr.PropertyType == XOMLPropertyType.String)
                        {
                            SetProperty(xr.PropertyName, obj, value);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Char && value.Length > 0)
                        {
                            SetProperty(xr.PropertyName, obj, value[0]);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Boolean)
                        {
                            SetBooleanProperty(xr.PropertyName, obj, value);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Int)
                        {
                            SetIntProperty(xr.PropertyName, obj, value);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.Enum || xr.PropertyType == XOMLPropertyType.Object)
                        {
                            SetPropertyValue(xr.PropertyName, obj, value);
                        }
                        else if (xr.PropertyType == XOMLPropertyType.List)
                        {
                            List <string> values = new List <string>();
                            foreach (XmlNode valueNode in nProperty.SelectNodes(string.Concat(nProperty.Name, ".", "value")))
                            {
                                values.Add(GetKeywordValue(valueNode, handler));
                            }
                            SetProperty(xr.PropertyName, obj, values);
                        }
                    }
                }

                #endregion

                #region Final Validation

                // Validate the field if doesn't exist in the configuration
                if (!hasMandatoryValidation && xr.Mandatory)
                {
                    throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyDoesNotExist), xr.PropertyName));
                }

                #endregion
            }

            #endregion

            return(obj);
        }
Example #26
0
        /// <summary>
        /// Metodo recursivo para obtener los campos requeridos
        /// </summary>
        /// <param name="handler">Handler</param>
        /// <returns>true si los valida correctamente, de lo contrario false</returns>
        private bool ValidateNode(XmlNode node, OwlHandler handler)
        {
            int  intContador = 1;
            bool bolEstado   = true;

            foreach (XmlNode nodoHijo in handler.ConfigMap.GetConditionNode(node))
            {
                #region Vars and previous validation

                bool         bolValActual   = false;
                XmlAttribute attr           = nodoHijo.Attributes["logical-operator"];
                string       operadorLogico = attr != null ? attr.Value : string.Empty;

                if (intContador != 1)
                {
                    // this validation is because if one validation is false in a "Y" Condition, all validation is false
                    if (operadorLogico == "and" && !bolEstado)
                    {
                        break;
                    }
                }

                #endregion

                #region Validate values

                XmlNode subSi = nodoHijo.HasChildNodes ? nodoHijo.SelectSingleNode("if") : null;
                if (subSi != null)
                {
                    // Si el nodo tiene subnodo si, se valida el si de adentro para seguir con las demas condiciones
                    bolValActual = ValidateNode(subSi, handler);
                }
                else
                {
                    #region Valores

                    // Obtienes nodos
                    XmlNode valor1 = nodoHijo.SelectSingleNode("value-1");
                    XmlNode valor2 = nodoHijo.SelectSingleNode("value-2");

                    if (valor1 == null || valor2 == null)
                    {
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.TagsDoesNotExists), nodoHijo.Name));
                    }

                    // Obtiene valores
                    string strValor1 = handler.XOMLValidator.GetKeywordValue(valor1, handler);
                    string strValor2 = handler.XOMLValidator.GetKeywordValue(valor2, handler);

                    #endregion

                    #region Tipo de comparacion

                    // Obtiene tipo de comparacion
                    XmlAttribute attr2           = valor2.Attributes["compare-operator"];
                    string       tipoComparacion = attr2 != null ? attr2.Value : string.Empty;
                    switch (tipoComparacion)
                    {
                        #region Texto

                    case "equal":
                        if (strValor1 == strValor2)
                        {
                            bolValActual = true;
                        }
                        else
                        {
                            bolValActual = false;
                        }
                        break;

                    case "different":
                        if (strValor1 != strValor2)
                        {
                            bolValActual = true;
                        }
                        else
                        {
                            bolValActual = false;
                        }
                        break;

                        #endregion

                        #region Numericos

                    case "greater":
                    case "less":
                    case "greater-equal":
                    case "less-equal":

                        decimal vValor1 = 0, vValor2 = 0;

                        #region Validaciones

                        if (!strValor1.IsDecimal())
                        {
                            throw new OwlException(string.Format(ETexts.GT(ErrorType.IfNonNumericValue), tipoComparacion, "compare-operator", strValor1, "value-1"));
                        }
                        else
                        {
                            vValor1 = Convert.ToDecimal(strValor1);
                        }

                        if (!strValor2.IsDecimal())
                        {
                            throw new OwlException(string.Format(ETexts.GT(ErrorType.IfNonNumericValue), tipoComparacion, "compare-operator", strValor2, "value-2"));
                        }
                        else
                        {
                            vValor2 = Convert.ToDecimal(strValor2);
                        }

                        #endregion

                        if (tipoComparacion == "greater")
                        {
                            if (vValor1 > vValor2)
                            {
                                bolValActual = true;
                            }
                            else
                            {
                                bolValActual = false;
                            }
                        }
                        else if (tipoComparacion == "less")
                        {
                            if (vValor1 < vValor2)
                            {
                                bolValActual = true;
                            }
                            else
                            {
                                bolValActual = false;
                            }
                        }
                        else if (tipoComparacion == "greater-equal")
                        {
                            if (vValor1 >= vValor2)
                            {
                                bolValActual = true;
                            }
                            else
                            {
                                bolValActual = false;
                            }
                        }
                        else if (tipoComparacion == "less-equal")
                        {
                            if (vValor1 <= vValor2)
                            {
                                bolValActual = true;
                            }
                            else
                            {
                                bolValActual = false;
                            }
                        }

                        break;

                        #endregion

                    default:
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), tipoComparacion, "compare-operator"));
                    }

                    #endregion
                }

                #endregion

                #region Validacion de operador logico

                if (intContador == 1)
                {
                    bolEstado = bolValActual;
                }
                else if (intContador != 1)
                {
                    if (operadorLogico == "or")
                    {
                        bolEstado = bolEstado || bolValActual;
                    }
                    else if (operadorLogico == "and")
                    {
                        bolEstado = bolEstado && bolValActual;
                        if (!bolEstado)
                        {
                            break;
                        }                          // this validation is because if one validation is false in a "Y" Condition, all validation is false
                    }
                    else
                    {
                        throw new OwlException(string.Format(ETexts.GT(ErrorType.XOMLPropertyInvalidValue), operadorLogico, "logical-operator"));
                    }
                }

                #endregion

                intContador++;
            }

            return(bolEstado);
        }