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

            context.ResponsePayload.TryToJObject(out entry);

            if (entry != null && entry.Type == JTokenType.Object)
            {
                JsonParserHelper.ClearPropertiesList();
                List <JProperty> props = JsonParserHelper.GetSpecifiedPropertiesFromEntryPayload(entry, @"type");

                foreach (var prop in props)
                {
                    if (@"LineString" == prop.Value.ToString().Trim('"'))
                    {
                        var nextProp = prop.Next as JProperty;

                        if (@"coordinates" != nextProp.Name)
                        {
                            continue;
                        }

                        var coordinateVals = nextProp.Value as JArray;

                        if (coordinateVals.Count >= 0)
                        {
                            passed = true;
                        }
                        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");
            }

            List <string> GeoTypes = new List <string>()
            {
                @"Point", @"LineString", @"Polygon", @"MultiPoint", @"MultiPolygon", @"GeometryCollection",
            };

            bool?passed = null;

            info = null;

            JObject entry;

            context.ResponsePayload.TryToJObject(out entry);

            if (entry != null && entry.Type == JTokenType.Object)
            {
                JsonParserHelper.ClearPropertiesList();
                List <JProperty> props = JsonParserHelper.GetSpecifiedPropertiesFromEntryPayload(entry, @"type");

                foreach (JProperty prop in props)
                {
                    if (GeoTypes.Contains(prop.Value.ToString().Trim('"')))
                    {
                        JProperty firstChild  = prop.Parent.First as JProperty;
                        JProperty secondChild = firstChild.Next as JProperty;

                        if (firstChild.Name == @"type" && secondChild.Name == @"coordinates")
                        {
                            passed = true;
                        }
                        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;

            JObject entry;

            context.ResponsePayload.TryToJObject(out entry);

            List <string> expandProps = ODataUriAnalyzer.GetQueryOptionValsFromUrl(context.Destination.ToString(), @"expand");

            if (entry != null && entry.Type == JTokenType.Object && expandProps.Count > 0)
            {
                var props = entry.Children();

                foreach (JProperty prop in props)
                {
                    if (expandProps.Contains(prop.Name))
                    {
                        passed = null;

                        if (prop.Value.Type == JTokenType.Object)
                        {
                            JObject jObj = prop.Value as JObject;
                            JsonParserHelper.ClearPropertiesList();

                            if (JsonParserHelper.GetSpecifiedPropertiesFromEntryPayload(jObj, Constants.OdataV4JsonIdentity).Count > 0)
                            {
                                passed = true;
                                break;
                            }
                            else
                            {
                                passed = false;
                            }
                        }
                        else if (prop.Value.Type == JTokenType.Array)
                        {
                            JArray jArr = prop.Value as JArray;

                            if (JsonParserHelper.GetSpecifiedPropertiesFromFeedPayload(jArr, Constants.OdataV4JsonIdentity).Count > 0)
                            {
                                passed = true;
                                break;
                            }
                            else
                            {
                                passed = false;
                            }
                        }
                    }
                }

                if (passed == false)
                {
                    info = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload);
                }
            }

            return(passed);
        }
Beispiel #4
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 entry;

            context.ResponsePayload.TryToJObject(out entry);

            if (entry != null && entry.Type == JTokenType.Object)
            {
                JsonParserHelper.ClearPropertiesList();
                List <JProperty> props = JsonParserHelper.GetSpecifiedPropertiesFromEntryPayload(entry, @"crs");

                foreach (var prop in props)
                {
                    if (prop.Value.Type == JTokenType.Object)
                    {
                        JProperty typeProp       = null;
                        JProperty propertiesProp = null;

                        var crsProps = prop.Value.Children();

                        foreach (JProperty crsProp in crsProps)
                        {
                            if (@"type" == crsProp.Name)
                            {
                                typeProp = crsProp;
                            }

                            if (@"properties" == crsProp.Name)
                            {
                                propertiesProp = crsProp;
                            }

                            if (typeProp != null && propertiesProp != null)
                            {
                                JProperty nameProp = null;

                                if (propertiesProp.Value.Type == JTokenType.Object)
                                {
                                    var ps = propertiesProp.Value.Children();

                                    foreach (JProperty p in ps)
                                    {
                                        if (@"name" == p.Name)
                                        {
                                            nameProp = p;
                                        }
                                    }
                                }

                                if (nameProp != null &&
                                    @"name" == typeProp.Value.ToString().Trim('"') &&
                                    nameProp.Value.ToString().Trim('"').Contains(@"EPSG"))
                                {
                                    passed = true;
                                }
                                else
                                {
                                    passed = false;
                                    info   = new ExtensionRuleViolationInfo(this.ErrorMessage, context.Destination, context.ResponsePayload);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(passed);
        }