예제 #1
0
        internal string ReadTypeNameFromMetadataPropertyValue()
        {
            string str = null;

            if (base.JsonReader.NodeType != JsonNodeType.StartObject)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonPropertyAndValueDeserializer_MetadataPropertyMustHaveObjectValue(base.JsonReader.NodeType));
            }
            base.JsonReader.ReadStartObject();
            ODataJsonReaderUtils.MetadataPropertyBitMask none = ODataJsonReaderUtils.MetadataPropertyBitMask.None;
            while (base.JsonReader.NodeType == JsonNodeType.Property)
            {
                string strB = base.JsonReader.ReadPropertyName();
                if (string.CompareOrdinal("type", strB) == 0)
                {
                    ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref none, ODataJsonReaderUtils.MetadataPropertyBitMask.Type, "type");
                    object obj2 = base.JsonReader.ReadPrimitiveValue();
                    str = obj2 as string;
                    if (str == null)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonPropertyAndValueDeserializer_InvalidTypeName(obj2));
                    }
                }
                else
                {
                    base.JsonReader.SkipValue();
                }
            }
            base.JsonReader.ReadEndObject();
            return(str);
        }
        /// <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);
        }
예제 #3
0
        internal ODataEntityReferenceLink ReadEntityReferenceLink()
        {
            base.JsonReader.ReadStartObject();
            base.JsonReader.ReadPropertyName();
            base.JsonReader.ReadStartObject();
            ODataEntityReferenceLink link = new ODataEntityReferenceLink();

            ODataJsonReaderUtils.MetadataPropertyBitMask none = ODataJsonReaderUtils.MetadataPropertyBitMask.None;
            while (base.JsonReader.NodeType == JsonNodeType.Property)
            {
                string strB = base.JsonReader.ReadPropertyName();
                if (string.CompareOrdinal("uri", strB) == 0)
                {
                    ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref none, ODataJsonReaderUtils.MetadataPropertyBitMask.Uri, "uri");
                    string propertyValue = base.JsonReader.ReadStringValue("uri");
                    ODataJsonReaderUtils.ValidateMetadataStringProperty(propertyValue, "uri");
                    link.Url = base.ProcessUriFromPayload(propertyValue);
                }
                else
                {
                    base.JsonReader.SkipValue();
                }
            }
            base.JsonReader.ReadEndObject();
            base.JsonReader.ReadEndObject();
            return(link);
        }
예제 #4
0
        private void ReadUriMetadataProperty(ODataEntry entry, ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField)
        {
            ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref metadataPropertiesFoundBitField, ODataJsonReaderUtils.MetadataPropertyBitMask.Uri, "uri");
            string propertyValue = base.JsonReader.ReadStringValue("uri");

            if (propertyValue != null)
            {
                ODataJsonReaderUtils.ValidateMetadataStringProperty(propertyValue, "uri");
                entry.EditLink = base.ProcessUriFromPayload(propertyValue);
            }
        }
예제 #5
0
 private void ReadFunctionsMetadataProperty(ODataEntry entry, ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField)
 {
     if ((base.MessageReaderSettings.MaxProtocolVersion >= ODataVersion.V3) && base.ReadingResponse)
     {
         ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref metadataPropertiesFoundBitField, ODataJsonReaderUtils.MetadataPropertyBitMask.Functions, "functions");
         this.ReadOperationsMetadata(entry, false);
     }
     else
     {
         base.JsonReader.SkipValue();
     }
 }
