/// <summary>
        /// Initializes a new instance of the <see cref="ODataJsonLightMetadataUriParseResult"/> class.
        /// </summary>
        /// <param name="model">The model to use when resolving the target of the URI.</param>
        /// <param name="metadataUriFromPayload">The metadata URI read from the payload.</param>
        private ODataJsonLightMetadataUriParser(IEdmModel model, Uri metadataUriFromPayload)
        {
            Debug.Assert(model != null, "model != null");

            if (!model.IsUserModel())
            {
                throw new ODataException(ODataErrorStrings.ODataJsonLightMetadataUriParser_NoModel);
            }

            this.model       = model;
            this.parseResult = new ODataJsonLightMetadataUriParseResult(metadataUriFromPayload);
        }
Exemple #2
0
        /// <summary>
        /// Read the start of the top-level data wrapper in JSON responses.
        /// </summary>
        /// <param name="payloadKind">The kind of payload we are reading; this guides the parsing of the metadata URI.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker.</param>
        /// <param name="isReadingNestedPayload">true if we are deserializing a nested payload, e.g. an entry, a feed or a collection within a parameters payload.</param>
        /// <param name="allowEmptyPayload">true if we allow a comletely empty payload; otherwise false.</param>
        /// <returns>The parsed metadata URI.</returns>
        /// <remarks>
        /// Pre-Condition:  JsonNodeType.None:      assumes that the JSON reader has not been used yet when not reading a nested payload.
        /// Post-Condition: The reader is positioned on the first property of the payload after having read (or skipped) the metadata URI property.
        ///                 Or the reader is positioned on an end-object node if there are no properties (other than the metadata URI which is required in responses and optional in requests).
        /// </remarks>
        internal Task ReadPayloadStartAsync(
            ODataPayloadKind payloadKind,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            bool isReadingNestedPayload,
            bool allowEmptyPayload)
        {
            DebugUtils.CheckNoExternalCallers();
            this.JsonReader.AssertNotBuffering();
            Debug.Assert(isReadingNestedPayload || this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: JSON reader must not have been used yet when not reading a nested payload.");

            return(TaskUtils.GetTaskForSynchronousOperation(() =>
            {
                string metadataUriAnnotationValue = this.ReadPayloadStartImplementation(
                    payloadKind,
                    duplicatePropertyNamesChecker,
                    isReadingNestedPayload,
                    allowEmptyPayload);

                // The metadata URI is only recognized in non-error response top-level payloads.
                // If the payload is nested (for example when we read URL literals) we don't recognize the metadata URI.
                // Top-level error payloads don't need and use the metadata URI.
                if (!isReadingNestedPayload && payloadKind != ODataPayloadKind.Error)
                {
                    this.metadataUriParseResult = this.jsonLightInputContext.PayloadKindDetectionState == null
                            ? null
                            : this.jsonLightInputContext.PayloadKindDetectionState.MetadataUriParseResult;
                    if (this.metadataUriParseResult == null && metadataUriAnnotationValue != null)
                    {
                        this.metadataUriParseResult = ODataJsonLightMetadataUriParser.Parse(
                            this.Model,
                            metadataUriAnnotationValue,
                            payloadKind,
                            this.Version,
                            this.MessageReaderSettings.ReaderBehavior);
                    }
                }

#if DEBUG
                this.metadataUriParseResultReady = true;
#endif
            }));
        }