Exemple #1
0
        /// <summary>
        /// Get the Keyword
        /// </summary>
        /// <param name="node">Configuration node</param>
        /// <param name="handler">Orquestation</param>
        /// <returns>Keyword Object</returns>
        public IKeyword GetXOMLKeyword(XmlNode node, OwlHandler handler)
        {
            if (node == null)
            {
                return(null);
            }

            #region Instancia

            // Para las instancias solo se permite Predeterminado, Variable y Reservada
            if (handler.Settings.Instance && (node.Name != "default" && node.Name != "variable" && node.Name != "key"))
            {
                return(null);
            }

            #endregion

            #region Value

            var className = node.Name.XOMLName();
            if (KeywordsList.Contains(className))
            {
                IXOMLObject keywordInstance = (IXOMLObject)Activator.CreateInstance(Type.GetType(string.Format("Fiive.Owl.Core.Keywords.{0}", className)));
                IKeyword    keyword         = (IKeyword)handler.XOMLValidator.GetXOMLObject(keywordInstance, node, handler);

                KeywordsType keywordType = (KeywordsType)Enum.Parse(typeof(KeywordsType), className);
                keyword.KeywordType = keywordType;
                return(keyword);
            }

            #endregion

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Obtiene el valor de la palabra clave
        /// </summary>
        /// <param name="handler">Orquestador</param>
        /// <returns>Valor</returns>
        public string GetValue(object handler)
        {
            OwlHandler config = (OwlHandler)handler;

            // Si es una instancia y no existe la variable se retorna un valor generico
            if (config.Settings.Instance && !config.ExistVariable(Value))
            {
                return(config.KeywordsManager.DefaultAlphanumericInstanceValue);
            }
            return(config[Value]);
        }
Exemple #3
0
        /// <summary>
        /// Add data in the EDI segment
        /// </summary>
        /// <param name="segment">Segment</param>
        /// <param name="node">Node with the configuration</param>
        /// <param name="handler">Orquestator</param>
        /// <param name="section">Parent Section</param>
        /// <param name="output">Output</param>
        /// <returns>Objeto con los datos</returns>
        public IANSISegment GetANSISegment(IANSISegment segment, XmlNode node, OwlHandler handler, SectionOutput section, GenericOutput output)
        {
            foreach (XmlNode nElement in handler.ConfigMap.GetNotHiddenOutputElements(node))
            {
                ElementOutput element = (ElementOutput)handler.XOMLValidator.GetXOMLObject(new ElementOutput(), nElement, handler);
                output.GetElementValue(element, nElement, section);
                SetProperty(element.Name, segment, element.Value);
            }

            return(segment);
        }
Exemple #4
0
        OwlHandler GetHandler(string config, string input)
        {
            OwlSettings settings = new OwlSettings
            {
                PathConfig = config
            };

            var owl = new OwlHandler(settings);

            owl.LoadConfigMap();
            owl.LoadInput(new XmlInput(input));

            return(owl);
        }
Exemple #5
0
 /// <summary>
 /// Obtiene un valor de una palabra clave
 /// </summary>
 /// <param name="nProperty">Nodo con la propiedad</param>
 /// <param name="handler">Orquestador</param>
 /// <returns>Valor</returns>
 public string GetKeywordValue(XmlNode nProperty, OwlHandler handler)
 {
     try
     {
         if (nProperty.FirstChild != null && nProperty.FirstChild.NodeType == XmlNodeType.Element)
         {
             return(handler.KeywordsManager.GetXOMLKeyword(nProperty.FirstChild, handler).GetValue(handler));
         }
         else
         {
             return(nProperty.InnerText);
         }
     }
     catch (TargetInvocationException e) { throw e.InnerException; }
 }
Exemple #6
0
        /// <summary>
        /// Get the Keyword
        /// </summary>
        /// <param name="values">Configuration node</param>
        /// <param name="handler">Orquestation</param>
        /// <returns>Keyword Object</returns>
        public IKeyword GetInlineKeyword(string[] values, OwlHandler handler)
        {
            #region Predeterminado

            if (values.GetSafeValue(0) == "default")
            {
                return(new Default {
                    Value = values.GetSafeValue(1)
                });
            }

            #endregion

            #region Variable

            if (values.GetSafeValue(0) == "variable")
            {
                return(new Variable {
                    Value = values.GetSafeValue(1)
                });
            }

            #endregion

            #region Reservada

            if (values.GetSafeValue(0) == "key")
            {
                return(new Key {
                    Value = values.GetSafeValue(1)
                });
            }

            #endregion

            #region Buscar

            if (!handler.Settings.Instance && values.GetSafeValue(0) == "xpath")
            {
                return(new Xpath {
                    Value = values.GetSafeValue(1)
                });
            }

            #endregion

            return(null);
        }
Exemple #7
0
        /// <summary>
        /// Valida los campos requeridos
        /// </summary>
        /// <param name="handler">Handler</param>
        /// <param name="isLater">true if is a later validation, otherwise false</param>
        /// <returns>true si los valida correctamente, de lo contrario false</returns>
        public bool Validate(OwlHandler handler, bool isLater)
        {
            if (_node == null)
            {
                return(true);
            }

            XmlAttribute attr = _node.Attributes["later"];
            string       val  = attr == null ? "no" : attr.Value;

            if ((isLater && val == "yes") || (!isLater && val == "no"))
            {
                return(ValidateNode(_node, handler));
            }

            return(true);
        }
Exemple #8
0
        protected string ValidateInlineXOML(string value, OwlHandler handler)
        {
            string[] parts = value.Split(new char[] { ':' }, 2);
            if (parts.Length == 1)
            {
                return(value);
            }
            else
            {
                IKeyword keyword = handler.KeywordsManager.GetInlineKeyword(parts, handler);
                if (keyword != null)
                {
                    return(keyword.GetValue(handler));
                }
            }

            return(value);
        }
Exemple #9
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");
                }
            }
        }
Exemple #10
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
        }
Exemple #11
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);
        }
Exemple #12
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);
        }
Exemple #13
0
        /// <summary>
        /// Get the Keyword
        /// </summary>
        /// <param name="node">Configuration node</param>
        /// <param name="handler">Orquestation</param>
        /// <returns>Keyword Object</returns>
        public IKeyword GetKeyword(XmlNode node, OwlHandler handler)
        {
            if (node == null)
            {
                return(null);
            }

            #region XOML

            if (node.HasChildNodes)
            {
                XmlNode nHijo = handler.ConfigMap.GetElementValueNode(node);
                if (nHijo != null)
                {
                    return(GetXOMLKeyword(nHijo.FirstChild, handler));
                }
            }

            #endregion

            #region Atributo

            #region Predeterminado

            if (node.Attributes["default"] != null)
            {
                return(new Default {
                    Value = node.Attributes["default"].Value
                });
            }

            #endregion

            #region Variable

            if (node.Attributes["variable"] != null)
            {
                return(new Variable {
                    Value = node.Attributes["variable"].Value
                });
            }

            #endregion

            #region Reservada

            if (node.Attributes["key"] != null)
            {
                return(new Key {
                    Value = node.Attributes["key"].Value
                });
            }

            #endregion

            #region Buscar

            if (!handler.Settings.Instance && node.Attributes["xpath"] != null)
            {
                return(new Xpath {
                    Value = node.Attributes["xpath"].Value
                });
            }

            #endregion

            #endregion

            return(null);
        }