예제 #6
0
        private object ReadNonEntityValueImplementation(IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, bool validateNullValue)
        {
            object obj2;
            SerializationTypeNameAnnotation annotation;
            EdmTypeKind  kind;
            JsonNodeType nodeType = base.JsonReader.NodeType;

            if (nodeType == JsonNodeType.StartArray)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonPropertyAndValueDeserializer_CannotReadPropertyValue(nodeType));
            }
            if (this.TryReadNullValue(expectedTypeReference, validateNullValue))
            {
                return(null);
            }
            string            payloadTypeName = this.FindTypeNameInPayload();
            IEdmTypeReference type            = ReaderValidationUtils.ResolvePayloadTypeNameAndComputeTargetType(EdmTypeKind.None, null, expectedTypeReference, payloadTypeName, base.Model, base.MessageReaderSettings, base.Version, new Func <EdmTypeKind>(this.GetNonEntityValueKind), out kind, out annotation);

            switch (kind)
            {
            case EdmTypeKind.Primitive:
            {
                IEdmPrimitiveTypeReference reference2 = (type == null) ? null : type.AsPrimitive();
                if ((payloadTypeName != null) && !reference2.IsSpatial())
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonPropertyAndValueDeserializer_InvalidPrimitiveTypeName(payloadTypeName));
                }
                obj2 = this.ReadPrimitiveValueImplementation(reference2, validateNullValue);
                break;
            }

            case EdmTypeKind.Complex:
                obj2 = this.ReadComplexValueImplementation((type == null) ? null : type.AsComplex(), payloadTypeName, annotation, duplicatePropertyNamesChecker);
                break;

            case EdmTypeKind.Collection:
            {
                IEdmCollectionTypeReference collectionValueTypeReference = ValidationUtils.ValidateCollectionType(type);
                obj2 = this.ReadCollectionValueImplementation(collectionValueTypeReference, payloadTypeName, annotation);
                break;
            }

            default:
                throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataJsonPropertyAndValueDeserializer_ReadPropertyValue));
            }
            if (collectionValidator != null)
            {
                string collectionItemTypeName = ODataJsonReaderUtils.GetPayloadTypeName(obj2);
                collectionValidator.ValidateCollectionItem(collectionItemTypeName, kind);
            }
            return(obj2);
        }
        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);
        }
예제 #8
0
        /// <summary>
        /// Reads the properties of an entity reference link.
        /// </summary>
        /// <param name="entityReferenceLinks">The <see cref="ODataEntityReferenceLinks"/> instance to set the read property values on.</param>
        /// <param name="propertiesFoundBitField">The bit field with all the properties already read.</param>
        /// <returns>true if the method found the 'results' property; otherwise false.</returns>
        private bool ReadEntityReferenceLinkProperties(
            ODataEntityReferenceLinks entityReferenceLinks,
            ref ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask propertiesFoundBitField)
        {
            Debug.Assert(entityReferenceLinks != null, "entityReferenceLinks != null");
            this.JsonReader.AssertNotBuffering();

            while (this.JsonReader.NodeType == JsonNodeType.Property)
            {
                string propertyName = this.JsonReader.ReadPropertyName();
                switch (propertyName)
                {
                case JsonConstants.ODataResultsName:
                    ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(
                        ref propertiesFoundBitField,
                        ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Results,
                        JsonConstants.ODataResultsName);
                    this.JsonReader.AssertNotBuffering();
                    return(true);

                case JsonConstants.ODataCountName:
                    ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(
                        ref propertiesFoundBitField,
                        ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Count,
                        JsonConstants.ODataCountName);
                    object countValue = this.JsonReader.ReadPrimitiveValue();
                    long?  count      = (long?)ODataJsonReaderUtils.ConvertValue(countValue, EdmCoreModel.Instance.GetInt64(true), this.MessageReaderSettings, this.Version, /*validateNullValue*/ true);
                    ODataJsonReaderUtils.ValidateCountPropertyInEntityReferenceLinks(count);
                    entityReferenceLinks.Count = count;
                    break;

                case JsonConstants.ODataNextLinkName:
                    ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(
                        ref propertiesFoundBitField,
                        ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.NextPageLink,
                        JsonConstants.ODataNextLinkName);
                    string nextLinkString = this.JsonReader.ReadStringValue(JsonConstants.ODataNextLinkName);
                    ODataJsonReaderUtils.ValidateEntityReferenceLinksStringProperty(nextLinkString, JsonConstants.ODataNextLinkName);
                    entityReferenceLinks.NextPageLink = this.ProcessUriFromPayload(nextLinkString);
                    break;

                default:
                    // Skip all unrecognized properties
                    this.JsonReader.SkipValue();
                    break;
                }
            }

            this.JsonReader.AssertNotBuffering();
            return(false);
        }
