Ejemplo n.º 1
0
        public virtual async Task <ActionEvent> ExecuteAsync(CancellationToken token)
        {
            HttpRequestItem requestItem = null;

            if (!token.IsCancellationRequested)
            {
                ++ExcuteTimes;
                try
                {
                    requestItem = BuildRequest();
                    var response = await HttpService.ExecuteHttpRequestAsync(requestItem, token).ConfigureAwait(false);

                    return(await HandleResponse(response).ConfigureAwait(false));
                }
                catch (TaskCanceledException) { }
                catch (OperationCanceledException) { }
                catch (Exception ex)
                {
                    ex = ex.InnerException ?? ex;
#if DEBUG
                    // 此处用于生成请求信息,然后用fiddler等工具测试
                    if (requestItem != null)
                    {
                        var url    = requestItem.RawUrl;
                        var header = requestItem.GetRequestHeader(HttpService.GetCookies(requestItem.RawUrl));
                        var data   = requestItem.RawData;
                        var len    = data.Length;
                    }
#endif
                    return(await HandleExceptionAsync(ex).ConfigureAwait(false));
                }
            }
            return(await NotifyActionEventAsync(ActionEvent.CreateEvent(ActionEventType.EvtCanceled, this)).ConfigureAwait(false));
        }