Beispiel #1
0
        /// <summary>
        /// Perform the actual cleanup work.
        /// </summary>
        /// <param name="disposing">If 'true' this method is called from user code; if 'false' it is called by the runtime.</param>
        protected virtual void Dispose(bool disposing)
        {
            HttpWebResponse response = this.httpWebResponse;

            this.httpWebResponse = null;
            if (response != null)
            {
                ((IDisposable)response).Dispose();
            }

            WebUtil.DisposeMessage(this.underlyingResponseMessage);
            this.underlyingResponseMessage = null;
        }
Beispiel #2
0
 /// <summary>
 /// Sets the stream of response message to local outputResponseStream.
 /// </summary>
 private void GetStreamFromResponseMessage()
 {
     if (HttpStatusCode.NoContent != this.StatusCode)
     {
         Stream stream = this.responseMessage.GetStream();
         if (null != stream)
         {
             this.outputResponseStream = stream;
         }
     }
     else
     {
         WebUtil.DisposeMessage(this.responseMessage);
     }
 }
Beispiel #3
0
        /// <summary>cleanup work to do once the request has completed</summary>
        protected override void CompletedRequest()
        {
            byte[] buffer = this.asyncStreamCopyBuffer;
            this.asyncStreamCopyBuffer = null;

            if ((null != buffer) && !this.usingBuffer)
            {
                this.PutAsyncResponseStreamCopyBuffer(buffer);
            }

            if (this.responseStreamOwner)
            {
                if (null != this.outputResponseStream)
                {
                    this.outputResponseStream.Position = 0;
                }
            }

            Debug.Assert(null != this.responseMessage || null != this.Failure || this.IsAborted, "should have response or exception");
            if (null != this.responseMessage)
            {
                if (!this.AllowDirectNetworkStreamReading)
                {
                    // we've cached off what we need, headers still accessible after close
                    WebUtil.DisposeMessage(this.responseMessage);
                }

                Version responseVersion;
                Exception ex = SaveResult.HandleResponse(
                    this.RequestInfo,
                    this.StatusCode,
                    this.responseMessage.GetHeader(XmlConstants.HttpDataServiceVersion),
                    this.GetResponseStream,
                    false,
                    out responseVersion);
                if (null != ex)
                {
                    this.HandleFailure(ex);
                }
                else
                {
                    this.responseInfo = this.CreateResponseInfo();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// dispose
        /// </summary>
        public void Dispose()
        {
            this.current = null;

            if (null != this.materializer)
            {
                this.materializer.Dispose();
            }

            if (null != this.writer)
            {
                this.writer.Dispose();
            }

            if (null != this.responseMessage)
            {
                WebUtil.DisposeMessage(this.responseMessage);
            }

            GC.SuppressFinalize(this);
        }
Beispiel #5
0
        /// <summary>invoked for derived classes to cleanup before callback is invoked</summary>
        protected override void CompletedRequest()
        {
            Debug.Assert(null != this.responseMessage || null != this.Failure, "should have response or exception");
            if (null != this.responseMessage)
            {
                // Can't use DataServiceContext.HandleResponse as this request didn't necessarily go to our server
                //   the MR could have been served by arbitrary server.
                InvalidOperationException failure = null;
                if (!WebUtil.SuccessStatusCode((HttpStatusCode)this.responseMessage.StatusCode))
                {
                    failure = SaveResult.GetResponseText(
                        this.responseMessage.GetStream,
                        (HttpStatusCode)this.responseMessage.StatusCode);
                }

                if (failure != null)
                {
                    // we've cached off what we need, headers still accessible after close
                    WebUtil.DisposeMessage(this.responseMessage);
                    this.HandleFailure(failure);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Synchronizely get the query set count from the server by executing the $count=value query
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>The server side count of the query set</returns>
        internal long GetQuerySetCount(DataServiceContext context)
        {
            Debug.Assert(null != context, "context is null");
            Version requestVersion = this.QueryComponents(context.Model).Version;

            if (requestVersion == null || requestVersion.Major < 2)
            {
                // minimum DSV for $count is V2.
                requestVersion = Util.DataServiceVersion2;
            }

            QueryResult               response       = null;
            QueryComponents           qc             = this.QueryComponents(context.Model);
            Uri                       requestUri     = qc.Uri;
            DataServiceRequest <long> serviceRequest = new DataServiceRequest <long>(requestUri, qc, null);

            HeaderCollection headers = new HeaderCollection();

            // Validate and set the request DSV header
            headers.SetRequestVersion(requestVersion, context.MaxProtocolVersionAsVersion);
            context.Format.SetRequestAcceptHeaderForCount(headers);

            string httpMethod = XmlConstants.HttpMethodGet;
            ODataRequestMessageWrapper request = context.CreateODataRequestMessage(
                context.CreateRequestArgsAndFireBuildingRequest(httpMethod, requestUri, headers, context.HttpStack, null /*descriptor*/),
                new string[] { XmlConstants.HttpRequestAccept } /*headersToReset*/,
                null /*descriptor*/);

            response = new QueryResult(this, Util.ExecuteMethodName, serviceRequest, request, new RequestInfo(context), null, null);
            response.AllowDirectNetworkStreamReading = context.AllowDirectNetworkStreamReading;

            IODataResponseMessage responseMessage = null;

            try
            {
                responseMessage = response.ExecuteQuery();
                if (HttpStatusCode.NoContent != response.StatusCode)
                {
                    StreamReader sr = new StreamReader(response.GetResponseStream());
                    long         r  = -1;

                    try
                    {
                        r = XmlConvert.ToInt64(sr.ReadToEnd());
                    }
                    finally
                    {
                        sr.Close();
                    }

                    return(r);
                }
                else
                {
                    throw new DataServiceQueryException(Strings.DataServiceRequest_FailGetCount, response.Failure);
                }
            }
            catch (InvalidOperationException ex)
            {
                QueryOperationResponse operationResponse = null;
                operationResponse = response.GetResponse <long>(MaterializeAtom.EmptyResults);
                if (null != operationResponse)
                {
                    operationResponse.Error = ex;
                    throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, operationResponse);
                }

                throw;
            }
            finally
            {
                WebUtil.DisposeMessage(responseMessage);
            }
        }
 /// <summary>Releases all resources used by the current instance of the <see cref="T:System.Data.Services.Client.DataServiceStreamResponse" /> class.</summary>
 public void Dispose()
 {
     WebUtil.DisposeMessage(this.responseMessage);
 }