예제 #9
0
 private void ReadIdMetadataProperty(ODataEntry entry, ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField)
 {
     if (base.UseServerFormatBehavior)
     {
         base.JsonReader.SkipValue();
     }
     else
     {
         ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref metadataPropertiesFoundBitField, ODataJsonReaderUtils.MetadataPropertyBitMask.Id, "id");
         string propertyValue = base.JsonReader.ReadStringValue("id");
         ODataJsonReaderUtils.ValidateMetadataStringProperty(propertyValue, "id");
         entry.Id = propertyValue;
     }
 }
예제 #10
0
        private object ReadPrimitiveValueImplementation(IEdmPrimitiveTypeReference expectedValueTypeReference, bool validateNullValue)
        {
            if ((expectedValueTypeReference != null) && expectedValueTypeReference.IsSpatial())
            {
                return(this.ReadSpatialValue(expectedValueTypeReference, validateNullValue));
            }
            object obj2 = base.JsonReader.ReadPrimitiveValue();

            if ((expectedValueTypeReference != null) && !base.MessageReaderSettings.DisablePrimitiveTypeConversion)
            {
                obj2 = ODataJsonReaderUtils.ConvertValue(obj2, expectedValueTypeReference, base.MessageReaderSettings, base.Version, validateNullValue);
            }
            return(obj2);
        }
예제 #11
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);
        }
예제 #12
0
 private void ReadMediaSourceMetadataProperty(ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField, ref ODataStreamReferenceValue mediaResource)
 {
     if (base.UseServerFormatBehavior)
     {
         base.JsonReader.SkipValue();
     }
     else
     {
         ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref metadataPropertiesFoundBitField, ODataJsonReaderUtils.MetadataPropertyBitMask.MediaUri, "media_src");
         ODataJsonReaderUtils.EnsureInstance <ODataStreamReferenceValue>(ref mediaResource);
         string propertyValue = base.JsonReader.ReadStringValue("media_src");
         ODataJsonReaderUtils.ValidateMetadataStringProperty(propertyValue, "media_src");
         mediaResource.ReadLink = base.ProcessUriFromPayload(propertyValue);
     }
 }
예제 #13
0
 private void ReadContentTypeMetadataProperty(ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField, ref ODataStreamReferenceValue mediaResource)
 {
     if (base.UseServerFormatBehavior)
     {
         base.JsonReader.SkipValue();
     }
     else
     {
         ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref metadataPropertiesFoundBitField, ODataJsonReaderUtils.MetadataPropertyBitMask.ContentType, "content_type");
         ODataJsonReaderUtils.EnsureInstance <ODataStreamReferenceValue>(ref mediaResource);
         string propertyValue = base.JsonReader.ReadStringValue("content_type");
         ODataJsonReaderUtils.ValidateMetadataStringProperty(propertyValue, "content_type");
         mediaResource.ContentType = propertyValue;
     }
 }
예제 #14
0
        internal void ValidateEntryMetadata(IODataJsonReaderEntryState entryState)
        {
            ODataEntry     entry      = entryState.Entry;
            IEdmEntityType entityType = entryState.EntityType;

            if (base.Model.HasDefaultStream(entityType) && (entry.MediaResource == null))
            {
                ODataStreamReferenceValue instance = null;
                ODataJsonReaderUtils.EnsureInstance <ODataStreamReferenceValue>(ref instance);
                entry.MediaResource = instance;
            }
            bool useDefaultFormatBehavior = base.UseDefaultFormatBehavior;

            ValidationUtils.ValidateEntryMetadata(entry, entityType, base.Model, useDefaultFormatBehavior);
        }
