private void HandleOperationException(InvalidOperationException e, HttpWebResponse response) { Func <Stream> getResponseStream = null; Descriptor descriptor = base.ChangedEntries[base.entryIndex]; Dictionary <string, string> headers = null; HttpStatusCode internalServerError = HttpStatusCode.InternalServerError; Version parsedResponseVersion = null; if (response != null) { headers = WebUtil.WrapResponseHeaders(response); base.HandleOperationResponseHeaders(response.StatusCode, headers); if (getResponseStream == null) { getResponseStream = () => WebUtil.GetResponseStream(response, (DataServiceContext)this.Source); } e = BaseSaveResult.HandleResponse(base.RequestInfo, response.StatusCode, response.Headers["DataServiceVersion"], getResponseStream, false, out parsedResponseVersion); internalServerError = response.StatusCode; } else { headers = new Dictionary <string, string>(StringComparer.Ordinal); headers.Add("Content-Type", "text/plain"); if (e.GetType() != typeof(DataServiceClientException)) { e = new DataServiceClientException(e.Message, e); } } this.cachedResponses.Add(new CachedResponse(descriptor, headers, internalServerError, parsedResponseVersion, null, e)); base.perRequest = null; this.CheckContinueOnError(); }
protected override void CompletedRequest() { byte[] asyncStreamCopyBuffer = this.asyncStreamCopyBuffer; this.asyncStreamCopyBuffer = null; if ((asyncStreamCopyBuffer != null) && !this.usingBuffer) { this.PutAsyncResponseStreamCopyBuffer(asyncStreamCopyBuffer); } if (this.responseStreamOwner && (this.outputResponseStream != null)) { this.outputResponseStream.Position = 0L; } if (this.httpWebResponse != null) { Version version; this.httpWebResponse.Close(); Exception e = BaseSaveResult.HandleResponse(this.RequestInfo, this.StatusCode, this.httpWebResponse.Headers["DataServiceVersion"], new Func <Stream>(this.GetResponseStream), false, out version); if (e != null) { base.HandleFailure(e); } else { this.responseInfo = this.RequestInfo.GetDeserializationInfo(null); } } }
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; } }
private Exception ProcessCurrentOperationResponse(ODataBatchReader batchReader) { MemoryStream stream2; Version version; IODataResponseMessage message = batchReader.CreateOperationResponseMessage(); Stream input = message.GetStream(); if (input == null) { System.Data.Services.Client.Error.ThrowBatchExpectedResponse(InternalError.NullResponseStream); } try { stream2 = new MemoryStream(); WebUtil.CopyStream(input, stream2, ref this.streamCopyBuffer); stream2.Position = 0L; } finally { input.Dispose(); } this.currentOperationResponse = new CurrentOperationResponse((HttpStatusCode)message.StatusCode, message.Headers, stream2); return(BaseSaveResult.HandleResponse(base.RequestInfo, this.currentOperationResponse.StatusCode, this.currentOperationResponse.GetHeader("DataServiceVersion"), () => this.currentOperationResponse.ContentStream, false, out version)); }
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); }