AddIfCancelManagerPresent() public static méthode

public static AddIfCancelManagerPresent ( HttpRequestMessage request, IHttpCancel action ) : void
request HttpRequestMessage
action IHttpCancel
Résultat void
Exemple #1
0
            public HttpTransportAsyncResult(bool preferSync, HttpRequestMessage request, HttpWebRequestTransportSettings settings, AsyncCallback callback, object state)
                : base(callback, state)
            {
                if (request.Uri == null)
                {
                    throw new ArgumentNullException("request", "request.Uri is null");
                }
                if (!request.Uri.IsAbsoluteUri)
                {
                    throw new UriFormatException("\"" + request.Uri + "\" is not an absolute URI");
                }
                this.stayedSync = true;
                this.settings   = settings;
                this.request    = request;

                CancelManager.AddIfCancelManagerPresent(this.request, this);

                CreateAndPrepareWebRequest(this);

                if (!HttpContent.IsNullOrEmpty(request.Content))
                {
                    var    writer = request.Content;
                    Stream stream;
                    if (!preferSync)
                    {
                        stayedSync = false;
                        Trace(this, "Going async");
                        this.timedOutReason = TimeoutReason.GetRequestStream;
                        var result = webRequest.BeginGetRequestStream(EndGetRequestStreamAndWriteCallback, this);
                        Trace(this, "called BeginGetRequestStream");
                        if (result.CompletedSynchronously)
                        {
                            Trace(this, "BeginGetRequestStream completed synchronously");
                            stream = webRequest.EndGetRequestStream(result);
                        }
                        else
                        {
                            Trace(this, "went async for BeginGetRequestStream");
                            RegisterAbortTimeout(result, TimeoutReason.GetRequestStream);
                            return;
                        }
                    }
                    else
                    {
                        stream = this.webRequest.GetRequestStream();
                    }
                    WriteToRequestStream(this, stream, writer);
                }

                this.timedOutReason = TimeoutReason.GetResponse;
                if (preferSync)
                {
                    PopulateWebResponse(this, null, PopulateWebResponseSyncFunc);
                }
                else
                {
                    var result = this.webRequest.BeginGetResponse(EndGetResponseCallback, this);
                    if (result.CompletedSynchronously)
                    {
                        this.stayedSync = true;
                        PopulateWebResponse(this, result, PopulateWebResponseEndSyncFunc);
                    }
                    else
                    {
                        this.stayedSync = false;
                        RegisterAbortTimeout(result, TimeoutReason.GetResponse);
                    }
                }
            }