예제 #15
0
 private void ReadPropertiesMetadataProperty(IODataJsonReaderEntryState entryState, ref ODataJsonReaderUtils.MetadataPropertyBitMask metadataPropertiesFoundBitField)
 {
     if (!base.ReadingResponse || (base.MessageReaderSettings.MaxProtocolVersion < ODataVersion.V3))
     {
         base.JsonReader.SkipValue();
     }
     else
     {
         ODataJsonReaderUtils.VerifyMetadataPropertyNotFound(ref metadataPropertiesFoundBitField, ODataJsonReaderUtils.MetadataPropertyBitMask.Properties, "properties");
         if (base.JsonReader.NodeType != JsonNodeType.StartObject)
         {
             throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_PropertyInEntryMustHaveObjectValue("properties", base.JsonReader.NodeType));
         }
         base.JsonReader.ReadStartObject();
         while (base.JsonReader.NodeType == JsonNodeType.Property)
         {
             string associationLinkName = base.JsonReader.ReadPropertyName();
             ValidationUtils.ValidateAssociationLinkName(associationLinkName);
             ReaderValidationUtils.ValidateNavigationPropertyDefined(associationLinkName, entryState.EntityType, base.MessageReaderSettings);
             base.JsonReader.ReadStartObject();
             while (base.JsonReader.NodeType == JsonNodeType.Property)
             {
                 if (string.CompareOrdinal(base.JsonReader.ReadPropertyName(), "associationuri") == 0)
                 {
                     string propertyValue = base.JsonReader.ReadStringValue("associationuri");
                     ODataJsonReaderUtils.ValidateMetadataStringProperty(propertyValue, "associationuri");
                     ODataAssociationLink associationLink = new ODataAssociationLink {
                         Name = associationLinkName,
                         Url  = base.ProcessUriFromPayload(propertyValue)
                     };
                     ValidationUtils.ValidateAssociationLink(associationLink);
                     entryState.DuplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(associationLink);
                     ReaderUtils.AddAssociationLinkToEntry(entryState.Entry, associationLink);
                 }
                 else
                 {
                     base.JsonReader.SkipValue();
                 }
             }
             base.JsonReader.ReadEndObject();
         }
         base.JsonReader.ReadEndObject();
     }
 }
예제 #16
0
        private bool ReadEntityReferenceLinkProperties(ODataEntityReferenceLinks entityReferenceLinks, ref ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask propertiesFoundBitField)
        {
            while (base.JsonReader.NodeType == JsonNodeType.Property)
            {
                string str3 = base.JsonReader.ReadPropertyName();
                if (str3 == null)
                {
                    goto Label_00D9;
                }
                if (!(str3 == "results"))
                {
                    if (str3 == "__count")
                    {
                        goto Label_0057;
                    }
                    if (str3 == "__next")
                    {
                        goto Label_00A2;
                    }
                    goto Label_00D9;
                }
                ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Results, "results");
                return(true);

Label_0057:
                ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.Count, "__count");
                long?propertyValue = (long?)ODataJsonReaderUtils.ConvertValue(base.JsonReader.ReadPrimitiveValue(), EdmCoreModel.Instance.GetInt64(true), base.MessageReaderSettings, base.Version, true);
                ODataJsonReaderUtils.ValidateCountPropertyInEntityReferenceLinks(propertyValue);
                entityReferenceLinks.Count = propertyValue;
                continue;
Label_00A2:
                ODataJsonReaderUtils.VerifyEntityReferenceLinksWrapperPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.EntityReferenceLinksWrapperPropertyBitMask.NextPageLink, "__next");
                string str2 = base.JsonReader.ReadStringValue("__next");
                ODataJsonReaderUtils.ValidateEntityReferenceLinksStringProperty(str2, "__next");
                entityReferenceLinks.NextPageLink = base.ProcessUriFromPayload(str2);
                continue;
Label_00D9:
                base.JsonReader.SkipValue();
            }
            return(false);
        }
예제 #17
0
        private void ReadFeedProperty(ODataFeed feed, string propertyName, bool isExpandedLinkContent)
        {
            switch (ODataJsonReaderUtils.DetermineFeedPropertyKind(propertyName))
            {
            case ODataJsonReaderUtils.FeedPropertyKind.Unsupported:
                base.JsonReader.SkipValue();
                return;

            case ODataJsonReaderUtils.FeedPropertyKind.Count:
            {
                if ((!base.ReadingResponse || (base.Version < ODataVersion.V2)) || isExpandedLinkContent)
                {
                    base.JsonReader.SkipValue();
                    return;
                }
                string propertyValue = base.JsonReader.ReadStringValue("__count");
                ODataJsonReaderUtils.ValidateFeedProperty(propertyValue, "__count");
                long num = (long)ODataJsonReaderUtils.ConvertValue(propertyValue, EdmCoreModel.Instance.GetInt64(false), base.MessageReaderSettings, base.Version, true);
                feed.Count = new long?(num);
                return;
            }

            case ODataJsonReaderUtils.FeedPropertyKind.Results:
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleFeedResultsPropertiesFound);

            case ODataJsonReaderUtils.FeedPropertyKind.NextPageLink:
            {
                if (!base.ReadingResponse || (base.Version < ODataVersion.V2))
                {
                    base.JsonReader.SkipValue();
                    return;
                }
                string str2 = base.JsonReader.ReadStringValue("__next");
                ODataJsonReaderUtils.ValidateFeedProperty(str2, "__next");
                feed.NextPageLink = base.ProcessUriFromPayload(str2);
                return;
            }
            }
            throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ODataJsonEntryAndFeedDeserializer_ReadFeedProperty));
        }
