Exemple #1
0
        private bool TryReadMessagePropertyValue(ODataError error)
        {
            this.ReadInternal();
            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                return(false);
            }
            this.ReadInternal();
            ODataJsonReaderUtils.ErrorPropertyBitMask none = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                string str2;
                string str3;
                string str4 = (string)this.currentBufferedNode.Value;
                if (str4 == null)
                {
                    goto Label_009D;
                }
                if (!(str4 == "lang"))
                {
                    if (str4 == "value")
                    {
                        goto Label_007B;
                    }
                    goto Label_009D;
                }
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageLanguage) && this.TryReadErrorStringPropertyValue(out str2))
                {
                    error.MessageLanguage = str2;
                    goto Label_009F;
                }
                return(false);

Label_007B:
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue) && this.TryReadErrorStringPropertyValue(out str3))
                {
                    error.Message = str3;
                    goto Label_009F;
                }
                return(false);

Label_009D:
                return(false);

Label_009F:
                this.ReadInternal();
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Try to read an inner error property value.
        /// </summary>
        /// <param name="innerError">An <see cref="ODataInnerError"/> instance that was read from the reader or null if none could be read.</param>
        /// <param name="recursionDepth">The number of times this method has been called recursively.</param>
        /// <returns>true if an <see cref="ODataInnerError"/> instance that was read; otherwise false.</returns>
        private bool TryReadInnerErrorPropertyValue(out ODataInnerError innerError, int recursionDepth)
        {
            Debug.Assert(this.currentBufferedNode.NodeType == JsonNodeType.Property, "this.currentBufferedNode.NodeType == JsonNodeType.Property");
            Debug.Assert(this.parsingInStreamError, "this.parsingInStreamError");
            this.AssertBuffering();

            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, this.maxInnerErrorDepth);

            // move the reader onto the property value
            this.ReadInternal();

            // we expect a start-object node here
            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                innerError = null;
                return(false);
            }

            // read the start-object node
            this.ReadInternal();

            innerError = new ODataInnerError();

            // we expect one of the supported properties for the value (or end-object)
            ODataJsonReaderUtils.ErrorPropertyBitMask propertiesFoundBitmask = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                // NOTE the Json reader already ensures that the value of a property node is a string
                string propertyName = (string)this.currentBufferedNode.Value;

                switch (propertyName)
                {
                case JsonConstants.ODataErrorInnerErrorMessageName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue))
                    {
                        return(false);
                    }

                    string message;
                    if (this.TryReadErrorStringPropertyValue(out message))
                    {
                        innerError.Message = message;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorInnerErrorTypeNameName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.TypeName))
                    {
                        return(false);
                    }

                    string typeName;
                    if (this.TryReadErrorStringPropertyValue(out typeName))
                    {
                        innerError.TypeName = typeName;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorInnerErrorStackTraceName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.StackTrace))
                    {
                        return(false);
                    }

                    string stackTrace;
                    if (this.TryReadErrorStringPropertyValue(out stackTrace))
                    {
                        innerError.StackTrace = stackTrace;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorInnerErrorInnerErrorName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError))
                    {
                        return(false);
                    }

                    ODataInnerError nestedInnerError;
                    if (this.TryReadInnerErrorPropertyValue(out nestedInnerError, recursionDepth))
                    {
                        innerError.InnerError = nestedInnerError;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                default:
                    // if we find a non-supported property in an inner error, we skip it
                    this.SkipValueInternal();
                    break;
                }

                this.ReadInternal();
            }

            Debug.Assert(this.currentBufferedNode.NodeType == JsonNodeType.EndObject, "this.currentBufferedNode.NodeType == JsonNodeType.EndObject");

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Try to read the message property value of an error value.
        /// </summary>
        /// <param name="error">An <see cref="ODataError"/> instance to set the read message property values on.</param>
        /// <returns>true if the message property values could be read; otherwise false.</returns>
        private bool TryReadMessagePropertyValue(ODataError error)
        {
            Debug.Assert(error != null, "error != null");
            Debug.Assert(this.currentBufferedNode.NodeType == JsonNodeType.Property, "this.currentBufferedNode.NodeType == JsonNodeType.Property");
            Debug.Assert(this.parsingInStreamError, "this.parsingInStreamError");
            this.AssertBuffering();

            // move the reader onto the property value
            this.ReadInternal();

            // we expect a start-object node here
            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                return(false);
            }

            // read the start-object node
            this.ReadInternal();

            // we expect one of the supported properties for the value (or end-object)
            ODataJsonReaderUtils.ErrorPropertyBitMask propertiesFoundBitmask = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                // NOTE the Json reader already ensures that the value of a property node is a string
                string propertyName = (string)this.currentBufferedNode.Value;

                switch (propertyName)
                {
                case JsonConstants.ODataErrorMessageLanguageName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageLanguage))
                    {
                        return(false);
                    }

                    string lang;
                    if (this.TryReadErrorStringPropertyValue(out lang))
                    {
                        error.MessageLanguage = lang;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorMessageValueName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue))
                    {
                        return(false);
                    }

                    string message;
                    if (this.TryReadErrorStringPropertyValue(out message))
                    {
                        error.Message = message;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                default:
                    // if we find a non-supported property we don't treat this as an error
                    return(false);
                }

                this.ReadInternal();
            }

            Debug.Assert(this.currentBufferedNode.NodeType == JsonNodeType.EndObject, "this.currentBufferedNode.NodeType == JsonNodeType.EndObject");

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Try to read an error structure from the stream. Return null if no error structure can be read.
        /// </summary>
        /// <param name="error">An <see cref="ODataError"/> instance that was read from the reader or null if none could be read.</param>
        /// <returns>true if an <see cref="ODataError"/> instance that was read; otherwise false.</returns>
        private bool TryReadErrorPropertyValue(out ODataError error)
        {
            Debug.Assert(this.parsingInStreamError, "this.parsingInStreamError");
            this.AssertBuffering();

            error = null;

            // we expect a start-object node here
            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                return(false);
            }

            // read the start-object node
            this.ReadInternal();

            error = new ODataError();

            // we expect one of the supported properties for the value (or end-object)
            ODataJsonReaderUtils.ErrorPropertyBitMask propertiesFoundBitmask = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                // NOTE the Json reader already ensures that the value of a property node is a string
                string propertyName = (string)this.currentBufferedNode.Value;
                switch (propertyName)
                {
                case JsonConstants.ODataErrorCodeName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.Code))
                    {
                        return(false);
                    }

                    string errorCode;
                    if (this.TryReadErrorStringPropertyValue(out errorCode))
                    {
                        error.ErrorCode = errorCode;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorMessageName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.Message))
                    {
                        return(false);
                    }

                    if (!this.TryReadMessagePropertyValue(error))
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorInnerErrorName:
                    if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError))
                    {
                        return(false);
                    }

                    ODataInnerError innerError;
                    if (!this.TryReadInnerErrorPropertyValue(out innerError, 0 /*recursionDepth */))
                    {
                        return(false);
                    }

                    error.InnerError = innerError;
                    break;

                default:
                    // if we find a non-supported property we don't treat this as an error
                    return(false);
                }

                this.ReadInternal();
            }

            // read the end object
            Debug.Assert(this.currentBufferedNode.NodeType == JsonNodeType.EndObject, "this.currentBufferedNode.NodeType == JsonNodeType.EndObject");
            this.ReadInternal();

            // if we don't find any properties it is not a valid error object
            return(propertiesFoundBitmask != ODataJsonReaderUtils.ErrorPropertyBitMask.None);
        }
