/// <summary> /// Verifies the extension rule. /// </summary> /// <param name="context">The Interop service context</param> /// <param name="info">out parameter to return violation information when rule does not pass</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; if (context.PayloadType == RuleEngine.PayloadType.Feed) { JObject feed; context.ResponsePayload.TryToJObject(out feed); var entries = JsonParserHelper.GetEntries(feed); foreach (JObject entry in entries) { if (entry != null && entry.Type == JTokenType.Object) { var jProps = entry.Children(); // New a string to record the annotation name. string record = string.Empty; foreach (JProperty jProp in jProps) { if (JsonSchemaHelper.IsJSONArrayOrPrimitiveAnnotation(jProp.Name)) { record = jProp.Name; } else { if (record == string.Empty) { continue; } else { // Prase the annotation name to two parts. string[] splitedStr = record.Split('@'); // If the string before the sign "@" are the same with property name, this rule will passed. if (jProp.Name == splitedStr[0]) { passed = true; record = string.Empty; continue; } else { passed = false; info = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload); break; } } } } } } } else if (context.PayloadType == RuleEngine.PayloadType.Entry) { JObject entry; context.ResponsePayload.TryToJObject(out entry); if (entry != null && entry.Type == JTokenType.Object) { var jProps = entry.Children(); // New a string to record the annotation name. string record = string.Empty; foreach (JProperty jProp in jProps) { if (JsonSchemaHelper.IsJSONArrayOrPrimitiveAnnotation(jProp.Name)) { record = jProp.Name; } else { if (record == string.Empty) { continue; } else { // Prase the annotation name to two parts. string[] splitedStr = record.Split('@'); // If the string before the sign "@" are the same with property name, this rule will passed. if (jProp.Name == splitedStr[0]) { passed = true; record = string.Empty; continue; } else { passed = false; info = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload); break; } } } } } } return(passed); }
/// <summary> /// Verifies the extension rule. /// </summary> /// <param name="context">The Interop service context</param> /// <param name="info">out parameter to return violation information when rule does not pass</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; if (context.PayloadType == RuleEngine.PayloadType.Feed) { JObject feed; context.ResponsePayload.TryToJObject(out feed); var entries = JsonParserHelper.GetEntries(feed); foreach (JObject entry in entries) { if (entry != null && entry.Type == JTokenType.Object) { var jProps = entry.Children(); foreach (JProperty jProp in jProps) { if (JsonSchemaHelper.IsJSONArrayOrPrimitiveAnnotation(jProp.Name)) { passed = null; string[] splitedStr = jProp.Name.Split('@'); JProperty nextProp = jProp.Next as JProperty; JProperty prevProp = jProp.Previous as JProperty; string annotatedPropName = nextProp.Name == splitedStr[0] ? nextProp.Name : prevProp.Name; if (annotatedPropName.Contains(splitedStr[0])) { if (jProp.Name == annotatedPropName + Constants.V4OdataType) { passed = true; continue; } else { passed = false; info = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload); return(passed); } } } } } } } else if (context.PayloadType == RuleEngine.PayloadType.Entry) { JObject entry; context.ResponsePayload.TryToJObject(out entry); if (entry != null && entry.Type == JTokenType.Object) { var jProps = entry.Children(); foreach (JProperty jProp in jProps) { if (JsonSchemaHelper.IsJSONArrayOrPrimitiveAnnotation(jProp.Name)) { passed = null; string[] splitedStr = jProp.Name.Split('@'); JProperty nextProp = jProp.Next as JProperty; JProperty prevProp = jProp.Previous as JProperty; string annotatedPropName = nextProp.Name == splitedStr[0] ? nextProp.Name : prevProp.Name; if (annotatedPropName.Contains(splitedStr[0])) { if (jProp.Name == annotatedPropName + Constants.V4OdataType) { passed = true; continue; } else { passed = false; info = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload); return(passed); } } } } } } return(passed); }