/// <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;

            JObject allobject;

            context.ResponsePayload.TryToJObject(out allobject);

            List <string> links = JsonParserHelper.GetPropValuesFromJSONObject(allobject, Constants.V4OdataId, StringCompareType.Equal);

            if (links.Count > 0)
            {
                passed = true;
            }
            else
            {
                passed = false;
                info   = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload);
            }

            return(passed);
        }
示例#2
0
        /// <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;

            JObject allobject;

            context.ResponsePayload.TryToJObject(out allobject);
            string mediaReadLinkAnnotation = Constants.V4OdataMediaEditLink;

            if (context.Version == ODataVersion.V3)
            {
                mediaReadLinkAnnotation = Constants.OdataMediaEditLink;
            }

            List <string> links = JsonParserHelper.GetPropValuesFromJSONObject(allobject, mediaReadLinkAnnotation, StringCompareType.Contain);

            if (links.Count > 0)
            {
                foreach (string link in links)
                {
                    if (!Uri.IsWellFormedUriString(link, UriKind.RelativeOrAbsolute))
                    {
                        passed = false;
                        info   = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload);
                        break;
                    }
                }

                if (passed == null)
                {
                    passed = true;
                }
            }

            return(passed);
        }