/// <summary>
 /// Sets condition property of the specified rule from the xml node
 /// </summary>
 /// <param name="rule">The specified rule to have its condition property be set</param>
 /// <param name="condition">xml node containing the condition verification</param>
 private static void SetRuleCondition(ref Rule rule, XElement condition)
 {
     if (condition != null)
     {
         rule.Condition = VerifierFactory.Create(condition);
     }
 }
Esempio n. 2
0
        public static IVerifier Create(XElement xml)
        {
            var attrProcessor = xml.Attribute("processor");

            if (attrProcessor == null)
            {
                return(null);
            }

            IVerifier verifier = null;

            try
            {
                switch (attrProcessor.Value)
                {
                case "rng":
                    verifier = VerifierFactory.CreateRngVerifier(xml.Elements().Single());
                    break;

                case "regex":
                    verifier = VerifierFactory.CreateRegexVerifier(xml.Element("regex"));
                    break;

                case "headerregex":
                    verifier = VerifierFactory.CreateHeaderRegexVerifier(xml.Elements().Single());
                    break;

                case "xslt+rng":
                    verifier = VerifierFactory.CreateXsltRngVerifier(xml.Elements().Single());
                    break;

                case "jsonschema":
                    verifier = VerifierFactory.CreateJsonSchemaVerifier(xml.Element("jsonschema"));
                    break;

                case "xslt+jsonschema":
                    verifier = VerifierFactory.CreateXstJsonSchemaVerifier(xml.Elements().Single());
                    break;

                default:
                    // not supported processor types
                    break;
                }
            }
            catch (Exception e)
            {
                if (!ExceptionHelper.IsCatchableExceptionType(e))
                {
                    throw;
                }

                verifier = null;
            }

            return(verifier);
        }
 /// <summary>
 /// Sets action property of the specified rule from the xml node
 /// </summary>
 /// <param name="rule">The specified rule to have its action property be set</param>
 /// <param name="action">xml node containing the action verification</param>
 private static void SetRuleAction(ref Rule rule, XElement action)
 {
     rule.Action = VerifierFactory.Create(action);
 }