Exemplo n.º 1
0
        /// <summary>
        /// Reads the DataServiceVersion header from the <paramref name="message"/> and parses it.
        /// If no DataServiceVersion header is found it sets the default version to be used for reading.
        /// </summary>
        /// <param name="message">The message to get the data service version header from.</param>
        /// <param name="defaultVersion">The default version to use if the header was not specified.</param>
        /// <returns>
        /// The <see cref="ODataVersion"/> retrieved from the DataServiceVersion header of the message.
        /// The default version if none is specified in the header.
        /// </returns>
        public static ODataVersion GetDataServiceVersion(this IODataRequestMessage message, ODataVersion defaultVersion)
        {
            // translation from IODataResponseMessage to ODataMessage to pass into GetDataServiceVersion.
            // we retain all of the data we need from the message, with a few extra data that aren't used in.
            // GetDataServiceVersion. Not ideal, but it works.
            ODataMessage odataMessage = new ODataRequestMessage(message, false /*writing*/, false /*disableMessageStreamDisposal*/, Int64.MaxValue /*maxMessageSize*/);

            return(ODataUtilsInternal.GetDataServiceVersion(odataMessage, defaultVersion));
        }
Exemplo n.º 2
0
 public ODataMessageReader(IODataResponseMessage responseMessage, ODataMessageReaderSettings settings, IEdmModel model)
 {
     this.readerPayloadKind = ODataPayloadKind.Unsupported;
     ExceptionUtils.CheckArgumentNotNull <IODataResponseMessage>(responseMessage, "responseMessage");
     this.settings = (settings == null) ? new ODataMessageReaderSettings() : new ODataMessageReaderSettings(settings);
     ReaderValidationUtils.ValidateMessageReaderSettings(this.settings, true);
     this.readingResponse = true;
     this.message         = new ODataResponseMessage(responseMessage, false, this.settings.DisableMessageStreamDisposal, this.settings.MessageQuotas.MaxReceivedMessageSize);
     this.urlResolver     = responseMessage as IODataUrlResolver;
     this.version         = ODataUtilsInternal.GetDataServiceVersion(this.message, this.settings.MaxProtocolVersion);
     this.model           = model ?? EdmCoreModel.Instance;
     ODataVersionChecker.CheckVersionSupported(this.version, this.settings);
 }
Exemplo n.º 3
0
 private void EnsureODataVersion()
 {
     if (!this.settings.Version.HasValue)
     {
         this.settings.Version = new ODataVersion?(ODataUtilsInternal.GetDataServiceVersion(this.message, ODataVersion.V3));
     }
     else
     {
         ODataUtilsInternal.SetDataServiceVersion(this.message, this.settings);
     }
     if ((((ODataVersion)this.settings.Version) >= ODataVersion.V3) && (this.settings.WriterBehavior.FormatBehaviorKind != ODataBehaviorKind.Default))
     {
         this.settings.WriterBehavior.UseDefaultFormatBehavior();
     }
 }
Exemplo n.º 4
0
        private bool TryGetSinglePayloadKindResultFromContentType(out IEnumerable <ODataPayloadKindDetectionResult> payloadKindResults, out MediaType contentType)
        {
            if (this.message.UseBufferingReadStream == true)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataMessageReader_DetectPayloadKindMultipleTimes);
            }
            IList <ODataPayloadKindDetectionResult> list = MediaTypeUtils.GetPayloadKindsForContentType(this.GetContentTypeHeader(), this.MediaTypeResolver, out contentType);

            payloadKindResults = from r in list
                                 where ODataUtilsInternal.IsPayloadKindSupported(r.PayloadKind, !this.readingResponse)
                                 select r;

            if (payloadKindResults.Count <ODataPayloadKindDetectionResult>() > 1)
            {
                this.message.UseBufferingReadStream = true;
                return(false);
            }
            return(true);
        }