예제 #18
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);
        }
예제 #19
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);
        }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
0
        private void ReadOperationsMetadata(ODataEntry entry, bool isActions)
        {
            string str = isActions ? "actions" : "functions";

            if (base.JsonReader.NodeType != JsonNodeType.StartObject)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_PropertyInEntryMustHaveObjectValue(str, base.JsonReader.NodeType));
            }
            base.JsonReader.ReadStartObject();
            HashSet <string> set = new HashSet <string>(StringComparer.Ordinal);

            while (base.JsonReader.NodeType == JsonNodeType.Property)
            {
                ODataOperation operation;
                string         item = base.JsonReader.ReadPropertyName();
                if (set.Contains(item))
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_RepeatMetadataValue(str, item));
                }
                set.Add(item);
                if (base.JsonReader.NodeType != JsonNodeType.StartArray)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MetadataMustHaveArrayValue(str, base.JsonReader.NodeType));
                }
                base.JsonReader.ReadStartArray();
                if (base.JsonReader.NodeType == JsonNodeType.StartObject)
                {
                    goto Label_0227;
                }
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_OperationMetadataArrayExpectedAnObject(str, base.JsonReader.NodeType));
Label_00E1:
                base.JsonReader.ReadStartObject();
                if (isActions)
                {
                    operation = new ODataAction();
                    ReaderUtils.AddActionToEntry(entry, (ODataAction)operation);
                }
                else
                {
                    operation = new ODataFunction();
                    ReaderUtils.AddFunctionToEntry(entry, (ODataFunction)operation);
                }
                operation.Metadata = base.ResolveUri(item);
                while (base.JsonReader.NodeType == JsonNodeType.Property)
                {
                    string str3 = base.JsonReader.ReadPropertyName();
                    string str6 = str3;
                    if (str6 == null)
                    {
                        goto Label_01E5;
                    }
                    if (!(str6 == "title"))
                    {
                        if (str6 == "target")
                        {
                            goto Label_019D;
                        }
                        goto Label_01E5;
                    }
                    if (operation.Title != null)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleOptionalPropertiesInOperation(str3, item, str));
                    }
                    string propertyValue = base.JsonReader.ReadStringValue("title");
                    ODataJsonReaderUtils.ValidateOperationJsonProperty(propertyValue, str3, item, str);
                    operation.Title = propertyValue;
                    continue;
Label_019D:
                    if (operation.Target != null)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleTargetPropertiesInOperation(item, str));
                    }
                    string str5 = base.JsonReader.ReadStringValue("target");
                    ODataJsonReaderUtils.ValidateOperationJsonProperty(str5, str3, item, str);
                    operation.Target = base.ProcessUriFromPayload(str5);
                    continue;
Label_01E5:
                    base.JsonReader.SkipValue();
                }
                if (operation.Target == null)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_OperationMissingTargetProperty(item, str));
                }
                base.JsonReader.ReadEndObject();
