예제 #1
0
        public void Execute()
        {
            if (_action.ActionFuture.IsCanceled)
            {
                return;
            }

            //_context.Logger.LogDebug($"[Action={GetType().Name}, HttpActorType={_type}] Begin");
            try
            {
                switch (_type)
                {
                case HttpActorType.BuildRequest:
                {
                    var service = _context.GetSerivce <IHttpService>(QQServiceType.HTTP);
                    var adaptor = new HttpAdaptor(_context, _action);
                    var request = _action.BuildRequest();
                    _action.ResponseFuture = service.ExecuteHttpRequestAsync(request, adaptor, _action.ActionFuture.Token);
                    break;
                }

                case HttpActorType.CancelRequest:
                    _action.CancelRequest();
                    break;

                case HttpActorType.OnHttpError:
                    _action.OnHttpError(_throwable);
                    break;

                case HttpActorType.OnHttpFinish:
                    _action.OnHttpFinish(_response);
                    break;

                case HttpActorType.OnHttpHeader:
                    _action.OnHttpHeader(_response);
                    break;

                case HttpActorType.OnHttpRead:
                    _action.OnHttpRead(_current, _total);
                    break;

                case HttpActorType.OnHttpWrite:
                    _action.OnHttpWrite(_current, _total);
                    break;
                }
            }
            // 统一异常处理
            catch (Exception ex)
            {
                // _context.Logger.LogDebug($"[Action={GetType().Name}, HttpActorType={_type}] Error");

                var qqEx = ex as QQException ?? new QQException(ex);
                _action.OnHttpError(qqEx);
            }
            //_context.Logger.LogDebug($"[Action={GetType().Name}, HttpActorType={_type}] End");
        }
예제 #2
0
        public void Execute()
        {
            try
            {
                switch (_type)
                {
                case HttpActorType.BUILD_REQUEST:
                {
                    var service = _context.GetSerivce <IHttpService>(QQServiceType.HTTP);
                    var request = _action.BuildRequest();
                    var future  = service.ExecuteHttpRequest(request, new HttpAdaptor(_context, _action));
                    _action.ResponseFuture = future;     // 为了取消任务的时候使用
                }
                break;

                case HttpActorType.CANCEL_REQUEST:
                    _action.CancelRequest();
                    break;

                case HttpActorType.ON_HTTP_ERROR:
                    _action.OnHttpError(_throwable);
                    break;

                case HttpActorType.ON_HTTP_FINISH:
                    _action.OnHttpFinish(_response);
                    break;

                case HttpActorType.ON_HTTP_HEADER:
                    _action.OnHttpHeader(_response);
                    break;

                case HttpActorType.ON_HTTP_READ:
                    _action.OnHttpRead(_current, _total);
                    break;

                case HttpActorType.ON_HTTP_WRITE:
                    _action.OnHttpWrite(_current, _total);
                    break;
                }
            }
            catch (QQException e)
            {
                _action.NotifyActionEvent(QQActionEventType.EVT_ERROR, e);
            }
        }