Esempio n. 1
0
 private void HandleOperationResponseData(HttpWebResponse response, Stream responseStream)
 {
     Version version;
     Func<Stream> getResponseStream = null;
     Dictionary<string, string> headers = WebUtil.WrapResponseHeaders(response);
     Descriptor descriptor = base.ChangedEntries[base.entryIndex];
     MaterializerEntry entry = null;
     Exception exception = BaseSaveResult.HandleResponse(base.RequestInfo, response.StatusCode, response.Headers["DataServiceVersion"], () => responseStream, false, out version);
     if (((responseStream != null) && (descriptor.DescriptorKind == DescriptorKind.Entity)) && (exception == null))
     {
         EntityDescriptor entityDescriptor = (EntityDescriptor) descriptor;
         if (((entityDescriptor.State == EntityStates.Added) || (entityDescriptor.StreamState == EntityStates.Added)) || ((entityDescriptor.State == EntityStates.Modified) || (entityDescriptor.StreamState == EntityStates.Modified)))
         {
             try
             {
                 ResponseInfo responseInfo = base.CreateResponseInfo(entityDescriptor);
                 if (getResponseStream == null)
                 {
                     getResponseStream = () => responseStream;
                 }
                 HttpWebResponseMessage message = new HttpWebResponseMessage(response, getResponseStream);
                 entry = ODataReaderEntityMaterializer.ParseSingleEntityPayload(message, responseInfo, entityDescriptor.Entity.GetType());
                 entityDescriptor.TransientEntityDescriptor = entry.EntityDescriptor;
             }
             catch (Exception exception2)
             {
                 exception = exception2;
                 if (!CommonUtil.IsCatchableExceptionType(exception2))
                 {
                     throw;
                 }
             }
         }
     }
     this.cachedResponses.Add(new CachedResponse(descriptor, headers, response.StatusCode, version, (entry != null) ? entry.Entry : null, exception));
     if (exception != null)
     {
         descriptor.SaveError = exception;
     }
 }
Esempio n. 2
0
 private DataServiceResponse HandleBatchResponse()
 {
     Func<Stream> func2 = null;
     Func<Stream> getResponseStream = null;
     DataServiceResponse response3;
     bool flag = true;
     try
     {
         Version version;
         ODataBatchReader reader;
         if ((base.batchResponse == null) || (base.batchResponse.StatusCode == HttpStatusCode.NoContent))
         {
             throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Batch_ExpectedResponse(1));
         }
         if (func2 == null)
         {
             func2 = () => this.ResponseStream;
         }
         Func<Stream> func = func2;
         BaseSaveResult.HandleResponse(base.RequestInfo, base.batchResponse.StatusCode, base.batchResponse.Headers["DataServiceVersion"], func, true, out version);
         if (this.ResponseStream == null)
         {
             System.Data.Services.Client.Error.ThrowBatchExpectedResponse(InternalError.NullResponseStream);
         }
         HttpWebResponseMessage responseMessage = new HttpWebResponseMessage(base.batchResponse, func);
         ODataMessageReaderSettings settings = WebUtil.CreateODataMessageReaderSettings(base.RequestInfo.GetDeserializationInfo(null), null, false);
         this.batchMessageReader = new ODataMessageReader(responseMessage, settings);
         try
         {
             reader = this.batchMessageReader.CreateODataBatchReader();
         }
         catch (Exception responseText)
         {
             string str;
             Encoding encoding;
             HttpProcessUtility.ReadContentType(base.batchResponse.ContentType, out str, out encoding);
             if (string.Equals("text/plain", str))
             {
                 if (getResponseStream == null)
                 {
                     getResponseStream = () => WebUtil.GetResponseStream(base.batchResponse, (DataServiceContext) base.Source);
                 }
                 responseText = BaseSaveResult.GetResponseText(getResponseStream, base.batchResponse.StatusCode);
             }
             throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Batch_ExpectedContentType(base.batchResponse.ContentType), responseText);
         }
         DataServiceResponse response = this.HandleBatchResponseInternal(reader);
         flag = false;
         response3 = response;
     }
     catch (DataServiceRequestException)
     {
         throw;
     }
     catch (InvalidOperationException exception3)
     {
         Dictionary<string, string> headers = WebUtil.WrapResponseHeaders(base.batchResponse);
         int statusCode = (base.batchResponse == null) ? 500 : ((int) base.batchResponse.StatusCode);
         DataServiceResponse response2 = new DataServiceResponse(headers, statusCode, null, this.IsBatch);
         throw new DataServiceRequestException(System.Data.Services.Client.Strings.DataServiceException_GeneralError, exception3, response2);
     }
     finally
     {
         if (flag)
         {
             Util.Dispose<ODataMessageReader>(ref this.batchMessageReader);
         }
     }
     return response3;
 }
Esempio n. 3
0
        private MaterializeAtom CreateMaterializer(ProjectionPlan plan, ODataPayloadKind payloadKind)
        {
            HttpWebResponseMessage message = new HttpWebResponseMessage(this.httpWebResponse, () => this.GetResponseStream());

            return(DataServiceRequest.Materialize(this.responseInfo, this.ServiceRequest.QueryComponents(this.responseInfo.MaxProtocolVersion), plan, this.ContentType, message, payloadKind));
        }