/// <summary> /// This method populates rule objects /// </summary> private void configureValidator() { try { if (this.ConfigXmlDocument == null) { throw new Exception("Xml configurations not set."); } var ruleElements = this.ConfigXmlDocument.Element("ConfigurationStore").Elements("Config").ToList()[0].Elements("rules").Descendants("rule").ToList(); if (ruleElements == null && ruleElements.Count == 0) { throw new Exception("No rules found...!!!"); } var ruleList = new List <IRule>(); foreach (var rulesElement in ruleElements) { var newRule = new ValidationRuleEngine.Implementations.Rule( (rulesElement.Attribute(XName.Get("name")) != null) ? rulesElement.Attribute(XName.Get("name")).Value : null, (rulesElement.Attribute(XName.Get("enabled")) == null) ? false : Convert.ToBoolean(rulesElement.Attribute(XName.Get("enabled")).Value)); var validationElements = rulesElement.Element(XName.Get("validations")) .Elements(XName.Get("validation")); if (validationElements != null && validationElements.Any()) { var validationList = new List <IValidation>(); foreach (var validationElement in validationElements) { Type elementType = Type.GetType(validationElement.Attribute(XName.Get("type")).Value); Validation newValidation = (Validation)Activator.CreateInstance(elementType, validationElement.Attribute(XName.Get("name")).Value, validationElement.Attribute(XName.Get("validator_type")).Value, (validationElement.Attribute(XName.Get("enabled")) != null) ? Convert.ToBoolean(validationElement.Attribute(XName.Get("enabled")).Value) : false, (validationElement.Attribute(XName.Get("on_failure_halt")) != null) ? Convert.ToBoolean(validationElement.Attribute(XName.Get("on_failure_halt")).Value) : false); //newValidation.Name = validationElement.Attribute(XName.Get("name")).Value; //newValidation.onFailureHalt = ; //newValidation.validator_type = ; //newValidation.enabled = ; //newValidation.currentXml = this.CurrentXmlDocument; var attributeElements = validationElement.Element(XName.Get("attributes")) .Elements(XName.Get("attribute")); if (attributeElements != null && attributeElements.Any()) { var attributeList = new List <ValidationRuleEngine.Configuration.Attribute>(); foreach (var attributeElement in attributeElements) { ValidationRuleEngine.Configuration.Attribute newAttribute = new Configuration.Attribute(); var serializer = new XmlSerializer(typeof(ValidationRuleEngine.Configuration.Attribute)); newAttribute = (ValidationRuleEngine.Configuration.Attribute)serializer.Deserialize(attributeElement.CreateReader()); attributeList.Add(newAttribute); } newValidation.LocalAttributes = attributeList; } var valActionElements = rulesElement.Element(XName.Get("actions")) .Elements(XName.Get("action")); if (valActionElements != null && valActionElements.Any()) { var actionList = new List <IAction>(); foreach (var valActionElement in valActionElements) { actionList.Add(Helper.XMLManagement <Action> .Instance.GetInstance <IAction>(valActionElement)); } newValidation.Actions = actionList; } newValidation.LoadGlobalAttributeValues(config.attributes, this.CurrentXmlDocument); validationList.Add(newValidation); } newRule.Validations = validationList; } var actionElements = rulesElement.Element(XName.Get("actions")) .Elements(XName.Get("action")); if (actionElements != null && actionElements.Any()) { var actionList = new List <IAction>(); foreach (var actionElement in actionElements) { actionList.Add(Helper.XMLManagement <Action> .Instance.GetInstance <IAction>(actionElement)); } newRule.Actions = actionList; } ruleList.Add(newRule); } this.Rules = ruleList; } catch (Exception ex) { Logger.Instance.GetLogInstance().Error(JsonConvert.SerializeObject(ex)); } }
/// <summary> /// This method populates rule objects /// </summary> private void configureValidator() { if (this.ConfigXmlDocument == null) { throw new Exception("Xml configurations not set."); } var ruleElements = this.ConfigXmlDocument.Element("ConfigurationStore").Elements("Config").ToList()[0].Elements("rules").Descendants("rule").ToList(); if (ruleElements == null && ruleElements.Count == 0) { throw new Exception("No rules found...!!!"); } var ruleList = new List <IRule>(); foreach (var rulesElement in ruleElements) { var newRule = new ValidationRuleEngine.Implementations.Rule( (rulesElement.Attribute(XName.Get("name")) != null) ? rulesElement.Attribute(XName.Get("name")).Value : null, (rulesElement.Element(XName.Get("path")) != null) ? rulesElement.Element(XName.Get("path")).Value : null, (rulesElement.Attribute(XName.Get("enabled")) == null) ? false : Convert.ToBoolean(rulesElement.Attribute(XName.Get("enabled")).Value)); var validationElements = rulesElement.Element(XName.Get("validations")) .Elements(XName.Get("validation")); if (validationElements != null && validationElements.Any()) { var validationList = new List <IValidation>(); foreach (var validationElement in validationElements) { var validation = XMLHelper <Validation> .Instance.GetInstance <IValidation>(validationElement); validation.LoadGlobalAttributeValues(this.config.attributes, this.CurrentXmlDocument); validationList.Add(validation); } newRule.Validations = validationList; } var actionElements = rulesElement.Element(XName.Get("actions")) .Elements(XName.Get("action")); if (actionElements != null && actionElements.Any()) { var actionList = new List <IAction>(); foreach (var actionElement in actionElements) { actionList.Add(XMLHelper <Action> .Instance.GetInstance <IAction>(actionElement)); } newRule.Actions = actionList; } ruleList.Add(newRule); } this.Rules = ruleList; }