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)); }
public virtual async Task <ActionEvent> ExecuteAsync(CancellationToken token) { ActionEvent lastEvent = null; while (_queue.Count != 0) { if (token.IsCancellationRequested) { _queue.Clear(); return(ActionEvent.CreateEvent(ActionEventType.EvtCanceled, this)); } var action = _queue.First.Value; var result = await action.ExecuteAsync(token).ConfigureAwait(false);; switch (result.Type) { case ActionEventType.EvtOK: _queue.RemoveFirst(); break; case ActionEventType.EvtError: case ActionEventType.EvtCanceled: _queue.Clear(); return(result); case ActionEventType.EvtRetry: case ActionEventType.EvtRepeat: continue; } lastEvent = result; } return(lastEvent ?? ActionEvent.EmptyOkEvent); }
public virtual async Task <ActionEvent> HandleExceptionAsync(Exception ex) { try { var @event = ActionEvent.CreateEvent(RetryTimes < MaxReTryTimes ? ActionEventType.EvtRetry : ActionEventType.EvtError, ex); return(await NotifyActionEventAsync(@event)); } catch (Exception e) { throw new Exception($"throw an unhandled exception when excute [{nameof(HandleExceptionAsync)}] method.", e); } }
protected override Task <ActionEvent> HandleExceptionAsync(Exception ex) { // SyncUrl为空说明正在测试host if (Session.SyncUrl == null) { if (++RetryTimes < MaxReTryTimes) { return(NotifyActionEventAsync(ActionEvent.CreateEvent(ActionEventType.EvtRetry, ex))); } else { RetryTimes = 0; return(TestNextHost()); } } else { return(base.HandleExceptionAsync(ex)); } }
protected virtual Task <ActionEvent> NotifyActionEventAsync(ActionEventType type, object target = null) { return(NotifyActionEventAsync(ActionEvent.CreateEvent(type, target))); }