/// <summary>
        /// Carrega as informações de validação de entrada para um grupo de regra de entrada específico.
        /// </summary>
        /// <param name="inputRulesGroupId"></param>
        /// <param name="uiContext"></param>
        /// <returns></returns>
        public override IInputValidationInfo GetInputValidateInfo(int inputRulesGroupId, string uiContext)
        {
            var           result        = new InputValidationInfo();
            InputValidate inputValidate = Settings.GetInputValidate(inputRulesGroupId, uiContext);

            if (inputValidate != null)
            {
                var aggregateValidator = new Validators.AggregateValidator();
                CalculateInputValidateInfo(result, inputValidate, aggregateValidator, new List <Guid>());
            }
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Lê os dados serializados.
 /// </summary>
 /// <param name="reader"></param>
 void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
 {
     reader.MoveToElement();
     if (!reader.IsEmptyElement)
     {
         reader.ReadStartElement();
         while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
         {
             if (reader.IsEmptyElement)
             {
                 reader.Skip();
                 continue;
             }
             if (reader.LocalName == "EntityTypes")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "EntityType")
                     {
                         var type = new EntityType();
                         ((System.Xml.Serialization.IXmlSerializable)type).ReadXml(reader);
                         EntityTypes.Add(type);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "PropertySettings")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "PropertySetting")
                     {
                         var settings = new PropertySettings();
                         ((System.Xml.Serialization.IXmlSerializable)settings).ReadXml(reader);
                         PropertySettings.Add(settings);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "ValidationTypes")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "ValidationType")
                     {
                         var validationType = new ValidationType();
                         ((System.Xml.Serialization.IXmlSerializable)validationType).ReadXml(reader);
                         ValidationTypes.Add(validationType);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "Validations")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "Validation")
                     {
                         var validation = new Validation();
                         ((System.Xml.Serialization.IXmlSerializable)validation).ReadXml(reader);
                         Validations.Add(validation);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "InputRules")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "InputRules")
                     {
                         var inputRules = new InputRules();
                         ((System.Xml.Serialization.IXmlSerializable)inputRules).ReadXml(reader);
                         InputRules.Add(inputRules);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "InputRulesGroups")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "InputRulesGroup")
                     {
                         var inputRulesGroup = new InputRulesGroup();
                         ((System.Xml.Serialization.IXmlSerializable)inputRulesGroup).ReadXml(reader);
                         InputRulesGroups.Add(inputRulesGroup);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "InputValidates")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "InputValidate")
                     {
                         var validate = new InputValidate();
                         ((System.Xml.Serialization.IXmlSerializable)validate).ReadXml(reader);
                         InputValidates.Add(validate);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else
             {
                 reader.Skip();
             }
         }
         reader.ReadEndElement();
     }
 }
        /// <summary>
        /// Calcula as informações de um Inputvalidate.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="inputValidate"></param>
        /// <param name="aggregateValidator"></param>
        /// <param name="ignoreUids">Identificador da validações que deve ser ignoradas</param>
        private void CalculateInputValidateInfo(IInputValidationInfo info, InputValidate inputValidate, Validators.AggregateValidator aggregateValidator, IList <Guid> ignoreUids)
        {
            if (inputValidate != null && !ignoreUids.Contains(inputValidate.Uid))
            {
                ignoreUids.Add(inputValidate.Uid);
                switch (inputValidate.Type)
                {
                case InputValidateType.CharacterUpperCase:
                    info.CharCase = CharacterCase.Upper;
                    break;

                case InputValidateType.CharacterLowerCase:
                    info.CharCase = CharacterCase.Lower;
                    break;

                case InputValidateType.Customization:
                    info.Customization = inputValidate.Customization;
                    if (info.Customization != null)
                    {
                        aggregateValidator.Add(new Validators.CustomizationValidator(info.Customization));
                    }
                    break;

                case InputValidateType.CheckDigits:
                    info.CheckDigits = inputValidate.CheckDigits;
                    if (info.CheckDigits != null)
                    {
                        aggregateValidator.Add(new Validators.CheckDigitsValidator(info.CheckDigits));
                    }
                    break;

                case InputValidateType.DefaultValue:
                    info.DefaultValue = inputValidate.Default;
                    break;

                case InputValidateType.Group:
                    foreach (var i in inputValidate.Group.Items.Select(f => Settings.InputValidates.FirstOrDefault(x => x.Uid == f.InputValidateUid)).Where(f => f != null))
                    {
                        CalculateInputValidateInfo(info, i, aggregateValidator, ignoreUids);
                    }
                    break;

                case InputValidateType.IndexedValues:
                    info.IndexedValues = inputValidate.IndexedValues;
                    break;

                case InputValidateType.Length:
                    info.Length = inputValidate.Length;
                    if (info.Length != null)
                    {
                        aggregateValidator.Add(new Validators.LengthValidator(info.Length));
                    }
                    break;

                case InputValidateType.Mask:
                    info.Mask = inputValidate.Mask;
                    break;

                case InputValidateType.Range:
                    info.Range = inputValidate.Range;
                    if (info.Range != null)
                    {
                        aggregateValidator.Add(new Validators.RangeValidator(info.Range));
                    }
                    break;

                case InputValidateType.ValidChars:
                    info.ValidChars = inputValidate.ValidChars;
                    if (info.ValidChars != null)
                    {
                        aggregateValidator.Add(new Validators.ValidCharsValidator(info.ValidChars));
                    }
                    break;

                case InputValidateType.Values:
                    info.Values = inputValidate.Values;
                    break;
                }
            }
        }