Label_0227:
                if (base.JsonReader.NodeType == JsonNodeType.StartObject)
                {
                    goto Label_00E1;
                }
                base.JsonReader.ReadEndArray();
            }
            base.JsonReader.ReadEndObject();
        }
        internal ODataError ReadTopLevelError()
        {
            base.JsonReader.DisableInStreamErrorDetection = true;
            ODataError error = new ODataError();

            try
            {
                base.ReadPayloadStart(false, false);
                base.JsonReader.ReadStartObject();
                ODataJsonReaderUtils.ErrorPropertyBitMask none = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
                while (base.JsonReader.NodeType == JsonNodeType.Property)
                {
                    string strB = base.JsonReader.ReadPropertyName();
                    if (string.CompareOrdinal("error", strB) != 0)
                    {
                        throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorWithInvalidProperty(strB));
                    }
                    ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Error, "error");
                    base.JsonReader.ReadStartObject();
                    while (base.JsonReader.NodeType == JsonNodeType.Property)
                    {
                        strB = base.JsonReader.ReadPropertyName();
                        string str2 = strB;
                        if (str2 == null)
                        {
                            goto Label_01B8;
                        }
                        if (!(str2 == "code"))
                        {
                            if (str2 == "message")
                            {
                                goto Label_00D9;
                            }
                            if (str2 == "innererror")
                            {
                                goto Label_019B;
                            }
                            goto Label_01B8;
                        }
                        ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Code, "code");
                        error.ErrorCode = base.JsonReader.ReadStringValue("code");
                        continue;
Label_00D9:
                        ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Message, "message");
                        base.JsonReader.ReadStartObject();
                        while (base.JsonReader.NodeType == JsonNodeType.Property)
                        {
                            strB = base.JsonReader.ReadPropertyName();
                            string str3 = strB;
                            if (str3 == null)
                            {
                                goto Label_0171;
                            }
                            if (!(str3 == "lang"))
                            {
                                if (str3 == "value")
                                {
                                    goto Label_014B;
                                }
                                goto Label_0171;
                            }
                            ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageLanguage, "lang");
                            error.MessageLanguage = base.JsonReader.ReadStringValue("lang");
                            continue;
Label_014B:
                            ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, "value");
                            error.Message = base.JsonReader.ReadStringValue("value");
                            continue;
Label_0171:
                            throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorMessageValueWithInvalidProperty(strB));
                        }
                        base.JsonReader.ReadEndObject();
                        continue;
Label_019B:
                        ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, "innererror");
                        error.InnerError = this.ReadInnerError(0);
                        continue;
Label_01B8:
                        throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorValueWithInvalidProperty(strB));
                    }
                    base.JsonReader.ReadEndObject();
                }
                base.JsonReader.ReadEndObject();
                base.ReadPayloadEnd(false, false);
            }
            finally
            {
                base.JsonReader.DisableInStreamErrorDetection = false;
            }
            return(error);
        }
예제 #24
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);
        }
        /// <summary>
        /// Read a top-level error.
        /// </summary>
        /// <returns>An <see cref="ODataError"/> representing the read error.</returns>
        internal ODataError ReadTopLevelError()
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: expected JsonNodeType.None, the reader must not have been used yet.");
            Debug.Assert(!this.JsonReader.DisableInStreamErrorDetection, "!JsonReader.DisableInStreamErrorDetection");
            this.JsonReader.AssertNotBuffering();

            // prevent the buffering JSON reader from detecting in-stream errors - we read the error ourselves
            // to throw proper exceptions
            this.JsonReader.DisableInStreamErrorDetection = true;

            ODataError error = new ODataError();

            try
            {
                // Read the start of the payload (no "d" wrapper for top-level errors)
                this.ReadPayloadStart(/*isReadingNestedPayload*/ false, /*expectResponseWrapper*/ false);

                // Read the start of the error object
                this.JsonReader.ReadStartObject();

                ODataJsonReaderUtils.ErrorPropertyBitMask propertiesFoundBitField = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
                while (this.JsonReader.NodeType == JsonNodeType.Property)
                {
                    string propertyName = this.JsonReader.ReadPropertyName();
                    if (string.CompareOrdinal(JsonConstants.ODataErrorName, propertyName) != 0)
                    {
                        // we only allow a single 'error' property for a top-level error object
                        throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorWithInvalidProperty(propertyName));
                    }

                    ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.Error, JsonConstants.ODataErrorName);

                    this.JsonReader.ReadStartObject();

                    while (this.JsonReader.NodeType == JsonNodeType.Property)
                    {
                        propertyName = this.JsonReader.ReadPropertyName();
                        switch (propertyName)
                        {
                        case JsonConstants.ODataErrorCodeName:
                            ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.Code, JsonConstants.ODataErrorCodeName);
                            error.ErrorCode = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorCodeName);
                            break;

                        case JsonConstants.ODataErrorMessageName:
                            ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.Message, JsonConstants.ODataErrorMessageName);
                            this.JsonReader.ReadStartObject();

                            while (this.JsonReader.NodeType == JsonNodeType.Property)
                            {
                                propertyName = this.JsonReader.ReadPropertyName();
                                switch (propertyName)
                                {
                                case JsonConstants.ODataErrorMessageLanguageName:
                                    ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageLanguage, JsonConstants.ODataErrorMessageLanguageName);
                                    error.MessageLanguage = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorMessageLanguageName);
                                    break;

                                case JsonConstants.ODataErrorMessageValueName:
                                    ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, JsonConstants.ODataErrorMessageValueName);
                                    error.Message = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorMessageValueName);
                                    break;

                                default:
                                    // we only allow a 'lang' and 'value' properties in the value of the 'message' property
                                    throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorMessageValueWithInvalidProperty(propertyName));
                                }
                            }

                            this.JsonReader.ReadEndObject();
                            break;

                        case JsonConstants.ODataErrorInnerErrorName:
                            ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, JsonConstants.ODataErrorInnerErrorName);
                            error.InnerError = this.ReadInnerError(0 /* recursionDepth */);
                            break;

                        default:
                            // we only allow a 'code', 'message' and 'innererror' properties in the value of the 'error' property
                            throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorValueWithInvalidProperty(propertyName));
                        }
                    }

                    this.JsonReader.ReadEndObject();
                }

                // Read the end of the error object
                this.JsonReader.ReadEndObject();

                // Read the end of the response (no "d" wrapper for top-level errors)
                this.ReadPayloadEnd(/*isReadingNestedPayload*/ false, /*expectResponseWrapper*/ false);
            }
            finally
            {
                this.JsonReader.DisableInStreamErrorDetection = false;
            }

            Debug.Assert(this.JsonReader.NodeType == JsonNodeType.EndOfInput, "Post-Condition: JsonNodeType.EndOfInput");
            this.JsonReader.AssertNotBuffering();

            return(error);
        }
