private OrientdbResponse <Stream> WebToOrientdbResponse(byte[] data, Stream responseStream,
                                                                HttpWebResponse response, string method, string path)
        {
            OrientdbResponse <Stream> cs = OrientdbResponse <Stream> .Create(ConnectionSettings,
                                                                             (int)response.StatusCode, method, path, data);

            cs.Response = responseStream;
            return(cs);
        }
        private IEnumerable <Task> _AsyncSteps(HttpWebRequest request, TaskCompletionSource <OrientdbResponse <Stream> > tcs,
                                               byte[] data, IRequestConfiguration requestSpecificConfig)
        {
            int timeout = GetRequestTimeout(requestSpecificConfig);

            if (data != null)
            {
                Task <Stream> getRequestStream = Task.Factory.FromAsync <Stream>(request.BeginGetRequestStream,
                                                                                 request.EndGetRequestStream, null);
                ThreadPool.RegisterWaitForSingleObject((getRequestStream as IAsyncResult).AsyncWaitHandle,
                                                       ThreadTimeoutCallback, request, timeout, true);
                yield return(getRequestStream);

                Stream requestStream = getRequestStream.Result;
                try
                {
                    Task writeToRequestStream = Task.Factory.FromAsync(requestStream.BeginWrite, requestStream.EndWrite,
                                                                       data, 0, data.Length, null);
                    yield return(writeToRequestStream);
                }
                finally
                {
                    requestStream.Close();
                }
            }

            // Get the response
            Task <WebResponse> getResponse = Task.Factory.FromAsync <WebResponse>(request.BeginGetResponse,
                                                                                  request.EndGetResponse, null);

            ThreadPool.RegisterWaitForSingleObject((getResponse as IAsyncResult).AsyncWaitHandle, ThreadTimeoutCallback,
                                                   request, timeout, true);
            yield return(getResponse);

            string path   = request.RequestUri.ToString();
            string method = request.Method;

            //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx
            //Either the stream or the response object needs to be closed but not both (although it won't)
            //throw any errors if both are closed atleast one of them has to be Closed.
            //Since we expose the stream we let closing the stream determining when to close the connection
            var    response              = (HttpWebResponse)getResponse.Result;
            Stream responseStream        = response.GetResponseStream();
            OrientdbResponse <Stream> cs = OrientdbResponse <Stream> .Create(ConnectionSettings, (int)response.StatusCode,
                                                                             method, path,
                                                                             data);

            cs.Response = responseStream;
            tcs.TrySetResult(cs);
        }
Beispiel #3
0
        private OrientdbResponse <Stream> ReturnConnectionStatus(HttpWebRequest request, byte[] data,
                                                                 IRequestConfiguration requestSpecificConfig = null)
        {
            string method = request.Method;
            string path   = request.RequestUri.ToString();

            OrientdbResponse <Stream> cs = OrientdbResponse <Stream> .Create(ConnectionSettings, _statusCode, method, path,
                                                                             data);

            cs.Response = new MemoryStream(_fixedResultBytes);
            if (ConnectionSettings.ConnectionStatusHandler != null)
            {
                ConnectionSettings.ConnectionStatusHandler(cs);
            }

            if (RecordRequests)
            {
                Requests.Add(Tuple.Create(method, request.RequestUri, data));
            }

            return(cs);
        }