/// <summary> /// Write an inner error property and message. /// </summary> /// <param name="jsonWriter">The JSON writer to write the error to.</param> /// <param name="innerError">Inner error details.</param> /// <param name="innerErrorPropertyName">The property name for the inner error property.</param> /// <param name="recursionDepth">The number of times this method has been called recursively.</param> /// <param name="maxInnerErrorDepth">The maximumum number of nested inner errors to allow.</param> private static void WriteInnerError(JsonWriter jsonWriter, ODataInnerError innerError, string innerErrorPropertyName, int recursionDepth, int maxInnerErrorDepth) { Debug.Assert(jsonWriter != null, "jsonWriter != null"); Debug.Assert(innerErrorPropertyName != null, "innerErrorPropertyName != null"); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth); // "innererror": { jsonWriter.WriteName(innerErrorPropertyName); jsonWriter.StartObjectScope(); //// NOTE: we add empty elements if no information is provided for the message, error type and stack trace //// to stay compatible with Astoria. // "message": "<message>" jsonWriter.WriteName(JsonConstants.ODataErrorInnerErrorMessageName); jsonWriter.WriteValue(innerError.Message ?? string.Empty); // "type": "<typename"> jsonWriter.WriteName(JsonConstants.ODataErrorInnerErrorTypeNameName); jsonWriter.WriteValue(innerError.TypeName ?? string.Empty); // "stacktrace": "<stacktrace>" jsonWriter.WriteName(JsonConstants.ODataErrorInnerErrorStackTraceName); jsonWriter.WriteValue(innerError.StackTrace ?? string.Empty); if (innerError.InnerError != null) { // "internalexception": { <nested inner error> } ODataJsonWriterUtils.WriteInnerError(jsonWriter, innerError.InnerError, JsonConstants.ODataErrorInnerErrorInnerErrorName, recursionDepth, maxInnerErrorDepth); } // } jsonWriter.EndObjectScope(); }
/// <summary> /// Reads an inner error payload. /// </summary> /// <param name="recursionDepth">The number of times this method has been called recursively.</param> /// <returns>An <see cref="ODataInnerError"/> representing the read inner error.</returns> /// <remarks> /// Pre-Condition: any - will throw if not StartObject /// Post-Condition: JsonNodeType.Property - The next property in the error value /// JsonNodeType.EndObject - The end of the error value /// </remarks> private ODataInnerError ReadInnerError(int recursionDepth) { Debug.Assert(this.JsonReader.DisableInStreamErrorDetection, "JsonReader.DisableInStreamErrorDetection"); this.JsonReader.AssertNotBuffering(); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, this.MessageReaderSettings.MessageQuotas.MaxNestingDepth); this.JsonReader.ReadStartObject(); ODataInnerError innerError = new ODataInnerError(); ODataJsonReaderUtils.ErrorPropertyBitMask propertiesFoundBitField = ODataJsonReaderUtils.ErrorPropertyBitMask.None; while (this.JsonReader.NodeType == JsonNodeType.Property) { string propertyName = this.JsonReader.ReadPropertyName(); switch (propertyName) { case JsonConstants.ODataErrorInnerErrorMessageName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, JsonConstants.ODataErrorInnerErrorMessageName); innerError.Message = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorInnerErrorMessageName); break; case JsonConstants.ODataErrorInnerErrorTypeNameName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.TypeName, JsonConstants.ODataErrorInnerErrorTypeNameName); innerError.TypeName = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorInnerErrorTypeNameName); break; case JsonConstants.ODataErrorInnerErrorStackTraceName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.StackTrace, JsonConstants.ODataErrorInnerErrorStackTraceName); innerError.StackTrace = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorInnerErrorStackTraceName); break; case JsonConstants.ODataErrorInnerErrorInnerErrorName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, JsonConstants.ODataErrorInnerErrorInnerErrorName); innerError.InnerError = this.ReadInnerError(recursionDepth); break; default: // skip any unsupported properties in the inner error this.JsonReader.SkipValue(); break; } } this.JsonReader.ReadEndObject(); this.JsonReader.AssertNotBuffering(); return(innerError); }
/// <summary> /// Reads the json object value from the jsonReader /// </summary> /// <param name="jsonReader">Json reader to read payload from the wire.</param> /// <param name="insideJsonObjectValue">true if the reader is positioned on the first property of the value which is a JSON Object /// (or the second property if the first one was odata.type).</param> /// <param name="inputContext">The input context with all the settings.</param> /// <param name="recursionDepth">The recursion depth to start with.</param> /// <returns>an instance of IDictionary containing the spatial value.</returns> private static IDictionary <string, object> ReadObjectValue(JsonReader jsonReader, bool insideJsonObjectValue, ODataInputContext inputContext, int recursionDepth) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(jsonReader != null, "jsonReader != null"); Debug.Assert(insideJsonObjectValue || jsonReader.NodeType == JsonNodeType.StartObject, "insideJsonObjectValue || jsonReader.NodeType == JsonNodeType.StartObject"); Debug.Assert( !insideJsonObjectValue || jsonReader.NodeType == JsonNodeType.Property || jsonReader.NodeType == JsonNodeType.EndObject, "!insideJsonObjectValue || jsonReader.NodeType == JsonNodeType.Property || jsonReader.NodeType == JsonNodeType.EndObject"); Debug.Assert(inputContext != null, "inputContext != null"); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, inputContext.MessageReaderSettings.MessageQuotas.MaxNestingDepth); IDictionary <string, object> jsonValue = new Dictionary <string, object>(StringComparer.Ordinal); if (!insideJsonObjectValue) { // Note that if the insideJsonObjectValue is true we will ignore the odata.type instance annotation // which might have been there. This is OK since for spatial we only need the normal properties anyway. jsonReader.ReadNext(); } while (jsonReader.NodeType != JsonNodeType.EndObject) { // read the property name string propertyName = jsonReader.ReadPropertyName(); // read the property value object propertyValue = null; switch (jsonReader.NodeType) { case JsonNodeType.PrimitiveValue: propertyValue = jsonReader.ReadPrimitiveValue(); break; case JsonNodeType.StartArray: propertyValue = ReadArrayValue(jsonReader, inputContext, recursionDepth); break; case JsonNodeType.StartObject: propertyValue = ReadObjectValue(jsonReader, /*insideJsonObjectValue*/ false, inputContext, recursionDepth); break; default: Debug.Assert(false, "We should never reach here - There should be matching end element"); return(null); } jsonValue.Add(propertyName, propertyValue); } jsonReader.ReadEndObject(); return(jsonValue); }
private ODataInnerError ReadInnerError(int recursionDepth) { ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, base.MessageReaderSettings.MessageQuotas.MaxNestingDepth); base.JsonReader.ReadStartObject(); ODataInnerError error = new ODataInnerError(); ODataJsonReaderUtils.ErrorPropertyBitMask none = ODataJsonReaderUtils.ErrorPropertyBitMask.None; while (base.JsonReader.NodeType == JsonNodeType.Property) { string str2 = base.JsonReader.ReadPropertyName(); if (str2 == null) { goto Label_010E; } if (!(str2 == "message")) { if (str2 == "type") { goto Label_00A2; } if (str2 == "stacktrace") { goto Label_00C8; } if (str2 == "internalexception") { goto Label_00F1; } goto Label_010E; } ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, "message"); error.Message = base.JsonReader.ReadStringValue("message"); continue; Label_00A2: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.TypeName, "type"); error.TypeName = base.JsonReader.ReadStringValue("type"); continue; Label_00C8: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.StackTrace, "stacktrace"); error.StackTrace = base.JsonReader.ReadStringValue("stacktrace"); continue; Label_00F1: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, "internalexception"); error.InnerError = this.ReadInnerError(recursionDepth); continue; Label_010E: base.JsonReader.SkipValue(); } base.JsonReader.ReadEndObject(); return(error); }
/// <summary> /// Reads an inner error payload. /// </summary> /// <param name="recursionDepth">The number of times this method has been called recursively.</param> /// <returns>An <see cref="ODataInnerError"/> representing the read inner error.</returns> /// <remarks> /// Pre-Condition: JsonNodeType.StartObject - The start of the "innererror" object. /// any - will throw if not StartObject. /// Post-Condition: any - The node after the "innererror" object's EndNode. /// </remarks> private ODataInnerError ReadInnerError(int recursionDepth) { Debug.Assert(this.JsonReader.DisableInStreamErrorDetection, "JsonReader.DisableInStreamErrorDetection"); this.JsonReader.AssertNotBuffering(); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, this.MessageReaderSettings.MessageQuotas.MaxNestingDepth); ODataInnerError innerError = new ODataInnerError(); this.ReadJsonObjectInErrorPayload((propertyName, duplicatePropertyNamesChecker) => this.ReadPropertyValueInInnerError(recursionDepth, innerError, propertyName)); this.JsonReader.AssertNotBuffering(); return(innerError); }
/// <summary> /// Asynchronously reads an inner error object. /// </summary> /// <param name="recursionDepth">The number of times this method has been called recursively.</param> /// <returns> /// A task that represents the asynchronous read operation. /// The value of the TResult parameter contains an <see cref="ODataInnerError"/> representing the read inner error. /// </returns> /// <remarks> /// Pre-Condition: JsonNodeType.StartObject - The start of the "innererror" object. /// any - will throw if not StartObject. /// Post-Condition: any - The node after the "innererror" object's EndNode. /// </remarks> private async Task <ODataInnerError> ReadInnerErrorAsync(int recursionDepth) { Debug.Assert(this.JsonReader.DisableInStreamErrorDetection, "JsonReader.DisableInStreamErrorDetection"); this.JsonReader.AssertNotBuffering(); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, this.MessageReaderSettings.MessageQuotas.MaxNestingDepth); ODataInnerError innerError = new ODataInnerError(); await this.ReadJsonObjectInErrorPayloadAsync( (propertyName, propertyAndAnnotationCollector) => this.ReadPropertyValueInInnerErrorAsync(recursionDepth, innerError, propertyName)).ConfigureAwait(false); this.JsonReader.AssertNotBuffering(); return(innerError); }
/// <summary> /// Write an inner error property and message. /// </summary> /// <param name="jsonWriter">The JSON writer to write the error to.</param> /// <param name="innerError">Inner error details.</param> /// <param name="innerErrorPropertyName">The property name for the inner error property.</param> /// <param name="recursionDepth">The number of times this method has been called recursively.</param> /// <param name="maxInnerErrorDepth">The maximum number of nested inner errors to allow.</param> private static void WriteInnerError( IJsonWriter jsonWriter, ODataInnerError innerError, string innerErrorPropertyName, int recursionDepth, int maxInnerErrorDepth) { Debug.Assert(jsonWriter != null, "jsonWriter != null"); Debug.Assert(innerErrorPropertyName != null, "innerErrorPropertyName != null"); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth); // "innererror": jsonWriter.WriteName(innerErrorPropertyName); jsonWriter.StartObjectScope(); if (innerError.Properties != null) { foreach (KeyValuePair <string, ODataValue> pair in innerError.Properties) { jsonWriter.WriteName(pair.Key); if (pair.Value is ODataNullValue && (pair.Key == JsonConstants.ODataErrorInnerErrorMessageName || pair.Key == JsonConstants.ODataErrorInnerErrorStackTraceName || pair.Key == JsonConstants.ODataErrorInnerErrorTypeNameName)) { // Write empty string for null values in stacktrace, type and message properties of inner error. jsonWriter.WriteODataValue(new ODataPrimitiveValue(string.Empty)); } else { jsonWriter.WriteODataValue(pair.Value); } } } if (innerError.InnerError != null) { // "internalexception": { <nested inner error> } WriteInnerError(jsonWriter, innerError.InnerError, JsonConstants.ODataErrorInnerErrorInnerErrorName, recursionDepth, maxInnerErrorDepth); } // } jsonWriter.EndObjectScope(); }
private static void WriteInnerError(JsonWriter jsonWriter, ODataInnerError innerError, string innerErrorPropertyName, int recursionDepth, int maxInnerErrorDepth) { ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth); jsonWriter.WriteName(innerErrorPropertyName); jsonWriter.StartObjectScope(); jsonWriter.WriteName("message"); jsonWriter.WriteValue(innerError.Message ?? string.Empty); jsonWriter.WriteName("type"); jsonWriter.WriteValue(innerError.TypeName ?? string.Empty); jsonWriter.WriteName("stacktrace"); jsonWriter.WriteValue(innerError.StackTrace ?? string.Empty); if (innerError.InnerError != null) { WriteInnerError(jsonWriter, innerError.InnerError, "internalexception", recursionDepth, maxInnerErrorDepth); } jsonWriter.EndObjectScope(); }
/// <summary> /// Asynchronously reads the json array from the reader. /// </summary> /// <param name="jsonReader">JsonReader instance.</param> /// <param name="inputContext">The input context with all the settings.</param> /// <param name="recursionDepth">The recursion depth to start with.</param> /// <returns>A task that represents the asynchronous read operation. /// The value of the TResult parameter contains a lit of JSON objects.</returns> /// <returns>a list of json objects.</returns> private static async Task <List <object> > ReadArrayValueAsync(IJsonReaderAsync jsonReader, ODataInputContext inputContext, int recursionDepth) { Debug.Assert(jsonReader != null, "jsonReader != null"); Debug.Assert(jsonReader.NodeType == JsonNodeType.StartArray, "jsonReader.NodeType == JsonNodeType.StartArray"); Debug.Assert(inputContext != null, "inputContext != null"); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, inputContext.MessageReaderSettings.MessageQuotas.MaxNestingDepth); List <object> items = new List <object>(); await jsonReader.ReadNextAsync() .ConfigureAwait(false); while (jsonReader.NodeType != JsonNodeType.EndArray) { switch (jsonReader.NodeType) { case JsonNodeType.PrimitiveValue: items.Add(await jsonReader.ReadPrimitiveValueAsync() .ConfigureAwait(false)); break; case JsonNodeType.StartObject: items.Add(await ReadObjectValueAsync(jsonReader, /*insideJsonObjectValue*/ false, inputContext, recursionDepth) .ConfigureAwait(false)); break; case JsonNodeType.StartArray: items.Add(await ReadArrayValueAsync(jsonReader, inputContext, recursionDepth) .ConfigureAwait(false)); break; default: Debug.Assert(false, "We should never have got here - the valid states in array are primitive value or object"); return(null); } } await jsonReader.ReadEndArrayAsync() .ConfigureAwait(false); return(items); }
/// <summary> /// Read the json array from the reader. /// </summary> /// <param name="jsonReader">JsonReader instance.</param> /// <param name="inputContext">The input context with all the settings.</param> /// <param name="recursionDepth">The recursion depth to start with.</param> /// <returns>a list of json objects.</returns> private static IEnumerable <object> ReadArrayValue(JsonReader jsonReader, ODataInputContext inputContext, int recursionDepth) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(jsonReader != null, "jsonReader != null"); Debug.Assert(jsonReader.NodeType == JsonNodeType.StartArray, "jsonReader.NodeType == JsonNodeType.StartArray"); Debug.Assert(inputContext != null, "inputContext != null"); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, inputContext.MessageReaderSettings.MessageQuotas.MaxNestingDepth); List <object> array = new List <object>(); jsonReader.ReadNext(); while (jsonReader.NodeType != JsonNodeType.EndArray) { switch (jsonReader.NodeType) { case JsonNodeType.PrimitiveValue: array.Add(jsonReader.ReadPrimitiveValue()); break; case JsonNodeType.StartObject: array.Add(ReadObjectValue(jsonReader, /*insideJsonObjectValue*/ false, inputContext, recursionDepth)); break; case JsonNodeType.StartArray: array.Add(ReadArrayValue(jsonReader, inputContext, recursionDepth)); break; default: Debug.Assert(false, "We should never have got here - the valid states in array are primitive value or object"); return(null); } } jsonReader.ReadEndArray(); return(array); }
/// <summary> /// Increases the recursion depth of values by 1. This will throw if the recursion depth exceeds the current limit. /// </summary> private void IncreaseRecursionDepth() { ValidationUtils.IncreaseAndValidateRecursionDepth(ref this.recursionDepth, this.MessageReaderSettings.MessageQuotas.MaxNestingDepth); }
/// <summary> /// Reads the content of an inner error element. /// </summary> /// <param name="xmlReader">The (buffering) Xml reader to read the error payload from.</param> /// <param name="recursionDepth">The number of times this function has been called recursively.</param> /// <param name="maxInnerErrorDepth">The maximumum number of recursive internalexception elements to allow.</param> /// <returns>The <see cref="ODataInnerError"/> representing the inner error.</returns> /// <remarks> /// Pre-Condition: XmlNodeType.Element - the m:innererror or m:internalexception element /// Post-Condition: Any - the node after the m:innererror/m:internalexception end element or the node after the empty m:innererror/m:internalexception element node. /// </remarks> private static ODataInnerError ReadInnerErrorElement(BufferingXmlReader xmlReader, int recursionDepth, int maxInnerErrorDepth) { Debug.Assert(xmlReader != null, "this.XmlReader != null"); Debug.Assert(xmlReader.NodeType == XmlNodeType.Element, "xmlReader.NodeType == XmlNodeType.Element"); Debug.Assert( xmlReader.LocalName == AtomConstants.ODataInnerErrorElementName || xmlReader.LocalName == AtomConstants.ODataInnerErrorInnerErrorElementName, "Expected reader to be positioned on 'm:innererror' or 'm:internalexception' element."); Debug.Assert(xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace), "this.XmlReader.NamespaceEquals(this.ODataMetadataNamespace)"); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth); ODataInnerError innerError = new ODataInnerError(); DuplicateInnerErrorElementPropertyBitMask elementsReadBitmask = DuplicateInnerErrorElementPropertyBitMask.None; if (!xmlReader.IsEmptyElement) { // Move to the first child node of the element. xmlReader.Read(); do { switch (xmlReader.NodeType) { case XmlNodeType.EndElement: // end of the <m:innererror> or <m:internalexception> element continue; case XmlNodeType.Element: if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace)) { switch (xmlReader.LocalName) { // <m:message> case AtomConstants.ODataInnerErrorMessageElementName: VerifyInnerErrorElementNotFound( ref elementsReadBitmask, DuplicateInnerErrorElementPropertyBitMask.Message, AtomConstants.ODataInnerErrorMessageElementName); innerError.Message = xmlReader.ReadElementValue(); continue; // <m:type> case AtomConstants.ODataInnerErrorTypeElementName: VerifyInnerErrorElementNotFound( ref elementsReadBitmask, DuplicateInnerErrorElementPropertyBitMask.TypeName, AtomConstants.ODataInnerErrorTypeElementName); innerError.TypeName = xmlReader.ReadElementValue(); continue; // <m:stacktrace> case AtomConstants.ODataInnerErrorStackTraceElementName: VerifyInnerErrorElementNotFound( ref elementsReadBitmask, DuplicateInnerErrorElementPropertyBitMask.StackTrace, AtomConstants.ODataInnerErrorStackTraceElementName); innerError.StackTrace = xmlReader.ReadElementValue(); continue; // <m:internalexception> case AtomConstants.ODataInnerErrorInnerErrorElementName: VerifyInnerErrorElementNotFound( ref elementsReadBitmask, DuplicateInnerErrorElementPropertyBitMask.InternalException, AtomConstants.ODataInnerErrorInnerErrorElementName); innerError.InnerError = ReadInnerErrorElement(xmlReader, recursionDepth, maxInnerErrorDepth); continue; default: break; } } break; default: break; } xmlReader.Skip(); }while (xmlReader.NodeType != XmlNodeType.EndElement); } // Read over the end element, or empty start element. xmlReader.Read(); return(innerError); }
/// <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) ODataJsonLightReaderUtils.ErrorPropertyBitMask propertiesFoundBitmask = ODataJsonLightReaderUtils.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 (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonLightReaderUtils.ErrorPropertyBitMask.MessageValue)) { return(false); } string message; if (this.TryReadErrorStringPropertyValue(out message)) { innerError.Message = message; } else { return(false); } break; case JsonConstants.ODataErrorInnerErrorTypeNameName: if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonLightReaderUtils.ErrorPropertyBitMask.TypeName)) { return(false); } string typeName; if (this.TryReadErrorStringPropertyValue(out typeName)) { innerError.TypeName = typeName; } else { return(false); } break; case JsonConstants.ODataErrorInnerErrorStackTraceName: if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonLightReaderUtils.ErrorPropertyBitMask.StackTrace)) { return(false); } string stackTrace; if (this.TryReadErrorStringPropertyValue(out stackTrace)) { innerError.StackTrace = stackTrace; } else { return(false); } break; case JsonConstants.ODataErrorInnerErrorInnerErrorName: if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(ref propertiesFoundBitmask, ODataJsonLightReaderUtils.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); }
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); }
private static ODataInnerError ReadInnerErrorElement(BufferingXmlReader xmlReader, int recursionDepth, int maxInnerErrorDepth) { ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth); ODataInnerError error = new ODataInnerError(); DuplicateInnerErrorElementPropertyBitMask none = DuplicateInnerErrorElementPropertyBitMask.None; if (xmlReader.IsEmptyElement) { goto Label_010F; } xmlReader.Read(); Label_0022: switch (xmlReader.NodeType) { case XmlNodeType.Element: string str; if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace) && ((str = xmlReader.LocalName) != null)) { if (!(str == "message")) { if (str == "type") { VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.TypeName, "type"); error.TypeName = xmlReader.ReadElementValue(); goto Label_0102; } if (str == "stacktrace") { VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.StackTrace, "stacktrace"); error.StackTrace = xmlReader.ReadElementValue(); goto Label_0102; } if (str == "internalexception") { VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.InternalException, "internalexception"); error.InnerError = ReadInnerErrorElement(xmlReader, recursionDepth, maxInnerErrorDepth); goto Label_0102; } } else { VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.Message, "message"); error.Message = xmlReader.ReadElementValue(); goto Label_0102; } } break; case XmlNodeType.EndElement: goto Label_0102; } xmlReader.Skip(); Label_0102: if (xmlReader.NodeType != XmlNodeType.EndElement) { goto Label_0022; } Label_010F: xmlReader.Read(); return(error); }