예제 #26
0
        private ODataStreamReferenceValue ReadStreamReferenceValue()
        {
            base.JsonReader.ReadStartObject();
            ODataStreamReferenceValue value2 = new ODataStreamReferenceValue();

            while (base.JsonReader.NodeType == JsonNodeType.Property)
            {
                string str6 = base.JsonReader.ReadPropertyName();
                if (str6 == null)
                {
                    goto Label_0186;
                }
                if (!(str6 == "edit_media"))
                {
                    if (str6 == "media_src")
                    {
                        goto Label_00BA;
                    }
                    if (str6 == "content_type")
                    {
                        goto Label_0106;
                    }
                    if (str6 == "media_etag")
                    {
                        goto Label_0146;
                    }
                    goto Label_0186;
                }
                if (value2.EditLink != null)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleMetadataPropertiesForStreamProperty("edit_media"));
                }
                string propertyValue = base.JsonReader.ReadStringValue("edit_media");
                ODataJsonReaderUtils.ValidateMediaResourceStringProperty(propertyValue, "edit_media");
                value2.EditLink = base.ProcessUriFromPayload(propertyValue);
                continue;
Label_00BA:
                if (value2.ReadLink != null)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleMetadataPropertiesForStreamProperty("media_src"));
                }
                string str3 = base.JsonReader.ReadStringValue("media_src");
                ODataJsonReaderUtils.ValidateMediaResourceStringProperty(str3, "media_src");
                value2.ReadLink = base.ProcessUriFromPayload(str3);
                continue;
Label_0106:
                if (value2.ContentType != null)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleMetadataPropertiesForStreamProperty("content_type"));
                }
                string str4 = base.JsonReader.ReadStringValue("content_type");
                ODataJsonReaderUtils.ValidateMediaResourceStringProperty(str4, "content_type");
                value2.ContentType = str4;
                continue;
Label_0146:
                if (value2.ETag != null)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleMetadataPropertiesForStreamProperty("media_etag"));
                }
                string str5 = base.JsonReader.ReadStringValue("media_etag");
                ODataJsonReaderUtils.ValidateMediaResourceStringProperty(str5, "media_etag");
                value2.ETag = str5;
                continue;
Label_0186:
                base.JsonReader.SkipValue();
            }
            base.JsonReader.ReadEndObject();
            return(value2);
        }