Example #1
0
        internal RequestDescription UpdateVersions(string acceptTypesText, ResourceSetWrapper resourceSet, IDataService service)
        {
            DataServiceHostWrapper host = service.OperationContext.Host;

            if ((host.HttpVerb == HttpVerbs.GET) || ((host.HttpVerb == HttpVerbs.POST) && (this.TargetSource == RequestTargetSource.ServiceOperation)))
            {
                if (this.TargetKind == RequestTargetKind.Resource)
                {
                    if (!this.LinkUri)
                    {
                        this.InitializeVersion(service.OperationContext);
                        bool    considerEpmInVersion = WebUtil.IsAtomResponseFormat(acceptTypesText, this.TargetKind, service.Configuration.DataServiceBehavior.MaxProtocolVersion, this.requestMaxVersion);
                        Version version = resourceSet.MinimumResponsePayloadVersion(service, considerEpmInVersion);
                        this.VerifyAndRaiseResponseVersion(version, service);
                    }
                }
                else if (((this.TargetResourceType != null) && (this.CountOption != RequestQueryCountOption.ValueOnly)) && (this.TargetKind != RequestTargetKind.MediaResource))
                {
                    this.VerifyAndRaiseResponseVersion(this.TargetResourceType.MetadataVersion, service);
                }
                else if (this.TargetKind == RequestTargetKind.OpenProperty)
                {
                    this.InitializeVersion(service.OperationContext);
                    Version effectiveMaxResponseVersion = WebUtil.GetEffectiveMaxResponseVersion(service.Configuration.DataServiceBehavior.MaxProtocolVersion, this.requestMaxVersion);
                    this.VerifyAndRaiseResponseVersion(effectiveMaxResponseVersion, service);
                }
            }
            else if (host.HttpVerb == HttpVerbs.PATCH)
            {
                this.VerifyProtocolVersion(Version3Dot0, service);
                this.VerifyRequestVersion(Version3Dot0, service);
            }
            return(this);
        }
Example #2
0
 internal ResponseBodyWriter(bool hasMoved, IDataService service, IEnumerator queryResults, RequestDescription requestDescription, IODataResponseMessage responseMessage, ODataPayloadKind payloadKind)
 {
     this.hasMoved           = hasMoved;
     this.service            = service;
     this.queryResults       = queryResults;
     this.requestDescription = requestDescription;
     this.responseMessage    = responseMessage;
     this.payloadKind        = payloadKind;
     this.encoding           = HttpProcessUtility.EncodingFromAcceptCharset(this.service.OperationContext.Host.RequestAcceptCharSet);
     if ((((payloadKind == ODataPayloadKind.Entry) || (payloadKind == ODataPayloadKind.Feed)) || ((payloadKind == ODataPayloadKind.Property) || (payloadKind == ODataPayloadKind.Collection))) || (((payloadKind == ODataPayloadKind.EntityReferenceLink) || (payloadKind == ODataPayloadKind.EntityReferenceLinks)) || (((payloadKind == ODataPayloadKind.Error) || (payloadKind == ODataPayloadKind.ServiceDocument)) || (payloadKind == ODataPayloadKind.Parameter))))
     {
         DataServiceHostWrapper host = service.OperationContext.Host;
         if (WebUtil.GetEffectiveMaxResponseVersion(service.Configuration.DataServiceBehavior.MaxProtocolVersion, host.RequestMaxVersion) > RequestDescription.Version2Dot0)
         {
             bool isEntityOrFeed = (payloadKind == ODataPayloadKind.Entry) || (payloadKind == ODataPayloadKind.Feed);
             if (WebUtil.ResponseMediaTypeWouldBeJsonLight(host.RequestAccept, isEntityOrFeed))
             {
                 requestDescription.VerifyAndRaiseResponseVersion(RequestDescription.Version3Dot0, service);
                 host.ResponseVersion = RequestDescription.Version3Dot0.ToString() + ";";
             }
         }
     }
     if (this.requestDescription.TargetKind == RequestTargetKind.MediaResource)
     {
         this.mediaResourceStream = service.StreamProvider.GetReadStream(this.queryResults.Current, RequestDescription.GetStreamProperty(this.requestDescription), this.service.OperationContext);
     }
     else if (payloadKind != ODataPayloadKind.BinaryValue)
     {
         string requestAcceptCharSet = this.service.OperationContext.Host.RequestAcceptCharSet;
         if (string.IsNullOrEmpty(requestAcceptCharSet) || (requestAcceptCharSet == "*"))
         {
             requestAcceptCharSet = "UTF-8";
         }
         if ((payloadKind == ODataPayloadKind.Value) && !string.IsNullOrEmpty(this.requestDescription.MimeType))
         {
             this.messageWriter = CreateMessageWriter(this.AbsoluteServiceUri, this.service, this.requestDescription.ActualResponseVersion, responseMessage, ODataFormat.RawValue);
         }
         else
         {
             this.messageWriter = CreateMessageWriter(this.AbsoluteServiceUri, this.service, this.requestDescription.ActualResponseVersion, responseMessage, this.service.OperationContext.Host.RequestAccept, requestAcceptCharSet);
         }
         try
         {
             this.contentFormat = ODataUtils.SetHeadersForPayload(this.messageWriter, payloadKind);
             if ((payloadKind == ODataPayloadKind.Value) && !string.IsNullOrEmpty(this.requestDescription.MimeType))
             {
                 responseMessage.SetHeader("Content-Type", this.requestDescription.MimeType);
             }
         }
         catch (ODataContentTypeException exception)
         {
             throw new DataServiceException(0x19f, null, System.Data.Services.Strings.DataServiceException_UnsupportedMediaType, null, exception);
         }
         string headerValue = this.requestDescription.ResponseVersion.ToString() + ";";
         responseMessage.SetHeader("DataServiceVersion", headerValue);
     }
 }