/// <summary> /// Recupera o criador de validadores. /// </summary> /// <param name="validationType">Tipo de validação.</param> /// <param name="culture"></param> /// <returns></returns> private IValidatorCreator GetValidatorCreator(ValidationType validationType, System.Globalization.CultureInfo culture) { IValidatorCreator creator = null; bool found = false; lock (_validatorCreators) found = _validatorCreators.TryGetValue(validationType.ValidationTypeId, out creator); if (!found) { System.Reflection.Assembly assembly = null; if (Reflection.AssemblyLoader.Instance.TryGet(validationType.Type.AssemblyName.Name, out assembly)) { Type validatorType = null; try { validatorType = assembly.GetType(validationType.Type.FullName, true, false); } catch (Exception ex) { _logger.Error(ResourceMessageFormatter.Create(() => Properties.Resources.GeneralValidationManager_ValidationTypeGetTypeError, validationType.Type.FullName, validationType.Name, Diagnostics.ExceptionFormatter.FormatException(ex, true)), ex); } if (validationType != null) { creator = ValidatorCreator.CreateCreator(validatorType, culture); lock (_validatorCreators) if (!_validatorCreators.ContainsKey(validationType.ValidationTypeId)) { _validatorCreators.Add(validationType.ValidationTypeId, creator); } } } else { _logger.Error(ResourceMessageFormatter.Create(() => Properties.Resources.GeneralValidationManager_ValidationTypeAssemblyNotFound, validationType.Type.AssemblyName.Name, validationType.Name)); } } return(creator); }
/// <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(); } }