Exemple #5
0
        private bool TryReadInnerErrorPropertyValue(out ODataInnerError innerError, int recursionDepth)
        {
            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, this.maxInnerErrorDepth);
            this.ReadInternal();
            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                innerError = null;
                return(false);
            }
            this.ReadInternal();
            innerError = new ODataInnerError();
            ODataJsonReaderUtils.ErrorPropertyBitMask none = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                string          str2;
                string          str3;
                string          str4;
                ODataInnerError error;
                string          str5 = (string)this.currentBufferedNode.Value;
                if (str5 == null)
                {
                    goto Label_0125;
                }
                if (!(str5 == "message"))
                {
                    if (str5 == "type")
                    {
                        goto Label_00B6;
                    }
                    if (str5 == "stacktrace")
                    {
                        goto Label_00D9;
                    }
                    if (str5 == "internalexception")
                    {
                        goto Label_0100;
                    }
                    goto Label_0125;
                }
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue) && this.TryReadErrorStringPropertyValue(out str2))
                {
                    innerError.Message = str2;
                    goto Label_012B;
                }
                return(false);

Label_00B6:
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.TypeName) && this.TryReadErrorStringPropertyValue(out str3))
                {
                    innerError.TypeName = str3;
                    goto Label_012B;
                }
                return(false);

Label_00D9:
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.StackTrace) && this.TryReadErrorStringPropertyValue(out str4))
                {
                    innerError.StackTrace = str4;
                    goto Label_012B;
                }
                return(false);

Label_0100:
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError) && this.TryReadInnerErrorPropertyValue(out error, recursionDepth))
                {
                    innerError.InnerError = error;
                    goto Label_012B;
                }
                return(false);

Label_0125:
                this.SkipValueInternal();
Label_012B:
                this.ReadInternal();
            }
            return(true);
        }
Exemple #6
0
        private bool TryReadErrorPropertyValue(out ODataError error)
        {
            error = null;
            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                return(false);
            }
            this.ReadInternal();
            error = new ODataError();
            ODataJsonReaderUtils.ErrorPropertyBitMask none = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                string          str2;
                ODataInnerError error2;
                string          str3 = (string)this.currentBufferedNode.Value;
                if (str3 == null)
                {
                    goto Label_00CC;
                }
                if (!(str3 == "code"))
                {
                    if (str3 == "message")
                    {
                        goto Label_0090;
                    }
                    if (str3 == "innererror")
                    {
                        goto Label_00A8;
                    }
                    goto Label_00CC;
                }
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Code) && this.TryReadErrorStringPropertyValue(out str2))
                {
                    error.ErrorCode = str2;
                    goto Label_00CE;
                }
                return(false);

Label_0090:
                if (ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Message) && this.TryReadMessagePropertyValue(error))
                {
                    goto Label_00CE;
                }
                return(false);

Label_00A8:
                if (!ODataJsonReaderUtils.ErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError))
                {
                    return(false);
                }
                if (!this.TryReadInnerErrorPropertyValue(out error2, 0))
                {
                    return(false);
                }
                error.InnerError = error2;
                goto Label_00CE;
Label_00CC:
                return(false);

Label_00CE:
                this.ReadInternal();
            }
            this.ReadInternal();
            return(none != ODataJsonReaderUtils.ErrorPropertyBitMask.None);
        }