/// <summary> /// Verify the code rule /// </summary> /// <param name="context">Service context</param> /// <param name="info">out paramater to return violation information when rule fail</param> /// <returns>true if rule passes; false otherwise</returns> public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info) { if (context == null) { throw new ArgumentNullException("context"); } bool?passed = null; info = null; XElement meta = XElement.Parse(context.MetadataDocument); XElement entry = XElement.Parse(context.ResponsePayload); string xpath = string.Format(".//*[local-name()='EntityType' and @Name='{0}']/*[local-name()='Property' and @Name and @m:FC_TargetPath]", context.EntityTypeShortName); var mappedProperties = meta.XPathSelectElements(xpath, ODataNamespaceManager.Instance); foreach (var mp in mappedProperties) { var custFeedProperty = new EntryCore2012CFP(mp, entry); string schema = custFeedProperty.GetRngSchema(); RngVerifier verifier = new RngVerifier(schema); TestResult result; passed = verifier.Verify(context, out result); if (!passed.Value) { info = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload, result.LineNumberInError); break; } } return(passed); }
/// <summary> /// Verify the code rule /// </summary> /// <param name="context">Service context</param> /// <param name="info">out paramater to return violation information when rule fail</param> /// <returns>true if rule passes; false otherwise</returns> public override bool? Verify(ServiceContext context, out ExtensionRuleViolationInfo info) { if (context == null) { throw new ArgumentNullException("context"); } bool? passed = null; info = null; XElement meta = XElement.Parse(context.MetadataDocument); XElement entry = XElement.Parse(context.ResponsePayload); string xpath = string.Format(".//*[local-name()='EntityType' and @Name='{0}']/*[local-name()='Property' and @Name and @m:FC_TargetPath]", context.EntityTypeShortName); var mappedProperties = meta.XPathSelectElements(xpath, ODataNamespaceManager.Instance); foreach (var mp in mappedProperties) { var custFeedProperty = new EntryCore2012CFP(mp, entry); string schema = custFeedProperty.GetRngSchema(); RngVerifier verifier = new RngVerifier(schema); TestResult result; passed = verifier.Verify(context, out result); if (!passed.Value) { info = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload, result.LineNumberInError); break; } } return passed; }